2001-09-20 05:19:47 +08:00
|
|
|
#include <osgUtil/RenderBin>
|
|
|
|
#include <osgUtil/RenderStage>
|
|
|
|
|
2001-10-04 22:35:42 +08:00
|
|
|
#include <algorithm>
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
using namespace osg;
|
|
|
|
using namespace osgUtil;
|
|
|
|
|
|
|
|
// register a RenderStage prototype with the RenderBin prototype list.
|
|
|
|
RegisterRenderBinProxy<RenderBin> s_registerRenderBinProxy;
|
|
|
|
|
2002-01-16 18:36:20 +08:00
|
|
|
#ifdef __DARWIN_OSX__
|
|
|
|
// PJA 10/1/02 - this is a hack to get OS X to build, if this code is included in DepthSortedBin.cpp it isnt executed
|
|
|
|
// register a RenderStage prototype with the RenderBin prototype list.
|
|
|
|
#include <osgUtil/DepthSortedBin>
|
|
|
|
RegisterRenderBinProxy<DepthSortedBin> s_registerDepthSortedBinProxy;
|
|
|
|
#endif
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
typedef std::map< std::string, osg::ref_ptr<RenderBin> > RenderBinPrototypeList;
|
|
|
|
|
|
|
|
RenderBinPrototypeList* renderBinPrototypeList()
|
|
|
|
{
|
|
|
|
static RenderBinPrototypeList s_renderBinPrototypeList;
|
|
|
|
return &s_renderBinPrototypeList;
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderBin* RenderBin::createRenderBin(const std::string& binName)
|
|
|
|
{
|
2001-12-24 22:12:38 +08:00
|
|
|
// cout << "creating RB "<<binName<<std::endl;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
RenderBinPrototypeList::iterator itr = renderBinPrototypeList()->find(binName);
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
if (itr != renderBinPrototypeList()->end()) return dynamic_cast<RenderBin*>(itr->second->cloneType());
|
2001-09-20 05:19:47 +08:00
|
|
|
else return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderBin::addRenderBinPrototype(RenderBin* proto)
|
|
|
|
{
|
|
|
|
if (proto)
|
|
|
|
{
|
|
|
|
(*renderBinPrototypeList())[proto->className()] = proto;
|
2001-12-24 22:12:38 +08:00
|
|
|
// cout << "Adding RB "<<proto->className()<<std::endl;
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderBin::removeRenderBinPrototype(RenderBin* proto)
|
|
|
|
{
|
|
|
|
if (proto)
|
|
|
|
{
|
|
|
|
RenderBinPrototypeList::iterator itr = renderBinPrototypeList()->find(proto->className());
|
|
|
|
if (itr != renderBinPrototypeList()->end()) renderBinPrototypeList()->erase(itr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderBin::RenderBin()
|
|
|
|
{
|
|
|
|
_binNum = 0;
|
|
|
|
_parent = NULL;
|
|
|
|
_stage = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderBin::~RenderBin()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderBin::reset()
|
|
|
|
{
|
|
|
|
_renderGraphList.clear();
|
|
|
|
_bins.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderBin::sort()
|
|
|
|
{
|
|
|
|
for(RenderBinList::iterator itr = _bins.begin();
|
|
|
|
itr!=_bins.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
itr->second->sort();
|
|
|
|
}
|
|
|
|
sort_local();
|
|
|
|
}
|
|
|
|
|
2001-10-04 22:35:42 +08:00
|
|
|
|
|
|
|
struct StateSortFunctor
|
|
|
|
{
|
|
|
|
const bool operator() (const RenderGraph* lhs,const RenderGraph* rhs)
|
|
|
|
{
|
|
|
|
return (*(lhs->_stateset)<*(rhs->_stateset));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RenderBin::sort_local()
|
|
|
|
{
|
|
|
|
// now sort the list into acending depth order.
|
|
|
|
// std::sort(_renderGraphList.begin(),_renderGraphList.end(),StateSortFunctor());
|
|
|
|
}
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
RenderBin* RenderBin::find_or_insert(int binNum,const std::string& binName)
|
|
|
|
{
|
|
|
|
// search for appropriate bin.
|
|
|
|
RenderBinList::iterator itr = _bins.find(binNum);
|
|
|
|
if (itr!=_bins.end()) return itr->second.get();
|
|
|
|
|
|
|
|
// create a renderin bin and insert into bin list.
|
|
|
|
RenderBin* rb = RenderBin::createRenderBin(binName);
|
|
|
|
if (rb)
|
|
|
|
{
|
|
|
|
|
|
|
|
RenderStage* rs = dynamic_cast<RenderStage*>(rb);
|
|
|
|
if (rs)
|
|
|
|
{
|
|
|
|
rs->_binNum = binNum;
|
|
|
|
rs->_parent = NULL;
|
|
|
|
rs->_stage = rs;
|
|
|
|
_stage->addToDependencyList(rs);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->_binNum = binNum;
|
|
|
|
rb->_parent = this;
|
|
|
|
rb->_stage = _stage;
|
|
|
|
_bins[binNum] = rb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderBin::draw(osg::State& state,RenderLeaf*& previous)
|
|
|
|
{
|
|
|
|
// draw first set of draw bins.
|
|
|
|
RenderBinList::iterator itr;
|
|
|
|
for(itr = _bins.begin();
|
|
|
|
itr->first<0 && itr!=_bins.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
itr->second->draw(state,previous);
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_local(state,previous);
|
|
|
|
|
|
|
|
for(;
|
|
|
|
itr!=_bins.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
itr->second->draw(state,previous);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderBin::draw_local(osg::State& state,RenderLeaf*& previous)
|
|
|
|
{
|
|
|
|
// draw local bin.
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-10-23 06:02:47 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
// stats
|
2001-11-05 03:29:20 +08:00
|
|
|
bool RenderBin::getStats(osg::Statistics* primStats)
|
|
|
|
{ // different by return type - collects the stats in this renderrBin
|
|
|
|
bool somestats=false;
|
2001-09-20 05:19:47 +08:00
|
|
|
for(RenderGraphList::iterator oitr=_renderGraphList.begin();
|
2001-11-05 03:29:20 +08:00
|
|
|
oitr!=_renderGraphList.end();
|
|
|
|
++oitr)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
for(RenderGraph::LeafList::iterator dw_itr = (*oitr)->_leaves.begin();
|
|
|
|
dw_itr != (*oitr)->_leaves.end();
|
|
|
|
++dw_itr)
|
|
|
|
{
|
|
|
|
RenderLeaf* rl = dw_itr->get();
|
|
|
|
Drawable* dw= rl->_drawable;
|
2001-11-05 03:29:20 +08:00
|
|
|
primStats->addOpaque(); // number of geosets
|
|
|
|
if (rl->_matrix.get()) primStats->addMatrix(); // number of matrices
|
2001-09-20 05:19:47 +08:00
|
|
|
if (dw) { // then tot up the types 1-14
|
2001-11-05 03:29:20 +08:00
|
|
|
dw->getStats(*primStats); // use sub-class to find the stats for each drawable
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
}
|
2001-11-05 03:29:20 +08:00
|
|
|
somestats=true;
|
|
|
|
}
|
|
|
|
return somestats;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderBin::getPrims(osg::Statistics* primStats)
|
|
|
|
{
|
|
|
|
static int ndepth;
|
|
|
|
ndepth++;
|
|
|
|
for(RenderBinList::iterator itr = _bins.begin();
|
|
|
|
itr!=_bins.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
primStats->addBins(1);
|
|
|
|
itr->second->getPrims(primStats);
|
|
|
|
}
|
|
|
|
getStats(primStats);
|
|
|
|
ndepth--;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RenderBin::getPrims(osg::Statistics* primStats, const int nbin)
|
|
|
|
{ // collect stats for array of bins, maximum nbin
|
|
|
|
// (which will be modified on next call if array of primStats is too small);
|
|
|
|
// return 1 for OK;
|
|
|
|
static int ndepth;
|
|
|
|
bool ok=false;
|
|
|
|
ndepth++;
|
|
|
|
int nb=primStats[0].getBins();
|
|
|
|
if (nb<nbin)
|
|
|
|
{ // if statement to protect against writing to bins beyond the maximum seen before
|
|
|
|
primStats[nb].setBinNo(nb);
|
|
|
|
primStats[nb].setDepth(ndepth);
|
|
|
|
getStats(primStats+nb);
|
|
|
|
}
|
|
|
|
primStats[0].addBins(1);
|
|
|
|
for(RenderBinList::iterator itr = _bins.begin();
|
|
|
|
itr!=_bins.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
if (itr->second->getPrims(primStats, nbin)) ok = true;
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
2001-11-05 03:29:20 +08:00
|
|
|
ok=true;
|
|
|
|
ndepth--;
|
|
|
|
return ok;
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|