Improved stats handling, and fixed a couple of stats bugs.

This commit is contained in:
Robert Osfield
2005-12-15 17:14:40 +00:00
parent 72554ca27e
commit 2815622c35
8 changed files with 71 additions and 74 deletions

View File

@@ -134,9 +134,7 @@ class OSGUTIL_EXPORT RenderBin : public osg::Object
const DrawCallback* getDrawCallback() const { return _drawCallback.get(); }
/** Extract stats for current draw list. */
bool getStats(Statistics* primStats);
void getPrims(Statistics* primStats);
bool getPrims(Statistics* primStats, int nbin);
bool getStats(Statistics& primStats) const;
void copyLeavesFromStateGraphListToRenderLeafList();

View File

@@ -195,10 +195,11 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin
void addToDependencyList(RenderStage* rs) { addPreRenderStage(rs); }
void addPreRenderStage(RenderStage* rs);
void addPostRenderStage(RenderStage* rs);
/** Extract stats for current draw list. */
bool getStats(Statistics* primStats);
bool getStats(Statistics& stats) const;
protected:

View File

@@ -456,7 +456,7 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced, public osg::CullSetting
virtual void flushDeletedGLObjects(double& availableTime);
/** Extract stats for current draw list. */
bool getStats(Statistics* primStats);
bool getStats(Statistics& primStats);
protected:

View File

@@ -62,8 +62,13 @@ class Statistics : public osg::PrimitiveFunctor
void reset()
{
numDrawables=0, nummat=0; depth=0; stattype=STAT_NONE;
nlights=0; nbins=0; nimpostor=0;
numDrawables=0;
nummat=0;
depth=0;
stattype=STAT_NONE;
nlights=0;
nbins=0;
nimpostor=0;
_vertexCount=0;
_primitiveCount.clear();
@@ -131,6 +136,8 @@ class Statistics : public osg::PrimitiveFunctor
{
_primitives_count[_currentPrimitiveFunctorMode] +=
_calculate_primitives_number_by_mode(_currentPrimitiveFunctorMode, _number_of_vertexes);
_vertexCount += _number_of_vertexes;
}
void addDrawable() { numDrawables++;}

View File

@@ -619,7 +619,7 @@ void ViewerEventHandler::StatsAndHelpDrawCallback::displayStats()
shitr != _veh->getOsgCameraGroup()->getSceneHandlerList().end();
++shitr)
{
(*shitr)->getSceneView()->getStats(&stats);
(*shitr)->getSceneView()->getStats(stats);
}
unsigned int primitives = 0;

View File

