I am having some problems with the FBO working as I would have expected.  I have included some code snippets to help.  It seems that culling an FBO node results in some kind of corruption of the node.  Let me explain what I am doing:

I create a Texture2D that is of size (4096, 4096).  This is obviously larger than my real frame buffer.  (Hence the need for the FBO.) 

     texture->setTextureSize(4096, 4096);
     texture->setInternalFormat(GL_RGB);
     texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
     texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);

I next create an osgCameraNode.  I set the viewport to the same size as the texture.

     camera->setClearColor(osg::Vec4(0.1f,0.1f,0.1f,1.0f));
     camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
     camera->setViewport(0, 0, 4096, 4096);
     camera->setRenderOrder(osg::CameraNode::PRE_RENDER);
     camera->setRenderTargetImplementation(osg::CameraNode::RenderTargetImplementation::FRAME_BUFFER_OBJECT);

Then, I finish setting up my FBO, establishing who is who's child, etc.

     image->allocateImage(4096, 4096, 1, GL_RGB, GL_UNSIGNED_BYTE);
     camera->attach(osg::CameraNode::COLOR_BUFFER, this->_pBufferImage);
     texture->setImage(0, this->_pBufferImage);
     camera->addChild(sceneManager->getScene().get());
     camera->setProjectionMatrixAsPerspective(this->getFieldOfView(), 1.4, 10.0, 40000.0);

Now, I have other camera's running while this FBO exists.  Having a FBO running of this size really kills performance, so I wanted a way to "turn off" the use of this FBO.  I created a culling callback and added it.  Then I added the whole thing to my master scene node.

     fboParent->setCullCallback(this->_fboCullCallback);
     fboParent->addChild(this->camera);
     masterSceneNode->addChild(this->fboParent);

I implemented the culling callback as:


CullCallback::CullCallback() : osg::NodeCallback()
{
    this->_skipCallback = false;
}
        
void CullCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
{
    if(this->_skipCallback == false)
    {
        traverse(node, nv);
    }
}

void CullCallback::setSkipCull(bool x)
{
    this->_skipCallback = x;
}   



Ok, now for the problem:  If I leave everything alone, the FBO works fine.  If I "setSkipCull(true)", then the FBO doesn''t render, as expected.  The problem comes when I "setSkipCull(false)" after setting it to TRUE.  The FBO does render, but only the size of the current viewport, not the original 4096x4096.  The rest of the buffer is black. 

I guess I don't understand why skipping the cull on the node would result in this behavior.  Is there a better way to turn the FBO rendering on and off?  Is this a problem in the osg code or my code?  I have tried to re-initialize the values for the FBO, its texture, etc, but it doesn't have any effect.  Any input would be greatly appreciated!


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to