From cafcecf03ddbdcc2b9bfb57fd60f702bee469b12 Mon Sep 17 00:00:00 2001 From: timoore Date: Sun, 18 Nov 2007 23:31:03 +0000 Subject: [PATCH] StateSet optimizations Use only one shared StateSet to control GL_NORMALIZE. This removes thousands of state sets from the scene graph. Fix a typo that was causing two copies of groundLights0 to be added to each tile. --- simgear/scene/model/animation.cxx | 26 ++++++++++++++++++++++++-- simgear/scene/tgdb/obj.cxx | 2 -- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/simgear/scene/model/animation.cxx b/simgear/scene/model/animation.cxx index f6b12e6e..3381743f 100644 --- a/simgear/scene/model/animation.cxx +++ b/simgear/scene/model/animation.cxx @@ -11,6 +11,9 @@ #include #include +#include +#include + #include #include #include @@ -1007,6 +1010,25 @@ SGScaleAnimation::createAnimationGroup(osg::Group& parent) } +// Don't create a new state state everytime we need GL_NORMALIZE! + +namespace +{ +OpenThreads::Mutex normalizeMutex; + +osg::StateSet* getNormalizeStateSet() +{ + static osg::ref_ptr normalizeStateSet; + OpenThreads::ScopedLock lock(normalizeMutex); + if (!normalizeStateSet.valid()) { + normalizeStateSet = new osg::StateSet; + normalizeStateSet->setMode(GL_NORMALIZE, osg::StateAttribute::ON); + normalizeStateSet->setDataVariance(osg::Object::STATIC); + } + return normalizeStateSet.get(); +} +} + //////////////////////////////////////////////////////////////////////// // Implementation of dist scale animation //////////////////////////////////////////////////////////////////////// @@ -1017,7 +1039,7 @@ public: { setName(configNode->getStringValue("name", "dist scale animation")); setReferenceFrame(RELATIVE_RF); - getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON); + setStateSet(getNormalizeStateSet()); _factor = configNode->getFloatValue("factor", 1); _offset = configNode->getFloatValue("offset", 0); _min_v = configNode->getFloatValue("min", SGLimitsf::epsilon()); @@ -1114,7 +1136,7 @@ public: { setReferenceFrame(RELATIVE_RF); setName(configNode->getStringValue("name", "flash animation")); - getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON); + setStateSet(getNormalizeStateSet()); _axis[0] = configNode->getFloatValue("axis/x", 0); _axis[1] = configNode->getFloatValue("axis/y", 0); diff --git a/simgear/scene/tgdb/obj.cxx b/simgear/scene/tgdb/obj.cxx index 758b1a37..89f19fc1 100644 --- a/simgear/scene/tgdb/obj.cxx +++ b/simgear/scene/tgdb/obj.cxx @@ -623,8 +623,6 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool calc_lights, bool osg::Geode* geode = new osg::Geode; groundLights0->addChild(geode); geode->addDrawable(SGLightFactory::getLights(tileGeometryBin.tileLights)); - - groundLights0->addChild(geode); geode->addDrawable(SGLightFactory::getLights(tileGeometryBin.randomTileLights, 4, -0.3f)); geode = new osg::Geode; -- 2.39.5