@@ -399,95 +399,66 @@ void RenderBin::drawImplementation(osg::State& state,RenderLeaf*& previous)
}
// stats
bool RenderBin::getStats(Statistics* primStats)
bool RenderBin::getStats(Statistics& stats) const
{
stats.addBins(1);
// different by return type - collects the stats in this renderrBin
bool somestats=false;
bool statsCollected = false;
// draw fine grained ordering.
for(RenderLeafList::iterator dw_itr = _renderLeafList.begin();
for(RenderLeafList::const_iterator dw_itr = _renderLeafList.begin();
dw_itr != _renderLeafList.end();
++dw_itr)
{
RenderLeaf* rl = *dw_itr;
Drawable* dw= rl->_drawable;
primStats->addDrawable(); // number of geosets
const RenderLeaf* rl = *dw_itr;
const Drawable* dw= rl->_drawable;
stats.addDrawable(); // number of geosets
if (rl->_modelview.get())
{
primStats->addMatrix(); // number of matrices
stats.addMatrix(); // number of matrices
}
if (dw)
{
// then tot up the primtive types and no vertices.
dw->accept(*primStats); // use sub-class to find the stats for each drawable
dw->accept(stats); // use sub-class to find the stats for each drawable
}
somestats = true;
statsCollected = true;
}
for(StateGraphList::iterator oitr=_stateGraphList.begin();
for(StateGraphList::const_iterator oitr=_stateGraphList.begin();
oitr!=_stateGraphList.end();
++oitr)
{
for(StateGraph::LeafList::iterator dw_itr = (*oitr)->_leaves.begin();
for(StateGraph::LeafList::const_iterator dw_itr = (*oitr)->_leaves.begin();
dw_itr != (*oitr)->_leaves.end();
++dw_itr)
{
RenderLeaf* rl = dw_itr->get();
Drawable* dw= rl->_drawable;
primStats->addDrawable(); // number of geosets
if (rl->_modelview.get()) primStats->addMatrix(); // number of matrices
const RenderLeaf* rl = dw_itr->get();
const Drawable* dw= rl->_drawable;
stats.addDrawable(); // number of geosets
if (rl->_modelview.get()) stats.addMatrix(); // number of matrices
if (dw)
{
// then tot up the primtive types and no vertices.
dw->accept(*primStats); // use sub-class to find the stats for each drawable
dw->accept(stats); // use sub-class to find the stats for each drawable
}
}
somestats=true;
statsCollected = true;
}
return somestats;
}
void RenderBin::getPrims(Statistics* primStats)
{
static int ndepth;
ndepth++;
for(RenderBinList::iterator itr = _bins.begin();
// now collects stats for any subbins.
for(RenderBinList::const_iterator itr = _bins.begin();
itr!=_bins.end();
++itr)
{
primStats->addBins(1);
itr->second->getPrims(primStats);
if (itr->second->getStats(stats))
{
statsCollected = true;
}
}
getStats(primStats);
ndepth--;
}
bool RenderBin::getPrims(Statistics* primStats, 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;
}
ok=true;
ndepth--;
return ok;
return statsCollected;
}

View File

@@ -886,13 +886,33 @@ void RenderStage::drawPostRenderStages(osg::State& state,RenderLeaf*& previous)
}
// Statistics features
bool RenderStage::getStats(Statistics* primStats)
bool RenderStage::getStats(Statistics& stats) const
{
if (_renderStageLighting.valid())
bool statsCollected = false;
for(RenderStageList::const_iterator pre_itr = _preRenderList.begin();
pre_itr != _preRenderList.end();
++pre_itr)
{
// need to re-implement by checking for lights in the scene
// by downcasting the positioned attribute list. RO. May 2002.
//primStats->addLight(_renderStageLighting->_lightList.size());
if ((*pre_itr)->getStats(stats))
{
statsCollected = true;
}
}
return RenderBin::getStats(primStats);
for(RenderStageList::const_iterator post_itr = _postRenderList.begin();
post_itr != _postRenderList.end();
++post_itr)
{
if ((*post_itr)->getStats(stats))
{
statsCollected = true;
}
}
if (RenderBin::getStats(stats))
{
statsCollected = true;
}
return statsCollected;
}

View File

@@ -1371,7 +1371,7 @@ void SceneView::getViewMatrixAsLookAt(Vec3& eye,Vec3& center,Vec3& up,float look
getViewMatrix().getLookAt(eye,center,up,lookDistance);
}
bool SceneView::getStats(Statistics* primStats)
bool SceneView::getStats(Statistics& stats)
{
if (_displaySettings.valid() && _displaySettings->getStereo())
{
@@ -1384,18 +1384,18 @@ bool SceneView::getStats(Statistics* primStats)
case(osg::DisplaySettings::VERTICAL_INTERLACE):
case(osg::DisplaySettings::HORIZONTAL_INTERLACE):
{
bool resultLeft = _renderStageLeft->getStats(primStats);
bool resultRight = _renderStageRight->getStats(primStats);
bool resultLeft = _renderStageLeft->getStats(stats);
bool resultRight = _renderStageRight->getStats(stats);
return resultLeft && resultRight;
}
case(osg::DisplaySettings::RIGHT_EYE):
case(osg::DisplaySettings::LEFT_EYE):
default:
return _renderStage->getStats(primStats);
return _renderStage->getStats(stats);
}
}
else
{
return _renderStage->getStats(primStats);
return _renderStage->getStats(stats);
}
}