From 5fb8877746541e1ed79bbc259802515281cca3f3 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 26 Mar 2015 00:11:23 +0100 Subject: [PATCH] Don't set the root node to dynamic --- apps/nifosgtest/test.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/nifosgtest/test.cpp b/apps/nifosgtest/test.cpp index 0f2e43a56..dec038825 100644 --- a/apps/nifosgtest/test.cpp +++ b/apps/nifosgtest/test.cpp @@ -41,9 +41,17 @@ public: osg::PolygonMode* mode = new osg::PolygonMode; mode->setMode(osg::PolygonMode::FRONT_AND_BACK, mWireframe ? osg::PolygonMode::LINE : osg::PolygonMode::FILL); - mNode->getOrCreateStateSet()->setAttributeAndModes(mode, osg::StateAttribute::ON); - mNode->getOrCreateStateSet()->setMode(GL_CULL_FACE, mWireframe ? osg::StateAttribute::OFF - : osg::StateAttribute::ON); + + // Create a new stateset instead of changing the old one, this alleviates the need to set + // the StateSet to DYNAMIC DataVariance, which would have a performance impact. + + osg::StateSet* stateset = new osg::StateSet; + stateset->setAttributeAndModes(mode, osg::StateAttribute::ON); + stateset->setMode(GL_CULL_FACE, mWireframe ? osg::StateAttribute::OFF + : osg::StateAttribute::ON); + + mNode->setStateSet(stateset); + return true; } default: @@ -138,10 +146,6 @@ int main(int argc, char** argv) // Mask to separate cull visitors from update visitors viewer.getCamera()->setCullMask(~(0x1)); - // We're going to change this from the event callback, set the variance to DYNAMIC so that - // we don't interfere with the draw thread. - root->getOrCreateStateSet()->setDataVariance(osg::Node::DYNAMIC); - viewer.addEventHandler(new osgViewer::StatsHandler); while (!viewer.done())