From e1b084749e5e415290b4f7b312850ae3943c648a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 17 Oct 2002 13:48:46 +0000 Subject: [PATCH] Renamed the RenderBin::sort_local to sortImplementation(), draw_local to drawImplementation() and added a new RenderBin::DrawCallback(). Added osgcubemap to the Make/ test scripts. --- Make/debugtests.bat | 5 +- Make/osgtests.bat | 3 + include/osgUtil/RenderBin | 35 ++++++--- include/osgUtil/RenderStage | 4 +- src/Demos/osggeometry/osggeometry.cpp | 2 +- src/Demos/sgv/sgv.cpp | 4 +- src/osgUtil/RenderBin.cpp | 103 ++++++++++++++------------ src/osgUtil/RenderStage.cpp | 8 +- 8 files changed, 100 insertions(+), 64 deletions(-) diff --git a/Make/debugtests.bat b/Make/debugtests.bat index 83c4b5b8b..12023ea72 100755 --- a/Make/debugtests.bat +++ b/Make/debugtests.bat @@ -62,11 +62,14 @@ echo osgcube osgcube more memleaks.log +echo osgcubemap glider.osg +osgcubemap glider.osg +more memleaks.log + echo osgclip osgclip cow.osg more memleaks.log - echo osghud dumptruck.osg osghud dumptruck.osg more memleaks.log diff --git a/Make/osgtests.bat b/Make/osgtests.bat index a3ad0d712..01b5154fe 100755 --- a/Make/osgtests.bat +++ b/Make/osgtests.bat @@ -43,6 +43,9 @@ osgbillboard echo osgcube osgcube +echo osgcubemap glider.osg +osgcubemap glider.osg + echo osgclip osgclip cow.osg diff --git a/include/osgUtil/RenderBin b/include/osgUtil/RenderBin index 14575261d..725f46f1e 100644 --- a/include/osgUtil/RenderBin +++ b/include/osgUtil/RenderBin @@ -65,27 +65,40 @@ class OSGUTIL_EXPORT RenderBin : public osg::Object void sort(); + virtual void sortImplementation(); + void setSortMode(SortMode mode); SortMode getSortMode() const { return _sortMode; } - virtual void sort_local(); - virtual void sort_local_by_state(); - virtual void sort_local_front_to_back(); - virtual void sort_local_back_to_front(); + virtual void sortByState(); + virtual void sortFrontToBack(); + virtual void sortBackToFront(); struct SortCallback : public osg::Referenced { - virtual void sort(RenderBin*) = 0; + virtual void sortImplementation(RenderBin*) = 0; }; - void setSortLocalCallback(SortCallback* sortCallback) { _sortLocalCallback = sortCallback; } - SortCallback* getSortLocalCallback() { return _sortLocalCallback.get(); } - const SortCallback* getSortLocalCallback() const { return _sortLocalCallback.get(); } + void setSortCallback(SortCallback* sortCallback) { _sortCallback = sortCallback; } + SortCallback* getSortCallback() { return _sortCallback.get(); } + const SortCallback* getSortCallback() const { return _sortCallback.get(); } + virtual void draw(osg::State& state,RenderLeaf*& previous); - virtual void draw_local(osg::State& state,RenderLeaf*& previous); + virtual void drawImplementation(osg::State& state,RenderLeaf*& previous); + + struct DrawCallback : public osg::Referenced + { + virtual void drawImplementation(RenderBin* bin,osg::State& state,RenderLeaf*& previous) = 0; + }; + + void setDrawCallback(DrawCallback* drawCallback) { _drawCallback = drawCallback; } + DrawCallback* getDrawCallback() { return _drawCallback.get(); } + const DrawCallback* getDrawCallback() const { return _drawCallback.get(); } + + /** extract stats for current draw list. */ bool getStats(osg::Statistics* primStats); @@ -107,8 +120,9 @@ class OSGUTIL_EXPORT RenderBin : public osg::Object SortMode _sortMode; - osg::ref_ptr _sortLocalCallback; + osg::ref_ptr _sortCallback; + osg::ref_ptr _drawCallback; typedef std::map< std::string, osg::ref_ptr > RenderBinPrototypeList; static RenderBinPrototypeList s_renderBinPrototypeList; @@ -143,3 +157,4 @@ class RegisterRenderBinProxy #endif + diff --git a/include/osgUtil/RenderStage b/include/osgUtil/RenderStage index 813ec4c74..57a12a53b 100644 --- a/include/osgUtil/RenderStage +++ b/include/osgUtil/RenderStage @@ -109,8 +109,10 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin } virtual void drawPreRenderStages(osg::State& state,RenderLeaf*& previous); - + virtual void draw(osg::State& state,RenderLeaf*& previous); + + virtual void drawImplementation(osg::State& state,RenderLeaf*& previous); void addToDependencyList(RenderStage* rs); diff --git a/src/Demos/osggeometry/osggeometry.cpp b/src/Demos/osggeometry/osggeometry.cpp index eb4a62d3d..3e526c5b6 100644 --- a/src/Demos/osggeometry/osggeometry.cpp +++ b/src/Demos/osggeometry/osggeometry.cpp @@ -663,7 +663,7 @@ int main( int argc, char **argv ) root->addChild( createScene() ); root->addChild( createBackground() ); - osgDB::writeNodeFile(*root,"geoemtry.osg"); + //osgDB::writeNodeFile(*root,"geoemtry.osg"); // add model to viewer. diff --git a/src/Demos/sgv/sgv.cpp b/src/Demos/sgv/sgv.cpp index f09ef9df1..e72b4bf7b 100644 --- a/src/Demos/sgv/sgv.cpp +++ b/src/Demos/sgv/sgv.cpp @@ -35,7 +35,7 @@ struct SortByMinimumDistanceFunctor struct MySortCallback : public osgUtil::RenderBin::SortCallback { - virtual void sort(osgUtil::RenderBin* renderbin) + virtual void sortImplementation(osgUtil::RenderBin* renderbin) { osgUtil::RenderBin::RenderGraphList& renderGraphList = renderbin->_renderGraphList; @@ -164,7 +164,7 @@ int main( int argc, char **argv ) osgUtil::RenderStage* renderstage = viewer.getViewportSceneView(0)->getRenderStage(); if (renderstage) { - renderstage->setSortLocalCallback(new MySortCallback); + renderstage->setSortCallback(new MySortCallback); // renderstage->setSortMode(osgUtil::RenderBin::SORT_FRONT_TO_BACK); } diff --git a/src/osgUtil/RenderBin.cpp b/src/osgUtil/RenderBin.cpp index 2d6bf52ca..861a181d0 100644 --- a/src/osgUtil/RenderBin.cpp +++ b/src/osgUtil/RenderBin.cpp @@ -69,7 +69,8 @@ RenderBin::RenderBin(const RenderBin& rhs,const CopyOp& copyop): _renderGraphList(rhs._renderGraphList), _renderLeafList(rhs._renderLeafList), _sortMode(rhs._sortMode), - _sortLocalCallback(rhs._sortLocalCallback) + _sortCallback(rhs._sortCallback), + _drawCallback(rhs._drawCallback) { } @@ -93,11 +94,11 @@ void RenderBin::sort() itr->second->sort(); } - if (_sortLocalCallback.valid()) + if (_sortCallback.valid()) { - _sortLocalCallback->sort(this); + _sortCallback->sortImplementation(this); } - else sort_local(); + else sortImplementation(); } void RenderBin::setSortMode(SortMode mode) @@ -105,18 +106,18 @@ void RenderBin::setSortMode(SortMode mode) _sortMode = mode; } -void RenderBin::sort_local() +void RenderBin::sortImplementation() { switch(_sortMode) { case(SORT_BY_STATE): - sort_local_by_state(); + sortByState(); break; case(SORT_FRONT_TO_BACK): - sort_local_front_to_back(); + sortFrontToBack(); break; case(SORT_BACK_TO_FRONT): - sort_local_back_to_front(); + sortBackToFront(); break; default: break; @@ -131,13 +132,13 @@ struct SortByStateFunctor } }; -void RenderBin::sort_local_by_state() +void RenderBin::sortByState() { // actually we'll do nothing right now, as fine grained sorting by state // appears to cost more to do than it saves in draw. The contents of // the RenderGraph leaves is already coasrse grained sorted, this // sorting is as a function of the cull traversal. - // cout << "doing sort_local_by_state "<get()); } } + + // empty the render graph list to prevent it being drawn along side the render leaf list (see drawImplementation.) + _renderGraphList.clear(); } RenderBin* RenderBin::find_or_insert(int binNum,const std::string& binName) @@ -237,6 +241,15 @@ RenderBin* RenderBin::find_or_insert(int binNum,const std::string& binName) } void RenderBin::draw(osg::State& state,RenderLeaf*& previous) +{ + if (_drawCallback.valid()) + { + _drawCallback->drawImplementation(this,state,previous); + } + else drawImplementation(state,previous); +} + +void RenderBin::drawImplementation(osg::State& state,RenderLeaf*& previous) { // draw first set of draw bins. RenderBinList::iterator itr; @@ -247,51 +260,45 @@ void RenderBin::draw(osg::State& state,RenderLeaf*& previous) itr->second->draw(state,previous); } - draw_local(state,previous); + // draw fine grained ordering. + for(RenderLeafList::iterator itr= _renderLeafList.begin(); + itr!= _renderLeafList.end(); + ++itr) + { + RenderLeaf* rl = *itr; + rl->render(state,previous); + previous = rl; + } + + + // draw coarse grained ordering. + for(RenderGraphList::iterator oitr=_renderGraphList.begin(); + oitr!=_renderGraphList.end(); + ++oitr) + { + + for(RenderGraph::LeafList::iterator dw_itr = (*oitr)->_leaves.begin(); + dw_itr != (*oitr)->_leaves.end(); + ++dw_itr) + { + RenderLeaf* rl = dw_itr->get(); + rl->render(state,previous); + previous = rl; + + } + } + + + // draw post bins. for(; itr!=_bins.end(); ++itr) { itr->second->draw(state,previous); } -} -void RenderBin::draw_local(osg::State& state,RenderLeaf*& previous) -{ - // draw local bin. - - if (!_renderLeafList.empty()) - { - // draw fine grained ordering. - for(RenderLeafList::iterator itr= _renderLeafList.begin(); - itr!= _renderLeafList.end(); - ++itr) - { - RenderLeaf* rl = *itr; - rl->render(state,previous); - previous = rl; - } - } - else - { - // draw coarse grained ordering. - for(RenderGraphList::iterator oitr=_renderGraphList.begin(); - oitr!=_renderGraphList.end(); - ++oitr) - { - for(RenderGraph::LeafList::iterator dw_itr = (*oitr)->_leaves.begin(); - dw_itr != (*oitr)->_leaves.end(); - ++dw_itr) - { - RenderLeaf* rl = dw_itr->get(); - rl->render(state,previous); - previous = rl; - - } - } - } } // stats diff --git a/src/osgUtil/RenderStage.cpp b/src/osgUtil/RenderStage.cpp index 388738035..d75e836ca 100644 --- a/src/osgUtil/RenderStage.cpp +++ b/src/osgUtil/RenderStage.cpp @@ -76,6 +76,12 @@ void RenderStage::drawPreRenderStages(osg::State& state,RenderLeaf*& previous) } void RenderStage::draw(osg::State& state,RenderLeaf*& previous) +{ + drawPreRenderStages(state,previous); + RenderBin::draw(state,previous); +} + +void RenderStage::drawImplementation(osg::State& state,RenderLeaf*& previous) { if (_stageDrawnThisFrame) return; @@ -129,7 +135,7 @@ void RenderStage::draw(osg::State& state,RenderLeaf*& previous) if (_renderStageLighting.valid()) _renderStageLighting->draw(state,previous); // draw the children and local. - RenderBin::draw(state,previous); + RenderBin::drawImplementation(state,previous); // now reset the state so its back in its default state. if (previous)