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.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
// 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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user