Refactored the view stats.

This commit is contained in:
Robert Osfield 2009-01-27 13:23:20 +00:00
parent 1787efc9a3
commit 29157f24d9
13 changed files with 269 additions and 106 deletions

View File

@ -16,6 +16,7 @@
#include <osg/Camera>
#include <osg/Light>
#include <osg/Stats>
#include <OpenThreads/Mutex>
@ -38,6 +39,17 @@ class OSG_EXPORT View : public virtual osg::Object
/** Take all the settings, Camera and Slaves from the passed in view, leaving it empty. */
virtual void take(View& rhs);
/** Set the Stats object used for collect various frame related timing and scene graph stats.*/
void setStats(osg::Stats* stats) { _stats = stats; }
/** Get the Viewers Stats object.*/
osg::Stats* getStats() { return _stats.get(); }
/** Get the Viewers Stats object.*/
const osg::Stats* getStats() const { return _stats.get(); }
/** Options for controlling the global lighting used for the view.*/
enum LightingMode
{
@ -139,6 +151,8 @@ class OSG_EXPORT View : public virtual osg::Object
virtual osg::GraphicsOperation* createRenderer(osg::Camera*) { return 0; }
osg::ref_ptr<osg::Stats> _stats;
LightingMode _lightingMode;
osg::ref_ptr<osg::Light> _light;

View File

@ -39,6 +39,17 @@ class OSGVIEWER_EXPORT CompositeViewer : public ViewerBase, public virtual osg::
/** read the viewer configuration from a configuration file.*/
bool readConfiguration(const std::string& filename);
/** Set the Stats object used for collect various frame related timing and scene graph stats.*/
virtual void setViewerStats(osg::Stats* stats) { _stats = stats; }
/** Get the Viewers Stats object.*/
virtual osg::Stats* getViewerStats() { return _stats.get(); }
/** Get the Viewers Stats object.*/
virtual const osg::Stats* getViewerStats() const { return _stats.get(); }
void addView(osgViewer::View* view);
void removeView(osgViewer::View* view);
@ -114,6 +125,8 @@ class OSGVIEWER_EXPORT CompositeViewer : public ViewerBase, public virtual osg::
bool _firstFrame;
osg::ref_ptr<osg::Stats> _stats;
osg::Timer_t _startTick;
osg::ref_ptr<osg::FrameStamp> _frameStamp;

View File

@ -41,6 +41,17 @@ class OSGVIEWER_EXPORT Viewer : public ViewerBase, public osgViewer::View
/** Take all the settings, Camera and Slaves from the passed in view(er), leaving it empty. */
virtual void take(View& rhs);
/** Set the Stats object used for collect various frame related timing and scene graph stats.*/
virtual void setViewerStats(osg::Stats* stats) { setStats(stats); }
/** Get the Viewers Stats object.*/
virtual osg::Stats* getViewerStats() { return getStats(); }
/** Get the Viewers Stats object.*/
virtual const osg::Stats* getViewerStats() const { return getStats(); }
/** read the viewer configuration from a configuration file.*/
virtual bool readConfiguration(const std::string& filename);

View File

@ -41,13 +41,13 @@ class OSGVIEWER_EXPORT ViewerBase : public virtual osg::Object
/** Set the Stats object used for collect various frame related timing and scene graph stats.*/
void setStats(osg::Stats* stats) { _stats = stats; }
virtual void setViewerStats(osg::Stats* stats) = 0;
/** Get the Viewers Stats object.*/
osg::Stats* getStats() { return _stats.get(); }
virtual osg::Stats* getViewerStats() = 0;
/** Get the Viewers Stats object.*/
const osg::Stats* getStats() const { return _stats.get(); }
virtual const osg::Stats* getViewerStats() const = 0;
/** read the viewer configuration from a configuration file.*/
@ -259,9 +259,6 @@ class OSGVIEWER_EXPORT ViewerBase : public virtual osg::Object
}
virtual void viewerInit() = 0;
osg::ref_ptr<osg::Stats> _stats;
bool _firstFrame;
bool _done;

View File

