From 248805fedd53dc3ed74e88711f72b8a7b62fc687 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 25 Oct 2017 16:13:26 +0100 Subject: [PATCH] Fixed pre compilation osg::Program state leaking into the main scene graph rendering --- include/osgUtil/GLObjectsVisitor | 3 +++ src/osgUtil/GLObjectsVisitor.cpp | 17 +++++++++++++++++ src/osgViewer/Renderer.cpp | 3 +-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/osgUtil/GLObjectsVisitor b/include/osgUtil/GLObjectsVisitor index b9a130f3e..c52d6cce6 100644 --- a/include/osgUtil/GLObjectsVisitor +++ b/include/osgUtil/GLObjectsVisitor @@ -97,6 +97,9 @@ class OSGUTIL_EXPORT GLObjectsVisitor : public osg::NodeVisitor void apply(osg::Drawable& drawable); void apply(osg::StateSet& stateset); + /** Do a compile traversal and then reset any state,*/ + void compile(osg::Node& node); + protected: typedef std::set DrawableAppliedSet; diff --git a/src/osgUtil/GLObjectsVisitor.cpp b/src/osgUtil/GLObjectsVisitor.cpp index b194b7990..25aa8c896 100644 --- a/src/osgUtil/GLObjectsVisitor.cpp +++ b/src/osgUtil/GLObjectsVisitor.cpp @@ -153,6 +153,23 @@ void GLObjectsVisitor::apply(osg::StateSet& stateset) } } +void GLObjectsVisitor::compile(osg::Node& node) +{ + if (_renderInfo.getState()) + { + node.accept(*this); + + if (_lastCompiledProgram.valid()) + { + osg::State* state = _renderInfo.getState(); + osg::GLExtensions* extensions = state->get(); + extensions->glUseProgram(0); + _renderInfo.getState()->setLastAppliedProgramObject(0); + } + } +} + + ///////////////////////////////////////////////////////////////// // // GLObjectsOperation diff --git a/src/osgViewer/Renderer.cpp b/src/osgViewer/Renderer.cpp index 71f93ccc5..06620af32 100644 --- a/src/osgViewer/Renderer.cpp +++ b/src/osgViewer/Renderer.cpp @@ -571,7 +571,6 @@ void Renderer::compile() { DEBUG_MESSAGE<<"Renderer::compile()"<getState()); - sceneView->getSceneData()->accept(glov); + glov.compile(*(sceneView->getSceneData())); } sceneView->getState()->checkGLErrors("After Renderer::compile");