def __init__(self, width, height, drawFunc): tex = GL.glGenTextures(1) GL.glBindTexture(GL.GL_TEXTURE_2D, tex) GL.glTexParameter(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST) GL.glTexParameter(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST) GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA8, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, None) self.enabled = False self._texID = tex if bool(FBO.glGenFramebuffers) and "Intel" not in GL.glGetString(GL.GL_VENDOR): buf = FBO.glGenFramebuffers(1) depthbuffer = FBO.glGenRenderbuffers(1) FBO.glBindFramebuffer(FBO.GL_FRAMEBUFFER, buf) FBO.glBindRenderbuffer(FBO.GL_RENDERBUFFER, depthbuffer) FBO.glRenderbufferStorage(FBO.GL_RENDERBUFFER, GL.GL_DEPTH_COMPONENT, width, height) FBO.glFramebufferRenderbuffer(FBO.GL_FRAMEBUFFER, FBO.GL_DEPTH_ATTACHMENT, FBO.GL_RENDERBUFFER, depthbuffer) FBO.glFramebufferTexture2D(FBO.GL_FRAMEBUFFER, FBO.GL_COLOR_ATTACHMENT0, GL.GL_TEXTURE_2D, tex, 0) status = FBO.glCheckFramebufferStatus(FBO.GL_FRAMEBUFFER) if status != FBO.GL_FRAMEBUFFER_COMPLETE: print "glCheckFramebufferStatus", status self.enabled = False return FBO.glBindFramebuffer(FBO.GL_FRAMEBUFFER, buf) with gl.glPushAttrib(GL.GL_VIEWPORT_BIT): GL.glViewport(0, 0, width, height) drawFunc() FBO.glBindFramebuffer(FBO.GL_FRAMEBUFFER, 0) FBO.glDeleteFramebuffers(1, [buf]) FBO.glDeleteRenderbuffers(1, [depthbuffer]) self.enabled = True else: GL.glReadBuffer(GL.GL_BACK) if bool(window_pos.glWindowPos2dARB): pixels = GL.glReadPixels(0, 0, width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE) GL.glPushAttrib(GL.GL_VIEWPORT_BIT | GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_TEST | GL.GL_STENCIL_BUFFER_BIT) GL.glDisable(GL.GL_STENCIL_TEST) GL.glViewport(0, 0, width, height) GL.glScissor(0, 0, width, height) with gl.glEnable(GL.GL_SCISSOR_TEST): drawFunc() GL.glBindTexture(GL.GL_TEXTURE_2D, tex) GL.glReadBuffer(GL.GL_BACK) GL.glCopyTexSubImage2D(GL.GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height) if bool(window_pos.glWindowPos2dARB): window_pos.glWindowPos2dARB(0,0) GL.glDrawPixels(width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixels) GL.glPopAttrib()
def __init__(self, width, height, drawFunc): tex = GL.glGenTextures(1) GL.glBindTexture(GL.GL_TEXTURE_2D, tex) GL.glTexParameter(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST) GL.glTexParameter(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST) GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA8, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, None) self.enabled = False self._texID = tex if bool(FBO.glGenFramebuffers) and "Intel" not in GL.glGetString(GL.GL_VENDOR): buf = FBO.glGenFramebuffers(1) depthbuffer = FBO.glGenRenderbuffers(1) FBO.glBindFramebuffer(FBO.GL_FRAMEBUFFER, buf) FBO.glBindRenderbuffer(FBO.GL_RENDERBUFFER, depthbuffer) FBO.glRenderbufferStorage(FBO.GL_RENDERBUFFER, GL.GL_DEPTH_COMPONENT, width, height) FBO.glFramebufferRenderbuffer(FBO.GL_FRAMEBUFFER, FBO.GL_DEPTH_ATTACHMENT, FBO.GL_RENDERBUFFER, depthbuffer) FBO.glFramebufferTexture2D(FBO.GL_FRAMEBUFFER, FBO.GL_COLOR_ATTACHMENT0, GL.GL_TEXTURE_2D, tex, 0) status = FBO.glCheckFramebufferStatus(FBO.GL_FRAMEBUFFER) if status != FBO.GL_FRAMEBUFFER_COMPLETE: print ("glCheckFramebufferStatus: " + str(status)) self.enabled = False return FBO.glBindFramebuffer(FBO.GL_FRAMEBUFFER, buf) with gl.glPushAttrib(GL.GL_VIEWPORT_BIT): GL.glViewport(0, 0, width, height) drawFunc() FBO.glBindFramebuffer(FBO.GL_FRAMEBUFFER, 0) FBO.glDeleteFramebuffers(1, [buf]) FBO.glDeleteRenderbuffers(1, [depthbuffer]) self.enabled = True else: GL.glReadBuffer(GL.GL_BACK) GL.glPushAttrib(GL.GL_VIEWPORT_BIT | GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_TEST | GL.GL_STENCIL_BUFFER_BIT) GL.glDisable(GL.GL_STENCIL_TEST) GL.glViewport(0, 0, width, height) GL.glScissor(0, 0, width, height) with gl.glEnable(GL.GL_SCISSOR_TEST): drawFunc() GL.glBindTexture(GL.GL_TEXTURE_2D, tex) GL.glReadBuffer(GL.GL_BACK) GL.glCopyTexSubImage2D(GL.GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height) GL.glPopAttrib()
def glDeleteRenderbuffer(renderbuffer): FBO.glDeleteRenderbuffers(1, [renderbuffer])