@ -72,7 +72,7 @@ void CompositeViewer::constructorInit()
_updateVisitor = new osgUtil::UpdateVisitor;
_updateVisitor->setFrameStamp(_frameStamp.get());
setStats(new osg::Stats("CompsiteViewer"));
setViewerStats(new osg::Stats("CompsiteViewer"));
}
CompositeViewer::~CompositeViewer()
@ -564,15 +564,15 @@ void CompositeViewer::advance(double simulationTime)
_frameStamp->setSimulationTime(simulationTime);
}
if (getStats() && getStats()->collectStats("frame_rate"))
if (getViewerStats() && getViewerStats()->collectStats("frame_rate"))
{
// update previous frame stats
double deltaFrameTime = _frameStamp->getReferenceTime() - prevousReferenceTime;
getStats()->setAttribute(previousFrameNumber, "Frame duration", deltaFrameTime);
getStats()->setAttribute(previousFrameNumber, "Frame rate", 1.0/deltaFrameTime);
getViewerStats()->setAttribute(previousFrameNumber, "Frame duration", deltaFrameTime);
getViewerStats()->setAttribute(previousFrameNumber, "Frame rate", 1.0/deltaFrameTime);
// update current frames stats
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Reference time", _frameStamp->getReferenceTime());
getViewerStats()->setAttribute(_frameStamp->getFrameNumber(), "Reference time", _frameStamp->getReferenceTime());
}
}
@ -944,14 +944,14 @@ void CompositeViewer::eventTraversal()
if (getStats() && getStats()->collectStats("event"))
if (getViewerStats() && getViewerStats()->collectStats("event"))
{
double endEventTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick());
// update current frames stats
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Event traversal begin time", beginEventTraversal);
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Event traversal end time", endEventTraversal);
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Event traversal time taken", endEventTraversal-beginEventTraversal);
getViewerStats()->setAttribute(_frameStamp->getFrameNumber(), "Event traversal begin time", beginEventTraversal);
getViewerStats()->setAttribute(_frameStamp->getFrameNumber(), "Event traversal end time", endEventTraversal);
getViewerStats()->setAttribute(_frameStamp->getFrameNumber(), "Event traversal time taken", endEventTraversal-beginEventTraversal);
}
}
@ -1034,14 +1034,14 @@ void CompositeViewer::updateTraversal()
}
if (getStats() && getStats()->collectStats("update"))
if (getViewerStats() && getViewerStats()->collectStats("update"))
{
double endUpdateTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick());
// update current frames stats
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Update traversal begin time", beginUpdateTraversal);
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Update traversal end time", endUpdateTraversal);
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Update traversal time taken", endUpdateTraversal-beginUpdateTraversal);
getViewerStats()->setAttribute(_frameStamp->getFrameNumber(), "Update traversal begin time", beginUpdateTraversal);
getViewerStats()->setAttribute(_frameStamp->getFrameNumber(), "Update traversal end time", endUpdateTraversal);
getViewerStats()->setAttribute(_frameStamp->getFrameNumber(), "Update traversal time taken", endUpdateTraversal-beginUpdateTraversal);
}
}

View File

