Changed RenderLeaf and StateGraph so that they use ref_ptr<> by default for Drawable and StateSet.

This commit is contained in:
Robert Osfield
2007-08-31 16:05:24 +00:00
parent 99f6865d4d
commit 4ba3f3c1a1
8 changed files with 37 additions and 19 deletions

View File

@@ -121,7 +121,7 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
*/
inline void popStateSet()
{
const osg::StateSet* ss = _currentStateGraph->_stateset;
const osg::StateSet* ss = _currentStateGraph->getStateSet();
if (ss->getRenderBinMode()==osg::StateSet::OVERRIDE_RENDERBIN_DETAILS)
{
--_numberOfEncloseOverrideRenderBinDetails;

View File

@@ -23,6 +23,8 @@
namespace osgUtil {
#define OSGUTIL_RENDERBACKEND_USE_REF_PTR
// Forward declare StateGraph
class StateGraph;
@@ -76,12 +78,12 @@ class OSGUTIL_EXPORT RenderLeaf : public osg::Referenced
StateGraph* _parent;
#if 1
osg::Drawable* _drawable;
const osg::Drawable* getDrawable() const { return _drawable; }
#else
#ifdef OSGUTIL_RENDERBACKEND_USE_REF_PTR
osg::ref_ptr<osg::Drawable> _drawable;
const osg::Drawable* getDrawable() const { return _drawable.get(); }
#else
osg::Drawable* _drawable;
const osg::Drawable* getDrawable() const { return _drawable; }
#endif
osg::ref_ptr<osg::RefMatrix> _projection;
osg::ref_ptr<osg::RefMatrix> _modelview;

View File

@@ -47,7 +47,6 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced
typedef std::vector< osg::ref_ptr<RenderLeaf> > LeafList;
StateGraph* _parent;
const osg::StateSet* _stateset;
int _depth;
ChildList _children;
@@ -96,6 +95,13 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced
osg::Referenced* getUserData() { return _userData.get(); }
const osg::Referenced* getUserData() const { return _userData.get(); }
#ifdef OSGUTIL_RENDERBACKEND_USE_REF_PTR
osg::ref_ptr<const osg::StateSet> _stateset;
const osg::StateSet* getStateSet() const { return _stateset.get(); }
#else
const osg::StateSet* _stateset;
const osg::StateSet* getStateSet() const { return _stateset.get(); }
#endif
/** return true if all of drawables, lights and children are empty.*/
inline bool empty() const
@@ -208,7 +214,7 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced
++itr)
{
StateGraph* rg = (*itr);
if (rg->_stateset) state.pushStateSet(rg->_stateset);
if (rg->getStateSet()) state.pushStateSet(rg->getStateSet());
}
return;
}
@@ -220,9 +226,9 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced
{
// state has changed so need to pop old state.
if (sg_curr->_stateset) state.popStateSet();
if (sg_curr->getStateSet()) state.popStateSet();
// and push new state.
if (sg_new->_stateset) state.pushStateSet(sg_new->_stateset);
if (sg_new->getStateSet()) state.pushStateSet(sg_new->getStateSet());
return;
}
@@ -230,7 +236,7 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced
// need to pop back up to the same depth as the new state group.
while (sg_curr->_depth>sg_new->_depth)
{
if (sg_curr->_stateset) state.popStateSet();
if (sg_curr->getStateSet()) state.popStateSet();
sg_curr = sg_curr->_parent;
}
@@ -251,7 +257,7 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced
// nodes have the same parent
while (sg_curr != sg_new)
{
if (sg_curr->_stateset) state.popStateSet();
if (sg_curr->getStateSet()) state.popStateSet();
sg_curr = sg_curr->_parent;
return_path.push_back(sg_new);
@@ -263,7 +269,7 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced
++itr)
{
StateGraph* rg = (*itr);
if (rg->_stateset) state.pushStateSet(rg->_stateset);
if (rg->getStateSet()) state.pushStateSet(rg->getStateSet());
}
}
@@ -273,7 +279,7 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced
// need to pop back all statesets and matrices.
while (sg_curr)
{
if (sg_curr->_stateset) state.popStateSet();
if (sg_curr->getStateSet()) state.popStateSet();
sg_curr = sg_curr->_parent;
}
@@ -285,7 +291,7 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced
// need to pop back all statesets and matrices.
while (sg_curr)
{
if (sg_curr->_stateset) ++numToPop;
if (sg_curr->getStateSet()) ++numToPop;
sg_curr = sg_curr->_parent;
}

