From 5e0169f6640ceb07899ff57288df284835f50cb2 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 29 Jun 2008 12:22:50 +0000 Subject: [PATCH] Changed the Optimizer::StateVisitor so that it can individually decide whether to optimize away duplicate state with dynamic, static and unspecified DataVarience. By default the code now optimizes away duplicate state with either static and unspecied state, previously it was just handling static state. --- include/osgUtil/Optimizer | 20 ++++++++++++++++++-- src/osgUtil/Optimizer.cpp | 18 +++++++++++++----- src/osgWrappers/osgUtil/Optimizer.cpp | 11 ++++++++--- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/include/osgUtil/Optimizer b/include/osgUtil/Optimizer index 572d57acc..8ee3b5e35 100644 --- a/include/osgUtil/Optimizer +++ b/include/osgUtil/Optimizer @@ -432,8 +432,16 @@ class OSGUTIL_EXPORT Optimizer public: /// default to traversing all children. - StateVisitor(Optimizer* optimizer=0): - BaseOptimizerVisitor(optimizer, SHARE_DUPLICATE_STATE) {} + StateVisitor(bool combineDynamicState, + bool combineStaticState, + bool combineUnspecifiedState, + Optimizer* optimizer=0): + BaseOptimizerVisitor(optimizer, SHARE_DUPLICATE_STATE) + { + _optimize[osg::Object::DYNAMIC] = combineDynamicState; + _optimize[osg::Object::STATIC] = combineStaticState; + _optimize[osg::Object::UNSPECIFIED] = combineUnspecifiedState; + } /** empty visitor, make it ready for next traversal.*/ virtual void reset(); @@ -447,10 +455,18 @@ class OSGUTIL_EXPORT Optimizer protected: void addStateSet(osg::StateSet* stateset,osg::Object* obj); + + inline bool optimize(osg::Object::DataVariance variance) + { + return _optimize[variance]; + } typedef std::set ObjectSet; typedef std::map StateSetMap; + // note, one element for DYNAMIC, STATIC and UNSPECIFIED + bool _optimize[3]; + StateSetMap _statesets; }; diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index aa85481d5..63d3d60af 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -188,7 +188,11 @@ void Optimizer::optimize(osg::Node* node, unsigned int options) { osg::notify(osg::INFO)<<"Optimizer::optimize() doing SHARE_DUPLICATE_STATE"<accept(osv); osv.optimize(); } @@ -203,7 +207,11 @@ void Optimizer::optimize(osg::Node* node, unsigned int options) tav.optimize(); // now merge duplicate state, that may have been introduced by merge textures into texture atlas' - StateVisitor osv(this); + bool combineDynamicState = false; + bool combineStaticState = true; + bool combineUnspecifiedState = true; + + StateVisitor osv(combineDynamicState, combineStaticState, combineUnspecifiedState, this); node->accept(osv); osv.optimize(); } @@ -464,7 +472,7 @@ void Optimizer::StateVisitor::optimize() aitr!=attributes.end(); ++aitr) { - if (aitr->second.first->getDataVariance()==osg::Object::STATIC) + if (optimize(aitr->second.first->getDataVariance())) { attributeToStateSetMap[aitr->second.first.get()].insert(StateSetUnitPair(sitr->first,NON_TEXTURE_ATTRIBUTE)); } @@ -479,7 +487,7 @@ void Optimizer::StateVisitor::optimize() aitr!=attributes.end(); ++aitr) { - if (aitr->second.first->getDataVariance()==osg::Object::STATIC) + if (optimize(aitr->second.first->getDataVariance())) { attributeToStateSetMap[aitr->second.first.get()].insert(StateSetUnitPair(sitr->first,unit)); } @@ -492,7 +500,7 @@ void Optimizer::StateVisitor::optimize() uitr!=uniforms.end(); ++uitr) { - if (uitr->second.first->getDataVariance()==osg::Object::STATIC) + if (optimize(uitr->second.first->getDataVariance())) { uniformToStateSetMap[uitr->second.first.get()].insert(sitr->first); } diff --git a/src/osgWrappers/osgUtil/Optimizer.cpp b/src/osgWrappers/osgUtil/Optimizer.cpp index a3adafe7e..ccfd52948 100644 --- a/src/osgWrappers/osgUtil/Optimizer.cpp +++ b/src/osgWrappers/osgUtil/Optimizer.cpp @@ -646,9 +646,8 @@ END_REFLECTOR BEGIN_OBJECT_REFLECTOR(osgUtil::Optimizer::StateVisitor) I_DeclaringFile("osgUtil/Optimizer"); I_BaseType(osgUtil::BaseOptimizerVisitor); - I_ConstructorWithDefaults1(IN, osgUtil::Optimizer *, optimizer, 0, - Properties::NON_EXPLICIT, - ____StateVisitor__Optimizer_P1, + I_ConstructorWithDefaults4(IN, bool, combineDynamicState, , IN, bool, combineStaticState, , IN, bool, combineUnspecifiedState, , IN, osgUtil::Optimizer *, optimizer, 0, + ____StateVisitor__bool__bool__bool__Optimizer_P1, "default to traversing all children. ", ""); I_Method0(void, reset, @@ -677,6 +676,12 @@ BEGIN_OBJECT_REFLECTOR(osgUtil::Optimizer::StateVisitor) __void__addStateSet__osg_StateSet_P1__osg_Object_P1, "", ""); + I_ProtectedMethod1(bool, optimize, IN, osg::Object::DataVariance, variance, + Properties::NON_VIRTUAL, + Properties::NON_CONST, + __bool__optimize__osg_Object_DataVariance, + "", + ""); END_REFLECTOR BEGIN_OBJECT_REFLECTOR(osgUtil::Optimizer::StaticObjectDetectionVisitor)