@ -24,7 +24,6 @@
#include <osg/PolygonMode>
#include <osg/Geometry>
#include <osgUtil/Statistics>
namespace osgViewer
{
@ -70,7 +69,7 @@ bool StatsHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdap
{
if (ea.getKey()==_keyEventTogglesOnScreenStats)
{
if (viewer->getStats())
if (viewer->getViewerStats())
{
if (!_initialized)
{
@ -89,9 +88,9 @@ bool StatsHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdap
{
case(NO_STATS):
{
viewer->getStats()->collectStats("frame_rate",false);
viewer->getStats()->collectStats("event",false);
viewer->getStats()->collectStats("update",false);
viewer->getViewerStats()->collectStats("frame_rate",false);
viewer->getViewerStats()->collectStats("event",false);
viewer->getViewerStats()->collectStats("update",false);
for(osgViewer::ViewerBase::Cameras::iterator itr = cameras.begin();
itr != cameras.end();
@ -106,7 +105,7 @@ bool StatsHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdap
}
}
viewer->getStats()->collectStats("scene",false);
viewer->getViewerStats()->collectStats("scene",false);
_camera->setNodeMask(0x0);
_switch->setAllChildrenOff();
@ -114,7 +113,7 @@ bool StatsHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdap
}
case(FRAME_RATE):
{
viewer->getStats()->collectStats("frame_rate",true);
viewer->getViewerStats()->collectStats("frame_rate",true);
_camera->setNodeMask(0xffffffff);
_switch->setValue(_frameRateChildNum, true);
@ -136,8 +135,8 @@ bool StatsHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdap
}
}
viewer->getStats()->collectStats("event",true);
viewer->getStats()->collectStats("update",true);
viewer->getViewerStats()->collectStats("event",true);
viewer->getViewerStats()->collectStats("update",true);
for(osgViewer::ViewerBase::Cameras::iterator itr = cameras.begin();
itr != cameras.end();
@ -174,7 +173,7 @@ bool StatsHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdap
_camera->setNodeMask(0xffffffff);
_switch->setValue(_viewerSceneChildNum, true);
viewer->getStats()->collectStats("scene",true);
viewer->getViewerStats()->collectStats("scene",true);
break;
}
@ -188,12 +187,12 @@ bool StatsHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdap
}
if (ea.getKey()==_keyEventPrintsOutStats)
{
if (viewer->getStats())
if (viewer->getViewerStats())
{
osg::notify(osg::NOTICE)<<std::endl<<"Stats report:"<<std::endl;
typedef std::vector<osg::Stats*> StatsList;
StatsList statsList;
statsList.push_back(viewer->getStats());
statsList.push_back(viewer->getViewerStats());
osgViewer::ViewerBase::Contexts contexts;
viewer->getContexts(contexts);
@ -213,7 +212,7 @@ bool StatsHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdap
}
}
for(int i = viewer->getStats()->getEarliestFrameNumber(); i<= viewer->getStats()->getLatestFrameNumber()-1; ++i)
for(int i = viewer->getViewerStats()->getEarliestFrameNumber(); i<= viewer->getViewerStats()->getLatestFrameNumber()-1; ++i)
{
for(StatsList::iterator itr = statsList.begin();
itr != statsList.end();
@ -386,7 +385,7 @@ struct CameraSceneStatsTextDrawCallback : public virtual osg::Drawable::DrawCall
if (stats->getAttribute(frameNumber, str, value)) \
viewStr << std::setw(7) << value << std::endl; \
else \
viewStr << std::setw(7) << "no value" << std::endl; \
viewStr << std::setw(7) << "." << std::endl; \
double value = 0.0;
@ -444,13 +443,9 @@ struct ViewSceneStatsTextDrawCallback : public virtual osg::Drawable::DrawCallba
if (delta > 200) // update every 100ms
{
_tickLastUpdated = tick;
osg::ref_ptr<osg::Node> sceneRoot = _view.valid() ? _view->getScene()->getSceneData() : 0;
if (sceneRoot.valid())
osg::Stats* stats = _view->getStats();
if (stats)
{
osgUtil::StatsVisitor statsVisitor;
sceneRoot->accept(statsVisitor);
std::ostringstream viewStr;
viewStr.clear();
viewStr.setf(std::ios::left,std::ios::adjustfield);
@ -465,33 +460,35 @@ struct ViewSceneStatsTextDrawCallback : public virtual osg::Drawable::DrawCallba
viewStr << std::endl;
unsigned int unique_primitives = 0;
osgUtil::Statistics::PrimitiveCountMap::iterator pcmitr;
for(pcmitr = statsVisitor._uniqueStats.GetPrimitivesBegin();
pcmitr != statsVisitor._uniqueStats.GetPrimitivesEnd();
++pcmitr)
int frameNumber = renderInfo.getState()->getFrameStamp()->getFrameNumber();
// if (!(renderer->getGraphicsThreadDoesCull()))
{
unique_primitives += pcmitr->second;
--frameNumber;
}
#define STATS_ATTRIBUTE_PAIR(str1, str2) \
if (stats->getAttribute(frameNumber, str1, value)) \
viewStr << std::setw(10) << value; \
else \
viewStr << std::setw(10) << "."; \
if (stats->getAttribute(frameNumber, str2, value)) \
viewStr << std::setw(10) << value << std::endl; \
else \
viewStr << std::setw(10) << "." << std::endl; \
unsigned int instanced_primitives = 0;
for(pcmitr = statsVisitor._instancedStats.GetPrimitivesBegin();
pcmitr != statsVisitor._instancedStats.GetPrimitivesEnd();
++pcmitr)
{
instanced_primitives += pcmitr->second;
}
double value = 0.0;
STATS_ATTRIBUTE_PAIR("Number of unique StateSet","Number of instanced Stateset")
STATS_ATTRIBUTE_PAIR("Number of unique Group","Number of instanced Group")
STATS_ATTRIBUTE_PAIR("Number of unique Transform","Number of instanced Transform")
STATS_ATTRIBUTE_PAIR("Number of unique LOD","Number of instanced LOD")
STATS_ATTRIBUTE_PAIR("Number of unique Switch","Number of instanced Switch")
STATS_ATTRIBUTE_PAIR("Number of unique Geode","Number of instanced Geode")
STATS_ATTRIBUTE_PAIR("Number of unique Drawable","Number of instanced Drawable")
STATS_ATTRIBUTE_PAIR("Number of unique Geometry","Number of instanced Geometry")
STATS_ATTRIBUTE_PAIR("Number of unique Vertices","Number of instanced Vertices")
STATS_ATTRIBUTE_PAIR("Number of unique Primitives","Number of instanced Primitives")
viewStr << std::setw(10) << statsVisitor._statesetSet.size() << std::setw(10) << statsVisitor._numInstancedStateSet << std::endl;
viewStr << std::setw(10) << statsVisitor._groupSet.size() << std::setw(10) << statsVisitor._numInstancedGroup << std::endl;
viewStr << std::setw(10) << statsVisitor._transformSet.size() << std::setw(10) << statsVisitor._numInstancedTransform << std::endl;
viewStr << std::setw(10) << statsVisitor._lodSet.size() << std::setw(10) << statsVisitor._numInstancedLOD << std::endl;
viewStr << std::setw(10) << statsVisitor._switchSet.size() << std::setw(10) << statsVisitor._numInstancedSwitch << std::endl;
viewStr << std::setw(10) << statsVisitor._geodeSet.size() << std::setw(10) << statsVisitor._numInstancedGeode << std::endl;
viewStr << std::setw(10) << statsVisitor._drawableSet.size() << std::setw(10) << statsVisitor._numInstancedDrawable << std::endl;
viewStr << std::setw(10) << statsVisitor._geometrySet.size() << std::setw(10) << statsVisitor._numInstancedGeometry << std::endl;
viewStr << std::setw(10) << statsVisitor._uniqueStats._vertexCount << std::setw(10) << statsVisitor._instancedStats._vertexCount << std::endl;
viewStr << std::setw(10) << unique_primitives << std::setw(10) << instanced_primitives << std::endl;
text->setText(viewStr.str());
}
@ -1050,7 +1047,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
frameRateValue->setPosition(pos);
frameRateValue->setText("0.0");
frameRateValue->setDrawCallback(new AveragedValueTextDrawCallback(viewer->getStats(),"Frame rate",-1, true, 1.0));
frameRateValue->setDrawCallback(new AveragedValueTextDrawCallback(viewer->getViewerStats(),"Frame rate",-1, true, 1.0));
pos.y() -= characterSize*1.5f;
@ -1119,11 +1116,11 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
eventValue->setPosition(pos);
eventValue->setText("0.0");
eventValue->setDrawCallback(new AveragedValueTextDrawCallback(viewer->getStats(),"Event traversal time taken",-1, false, 1000.0));
eventValue->setDrawCallback(new AveragedValueTextDrawCallback(viewer->getViewerStats(),"Event traversal time taken",-1, false, 1000.0));
pos.x() = startBlocks;
osg::Geometry* geometry = createGeometry(pos, characterSize *0.8, colorUpdateAlpha, _numBlocks);
geometry->setDrawCallback(new BlockDrawCallback(this, startBlocks, viewer->getStats(), viewer->getStats(), "Event traversal begin time", "Event traversal end time", -1, _numBlocks));
geometry->setDrawCallback(new BlockDrawCallback(this, startBlocks, viewer->getViewerStats(), viewer->getViewerStats(), "Event traversal begin time", "Event traversal end time", -1, _numBlocks));
geode->addDrawable(geometry);
pos.y() -= characterSize*1.5f;
@ -1152,11 +1149,11 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
updateValue->setPosition(pos);
updateValue->setText("0.0");
updateValue->setDrawCallback(new AveragedValueTextDrawCallback(viewer->getStats(),"Update traversal time taken",-1, false, 1000.0));
updateValue->setDrawCallback(new AveragedValueTextDrawCallback(viewer->getViewerStats(),"Update traversal time taken",-1, false, 1000.0));
pos.x() = startBlocks;
osg::Geometry* geometry = createGeometry(pos, characterSize *0.8, colorUpdateAlpha, _numBlocks);
geometry->setDrawCallback(new BlockDrawCallback(this, startBlocks, viewer->getStats(), viewer->getStats(), "Update traversal begin time", "Update traversal end time", -1, _numBlocks));
geometry->setDrawCallback(new BlockDrawCallback(this, startBlocks, viewer->getViewerStats(), viewer->getViewerStats(), "Update traversal begin time", "Update traversal end time", -1, _numBlocks));
geode->addDrawable(geometry);
pos.y() -= characterSize*1.5f;
@ -1169,7 +1166,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
citr != cameras.end();
++citr)
{
group->addChild(createCameraTimeStats(font, pos, startBlocks, acquireGPUStats, characterSize, viewer->getStats(), *citr));
group->addChild(createCameraTimeStats(font, pos, startBlocks, acquireGPUStats, characterSize, viewer->getViewerStats(), *citr));
}
// add frame ticks
@ -1187,7 +1184,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
geode->addDrawable(ticks);
osg::Geometry* frameMarkers = createFrameMarkers(pos, height, colourTicks, _numBlocks + 1);
frameMarkers->setDrawCallback(new FrameMarkerDrawCallback(this, startBlocks, viewer->getStats(), 0, _numBlocks + 1));
frameMarkers->setDrawCallback(new FrameMarkerDrawCallback(this, startBlocks, viewer->getViewerStats(), 0, _numBlocks + 1));
geode->addDrawable(frameMarkers);
pos.x() = leftPos;
@ -1203,17 +1200,17 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
StatsGraph* statsGraph = new StatsGraph(pos, width, height);
group->addChild(statsGraph);
statsGraph->addStatGraph(viewer->getStats(), viewer->getStats(), colorFR, 100, "Frame rate");
statsGraph->addStatGraph(viewer->getStats(), viewer->getStats(), colorEvent, 0.016, "Event traversal time taken");
statsGraph->addStatGraph(viewer->getStats(), viewer->getStats(), colorUpdate, 0.016, "Update traversal time taken");
statsGraph->addStatGraph(viewer->getViewerStats(), viewer->getViewerStats(), colorFR, 100, "Frame rate");
statsGraph->addStatGraph(viewer->getViewerStats(), viewer->getViewerStats(), colorEvent, 0.016, "Event traversal time taken");
statsGraph->addStatGraph(viewer->getViewerStats(), viewer->getViewerStats(), colorUpdate, 0.016, "Update traversal time taken");
for(ViewerBase::Cameras::iterator citr = cameras.begin();
citr != cameras.end();
++citr)
{
statsGraph->addStatGraph(viewer->getStats(), (*citr)->getStats(), colorCull, 0.016, "Cull traversal time taken");
statsGraph->addStatGraph(viewer->getStats(), (*citr)->getStats(), colorDraw, 0.016, "Draw traversal time taken");
statsGraph->addStatGraph(viewer->getStats(), (*citr)->getStats(), colorGPU, 0.016, "GPU draw time taken");
statsGraph->addStatGraph(viewer->getViewerStats(), (*citr)->getStats(), colorCull, 0.016, "Cull traversal time taken");
statsGraph->addStatGraph(viewer->getViewerStats(), (*citr)->getStats(), colorDraw, 0.016, "Draw traversal time taken");
statsGraph->addStatGraph(viewer->getViewerStats(), (*citr)->getStats(), colorGPU, 0.016, "GPU draw time taken");
}
geode->addDrawable(createBackgroundRectangle( pos + osg::Vec3(-backgroundMargin, backgroundMargin, 0),

View File

@ -177,7 +177,7 @@ void Viewer::constructorInit()
_updateVisitor = new osgUtil::UpdateVisitor;
_updateVisitor->setFrameStamp(_frameStamp.get());
setStats(new osg::Stats("Viewer"));
setViewerStats(new osg::Stats("Viewer"));
}
Viewer::~Viewer()
@ -516,15 +516,15 @@ void Viewer::advance(double simulationTime)
_frameStamp->setSimulationTime(simulationTime);
}
if (getStats() && getStats()->collectStats("frame_rate"))
if (getViewerStats() && getViewerStats()->collectStats("frame_rate"))
{
// update previous frame stats
double deltaFrameTime = _frameStamp->getReferenceTime() - prevousReferenceTime;
getStats()->setAttribute(previousFrameNumber, "Frame duration", deltaFrameTime);
getStats()->setAttribute(previousFrameNumber, "Frame rate", 1.0/deltaFrameTime);
getViewerStats()->setAttribute(previousFrameNumber, "Frame duration", deltaFrameTime);
getViewerStats()->setAttribute(previousFrameNumber, "Frame rate", 1.0/deltaFrameTime);
// update current frames stats
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Reference time", _frameStamp->getReferenceTime());
getViewerStats()->setAttribute(_frameStamp->getFrameNumber(), "Reference time", _frameStamp->getReferenceTime());
}
if (osg::Referenced::getDeleteHandler())
@ -854,14 +854,14 @@ void Viewer::eventTraversal()
}
}
if (getStats() && getStats()->collectStats("event"))
if (getViewerStats() && getViewerStats()->collectStats("event"))
{
double endEventTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick());
// update current frames stats
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Event traversal begin time", beginEventTraversal);
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Event traversal end time", endEventTraversal);
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Event traversal time taken", endEventTraversal-beginEventTraversal);
getViewerStats()->setAttribute(_frameStamp->getFrameNumber(), "Event traversal begin time", beginEventTraversal);
getViewerStats()->setAttribute(_frameStamp->getFrameNumber(), "Event traversal end time", endEventTraversal);
getViewerStats()->setAttribute(_frameStamp->getFrameNumber(), "Event traversal time taken", endEventTraversal-beginEventTraversal);
}
}
@ -926,14 +926,14 @@ void Viewer::updateTraversal()
updateSlaves();
if (getStats() && getStats()->collectStats("update"))
if (getViewerStats() && getViewerStats()->collectStats("update"))
{
double endUpdateTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick());
// update current frames stats
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Update traversal begin time", beginUpdateTraversal);
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Update traversal end time", endUpdateTraversal);
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Update traversal time taken", endUpdateTraversal-beginUpdateTraversal);
getViewerStats()->setAttribute(_frameStamp->getFrameNumber(), "Update traversal begin time", beginUpdateTraversal);
getViewerStats()->setAttribute(_frameStamp->getFrameNumber(), "Update traversal end time", endUpdateTraversal);
getViewerStats()->setAttribute(_frameStamp->getFrameNumber(), "Update traversal time taken", endUpdateTraversal-beginUpdateTraversal);
}
}

