diff --git a/src/osgUtil/GLObjectsVisitor.cpp b/src/osgUtil/GLObjectsVisitor.cpp index 94b10d099..88b566673 100644 --- a/src/osgUtil/GLObjectsVisitor.cpp +++ b/src/osgUtil/GLObjectsVisitor.cpp @@ -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):