def _update(self): # We need to activate before we can add attachements gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, self._handle) # Attach any RenderBuffers or Textures # Note that we only enable the object briefly to attach it. # After that, the object does not need to be bound. while self._pending_attachments: attachment, object, level = self._pending_attachments.pop(0) if object == 0: gl.glFramebufferRenderbuffer(gl.GL_FRAMEBUFFER, attachment, gl.GL_RENDERBUFFER, 0) elif isinstance(object, RenderBuffer): with object: gl.glFramebufferRenderbuffer(gl.GL_FRAMEBUFFER, attachment, gl.GL_RENDERBUFFER, object.handle) elif isinstance(object, Texture2D): # note that we use private variable _target from Texture with object: gl.glFramebufferTexture2D(gl.GL_FRAMEBUFFER, attachment, object._target, object.handle, level) else: raise FrameBufferError('Invalid attachment. This should not happen.') # Check if True: res = gl.glCheckFramebufferStatus(gl.GL_FRAMEBUFFER) if res == gl.GL_FRAMEBUFFER_COMPLETE: pass elif res == 0: raise FrameBufferError('Target not equal to GL_FRAMEBUFFER') elif res == gl.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: raise FrameBufferError('FrameBuffer attachments are incomplete.') elif res == gl.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: raise FrameBufferError('No valid attachments in the FrameBuffer.') elif res == gl.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: raise FrameBufferError('attachments do not have the same width and height.') #elif res == gl.GL_FRAMEBUFFER_INCOMPLETE_FORMATS: # Not in our namespace? # raise FrameBufferError('Internal format of attachment is not renderable.') elif res == gl.GL_FRAMEBUFFER_UNSUPPORTED: raise FrameBufferError('Combination of internal formats used by attachments is not supported.')
def _deactivate(self): gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, 0)
def _activate(self): gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, self._handle)