]> git.mxchange.org Git - simgear.git/commitdiff
StateSet optimizations
authortimoore <timoore>
Sun, 18 Nov 2007 23:31:03 +0000 (23:31 +0000)
committertimoore <timoore>
Sun, 18 Nov 2007 23:31:03 +0000 (23:31 +0000)
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
simgear/scene/tgdb/obj.cxx

index f6b12e6e2e74f728627802d52a1f7ab1005b7bf0..3381743f4b489d8d0d5a10035665b17982e95dd6 100644 (file)
@@ -11,6 +11,9 @@
 #include <math.h>
 #include <algorithm>
 
+#include <OpenThreads/Mutex>
+#include <OpenThreads/ScopedLock>
+
 #include <osg/AlphaFunc>
 #include <osg/Drawable>
 #include <osg/Geode>
@@ -1007,6 +1010,25 @@ SGScaleAnimation::createAnimationGroup(osg::Group& parent)
 }
 
 \f
+// Don't create a new state state everytime we need GL_NORMALIZE!
+
+namespace
+{
+OpenThreads::Mutex normalizeMutex;
+
+osg::StateSet* getNormalizeStateSet()
+{
+    static osg::ref_ptr<osg::StateSet> normalizeStateSet;
+    OpenThreads::ScopedLock<OpenThreads::Mutex> 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);
index 758b1a37030b00f1cd6768c355ec5fed303fb038..89f19fc15a67aef45958943c6972f6d59df886ff 100644 (file)
@@ -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;