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:
parent
ee8ded2a90
commit
e1b084749e
@ -62,11 +62,14 @@ echo osgcube
|
|||||||
osgcube
|
osgcube
|
||||||
more memleaks.log
|
more memleaks.log
|
||||||
|
|
||||||
|
echo osgcubemap glider.osg
|
||||||
|
osgcubemap glider.osg
|
||||||
|
more memleaks.log
|
||||||
|
|
||||||
echo osgclip
|
echo osgclip
|
||||||
osgclip cow.osg
|
osgclip cow.osg
|
||||||
more memleaks.log
|
more memleaks.log
|
||||||
|
|
||||||
|
|
||||||
echo osghud dumptruck.osg
|
echo osghud dumptruck.osg
|
||||||
osghud dumptruck.osg
|
osghud dumptruck.osg
|
||||||
more memleaks.log
|
more memleaks.log
|
||||||
|
@ -43,6 +43,9 @@ osgbillboard
|
|||||||
echo osgcube
|
echo osgcube
|
||||||
osgcube
|
osgcube
|
||||||
|
|
||||||
|
echo osgcubemap glider.osg
|
||||||
|
osgcubemap glider.osg
|
||||||
|
|
||||||
echo osgclip
|
echo osgclip
|
||||||
osgclip cow.osg
|
osgclip cow.osg
|
||||||
|
|
||||||
|
@ -65,27 +65,40 @@ class OSGUTIL_EXPORT RenderBin : public osg::Object
|
|||||||
|
|
||||||
void sort();
|
void sort();
|
||||||
|
|
||||||
|
virtual void sortImplementation();
|
||||||
|
|
||||||
void setSortMode(SortMode mode);
|
void setSortMode(SortMode mode);
|
||||||
SortMode getSortMode() const { return _sortMode; }
|
SortMode getSortMode() const { return _sortMode; }
|
||||||
|
|
||||||
virtual void sort_local();
|
virtual void sortByState();
|
||||||
virtual void sort_local_by_state();
|
virtual void sortFrontToBack();
|
||||||
virtual void sort_local_front_to_back();
|
virtual void sortBackToFront();
|
||||||
virtual void sort_local_back_to_front();
|
|
||||||
|
|
||||||
struct SortCallback : public osg::Referenced
|
struct SortCallback : public osg::Referenced
|
||||||
{
|
{
|
||||||
virtual void sort(RenderBin*) = 0;
|
virtual void sortImplementation(RenderBin*) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void setSortLocalCallback(SortCallback* sortCallback) { _sortLocalCallback = sortCallback; }
|
void setSortCallback(SortCallback* sortCallback) { _sortCallback = sortCallback; }
|
||||||
SortCallback* getSortLocalCallback() { return _sortLocalCallback.get(); }
|
SortCallback* getSortCallback() { return _sortCallback.get(); }
|
||||||
const SortCallback* getSortLocalCallback() const { return _sortLocalCallback.get(); }
|
const SortCallback* getSortCallback() const { return _sortCallback.get(); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual void draw(osg::State& state,RenderLeaf*& previous);
|
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. */
|
/** extract stats for current draw list. */
|
||||||
bool getStats(osg::Statistics* primStats);
|
bool getStats(osg::Statistics* primStats);
|
||||||
@ -107,8 +120,9 @@ class OSGUTIL_EXPORT RenderBin : public osg::Object
|
|||||||
|
|
||||||
|
|
||||||
SortMode _sortMode;
|
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;
|
typedef std::map< std::string, osg::ref_ptr<RenderBin> > RenderBinPrototypeList;
|
||||||
static RenderBinPrototypeList s_renderBinPrototypeList;
|
static RenderBinPrototypeList s_renderBinPrototypeList;
|
||||||
@ -143,3 +157,4 @@ class RegisterRenderBinProxy
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -109,8 +109,10 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void drawPreRenderStages(osg::State& state,RenderLeaf*& previous);
|
virtual void drawPreRenderStages(osg::State& state,RenderLeaf*& previous);
|
||||||
|
|
||||||
virtual void draw(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);
|
void addToDependencyList(RenderStage* rs);
|
||||||
|
|
||||||
|
@ -663,7 +663,7 @@ int main( int argc, char **argv )
|
|||||||
root->addChild( createScene() );
|
root->addChild( createScene() );
|
||||||
root->addChild( createBackground() );
|
root->addChild( createBackground() );
|
||||||
|
|
||||||
osgDB::writeNodeFile(*root,"geoemtry.osg");
|
//osgDB::writeNodeFile(*root,"geoemtry.osg");
|
||||||
|
|
||||||
|
|
||||||
// add model to viewer.
|
// add model to viewer.
|
||||||
|
@ -35,7 +35,7 @@ struct SortByMinimumDistanceFunctor
|
|||||||
|
|
||||||
struct MySortCallback : public osgUtil::RenderBin::SortCallback
|
struct MySortCallback : public osgUtil::RenderBin::SortCallback
|
||||||
{
|
{
|
||||||
virtual void sort(osgUtil::RenderBin* renderbin)
|
virtual void sortImplementation(osgUtil::RenderBin* renderbin)
|
||||||
{
|
{
|
||||||
|
|
||||||
osgUtil::RenderBin::RenderGraphList& renderGraphList = renderbin->_renderGraphList;
|
osgUtil::RenderBin::RenderGraphList& renderGraphList = renderbin->_renderGraphList;
|
||||||
@ -164,7 +164,7 @@ int main( int argc, char **argv )
|
|||||||
osgUtil::RenderStage* renderstage = viewer.getViewportSceneView(0)->getRenderStage();
|
osgUtil::RenderStage* renderstage = viewer.getViewportSceneView(0)->getRenderStage();
|
||||||
if (renderstage)
|
if (renderstage)
|
||||||
{
|
{
|
||||||
renderstage->setSortLocalCallback(new MySortCallback);
|
renderstage->setSortCallback(new MySortCallback);
|
||||||
// renderstage->setSortMode(osgUtil::RenderBin::SORT_FRONT_TO_BACK);
|
// renderstage->setSortMode(osgUtil::RenderBin::SORT_FRONT_TO_BACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,8 @@ RenderBin::RenderBin(const RenderBin& rhs,const CopyOp& copyop):
|
|||||||
_renderGraphList(rhs._renderGraphList),
|
_renderGraphList(rhs._renderGraphList),
|
||||||
_renderLeafList(rhs._renderLeafList),
|
_renderLeafList(rhs._renderLeafList),
|
||||||
_sortMode(rhs._sortMode),
|
_sortMode(rhs._sortMode),
|
||||||
_sortLocalCallback(rhs._sortLocalCallback)
|
_sortCallback(rhs._sortCallback),
|
||||||
|
_drawCallback(rhs._drawCallback)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -93,11 +94,11 @@ void RenderBin::sort()
|
|||||||
itr->second->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)
|
void RenderBin::setSortMode(SortMode mode)
|
||||||
@ -105,18 +106,18 @@ void RenderBin::setSortMode(SortMode mode)
|
|||||||
_sortMode = mode;
|
_sortMode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderBin::sort_local()
|
void RenderBin::sortImplementation()
|
||||||
{
|
{
|
||||||
switch(_sortMode)
|
switch(_sortMode)
|
||||||
{
|
{
|
||||||
case(SORT_BY_STATE):
|
case(SORT_BY_STATE):
|
||||||
sort_local_by_state();
|
sortByState();
|
||||||
break;
|
break;
|
||||||
case(SORT_FRONT_TO_BACK):
|
case(SORT_FRONT_TO_BACK):
|
||||||
sort_local_front_to_back();
|
sortFrontToBack();
|
||||||
break;
|
break;
|
||||||
case(SORT_BACK_TO_FRONT):
|
case(SORT_BACK_TO_FRONT):
|
||||||
sort_local_back_to_front();
|
sortBackToFront();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
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
|
// 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
|
// appears to cost more to do than it saves in draw. The contents of
|
||||||
// the RenderGraph leaves is already coasrse grained sorted, this
|
// the RenderGraph leaves is already coasrse grained sorted, this
|
||||||
// sorting is as a function of the cull traversal.
|
// sorting is as a function of the cull traversal.
|
||||||
// cout << "doing sort_local_by_state "<<this<<endl;
|
// cout << "doing sortByState "<<this<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FrontToBackSortFunctor
|
struct FrontToBackSortFunctor
|
||||||
@ -149,7 +150,7 @@ struct FrontToBackSortFunctor
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void RenderBin::sort_local_front_to_back()
|
void RenderBin::sortFrontToBack()
|
||||||
{
|
{
|
||||||
copyLeavesFromRenderGraphListToRenderLeafList();
|
copyLeavesFromRenderGraphListToRenderLeafList();
|
||||||
|
|
||||||
@ -167,7 +168,7 @@ struct BackToFrontSortFunctor
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void RenderBin::sort_local_back_to_front()
|
void RenderBin::sortBackToFront()
|
||||||
{
|
{
|
||||||
copyLeavesFromRenderGraphListToRenderLeafList();
|
copyLeavesFromRenderGraphListToRenderLeafList();
|
||||||
|
|
||||||
@ -204,6 +205,9 @@ void RenderBin::copyLeavesFromRenderGraphListToRenderLeafList()
|
|||||||
_renderLeafList.push_back(dw_itr->get());
|
_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)
|
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)
|
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.
|
// draw first set of draw bins.
|
||||||
RenderBinList::iterator itr;
|
RenderBinList::iterator itr;
|
||||||
@ -247,51 +260,45 @@ void RenderBin::draw(osg::State& state,RenderLeaf*& previous)
|
|||||||
itr->second->draw(state,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(;
|
for(;
|
||||||
itr!=_bins.end();
|
itr!=_bins.end();
|
||||||
++itr)
|
++itr)
|
||||||
{
|
{
|
||||||
itr->second->draw(state,previous);
|
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
|
// stats
|
||||||
|
@ -76,6 +76,12 @@ void RenderStage::drawPreRenderStages(osg::State& state,RenderLeaf*& previous)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RenderStage::draw(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;
|
if (_stageDrawnThisFrame) return;
|
||||||
|
|
||||||
@ -129,7 +135,7 @@ void RenderStage::draw(osg::State& state,RenderLeaf*& previous)
|
|||||||
if (_renderStageLighting.valid()) _renderStageLighting->draw(state,previous);
|
if (_renderStageLighting.valid()) _renderStageLighting->draw(state,previous);
|
||||||
|
|
||||||
// draw the children and local.
|
// draw the children and local.
|
||||||
RenderBin::draw(state,previous);
|
RenderBin::drawImplementation(state,previous);
|
||||||
|
|
||||||
// now reset the state so its back in its default state.
|
// now reset the state so its back in its default state.
|
||||||
if (previous)
|
if (previous)
|
||||||
|
Loading…
Reference in New Issue
Block a user