View File

@ -27,6 +27,7 @@
#include <osgUtil/Optimizer>
#include <osgUtil/IntersectionVisitor>
#include <osgUtil/Statistics>
static osg::ApplicationUsageProxy ViewerBase_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_CONFIG_FILE <filename>","Specify a viewer configuration file to load by default.");
static osg::ApplicationUsageProxy ViewerBase_e1(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_THREADING <value>","Set the threading model using by Viewer, <value> can be SingleThreaded, CullDrawThreadPerContext, DrawThreadPerContext or CullThreadPerCameraDrawThreadPerContext.");
@ -639,6 +640,66 @@ void ViewerBase::renderingTraversals()
osg::FrameStamp* frameStamp = getViewerFrameStamp();
if (getViewerStats() && getViewerStats()->collectStats("scene"))
{
int frameNumber = frameStamp ? frameStamp->getFrameNumber() : 0;
Views views;
getViews(views);
for(Views::iterator vitr = views.begin();
vitr != views.end();
++vitr)
{
View* view = *vitr;
osg::Stats* stats = view->getStats();
osg::Node* sceneRoot = view->getSceneData();
if (sceneRoot)
{
osgUtil::StatsVisitor statsVisitor;
sceneRoot->accept(statsVisitor);
unsigned int unique_primitives = 0;
osgUtil::Statistics::PrimitiveCountMap::iterator pcmitr;
for(pcmitr = statsVisitor._uniqueStats.GetPrimitivesBegin();
pcmitr != statsVisitor._uniqueStats.GetPrimitivesEnd();
++pcmitr)
{
unique_primitives += pcmitr->second;
}
stats->setAttribute(frameNumber, "Number of unique StateSet", static_cast<double>(statsVisitor._statesetSet.size()));
stats->setAttribute(frameNumber, "Number of unique Group", static_cast<double>(statsVisitor._groupSet.size()));
stats->setAttribute(frameNumber, "Number of unique Transform", static_cast<double>(statsVisitor._transformSet.size()));
stats->setAttribute(frameNumber, "Number of unique LOD", static_cast<double>(statsVisitor._lodSet.size()));
stats->setAttribute(frameNumber, "Number of unique Switch", static_cast<double>(statsVisitor._switchSet.size()));
stats->setAttribute(frameNumber, "Number of unique Geode", static_cast<double>(statsVisitor._geodeSet.size()));
stats->setAttribute(frameNumber, "Number of unique Drawable", static_cast<double>(statsVisitor._drawableSet.size()));
stats->setAttribute(frameNumber, "Number of unique Geometry", static_cast<double>(statsVisitor._geometrySet.size()));
stats->setAttribute(frameNumber, "Number of unique Vertices", static_cast<double>(statsVisitor._uniqueStats._vertexCount));
stats->setAttribute(frameNumber, "Number of unique Primitives", static_cast<double>(unique_primitives));
unsigned int instanced_primitives = 0;
for(pcmitr = statsVisitor._instancedStats.GetPrimitivesBegin();
pcmitr != statsVisitor._instancedStats.GetPrimitivesEnd();
++pcmitr)
{
instanced_primitives += pcmitr->second;
}
stats->setAttribute(frameNumber, "Number of instanced Stateset", static_cast<double>(statsVisitor._numInstancedStateSet));
stats->setAttribute(frameNumber, "Number of instanced Group", static_cast<double>(statsVisitor._numInstancedGroup));
stats->setAttribute(frameNumber, "Number of instanced Transform", static_cast<double>(statsVisitor._numInstancedTransform));
stats->setAttribute(frameNumber, "Number of instanced LOD", static_cast<double>(statsVisitor._numInstancedLOD));
stats->setAttribute(frameNumber, "Number of instanced Switch", static_cast<double>(statsVisitor._numInstancedSwitch));
stats->setAttribute(frameNumber, "Number of instanced Geode", static_cast<double>(statsVisitor._numInstancedGeode));
stats->setAttribute(frameNumber, "Number of instanced Drawable", static_cast<double>(statsVisitor._numInstancedDrawable));
stats->setAttribute(frameNumber, "Number of instanced Geometry", static_cast<double>(statsVisitor._numInstancedGeometry));
stats->setAttribute(frameNumber, "Number of instanced Vertices", static_cast<double>(statsVisitor._instancedStats._vertexCount));
stats->setAttribute(frameNumber, "Number of instanced Primitives", static_cast<double>(instanced_primitives));
}
}
}
Scenes scenes;
getScenes(scenes);
@ -756,14 +817,14 @@ void ViewerBase::renderingTraversals()
releaseContext();
}
if (getStats() && getStats()->collectStats("update"))
if (getViewerStats() && getViewerStats()->collectStats("update"))
{
double endRenderingTraversals = elapsedTime();
// update current frames stats
getStats()->setAttribute(frameStamp->getFrameNumber(), "Rendering traversals begin time ", beginRenderingTraversals);
getStats()->setAttribute(frameStamp->getFrameNumber(), "Rendering traversals end time ", endRenderingTraversals);
getStats()->setAttribute(frameStamp->getFrameNumber(), "Rendering traversals time taken", endRenderingTraversals-beginRenderingTraversals);
getViewerStats()->setAttribute(frameStamp->getFrameNumber(), "Rendering traversals begin time ", beginRenderingTraversals);
getViewerStats()->setAttribute(frameStamp->getFrameNumber(), "Rendering traversals end time ", endRenderingTraversals);
getViewerStats()->setAttribute(frameStamp->getFrameNumber(), "Rendering traversals time taken", endRenderingTraversals-beginRenderingTraversals);
}
}

