Example #1
0
 def _gen(self):
     gl.glRenderbufferStorageEXT(self.target, self.internal_fmt, self.width, self.height)
Example #2
0
 def _gen(self):
     gl.glRenderbufferStorageEXT(self.target, self.internal_fmt, self.width,
                                 self.height)
Example #3
0
    def __init__(self, width, height):
        """Creates a FBO"""
        self.initialized = False

        assert self.supported()

        self.width = width
        self.height = height

        self.framebuffer_id = ctypes.c_uint(0)
        self.depthbuffer_id = ctypes.c_uint(0)
        self.texture_id = ctypes.c_uint(0)

        # Frame buffer
        gl.glGenFramebuffersEXT(
                1,  # number of buffers created
                ctypes.byref(self.framebuffer_id),  # dest. id
            )

        self.initialized = True

        with self._bound_context(gl.GL_FRAMEBUFFER_EXT):
            # Depth buffer
            gl.glGenRenderbuffersEXT(
                    1,  # no. of buffers created
                    ctypes.byref(self.depthbuffer_id),  # dest. id
                )
            gl.glBindRenderbufferEXT(
                    gl.GL_RENDERBUFFER_EXT,  # target
                    self.depthbuffer_id,  # id
                )
            gl.glRenderbufferStorageEXT(
                    gl.GL_RENDERBUFFER_EXT,  # target
                    gl.GL_DEPTH_COMPONENT,  # internal format
                    self.width, self.height,  # size
                )
            gl.glFramebufferRenderbufferEXT(
                    gl.GL_FRAMEBUFFER_EXT,  # target
                    gl.GL_DEPTH_ATTACHMENT_EXT,  # attachment point
                    gl.GL_RENDERBUFFER_EXT,  # renderbuffer target
                    self.depthbuffer_id,  # renderbuffer id
                )

            # Target Texture
            gl.glGenTextures(
                    1,  # no. of textures
                    ctypes.byref(self.texture_id),  # dest. id
                )
            gl.glBindTexture(
                    gl.GL_TEXTURE_2D,  # target
                    self.texture_id,  # texture id
                )

            # Black magic (props to pyprocessing!)
            # (nearest works, as well as linear)
            gl.glTexParameteri(
                    gl.GL_TEXTURE_2D,  # target
                    gl.GL_TEXTURE_MAG_FILTER,  # property name
                    gl.GL_LINEAR,  # value
                )
            gl.glTexParameteri(
                    gl.GL_TEXTURE_2D,  # target
                    gl.GL_TEXTURE_MIN_FILTER,  # property name
                    gl.GL_LINEAR,  # value
                )

            # Attach texture to FBO
            gl.glTexImage2D(
                    gl.GL_TEXTURE_2D,  # target
                    0,  # mipmap level (0=default)
                    gl.GL_RGBA8,  # internal format
                    self.width, self.height,  # size
                    0,  # border
                    gl.GL_RGBA,  # format
                    gl.GL_UNSIGNED_BYTE,  # type
                    None,  # data
                )
            gl.glFramebufferTexture2DEXT(
                    gl.GL_FRAMEBUFFER_EXT,  # target
                    gl.GL_COLOR_ATTACHMENT0_EXT,  # attachment point
                    gl.GL_TEXTURE_2D,  # texture target
                    self.texture_id,  # tex id
                    0,  # mipmap level
                )

            # sanity check
            status = gl.glCheckFramebufferStatusEXT(gl.GL_FRAMEBUFFER_EXT)
            assert status == gl.GL_FRAMEBUFFER_COMPLETE_EXT