21 May 21:14
Capture off-screen / Aux buffer in PostDrawCallback?
Hi all,
I have a multiple render target setup where a texture is attached to an FBO on GL_COLOR_ATTACHMENT2. The
other target is simply the frame buffer on GL_COLOR_ATTACHMENT0. Both targets are the same size and
format.
A fragment shader uses glFragData[0] and glFragData[2] to write to the targets and I'm getting the
expected onscreen data from glFragData[0]. The problem comes in when I try to use a PostDrawCallback to
read from GL_COLOR_ATTACHMENT2 so I can move it to an image and manipulate the data on the CPU.
In the code below, if I have glReadBuffer(GL_COLOR_ATTACHMENT2) then I get an "Warning: detected OpenGL
error 'invalid enumerant' at end of SceneView::draw()". glReadBuffer(GL_BACK) works fine but that's
not the data I want.
Is this because the FBO is already detached when the callback is invoked? Is there another place I can 'hook
in' to do this? I've tried simply attaching an osg::image as the secondary render target but I don't need to
do this on every frame and it's too big of a performance hit.
Callback code:
Code:
virtual void operator()(osg::RenderInfo& renderInfo) const {
osg::GraphicsContext* gc = renderInfo.getCurrentCamera()->getGraphicsContext();
osg::GLBufferObject::Extensions* ext = osg::GLBufferObject::getExtensions(
gc->getState()->getContextID(),true);
int width = gc->getTraits()->width;
int height = gc->getTraits()->height;
if( m_starMapImage->s() != width || m_starMapImage->t() != height ) {
(Continue reading)
RSS Feed