def test_create_from_textures(self): fbo = FBO.create_from_textures( [ Texture2D.create((256, 256)), Texture2D.create((256, 256)), ], DepthTexture.create(((256, 256))), )
def __init__(self, width, height, gbuffer=None, lightbuffer=None): self.ctx = context.ctx() self.width = width self.height = height self.size = (width, height) self.depth_sampler = samplers.create(texture_compare_mode=False, min_filter=moderngl.LINEAR, mag_filter=moderngl.LINEAR) # FBOs self.gbuffer = gbuffer self.lightbuffer = lightbuffer # Light Info self.point_lights = [] # Create geometry buffer if not supplied depth_buffer = DepthTexture(self.size) if not self.gbuffer: self.gbuffer = FBO.create_from_textures( [ Texture2D.create(self.size, 4, dtype='f1'), Texture2D.create(self.size, 3, dtype='f2'), ], depth_buffer=depth_buffer, ) if not self.lightbuffer: self.lightbuffer = FBO.create_from_textures( [Texture2D.create(self.size, 4)], # depth_buffer=depth_buffer, ) # Unit cube for point lights (cube with radius 1.0) self.unit_cube = geometry.cube(width=2, height=2, depth=2) self.point_light_shader = resources.shaders.get( "deferred/light_point.glsl", create=True) # Debug draw lights self.debug_shader = resources.shaders.get("deferred/debug.glsl", create=True) # Combine shader self.combine_shader = resources.shaders.get("deferred/combine.glsl", create=True) self.quad = geometry.quad_fs()
def create(size, components=4, depth=False, dtype='f1', layers=1) -> 'FBO': """ Create a single or multi layer FBO :param size: (tuple) with and height :param components: (tuple) number of components. 1, 2, 3, 4 :param depth: (bool) Create a depth attachment :param dtype: (string) data type per r, g, b, a ... :param layers: (int) number of color attachments :return: A new FBO """ instance = FBO() # Add N layers of color attachments for _ in range(layers): tex = Texture2D.create(size, components, dtype=dtype) instance.color_buffers.append(tex) # Set depth attachment is specified if depth: instance.depth_buffer = DepthTexture(size) instance.fbo = context.ctx().framebuffer( color_attachments=[b.mglo for b in instance.color_buffers], depth_attachment=instance.depth_buffer.mglo if instance.depth_buffer is not None else None) return instance
def test_create(self): texture = Texture2D.create((256, 256)) self.assertProperties(texture) array = TextureArray.create((256, 256, 4)) self.assertProperties(array) depth_texture = DepthTexture.create((256, 256)) self.assertProperties(depth_texture)
def load(self, path): # data:image/png;base64,iVBOR texture = Texture2D(self.uri, mipmap=True) # Image is stored in bufferView if self.bufferView is not None: image = Image.open(io.BytesIO(self.bufferView.read_raw())) # Image is embedded elif self.uri and self.uri.startswith('data:'): data = self.uri[self.uri.find(',') + 1:] image = Image.open(io.BytesIO(base64.b64decode(data))) else: path = os.path.join(path, self.uri) image = Image.open(path) texture.set_image(image, flip=False) return texture
def test_read_into(self): texture = Texture2D.create((4, 4), components=4) buff = bytearray([0] * 16 * 4) texture.read_into(buff)
def test_read(self): texture = Texture2D.create((4, 4), components=4) texture.read()