From 4ba3f3c1a1cf77d1f465bb109a052b62127f5cd0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 31 Aug 2007 16:05:24 +0000 Subject: [PATCH] Changed RenderLeaf and StateGraph so that they use ref_ptr<> by default for Drawable and StateSet. --- include/osgUtil/CullVisitor | 2 +- include/osgUtil/RenderLeaf | 10 ++++++---- include/osgUtil/StateGraph | 24 +++++++++++++++--------- src/osgSim/OverlayNode.cpp | 2 +- src/osgUtil/RenderLeaf.cpp | 6 +++--- src/osgViewer/Viewer.cpp | 2 ++ src/osgWrappers/osgUtil/RenderLeaf.cpp | 2 +- src/osgWrappers/osgUtil/StateGraph.cpp | 8 ++++++++ 8 files changed, 37 insertions(+), 19 deletions(-) diff --git a/include/osgUtil/CullVisitor b/include/osgUtil/CullVisitor index d1e94cef5..a5d4173a6 100644 --- a/include/osgUtil/CullVisitor +++ b/include/osgUtil/CullVisitor @@ -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; diff --git a/include/osgUtil/RenderLeaf b/include/osgUtil/RenderLeaf index 51184efe5..a4958050d 100644 --- a/include/osgUtil/RenderLeaf +++ b/include/osgUtil/RenderLeaf @@ -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 _drawable; const osg::Drawable* getDrawable() const { return _drawable.get(); } +#else + osg::Drawable* _drawable; + const osg::Drawable* getDrawable() const { return _drawable; } #endif osg::ref_ptr _projection; osg::ref_ptr _modelview; diff --git a/include/osgUtil/StateGraph b/include/osgUtil/StateGraph index 8922a9c16..2afe6aadd 100644 --- a/include/osgUtil/StateGraph +++ b/include/osgUtil/StateGraph @@ -47,7 +47,6 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced typedef std::vector< osg::ref_ptr > 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 _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; } diff --git a/src/osgSim/OverlayNode.cpp b/src/osgSim/OverlayNode.cpp index df0a6b797..9cbc195d9 100644 --- a/src/osgSim/OverlayNode.cpp +++ b/src/osgSim/OverlayNode.cpp @@ -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); diff --git a/src/osgUtil/RenderLeaf.cpp b/src/osgUtil/RenderLeaf.cpp index ca19b6dbe..ebebd2891 100644 --- a/src/osgUtil/RenderLeaf.cpp +++ b/src/osgUtil/RenderLeaf.cpp @@ -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); diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index 206758b6a..73decfdd7 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -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) diff --git a/src/osgWrappers/osgUtil/RenderLeaf.cpp b/src/osgWrappers/osgUtil/RenderLeaf.cpp index 27ba19934..d33c31be3 100644 --- a/src/osgWrappers/osgUtil/RenderLeaf.cpp +++ b/src/osgWrappers/osgUtil/RenderLeaf.cpp @@ -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); diff --git a/src/osgWrappers/osgUtil/StateGraph.cpp b/src/osgWrappers/osgUtil/StateGraph.cpp index 6cb2195b1..c8588384b 100644 --- a/src/osgWrappers/osgUtil/StateGraph.cpp +++ b/src/osgWrappers/osgUtil/StateGraph.cpp @@ -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);