From 1320c923ca1412907d4fb77d65e78eca2c74ee10 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 20 Feb 2015 15:12:57 +0000 Subject: [PATCH] Changed the toggle of defines so that it works with assumed defaults now set up by the GeometryPool so that when toggling it doesn't have a delay in what the user would expect git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14708 16af8721-9629-0410-8352-f15c8da7e697 --- examples/osgterrain/osgterrain.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/examples/osgterrain/osgterrain.cpp b/examples/osgterrain/osgterrain.cpp index 90097989c..44165f5a0 100644 --- a/examples/osgterrain/osgterrain.cpp +++ b/examples/osgterrain/osgterrain.cpp @@ -167,7 +167,7 @@ public: } else if (ea.getKey()=='d') { - toggleDefine("COMPUTE_DIAGONALS"); + toggleDefine("COMPUTE_DIAGONALS", osg::StateAttribute::OFF); return true; } @@ -178,20 +178,21 @@ public: } } - void toggleDefine(const std::string& defineName) + void toggleDefine(const std::string& defineName, int expectedDefault=osg::StateAttribute::ON) { osg::StateSet::DefineList& defineList = _terrain->getOrCreateStateSet()->getDefineList(); osg::StateSet::DefineList::iterator itr = defineList.find(defineName); if (itr==defineList.end()) { - defineList[defineName].second = (osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); - } - else - { - osg::StateSet::DefinePair& dp = itr->second; - if ( (dp.second & osg::StateAttribute::ON)==0) dp.second = (osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); - else dp.second = (osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE); + defineList[defineName].second = (expectedDefault | osg::StateAttribute::OVERRIDE); // assume the defines start off. + itr = defineList.find(defineName); } + + osg::StateSet::DefinePair& dp = itr->second; + if ( (dp.second & osg::StateAttribute::ON)==0) dp.second = (osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); + else dp.second = (osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE); + + } protected: