diff --git a/include/osg/StateSet b/include/osg/StateSet index 3ab52fcd9..33995ffe0 100644 --- a/include/osg/StateSet +++ b/include/osg/StateSet @@ -35,7 +35,7 @@ class SG_EXPORT StateSet : public Object 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; + int compare(const StateSet& rhs,bool compareAttributeContents=false) const; bool operator < (const StateSet& rhs) const { return compare(rhs)<0; } bool operator == (const StateSet& rhs) const { return compare(rhs)==0; } diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index 231f21c2a..08f2303af 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -40,29 +40,54 @@ StateSet::~StateSet() // delete the memory manually. } -int StateSet::compare(const StateSet& rhs) const +int StateSet::compare(const StateSet& rhs,bool compareAttributeContents) const { - // now check to see how the attributes compare. - AttributeList::const_iterator lhs_attr_itr = _attributeList.begin(); - AttributeList::const_iterator rhs_attr_itr = rhs._attributeList.begin(); - while (lhs_attr_itr!=_attributeList.end() && rhs_attr_itr!=rhs._attributeList.end()) + if (compareAttributeContents) { - if (lhs_attr_itr->firstfirst) return -1; - else if (rhs_attr_itr->firstfirst) return 1; - if (lhs_attr_itr->second.firstsecond.first) return -1; - else if (rhs_attr_itr->second.firstsecond.first) return 1; - if (lhs_attr_itr->second.secondsecond.second) return -1; - else if (rhs_attr_itr->second.secondsecond.second) return 1; - ++lhs_attr_itr; - ++rhs_attr_itr; + // now check to see how the attributes compare. + AttributeList::const_iterator lhs_attr_itr = _attributeList.begin(); + AttributeList::const_iterator rhs_attr_itr = rhs._attributeList.begin(); + while (lhs_attr_itr!=_attributeList.end() && rhs_attr_itr!=rhs._attributeList.end()) + { + if (lhs_attr_itr->firstfirst) return -1; + else if (rhs_attr_itr->firstfirst) return 1; + if (*(lhs_attr_itr->second.first)<*(rhs_attr_itr->second.first)) return -1; + else if (*(rhs_attr_itr->second.first)<*(lhs_attr_itr->second.first)) return 1; + if (lhs_attr_itr->second.secondsecond.second) return -1; + else if (rhs_attr_itr->second.secondsecond.second) return 1; + ++lhs_attr_itr; + ++rhs_attr_itr; + } + if (lhs_attr_itr==_attributeList.end()) + { + if (rhs_attr_itr!=rhs._attributeList.end()) return -1; + } + else if (rhs_attr_itr == rhs._attributeList.end()) return 1; } - if (lhs_attr_itr==_attributeList.end()) + else // just compare pointers. { - if (rhs_attr_itr!=rhs._attributeList.end()) return -1; + // now check to see how the attributes compare. + AttributeList::const_iterator lhs_attr_itr = _attributeList.begin(); + AttributeList::const_iterator rhs_attr_itr = rhs._attributeList.begin(); + while (lhs_attr_itr!=_attributeList.end() && rhs_attr_itr!=rhs._attributeList.end()) + { + if (lhs_attr_itr->firstfirst) return -1; + else if (rhs_attr_itr->firstfirst) return 1; + if (lhs_attr_itr->second.firstsecond.first) return -1; + else if (rhs_attr_itr->second.firstsecond.first) return 1; + if (lhs_attr_itr->second.secondsecond.second) return -1; + else if (rhs_attr_itr->second.secondsecond.second) return 1; + ++lhs_attr_itr; + ++rhs_attr_itr; + } + if (lhs_attr_itr==_attributeList.end()) + { + if (rhs_attr_itr!=rhs._attributeList.end()) return -1; + } + else if (rhs_attr_itr == rhs._attributeList.end()) return 1; } - else if (rhs_attr_itr == rhs._attributeList.end()) return 1; - + // we've got here so attributes must be equal... // check to see how the modes compare.