From 8ff77c10f98f54863eada5fb0e3d83df986332a2 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 30 Sep 2013 18:16:08 +0000 Subject: [PATCH] From Farshid Lashkari, "I have a scene that makes heavy use of the StateSet::compare method and my profiler showed that a lot of time was being spent inside it. I made a small change to the method so that it performs a quick size comparison between the attribute/mode lists and bin mode before iterating through all the attributes. This made a noticeable improvement in my scene. I've attached the change." --- src/osg/StateSet.cpp | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index 806a22960..4525944c5 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -274,6 +274,32 @@ int StateSet::compare(const StateSet& rhs,bool compareAttributeContents) const if (_textureAttributeList.size()rhs._textureAttributeList.size()) return 1; + if (_textureModeList.size()rhs._textureModeList.size()) return 1; + + if (_attributeList.size()rhs._attributeList.size()) return 1; + + if (_modeList.size()rhs._modeList.size()) return 1; + + if (_uniformList.size()rhs._uniformList.size()) return 1; + + // check render bin details + + if ( _binMode < rhs._binMode ) return -1; + else if ( _binMode > rhs._binMode ) return 1; + + if ( _binMode != INHERIT_RENDERBIN_DETAILS ) + { + if ( _binNum < rhs._binNum ) return -1; + else if ( _binNum > rhs._binNum ) return 1; + + if ( _binName < rhs._binName ) return -1; + else if ( _binName > rhs._binName ) return 1; + } + for(unsigned int ai=0;ai<_textureAttributeList.size();++ai) { const AttributeList& rhs_attributeList = _textureAttributeList[ai]; @@ -373,10 +399,6 @@ int StateSet::compare(const StateSet& rhs,bool compareAttributeContents) const // we've got here so attributes must be equal... - - if (_textureModeList.size()rhs._textureModeList.size()) return 1; - // check to see how the modes compare. // first check the rest of the texture modes for(unsigned int ti=0;ti<_textureModeList.size();++ti) @@ -441,20 +463,6 @@ int StateSet::compare(const StateSet& rhs,bool compareAttributeContents) const } else if (rhs_uniform_itr == rhs._uniformList.end()) return 1; - // check render bin details - - if ( _binMode < rhs._binMode ) return -1; - else if ( _binMode > rhs._binMode ) return 1; - - if ( _binMode != INHERIT_RENDERBIN_DETAILS ) - { - if ( _binNum < rhs._binNum ) return -1; - else if ( _binNum > rhs._binNum ) return 1; - - if ( _binName < rhs._binName ) return -1; - else if ( _binName > rhs._binName ) return 1; - } - return 0; }