def _get_final_buffer(self, size): render_textures = dict( color=Texture(size, unit=0, params={gl.GL_TEXTURE_MIN_FILTER: gl.GL_LINEAR}), normal=Texture(size, unit=1, params={gl.GL_TEXTURE_MIN_FILTER: gl.GL_LINEAR}), position=Texture(size, unit=2, params={gl.GL_TEXTURE_MIN_FILTER: gl.GL_LINEAR}), ) return FrameBuffer(size, render_textures, autoclear=True)
def get_layer_preview_texture(self, layer, colors, size=(32, 32)): w, h = layer.size size = w, h texture = Texture(size, params={gl.GL_TEXTURE_MIN_FILTER: gl.GL_LINEAR}) texture.clear() data = as_rgba(layer.get_data(self.drawing.frame), colors) gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 4) gl.glTextureSubImage2D( texture.name, 0, 0, 0, w, h, # min(w, bw), min(w, bh), gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, data.tobytes("F")) return texture
def get_brush_preview_texture(self, brush, colors=None, size=(8, 8)): colors = colors or self.drawing.palette.as_tuple() bw, bh = brush.size w, h = size w, h = size = max(w, bw), max(h, bh) texture = Texture(size) texture.clear() data = as_rgba(brush.data, colors).tobytes("F") gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 4) gl.glTextureSubImage2D( texture.name, 0, max(0, w // 2 - bw // 2), max(0, h // 2 - bh // 2), bw, bh, # min(w, bw), min(w, bh), gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, data) return texture
def on_resize(self, width, height): self.size = width, height # We need to recreate the offscreen buffer if the window size changes # This includes when the window is first created. render_textures = dict( # These will represent the different channels of the framebuffer, # that the shader can render to. color=Texture(self.size, unit=0), normal=NormalTexture(self.size, unit=1), position=NormalTexture(self.size, unit=2), ) self.offscreen_buffer = FrameBuffer(self.size, render_textures, autoclear=True, set_viewport=True) render_textures2 = dict(color=Texture(self.size, unit=0), ) self.offscreen_buffer2 = FrameBuffer(self.size, render_textures2, autoclear=True, set_viewport=True) return pyglet.event.EVENT_HANDLED # Work around pyglet internals
def _get_offscreen_buffer(size): return FrameBuffer(size, textures=dict(color=Texture(size, unit=0)))
def _get_overlay_texture(self, overlay): texture = Texture(overlay.size, unit=1) texture.clear() return texture
def _get_offscreen_buffer(self, drawing): return FrameBuffer(drawing.size, textures=dict(color=Texture(drawing.size, unit=0)))
def _get_texture(self, size): return Texture(size)