I'm almost there, just can't seem to figure out how to attach the 
osg::FrameBufferObject instances to the camera in a way that they will be 
recorded in the buffer attachment map. I've summarized the process below, 
replacing some variables with uppercase descriptions of what they represent. 
Anyone have an idea of how to fill in the TODO tags below?


Code:

void IRCamera::initBuffers( osg::GraphicsContext* pGfxContext )
{
// Get graphics context state and ID and the FBO extensions
osg::State* pGfxContextState = pGfxContext->getState();

unsigned int gfxContextID = pGfxContextState->getContextID();

osg::FBOExtensions* pFBOExtensions = osg::FBOExtensions::instance( 
gfxContextID, true );

// Extract some info ...
bool isMultiSample = N_COLOR_SAMPLES > 0;
bool isCSAA = N_COVERAGE_SAMPLES > N_COLOR_SAMPLES;
size_t texWidth = COLOR_TEXTURE->getTextureWidth();
size_t texHeight = COLOR_TEXTURE->getTextureHeight();

// Create the framebuffer objects and apply the graphics context state to them

m_RenderFBO = new osg::FrameBufferObject();
m_RenderFBO->apply( *pGfxContextState );

m_ResolveFBO = new osg::FrameBufferObject();
m_ResolveFBO->apply( *pGfxContextState );

// Non-multisample setup just attaches textures directly to the FBO's
if ( !isMultiSample )
{
// Attach color texture to the render FBO
m_RenderFBO->setAttachment(
osg::Camera::COLOR_BUFFER,
osg::FrameBufferAttachment( COLOR_TEXTURE )
);

// Attach depth texture to the render FBO
m_RenderFBO->setAttachment(
osg::Camera::DEPTH_BUFFER,
osg::FrameBufferAttachment( DEPTH_TEXTURE )
);

// @TODO@: ATTACH THE RENDER FBO SOMEHOW SO THAT IT IS REGISTERED 
//         IN THE BUFFER ATTACHMENT MAP
}

// Multisample setup
else
{
// Create and attach a color renderbuffer to the RENDER FBO
osg::RenderBuffer* pColorRB =
new osg::RenderBuffer( 
texWidth,
texHeight,
COLOR_BUFFER_FORMAT,
N_COVERAGE_SAMPLES,
N_COLOR_SAMPLES
);
m_RenderFBO->setAttachment(
osg::Camera::COLOR_BUFFER,
osg::FrameBufferAttachment( pColorRB )
);

// Create and attach a depth renderbuffer to the RENDER FBO
osg::RenderBuffer* pDepthRB =
new osg::RenderBuffer( 
texWidth,
texHeight,
DEPTH_BUFFER_FORMAT,
N_COVERAGE_SAMPLES,
N_COLOR_SAMPLES
);
m_RenderFBO->setAttachment(
osg::Camera::DEPTH_BUFFER,
osg::FrameBufferAttachment( pDepthRB )
);

// @TODO@: ATTACH THE RENDER FBO SOMEHOW SO THAT IT IS REGISTERED 
//         IN THE BUFFER ATTACHMENT MAP

// Attach color texture to RESOLVE FBO
m_ResolveFBO->setAttachment( 
osg::Camera::COLOR_BUFFER,
osg::FrameBufferAttachment( COLOR_TEXTURE )
);

// Attach depth texture to RESOLVE FBO
m_ResolveFBO->setAttachment( 
osg::Camera::DEPTH_BUFFER,
osg::FrameBufferAttachment( DEPTH_TEXTURE )
);

// @TODO@: ATTACH THE RESOLVE FBO SOMEHOW SO THAT IT IS REGISTERED 
//         IN THE BUFFER ATTACHMENT MAP
}

// Double check everything
size_t nBuffers = this->getBufferAttachmentMap().size();
cout << "BUFFER ATTACHMENT MAP SIZE : " << nBuffers << endl;

sgp_core::String errorMsg;
try
{
sgp_osg::CheckFramebufferStatus( pGfxContext );
}
catch( ... )
{
pFBOExtensions->glBindFramebuffer( GL_FRAMEBUFFER_EXT, 0 );
SGP_RETHROW;
}




------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=48253#48253





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to