Added clean up of osg::Program that are applied by the GLObjectsVisitor, which addresses a state leak that creates GL error once the main scene graph is rendered.

This commit is contained in:
Robert Osfield 2014-01-23 09:41:09 +00:00
parent 7f9f7dd216
commit ea429d5d46

View File

@ -31,19 +31,31 @@ GLObjectsVisitor::GLObjectsVisitor(Mode mode)
}
void GLObjectsVisitor::apply(osg::Node& node)
{
bool programSetBefore = _lastCompiledProgram.valid();
if (node.getStateSet())
{
apply(*(node.getStateSet()));
}
traverse(node);
bool programSetAfter = _renderInfo.getState()->getLastAppliedProgramObject()!=0;
if (programSetBefore && !programSetAfter)
{
osg::GL2Extensions* extensions = osg::GL2Extensions::Get(_renderInfo.getState()->getContextID(), true);
extensions->glUseProgram(0);
_renderInfo.getState()->setLastAppliedProgramObject(0);
_lastCompiledProgram = 0;
}
}
void GLObjectsVisitor::apply(osg::Geode& node)
{
bool programSetBefore = _lastCompiledProgram.valid();
if (node.getStateSet())
{
apply(*(node.getStateSet()));
@ -61,6 +73,15 @@ void GLObjectsVisitor::apply(osg::Geode& node)
}
}
}
bool programSetAfter = _lastCompiledProgram.valid();
if (!programSetBefore && programSetAfter)
{
osg::GL2Extensions* extensions = osg::GL2Extensions::Get(_renderInfo.getState()->getContextID(), true);
extensions->glUseProgram(0);
_renderInfo.getState()->setLastAppliedProgramObject(0);
_lastCompiledProgram = 0;
}
}
void GLObjectsVisitor::apply(osg::Drawable& drawable)
@ -159,7 +180,7 @@ void GLObjectsVisitor::apply(osg::StateSet& stateset)
/////////////////////////////////////////////////////////////////
//
// GLObjectsVisitor
// GLObjectsOperation
//
GLObjectsOperation::GLObjectsOperation(GLObjectsVisitor::Mode mode):