14 #ifndef OSGUTIL_STATEGRAPH
15 #define OSGUTIL_STATEGRAPH 1
18 #include <osg/Drawable>
19 #include <osg/StateSet>
23 #include <osgUtil/RenderLeaf>
35 return (lhs->_depth < rhs->_depth);
46 typedef std::map< const osg::StateSet*, osg::ref_ptr<StateGraph> >
ChildList;
47 typedef std::vector< osg::ref_ptr<RenderLeaf> >
LeafList;
51 #ifdef OSGUTIL_RENDERBACKEND_USE_REF_PTR
69 osg::Referenced(false),
81 osg::Referenced(false),
90 if (_parent) _depth = _parent->
_depth + 1;
92 if (_parent && _parent->
_dynamic) _dynamic =
true;
106 #ifdef OSGUTIL_RENDERBACKEND_USE_REF_PTR
107 const osg::StateSet* getStateSet()
const {
return _stateset.get(); }
115 return _leaves.empty() && _children.empty();
120 return _leaves.empty();
126 if (_averageDistance==FLT_MAX && !_leaves.empty())
128 _averageDistance = 0.0f;
129 for(LeafList::const_iterator itr=_leaves.begin();
133 _averageDistance += (*itr)->_depth;
135 _averageDistance /= (float)_leaves.size();
138 return _averageDistance;
143 if (_minimumDistance==FLT_MAX && !_leaves.empty())
145 LeafList::const_iterator itr=_leaves.begin();
146 _minimumDistance = (*itr)->_depth;
152 if ((*itr)->_depth<_minimumDistance) _minimumDistance=(*itr)->_depth;
156 return _minimumDistance;
178 ChildList::iterator itr = _children.find(stateset);
179 if (itr!=_children.end())
return itr->second.get();
184 _children[stateset] = sg;
193 _averageDistance = FLT_MAX;
194 _minimumDistance = FLT_MAX;
195 _leaves.push_back(leaf);
197 if (_dynamic) leaf->
_dynamic =
true;
203 if (sg_new==sg_curr || sg_new==
NULL)
return;
209 std::vector<StateGraph*> return_path;
210 return_path.reserve(sg_new->
_depth+1);
215 return_path.push_back(sg_new);
219 for(std::vector<StateGraph*>::reverse_iterator itr=return_path.rbegin();
220 itr!=return_path.rend();
251 std::vector<StateGraph*> return_path;
252 return_path.reserve(sg_new->
_depth+1);
257 return_path.push_back(sg_new);
266 while (sg_curr != sg_new)
271 return_path.push_back(sg_new);
275 for(std::vector<StateGraph*>::reverse_iterator itr=return_path.rbegin();
276 itr!=return_path.rend();
314 StateGraph& operator = (
const StateGraph&) {
return *
this; }
void setUserData(osg::Referenced *obj)
osg::Referenced * getUserData()
StateGraph(StateGraph *parent, const osg::StateSet *stateset)
const osg::StateSet * _stateset
float getAverageDistance() const
const osg::StateSet * getStateSet() const
StateGraph * find_or_insert(const osg::StateSet *stateset)
void setStateSet(const osg::StateSet *stateset)
StateGraph * cloneType() const
osg::ref_ptr< osg::Referenced > _userData
DataVariance getDataVariance() const
static void moveStateGraph(osg::State &state, StateGraph *sg_curr, StateGraph *sg_new)
static int numToPop(StateGraph *sg_curr)
float getMinimumDistance() const
std::map< const osg::StateSet *, osg::ref_ptr< StateGraph > > ChildList
const osg::Referenced * getUserData() const
void pushStateSet(const StateSet *dstate)
static void moveToRootStateGraph(osg::State &state, StateGraph *sg_curr)
void addLeaf(RenderLeaf *leaf)
bool leaves_empty() const
std::vector< osg::ref_ptr< RenderLeaf > > LeafList
bool operator()(const osg::ref_ptr< RenderLeaf > &lhs, const osg::ref_ptr< RenderLeaf > &rhs)
Shader generator framework.