View File

@@ -1716,7 +1716,7 @@ void OverlayNode::traverse_VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY(osg::NodeVis
osgUtil::StateGraph* sg = cv->getCurrentStateGraph();
while(sg)
{
const osg::StateSet* stateset = sg->_stateset;
const osg::StateSet* stateset = sg->getStateSet();
if (stateset)
{
statesetStack.push_front(stateset);

View File

@@ -44,14 +44,14 @@ void RenderLeaf::render(osg::RenderInfo& renderInfo,RenderLeaf* previous)
StateGraph::moveStateGraph(state,prev_rg_parent,rg->_parent);
// send state changes and matrix changes to OpenGL.
state.apply(rg->_stateset);
state.apply(rg->getStateSet());
}
else if (rg!=prev_rg)
{
// send state changes and matrix changes to OpenGL.
state.apply(rg->_stateset);
state.apply(rg->getStateSet());
}
@@ -68,7 +68,7 @@ void RenderLeaf::render(osg::RenderInfo& renderInfo,RenderLeaf* previous)
// apply state if required.
StateGraph::moveStateGraph(state,NULL,_parent->_parent);
state.apply(_parent->_stateset);
state.apply(_parent->getStateSet());
// draw the drawable
_drawable->draw(renderInfo);

View File

@@ -534,8 +534,10 @@ void Viewer::startThreading()
_endRenderingDispatchBarrier = 0;
_endDynamicDrawBlock = new osg::EndOfDynamicDrawBlock(numViewerDoubleBufferedRenderingOperation);
#ifndef OSGUTIL_RENDERBACKEND_USE_REF_PTR
if (!osg::Referenced::getDeleteHandler()) osg::Referenced::setDeleteHandler(new osg::DeleteHandler(2));
else osg::Referenced::getDeleteHandler()->setNumFramesToRetainObjects(2);
#endif
}
if (numThreadsOnStartBarrier>1)

View File

@@ -56,7 +56,7 @@ BEGIN_OBJECT_REFLECTOR(osgUtil::RenderLeaf)
__C5_osg_Drawable_P1__getDrawable,
0);
I_PublicMemberProperty(osgUtil::StateGraph *, _parent);
I_PublicMemberProperty(osg::Drawable *, _drawable);
I_PublicMemberProperty(osg::ref_ptr< osg::Drawable >, _drawable);
I_PublicMemberProperty(osg::ref_ptr< osg::RefMatrix >, _projection);
I_PublicMemberProperty(osg::ref_ptr< osg::RefMatrix >, _modelview);
I_PublicMemberProperty(float, _depth);

View File

@@ -65,6 +65,11 @@ BEGIN_OBJECT_REFLECTOR(osgUtil::StateGraph)
__C5_osg_Referenced_P1__getUserData,
"",
"");
I_Method0(const osg::StateSet *, getStateSet,
Properties::NON_VIRTUAL,
__C5_osg_StateSet_P1__getStateSet,
"",
"");
I_Method0(bool, empty,
Properties::NON_VIRTUAL,
__bool__empty,
@@ -133,6 +138,9 @@ BEGIN_OBJECT_REFLECTOR(osgUtil::StateGraph)
I_SimpleProperty(float, MinimumDistance,
__float__getMinimumDistance,
0);
I_SimpleProperty(const osg::StateSet *, StateSet,
__C5_osg_StateSet_P1__getStateSet,
0);
I_SimpleProperty(osg::Referenced *, UserData,
__osg_Referenced_P1__getUserData,
__void__setUserData__osg_Referenced_P1);