14#ifndef OSGUTIL_STATEGRAPH
15#define OSGUTIL_STATEGRAPH 1
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
88 if (_parent) _depth = _parent->
_depth + 1;
90 if (_parent && _parent->
_dynamic) _dynamic =
true;
102 virtual const char*
className()
const {
return "StateGraph"; }
110#ifdef OSGUTIL_RENDERBACKEND_USE_REF_PTR
119 return _leaves.empty() && _children.empty();
124 return _leaves.empty();
130 if (_averageDistance==FLT_MAX && !_leaves.empty())
132 _averageDistance = 0.0f;
133 for(LeafList::const_iterator itr=_leaves.begin();
137 _averageDistance += (*itr)->_depth;
139 _averageDistance /= (float)_leaves.size();
142 return _averageDistance;
147 if (_minimumDistance==FLT_MAX && !_leaves.empty())
149 LeafList::const_iterator itr=_leaves.begin();
150 _minimumDistance = (*itr)->_depth;
156 if ((*itr)->_depth<_minimumDistance) _minimumDistance=(*itr)->_depth;
160 return _minimumDistance;
181 for(ChildList::iterator itr = _children.begin();
182 itr != _children.end();
185 (itr->second)->resizeGLObjectBuffers(maxSize);
188 for(LeafList::iterator itr = _leaves.begin();
189 itr != _leaves.end();
192 (*itr)->resizeGLObjectBuffers(maxSize);
198 if (_stateset) _stateset->releaseGLObjects(state);
200 for(ChildList::const_iterator itr = _children.begin();
201 itr != _children.end();
204 (itr->second)->releaseGLObjects(state);
207 for(LeafList::const_iterator itr = _leaves.begin();
208 itr != _leaves.end();
211 (*itr)->releaseGLObjects(state);
218 ChildList::iterator itr = _children.find(stateset);
219 if (itr!=_children.end())
return itr->second.get();
224 _children[stateset] = sg;
233 _averageDistance = FLT_MAX;
234 _minimumDistance = FLT_MAX;
235 _leaves.push_back(leaf);
237 if (_dynamic) leaf->
_dynamic =
true;
243 if (sg_new==sg_curr || sg_new==
NULL)
return;
249 std::vector<StateGraph*> return_path;
250 return_path.reserve(sg_new->
_depth+1);
255 return_path.push_back(sg_new);
259 for(std::vector<StateGraph*>::reverse_iterator itr=return_path.rbegin();
260 itr!=return_path.rend();
291 std::vector<StateGraph*> return_path;
292 return_path.reserve(sg_new->
_depth+1);
297 return_path.push_back(sg_new);
306 while (sg_curr != sg_new)
311 return_path.push_back(sg_new);
315 for(std::vector<StateGraph*>::reverse_iterator itr=return_path.rbegin();
316 itr!=return_path.rend();
354 StateGraph& operator = (
const StateGraph&) {
return *
this; }
StateGraph * _parent
Definition RenderLeaf:92
bool _dynamic
Definition RenderLeaf:104
virtual const char * className() const
Definition StateGraph:102
osg::ref_ptr< osg::Referenced > _userData
Definition StateGraph:64
float _minimumDistance
Definition StateGraph:62
bool _dynamic
Definition StateGraph:66
StateGraph * find_or_insert(const osg::StateSet *stateset)
Definition StateGraph:215
ChildList _children
Definition StateGraph:58
virtual bool isSameKindAs(const osg::Object *obj) const
Definition StateGraph:100
StateGraph(StateGraph *parent, const osg::StateSet *stateset)
Definition StateGraph:79
osg::Referenced * getUserData()
Definition StateGraph:105
void releaseGLObjects(osg::State *state=0) const
Definition StateGraph:196
LeafList _leaves
Definition StateGraph:59
float getAverageDistance() const
Definition StateGraph:128
void setStateSet(const osg::StateSet *stateset)
Definition StateGraph:108
bool leaves_empty() const
Definition StateGraph:122
virtual StateGraph * cloneStateGraph() const
Definition StateGraph:98
static int numToPop(StateGraph *sg_curr)
Definition StateGraph:336
virtual osg::Object * cloneType() const
Definition StateGraph:97
StateGraph * _parent
Definition StateGraph:49
static void moveToRootStateGraph(osg::State &state, StateGraph *sg_curr)
Definition StateGraph:325
StateGraph()
Definition StateGraph:68
void addLeaf(RenderLeaf *leaf)
Definition StateGraph:229
void resizeGLObjectBuffers(unsigned int maxSize)
Definition StateGraph:179
void setUserData(osg::Referenced *obj)
Definition StateGraph:104
std::map< const osg::StateSet *, osg::ref_ptr< StateGraph > > ChildList
Definition StateGraph:46
const osg::StateSet * getStateSet() const
Definition StateGraph:113
float getMinimumDistance() const
Definition StateGraph:145
virtual const char * libraryName() const
Definition StateGraph:101
float _averageDistance
Definition StateGraph:61
~StateGraph()
Definition StateGraph:94
static void moveStateGraph(osg::State &state, StateGraph *sg_curr, StateGraph *sg_new)
Definition StateGraph:241
bool empty() const
Definition StateGraph:117
int _depth
Definition StateGraph:57
void sortFrontToBack()
Definition StateGraph:163
const osg::StateSet * _stateset
Definition StateGraph:54
std::vector< osg::ref_ptr< RenderLeaf > > LeafList
Definition StateGraph:47
virtual osg::Object * clone(const osg::CopyOp &) const
Definition StateGraph:99
const osg::Referenced * getUserData() const
Definition StateGraph:106
@ DYNAMIC
Definition Object:218
DataVariance getDataVariance() const
Definition Object:231
void pushStateSet(const StateSet *dstate)
T * get() const
Definition ref_ptr:117
Shader generator framework.
Definition NodeVisitor:25
author: Julien Valentin 2017 (mp3butcher@hotmail.com)
Definition AlphaFunc:19
#define OSGUTIL_EXPORT
Definition osgUtil/Export:40
#define NULL
Definition osg/Export:55
bool operator()(const osg::ref_ptr< RenderLeaf > &lhs, const osg::ref_ptr< RenderLeaf > &rhs)
Definition StateGraph:33