Added support for osg::StateSet comparison operators and using this new feature

added support in osgUtil::OptimizeStateVisitor for removing duplicate
StateSet's from the scene graph, previously only duplicated StateAttributes
we're removed.
This commit is contained in:
Robert Osfield
2001-10-01 23:02:14 +00:00
parent 0d0b33f4b0
commit fc1fa57275
4 changed files with 192 additions and 75 deletions

View File

@@ -28,6 +28,13 @@ class SG_EXPORT StateSet : public Object
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const StateSet*>(obj)!=NULL; }
virtual const char* className() const { return "StateSet"; }
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
int compare(const StateSet& rhs) const;
bool operator < (const StateSet& rhs) const { return compare(rhs)<0; }
bool operator == (const StateSet& rhs) const { return compare(rhs)==0; }
bool operator != (const StateSet& rhs) const { return compare(rhs)!=0; }
/** set all the modes to on or off so that it defines a
complete state, typically used for a default global state.*/
void setGlobalDefaults();

View File

@@ -20,7 +20,6 @@ class OSGUTIL_EXPORT OptimizeStateVisitor : public osg::NodeVisitor
/** empty visitor, make it ready for next traversal.*/
virtual void reset();
void addStateSet(osg::StateSet* stateset);
virtual void apply(osg::Node& node);
@@ -30,8 +29,12 @@ class OSGUTIL_EXPORT OptimizeStateVisitor : public osg::NodeVisitor
protected:
typedef std::set<osg::StateSet*> StateSetList;
StateSetList _statesets;
void addStateSet(osg::StateSet* stateset,osg::Object* obj);
typedef std::set<osg::Object*> ObjectSet;
typedef std::map<osg::StateSet*,ObjectSet> StateSetMap;
StateSetMap _statesets;
};