Renamed the RenderBin::sort_local to sortImplementation(),

draw_local to drawImplementation() and added a new RenderBin::DrawCallback().

Added osgcubemap to the Make/ test scripts.
This commit is contained in:
Robert Osfield 2002-10-17 13:48:46 +00:00
parent ee8ded2a90
commit e1b084749e
8 changed files with 100 additions and 64 deletions

View File

@ -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

View File

@ -43,6 +43,9 @@ osgbillboard
echo osgcube
osgcube
echo osgcubemap glider.osg
osgcubemap glider.osg
echo osgclip
osgclip cow.osg

View File

@ -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<SortCallback> _sortLocalCallback;
osg::ref_ptr<SortCallback> _sortCallback;
osg::ref_ptr<DrawCallback> _drawCallback;
typedef std::map< std::string, osg::ref_ptr<RenderBin> > RenderBinPrototypeList;
static RenderBinPrototypeList s_renderBinPrototypeList;
@ -143,3 +157,4 @@ class RegisterRenderBinProxy
#endif

View File

@ -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);

View File

@ -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.

View File

@ -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);
}

View File

@ -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 "<<this<<endl;
// cout << "doing sortByState "<<this<<endl;
}
struct FrontToBackSortFunctor
@ -149,7 +150,7 @@ struct FrontToBackSortFunctor
};
void RenderBin::sort_local_front_to_back()
void RenderBin::sortFrontToBack()
{
copyLeavesFromRenderGraphListToRenderLeafList();
@ -167,7 +168,7 @@ struct BackToFrontSortFunctor
}
};
void RenderBin::sort_local_back_to_front()
void RenderBin::sortBackToFront()
{
copyLeavesFromRenderGraphListToRenderLeafList();
@ -204,6 +205,9 @@ void RenderBin::copyLeavesFromRenderGraphListToRenderLeafList()
_renderLeafList.push_back(dw_itr->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

View File

@ -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)