View File

@ -17,6 +17,7 @@
#include <osg/Matrix>
#include <osg/Matrixd>
#include <osg/Object>
#include <osg/Stats>
#include <osg/View>
// Must undefine IN and OUT macros defined in Windows headers
@ -74,6 +75,21 @@ BEGIN_OBJECT_REFLECTOR(osg::View)
__void__take__View_R1,
"Take all the settings, Camera and Slaves from the passed in view, leaving it empty. ",
"");
I_Method1(void, setStats, IN, osg::Stats *, stats,
Properties::NON_VIRTUAL,
__void__setStats__osg_Stats_P1,
"Set the Stats object used for collect various frame related timing and scene graph stats. ",
"");
I_Method0(osg::Stats *, getStats,
Properties::NON_VIRTUAL,
__osg_Stats_P1__getStats,
"Get the Viewers Stats object. ",
"");
I_Method0(const osg::Stats *, getStats,
Properties::NON_VIRTUAL,
__C5_osg_Stats_P1__getStats,
"Get the Viewers Stats object. ",
"");
I_Method1(void, setLightingMode, IN, osg::View::LightingMode, lightingMode,
Properties::NON_VIRTUAL,
__void__setLightingMode__LightingMode,
@ -204,6 +220,9 @@ BEGIN_OBJECT_REFLECTOR(osg::View)
0,
0,
__bool__removeSlave__unsigned_int);
I_SimpleProperty(osg::Stats *, Stats,
__osg_Stats_P1__getStats,
__void__setStats__osg_Stats_P1);
END_REFLECTOR
BEGIN_VALUE_REFLECTOR(osg::View::Slave)

