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:
@@ -29,6 +29,50 @@ StateSet::~StateSet()
|
||||
// delete the memory manually.
|
||||
}
|
||||
|
||||
int StateSet::compare(const StateSet& rhs) const
|
||||
{
|
||||
// check to see how the modes compare.
|
||||
ModeList::const_iterator lhs_mode_itr = _modeList.begin();
|
||||
ModeList::const_iterator rhs_mode_itr = rhs._modeList.begin();
|
||||
while (lhs_mode_itr!=_modeList.end() && rhs_mode_itr!=rhs._modeList.end())
|
||||
{
|
||||
if (lhs_mode_itr->first<rhs_mode_itr->first) return -1;
|
||||
else if (rhs_mode_itr->first<lhs_mode_itr->first) return 1;
|
||||
if (lhs_mode_itr->second<rhs_mode_itr->second) return -1;
|
||||
else if (rhs_mode_itr->second<lhs_mode_itr->second) return 1;
|
||||
++lhs_mode_itr;
|
||||
++rhs_mode_itr;
|
||||
}
|
||||
if (lhs_mode_itr==_modeList.end())
|
||||
{
|
||||
if (rhs_mode_itr!=rhs._modeList.end()) return -1;
|
||||
}
|
||||
else if (rhs_mode_itr == rhs._modeList.end()) return 1;
|
||||
|
||||
// we've got here so modes must be equal...
|
||||
|
||||
// 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->first<rhs_attr_itr->first) return -1;
|
||||
else if (rhs_attr_itr->first<lhs_attr_itr->first) 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.second<rhs_attr_itr->second.second) return -1;
|
||||
else if (rhs_attr_itr->second.second<lhs_attr_itr->second.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;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void StateSet::setGlobalDefaults()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user