From 7c38643a77c5e72177d5487bafb8729054f7bc41 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 20 Apr 2010 10:59:44 +0000 Subject: [PATCH] From Tim Moore, "I noticed that the "Materials" statistic in the camera scene stats display seemed to be identical to the number of drawables. In fact, it displays the nummat member of osgUtil::Statistics, but that variable has nothing to do with materials. nummat tracks the number of matrices associated with Drawable objects in a RenderBin; as I understand it, Drawables pretty much always have a model-view matrix tied to them in RenderBins, so this statistic doesn't seem very useful. So, I added statistics for the number of StateGraph objects in RenderBins and also for the number of Drawables in the "fine grain ordering" of RenderBins. The latter corresponds to the number of Drawables in the scene that are sorted by some criteria other than graphics state; usually that is distance for semi-transparent objects, though it could be traversal order. These two statistics give an idea of the number of graphic state changes happening in a visible scene: each StateGraph implies a state change, and there could be a change for each sorted object too. You can also subtract the number of sorted Drawables from the total number of Drawables and get an idea of how many Drawables are being drawn for each StateGraph. " --- include/osgUtil/Statistics | 5 ++++- src/osgUtil/RenderBin.cpp | 4 ++-- src/osgUtil/Statistics.cpp | 4 ++++ src/osgViewer/Renderer.cpp | 6 ++++-- src/osgViewer/StatsHandler.cpp | 6 ++++-- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/include/osgUtil/Statistics b/include/osgUtil/Statistics index 96a84f4e4..f2ad6d337 100644 --- a/include/osgUtil/Statistics +++ b/include/osgUtil/Statistics @@ -110,6 +110,8 @@ class OSGUTIL_EXPORT Statistics : public osg::PrimitiveFunctor void addBins(int np) { nbins+= np; } void setBinNo(int n) { _binNo=n;} + void addStateGraphs(int n) { numStateGraphs += n; } + void addOrderedLeaves(int n) { numOrderedLeaves += n; } void add(const Statistics& stats); @@ -123,12 +125,13 @@ class OSGUTIL_EXPORT Statistics : public osg::PrimitiveFunctor /// deprecated PrimitiveCountMap::iterator GetPrimitivesEnd() { return _primitives_count.end(); } - int numDrawables, nummat, nbins; + int numDrawables, nummat, nbins, numStateGraphs; int nlights; int depth; // depth into bins - eg 1.1,1.2,1.3 etc int _binNo; StatsType stattype; int nimpostor; // number of impostors rendered + int numOrderedLeaves; // leaves from RenderBin fine grain ordering unsigned int _vertexCount; PrimitiveValueMap _primitiveCount; diff --git a/src/osgUtil/RenderBin.cpp b/src/osgUtil/RenderBin.cpp index 803b97c58..39d84b0c9 100644 --- a/src/osgUtil/RenderBin.cpp +++ b/src/osgUtil/RenderBin.cpp @@ -522,7 +522,7 @@ bool RenderBin::getStats(Statistics& stats) const // different by return type - collects the stats in this renderrBin bool statsCollected = false; - + stats.addOrderedLeaves(_renderLeafList.size()); // draw fine grained ordering. for(RenderLeafList::const_iterator dw_itr = _renderLeafList.begin(); dw_itr != _renderLeafList.end(); @@ -543,7 +543,7 @@ bool RenderBin::getStats(Statistics& stats) const } statsCollected = true; } - + stats.addStateGraphs(_stateGraphList.size()); for(StateGraphList::const_iterator oitr=_stateGraphList.begin(); oitr!=_stateGraphList.end(); ++oitr) diff --git a/src/osgUtil/Statistics.cpp b/src/osgUtil/Statistics.cpp index 51d47836d..719402111 100644 --- a/src/osgUtil/Statistics.cpp +++ b/src/osgUtil/Statistics.cpp @@ -43,6 +43,8 @@ void Statistics::reset() nlights=0; nbins=0; nimpostor=0; + numStateGraphs=0; + numOrderedLeaves=0; _vertexCount=0; _primitiveCount.clear(); @@ -111,6 +113,8 @@ void Statistics::add(const Statistics& stats) nlights += stats.nlights; nbins += stats.nbins; nimpostor += stats.nimpostor; + numStateGraphs += stats.numStateGraphs; + numOrderedLeaves += stats.numOrderedLeaves; _vertexCount += stats._vertexCount; // _primitiveCount += stats._primitiveCount; diff --git a/src/osgViewer/Renderer.cpp b/src/osgViewer/Renderer.cpp index f26c9d7f0..20dad3625 100644 --- a/src/osgViewer/Renderer.cpp +++ b/src/osgViewer/Renderer.cpp @@ -380,8 +380,9 @@ void Renderer::cull() stats->setAttribute(frameNumber, "Visible number of lights", static_cast(sceneStats.nlights)); stats->setAttribute(frameNumber, "Visible number of render bins", static_cast(sceneStats.nbins)); stats->setAttribute(frameNumber, "Visible depth", static_cast(sceneStats.depth)); - stats->setAttribute(frameNumber, "Visible number of materials", static_cast(sceneStats.nummat)); + stats->setAttribute(frameNumber, "Number of StateGraphs", static_cast(sceneStats.numStateGraphs)); stats->setAttribute(frameNumber, "Visible number of impostors", static_cast(sceneStats.nimpostor)); + stats->setAttribute(frameNumber, "Number of ordered leaves", static_cast(sceneStats.numOrderedLeaves)); osgUtil::Statistics::PrimitiveCountMap& pcm = sceneStats.getPrimitiveCountMap(); stats->setAttribute(frameNumber, "Visible number of GL_POINTS", static_cast(pcm[GL_POINTS])); @@ -598,8 +599,9 @@ void Renderer::cull_draw() stats->setAttribute(frameNumber, "Visible number of lights", static_cast(sceneStats.nlights)); stats->setAttribute(frameNumber, "Visible number of render bins", static_cast(sceneStats.nbins)); stats->setAttribute(frameNumber, "Visible depth", static_cast(sceneStats.depth)); - stats->setAttribute(frameNumber, "Visible number of materials", static_cast(sceneStats.nummat)); + stats->setAttribute(frameNumber, "Number of StateGraphs", static_cast(sceneStats.numStateGraphs)); stats->setAttribute(frameNumber, "Visible number of impostors", static_cast(sceneStats.nimpostor)); + stats->setAttribute(frameNumber, "Number of ordered leaves", static_cast(sceneStats.numOrderedLeaves)); } #if 0 diff --git a/src/osgViewer/StatsHandler.cpp b/src/osgViewer/StatsHandler.cpp index 93e3bd20c..e74ea67a1 100644 --- a/src/osgViewer/StatsHandler.cpp +++ b/src/osgViewer/StatsHandler.cpp @@ -412,9 +412,10 @@ struct CameraSceneStatsTextDrawCallback : public virtual osg::Drawable::DrawCall STATS_ATTRIBUTE("Visible number of lights") STATS_ATTRIBUTE("Visible number of render bins") STATS_ATTRIBUTE("Visible depth") - STATS_ATTRIBUTE("Visible number of materials") + STATS_ATTRIBUTE("Number of StateGraphs") STATS_ATTRIBUTE("Visible number of impostors") STATS_ATTRIBUTE("Visible number of drawables") + STATS_ATTRIBUTE("Number of ordered leaves") STATS_ATTRIBUTE("Visible vertex count") STATS_ATTRIBUTE("Visible number of GL_POINTS") @@ -1417,9 +1418,10 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer) viewStr << "Lights" << std::endl; viewStr << "Bins" << std::endl; viewStr << "Depth" << std::endl; - viewStr << "Materials" << std::endl; + viewStr << "State graphs" << std::endl; viewStr << "Imposters" << std::endl; viewStr << "Drawables" << std::endl; + viewStr << "Sorted" << std::endl; viewStr << "Vertices" << std::endl; viewStr << "Points" << std::endl; viewStr << "Lines" << std::endl;