Exemple #1
0
    def __init__(self, texture, *args, **kwargs):
        """A Framebuffer object, which when bound redirects draws to its texture.  This is useful for deferred rendering."""

        super(FBO, self).__init__(*args, **kwargs)
        self._old_viewport_size = (gl.GLint * 4)()
        self.texture = texture
        self.renderbuffer = tex.RenderBuffer(
            texture.width, texture.height) if not isinstance(
                texture, tex.DepthTexture) else None

        with self:  #, self.texture:  # TODO: Figure out whether texture should also be bound here.

            # Attach the textures to the FBO
            for texture in [self.texture, self.renderbuffer
                            ] if self.renderbuffer else [self.texture]:
                texture.attach_to_fbo()

            # Set Draw and Read locations for the FBO (currently, just turn it off if not doing any color stuff)
            if isinstance(texture, tex.DepthTexture):
                gl.glDrawBuffer(gl.GL_NONE)  # No color in this buffer
                gl.glReadBuffer(gl.GL_NONE)

        # check FBO status (warning appears for debugging)
        FBOstatus = gl.glCheckFramebufferStatusEXT(gl.GL_FRAMEBUFFER_EXT)
        if FBOstatus != gl.GL_FRAMEBUFFER_COMPLETE_EXT:
            raise BufferError(
                "GL_FRAMEBUFFER_COMPLETE failed, CANNOT use FBO.\n{0}\n".
                format(FBOstatus))
Exemple #2
0
    def __init__(self, texture, *args, **kwargs):
        """A Framebuffer object, which when bound redirects draws to its texture.  This is useful for deferred rendering."""

        super(FBO, self).__init__(*args, **kwargs)
        self.id = create_opengl_object(gl.glGenFramebuffersEXT)
        self._old_viewport = get_viewport()
        self.texture = texture
        self.renderbuffer = RenderBuffer(
            texture.width,
            texture.height) if not isinstance(texture, DepthTexture) else None

        with self:

            # Attach the textures to the FBO
            self.texture.attach_to_fbo()
            if self.renderbuffer:
                self.renderbuffer.attach_to_fbo()

            # Set Draw and Read locations for the FBO (currently, just turn it off if not doing any color stuff)
            if isinstance(texture, DepthTexture):
                gl.glDrawBuffer(gl.GL_NONE)  # No color in this buffer
                gl.glReadBuffer(gl.GL_NONE)

        # check FBO status (warning appears for debugging)
        FBOstatus = gl.glCheckFramebufferStatusEXT(gl.GL_FRAMEBUFFER_EXT)
        if FBOstatus != gl.GL_FRAMEBUFFER_COMPLETE_EXT:
            raise BufferError(
                "GL_FRAMEBUFFER_COMPLETE failed, CANNOT use FBO.\n{0}\n".
                format(FBOstatus))
Exemple #3
0
def blit_fbo(width, height, src_id, target_id, target_image=gl.GL_BACK):
    # For drawing a multisampled FBO to a non-multisampled FBO or to the
    # screen. See
    # https://www.khronos.org/opengl/wiki/Multisampling#Allocating_a_Multisample_Render_Target
    gl.glBindFramebuffer(gl.GL_READ_FRAMEBUFFER, src_id)
    gl.glBindFramebuffer(gl.GL_DRAW_FRAMEBUFFER, target_id)
    gl.glDrawBuffer(target_image)
    gl.glBlitFramebuffer(0, 0, width, height, 0, 0, width, height,
                         gl.GL_COLOR_BUFFER_BIT, gl.GL_NEAREST)
def draw_canvas():
    # Draw full-screen canvas
    gl.glDrawBuffer(gl.GL_COLOR_ATTACHMENT0_EXT)
    gl.glBegin(gl.GL_QUADS)
    for coords in [(-1.0, -1.0),
                   (1.0, -1.0),
                   (1.0, 1.0),
                   (-1.0,  1.0)]:
        gl.glVertex3f(coords[0], coords[1], 0.0)

    gl.glEnd()
Exemple #5
0
    def __init__(self, texture, *args, **kwargs):
        """A Framebuffer object, which when bound redirects draws to its texture.  This is useful for deferred rendering."""

        super(FBO, self).__init__(*args, **kwargs)
        self._old_viewport_size = (gl.GLint * 4)()
        self.texture = texture
        self.renderbuffer = tex.RenderBuffer(texture.width, texture.height) if not isinstance(texture, tex.DepthTexture) else None

        with self: #, self.texture:  # TODO: Figure out whether texture should also be bound here.

            # Attach the textures to the FBO
            for texture in [self.texture, self.renderbuffer] if self.renderbuffer else [self.texture]:
                texture.attach_to_fbo()

            # Set Draw and Read locations for the FBO (currently, just turn it off if not doing any color stuff)
            if isinstance(texture, tex.DepthTexture):
                gl.glDrawBuffer(gl.GL_NONE)  # No color in this buffer
                gl.glReadBuffer(gl.GL_NONE)

        # check FBO status (warning appears for debugging)
        FBOstatus = gl.glCheckFramebufferStatusEXT(gl.GL_FRAMEBUFFER_EXT)
        if FBOstatus != gl.GL_FRAMEBUFFER_COMPLETE_EXT:
            raise BufferError("GL_FRAMEBUFFER_COMPLETE failed, CANNOT use FBO.\n{0}\n".format(FBOstatus))