View File

@ -207,15 +207,25 @@ BEGIN_OBJECT_REFLECTOR(osgUtil::Statistics)
__void__add__C5_Statistics_R1,
"",
"");
I_Method0(osgUtil::Statistics::PrimitiveCountMap &, getPrimitiveCountMap,
Properties::NON_VIRTUAL,
__PrimitiveCountMap_R1__getPrimitiveCountMap,
"",
"");
I_Method0(const osgUtil::Statistics::PrimitiveCountMap &, getPrimitiveCountMap,
Properties::NON_VIRTUAL,
__C5_PrimitiveCountMap_R1__getPrimitiveCountMap,
"",
"");
I_Method0(osgUtil::Statistics::PrimitiveCountMap::iterator, GetPrimitivesBegin,
Properties::NON_VIRTUAL,
__PrimitiveCountMap_iterator__GetPrimitivesBegin,
"",
"deprecated ",
"");
I_Method0(osgUtil::Statistics::PrimitiveCountMap::iterator, GetPrimitivesEnd,
Properties::NON_VIRTUAL,
__PrimitiveCountMap_iterator__GetPrimitivesEnd,
"",
"deprecated ",
"");
I_SimpleProperty(int, BinNo,
0,
@ -226,6 +236,9 @@ BEGIN_OBJECT_REFLECTOR(osgUtil::Statistics)
I_SimpleProperty(int, Depth,
0,
__void__setDepth__int);
I_SimpleProperty(osgUtil::Statistics::PrimitiveCountMap &, PrimitiveCountMap,
__PrimitiveCountMap_R1__getPrimitiveCountMap,
0);
I_SimpleProperty(osgUtil::Statistics::StatsType, Type,
0,
__void__setType__StatsType);

View File

@ -16,6 +16,7 @@
#include <osg/CopyOp>
#include <osg/FrameStamp>
#include <osg/Object>
#include <osg/Stats>
#include <osg/Timer>
#include <osgViewer/CompositeViewer>
#include <osgViewer/View>
@ -75,6 +76,21 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::CompositeViewer)
__bool__readConfiguration__C5_std_string_R1,
"read the viewer configuration from a configuration file. ",
"");
I_Method1(void, setViewerStats, IN, osg::Stats *, stats,
Properties::VIRTUAL,
__void__setViewerStats__osg_Stats_P1,
"Set the Stats object used for collect various frame related timing and scene graph stats. ",
"");
I_Method0(osg::Stats *, getViewerStats,
Properties::VIRTUAL,
__osg_Stats_P1__getViewerStats,
"Get the Viewers Stats object. ",
"");
I_Method0(const osg::Stats *, getViewerStats,
Properties::VIRTUAL,
__C5_osg_Stats_P1__getViewerStats,
"Get the Viewers Stats object. ",
"");
I_Method1(void, addView, IN, osgViewer::View *, view,
Properties::NON_VIRTUAL,
__void__addView__osgViewer_View_P1,
@ -257,5 +273,8 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::CompositeViewer)
I_SimpleProperty(osg::FrameStamp *, ViewerFrameStamp,
__osg_FrameStamp_P1__getViewerFrameStamp,
0);
I_SimpleProperty(osg::Stats *, ViewerStats,
__osg_Stats_P1__getViewerStats,
__void__setViewerStats__osg_Stats_P1);
END_REFLECTOR

