Changeset 13041 for OpenSceneGraph/trunk/include/osgUtil/StateGraph
- Timestamp:
- 03/21/12 18:36:20 (15 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/include/osgUtil/StateGraph (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgUtil/StateGraph
r12745 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 42 42 { 43 43 public: 44 44 45 45 46 46 typedef std::map< const osg::StateSet*, osg::ref_ptr<StateGraph> > ChildList; … … 58 58 ChildList _children; 59 59 LeafList _leaves; 60 60 61 61 mutable float _averageDistance; 62 62 mutable float _minimumDistance; 63 63 64 64 osg::ref_ptr<osg::Referenced> _userData; 65 65 … … 89 89 { 90 90 if (_parent) _depth = _parent->_depth + 1; 91 91 92 92 if (_parent && _parent->_dynamic) _dynamic = true; 93 93 else _dynamic = stateset->getDataVariance()==osg::Object::DYNAMIC; 94 94 } 95 95 96 96 ~StateGraph() {} 97 97 98 98 StateGraph* cloneType() const { return new StateGraph; } 99 99 100 100 void setUserData(osg::Referenced* obj) { _userData = obj; } 101 101 osg::Referenced* getUserData() { return _userData.get(); } … … 115 115 return _leaves.empty() && _children.empty(); 116 116 } 117 117 118 118 inline bool leaves_empty() const 119 119 { … … 134 134 } 135 135 _averageDistance /= (float)_leaves.size(); 136 136 137 137 } 138 138 return _averageDistance; 139 139 } 140 140 141 141 inline float getMinimumDistance() const 142 142 { … … 152 152 if ((*itr)->_depth<_minimumDistance) _minimumDistance=(*itr)->_depth; 153 153 } 154 154 155 155 } 156 156 return _minimumDistance; … … 171 171 /** Recursively prune the StateGraph of empty children.*/ 172 172 void prune(); 173 174 173 174 175 175 inline StateGraph* find_or_insert(const osg::StateSet* stateset) 176 176 { … … 178 178 ChildList::iterator itr = _children.find(stateset); 179 179 if (itr!=_children.end()) return itr->second.get(); 180 180 181 181 // create a state group and insert it into the children list 182 182 // then return the state group. … … 210 210 211 211 // need to pop back root render graph. 212 do 212 do 213 213 { 214 214 return_path.push_back(sg_new); … … 225 225 return; 226 226 } 227 227 228 228 229 229 // first handle the typical case which is two state groups … … 231 231 if (sg_curr->_parent==sg_new->_parent) 232 232 { 233 233 234 234 // state has changed so need to pop old state. 235 235 if (sg_curr->getStateSet()) state.popStateSet(); … … 238 238 return; 239 239 } 240 240 241 241 242 242 // need to pop back up to the same depth as the new state group. … … 246 246 sg_curr = sg_curr->_parent; 247 247 } 248 248 249 249 // use return path to trace back steps to sg_new. 250 250 std::vector<StateGraph*> return_path; … … 256 256 sg_new = sg_new->_parent; 257 257 } 258 258 259 259 // now pop back up both parent paths until they agree. 260 260 … … 270 270 sg_new = sg_new->_parent; 271 271 } 272 272 273 273 for(std::vector<StateGraph*>::reverse_iterator itr=return_path.rbegin(); 274 274 itr!=return_path.rend(); … … 289 289 sg_curr = sg_curr->_parent; 290 290 } 291 292 } 293 291 292 } 293 294 294 inline static int numToPop(StateGraph* sg_curr) 295 295 { … … 301 301 sg_curr = sg_curr->_parent; 302 302 } 303 303 304 304 return numToPop; 305 305 }
