[osg-users] Read FBO with PBO

Cary, Karl A. KARL.A.CARY at leidos.com
Fri Jul 7 13:41:39 PDT 2017

I have a unique situation where I have to render my full scene to the screen, but then also render a separate subset out to a shared memory segment. This was achieved by creating a second camera, attaching the needed subset, rendering to an FBO with a texture applied, and then doing a readImageFromCurrentTexture in the final draw callback. This all works. The resultant data is then memcpy'd to the location in shared memory that it needs to go (unfortunately I can't change that requirement at all, the target is raw data at the location). Alternatively I also tried applying the image directly to the fbo rather than a texture, and it was slightly faster, but still very slow. To test that this method will ultimately work, if I attach the texture but then only do the readImageFromCurrentTexture if I signal it, via keyboard input, the scene continues to render to the FBO and the last scene copied from the texture will be continually sent to the shared memory segment. The performance of this is what we are looking for, we just have the one frame hit every time I signal it. All this really does is prove that if I can speed up the read, this solution will work.

The issue I have is the readImageFromCurrentTexture is extremely slow, about 20 ms. My initial thought was to use a pixel buffer object just like in the osgscreencapture example, which we have done before for applying some post processing effects with the data from the backbuffer with great success. The problem is, I can't figure out how to bind to the frame buffer object. In raw GL, you bind to GL_COLOR_ATTACHMENT0_EXT. That fails and gives a State::apply error and results in simply reading the back buffer instead. I have tried all of the COLOR_ATTACHMENT buffers and they all give me the same result.

Is it possible to bind just to the texture and do a glTexSubImage2D instead of a glReadPixels? If so, how do I actually get that set up? I have attempted to do it the same way I bind the texture for doing the readImageFromCurrentTexture but that does not work either.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5625 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20170707/26388b11/attachment-0002.bin>

More information about the osg-users mailing list