View File

@ -17,6 +17,7 @@
#include <osg/FrameStamp>
#include <osg/Node>
#include <osg/Object>
#include <osg/Stats>
#include <osg/Timer>
#include <osgViewer/GraphicsWindow>
#include <osgViewer/View>
@ -77,6 +78,21 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::Viewer)
__void__take__View_R1,
"Take all the settings, Camera and Slaves from the passed in view(er), leaving it empty. ",
"");
I_Method1(void, setViewerStats, IN, osg::Stats *, stats,
Properties::VIRTUAL,
__void__setViewerStats__osg_Stats_P1,
"Set the Stats object used for collect various frame related timing and scene graph stats. ",
"");
I_Method0(osg::Stats *, getViewerStats,
Properties::VIRTUAL,
__osg_Stats_P1__getViewerStats,
"Get the Viewers Stats object. ",
"");
I_Method0(const osg::Stats *, getViewerStats,
Properties::VIRTUAL,
__C5_osg_Stats_P1__getViewerStats,
"Get the Viewers Stats object. ",
"");
I_Method1(bool, readConfiguration, IN, const std::string &, filename,
Properties::VIRTUAL,
__bool__readConfiguration__C5_std_string_R1,
@ -219,5 +235,8 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::Viewer)
I_SimpleProperty(osg::FrameStamp *, ViewerFrameStamp,
__osg_FrameStamp_P1__getViewerFrameStamp,
0);
I_SimpleProperty(osg::Stats *, ViewerStats,
__osg_Stats_P1__getViewerStats,
__void__setViewerStats__osg_Stats_P1);
END_REFLECTOR

