how copy texture into pbo ?

Joost Rekveld <[email protected]>
Newsgroups gmane.comp.python.opengl.user
Message-ID <[email protected]>
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.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
PyOpenGL Homepage
http://pyopengl.sourceforge.net
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.