[PyOpenGL-Users] how copy texture into pbo ?
Brought to you by:
mcfletch
From: Joost R. <li...@lu...> - 2012-05-07 03:00:11
|
Dear list people, this is my first posting to this list, and I'm writing because after having used PyOpenGL happily for some time, I'm now seriously stuck. I am currently working on a package that allows me to use GLSL shaders and OpenCL programs for image processing, using textures as the standardized way to get my data in and out of the GLSL shaders and OpenCL programs. Everything works, except that I can not succeed in copying a texture into a pbo (pixel buffer object). I'm using pbo's to get my texture data in/out of OpenCL and that works nice and fast: I can copy my OpenCL output from its pbo to a texture and display it, and I also can load data from the cpu into a pbo. But I am hopelessly stuck trying to copy texture data into a pbo, which is what I need to do to load my source images into OpenCL. I've read about two ways to do this: variant 1 binds the pbo, binds the texture and uses glGetTexImage() variant 2 attaches the texture to a frame buffer object, binds the fbo and the pbo and uses glReadPixels() I also read that the PyOpenGL versions of both glReadPixels() and glGetTexImage() automatically convert a zero-pointer to an array, which is not good when having a bound pbo, so for that reason I am using the OpenGL.raw.GL variants. But in both these cases I get an 'Invalid Operation' error, and I really do not see what I am doing wrong. Below two versions of the load_texture() method of my pixelbuffer class, I hope I didn't strip them down too far... Any help very much appreciated ! variant 1: def _load_texture(self, texture): glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, self.id) glEnable(texture.target) glActiveTexture(GL_TEXTURE0_ARB) glBindTexture(texture.target, texture.id) OpenGL.raw.GL.glGetTexImage(texture.target, 0, texture.gl_imageformat, texture.gl_dtype, ctypes.c_void_p(0)) glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0) glDisable(texture.target) variant 2: def _load_texture(self, texture): fbo = FrameBufferObject.from_textures([texture]) glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.target, texture.id, 0) glReadBuffer(GL_COLOR_ATTACHMENT0) glBindFramebuffer(GL_FRAMEBUFFER, fbo.id) glBindBuffer(GL_PIXEL_PACK_BUFFER, self.id) OpenGL.raw.GL.glReadPixels( 0, 0, self.size[0], self.size[1], texture.gl_imageformat, texture.gl_dtype, ctypes.c_void_p(0)) glBindBuffer(GL_PIXEL_PACK_BUFFER, 0) glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, 0, 0) glBindFramebuffer(GL_FRAMEBUFFER, 0) with kind regards, Joost. |