View File

@ -70,19 +70,19 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osgViewer::ViewerBase)
____ViewerBase__C5_ViewerBase_R1,
"",
"");
I_Method1(void, setStats, IN, osg::Stats *, stats,
Properties::NON_VIRTUAL,
__void__setStats__osg_Stats_P1,
I_Method1(void, setViewerStats, IN, osg::Stats *, stats,
Properties::PURE_VIRTUAL,
__void__setViewerStats__osg_Stats_P1,
"Set the Stats object used for collect various frame related timing and scene graph stats. ",
"");
I_Method0(osg::Stats *, getStats,
Properties::NON_VIRTUAL,
__osg_Stats_P1__getStats,
I_Method0(osg::Stats *, getViewerStats,
Properties::PURE_VIRTUAL,
__osg_Stats_P1__getViewerStats,
"Get the Viewers Stats object. ",
"");
I_Method0(const osg::Stats *, getStats,
Properties::NON_VIRTUAL,
__C5_osg_Stats_P1__getStats,
I_Method0(const osg::Stats *, getViewerStats,
Properties::PURE_VIRTUAL,
__C5_osg_Stats_P1__getViewerStats,
"Get the Viewers Stats object. ",
"");
I_Method1(bool, readConfiguration, IN, const std::string &, filename,
@ -374,9 +374,6 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osgViewer::ViewerBase)
I_SimpleProperty(bool, ReleaseContextAtEndOfFrameHint,
__bool__getReleaseContextAtEndOfFrameHint,
__void__setReleaseContextAtEndOfFrameHint__bool);
I_SimpleProperty(osg::Stats *, Stats,
__osg_Stats_P1__getStats,
__void__setStats__osg_Stats_P1);
I_SimpleProperty(osgViewer::ViewerBase::ThreadingModel, ThreadingModel,
__ThreadingModel__getThreadingModel,
__void__setThreadingModel__ThreadingModel);
@ -389,6 +386,9 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osgViewer::ViewerBase)
I_SimpleProperty(osg::FrameStamp *, ViewerFrameStamp,
__osg_FrameStamp_P1__getViewerFrameStamp,
0);
I_SimpleProperty(osg::Stats *, ViewerStats,
__osg_Stats_P1__getViewerStats,
__void__setViewerStats__osg_Stats_P1);
END_REFLECTOR
STD_VECTOR_REFLECTOR(std::vector< OpenThreads::Thread * >)