From Paul Melis, "Here is an updated osgViewer::StatsHandler. It has the following changes:
- The text and dark background rectangles are now correctly placed, and slightly resized here and there. - All counters (vertices, etc) now use a fixed formatting with 0 digits precision, to prevent the text from being shown in scientific notation when the number get large (e.g. 6.34344e+6). I tested with a scene containing roughly 4 million vertices, to make sure its stats would display correctly. I also made slight changes to osgcompositeviewer (attached) to aid in testing the stats display, specifically displaying of camera and view names."
This commit is contained in:
parent
baa25411fd
commit
2b45fd1510
@ -163,6 +163,7 @@ int main( int argc, char **argv )
|
||||
// view one
|
||||
{
|
||||
osgViewer::View* view = new osgViewer::View;
|
||||
view->setName("View one");
|
||||
viewer.addView(view);
|
||||
|
||||
view->setUpViewOnSingleScreen(0);
|
||||
@ -179,6 +180,7 @@ int main( int argc, char **argv )
|
||||
// view two
|
||||
{
|
||||
osgViewer::View* view = new osgViewer::View;
|
||||
view->setName("View two");
|
||||
viewer.addView(view);
|
||||
|
||||
view->setUpViewOnSingleScreen(1);
|
||||
@ -234,9 +236,11 @@ int main( int argc, char **argv )
|
||||
// view one
|
||||
{
|
||||
osgViewer::View* view = new osgViewer::View;
|
||||
view->setName("View one");
|
||||
viewer.addView(view);
|
||||
|
||||
view->setSceneData(scene.get());
|
||||
view->getCamera()->setName("Cam one");
|
||||
view->getCamera()->setViewport(new osg::Viewport(0,0, traits->width/2, traits->height/2));
|
||||
view->getCamera()->setGraphicsContext(gc.get());
|
||||
view->setCameraManipulator(new osgGA::TrackballManipulator);
|
||||
@ -257,9 +261,11 @@ int main( int argc, char **argv )
|
||||
// view two
|
||||
{
|
||||
osgViewer::View* view = new osgViewer::View;
|
||||
view->setName("View two");
|
||||
viewer.addView(view);
|
||||
|
||||
view->setSceneData(scene.get());
|
||||
view->getCamera()->setName("Cam two");
|
||||
view->getCamera()->setViewport(new osg::Viewport(traits->width/2,0, traits->width/2, traits->height/2));
|
||||
view->getCamera()->setGraphicsContext(gc.get());
|
||||
view->setCameraManipulator(new osgGA::TrackballManipulator);
|
||||
@ -272,10 +278,12 @@ int main( int argc, char **argv )
|
||||
// view three
|
||||
{
|
||||
osgViewer::View* view = new osgViewer::View;
|
||||
view->setName("View three");
|
||||
viewer.addView(view);
|
||||
|
||||
view->setSceneData(osgDB::readNodeFile("cessnafire.osg"));
|
||||
|
||||
view->getCamera()->setName("Cam three");
|
||||
view->getCamera()->setProjectionMatrixAsPerspective(30.0, double(traits->width) / double(traits->height/2), 1.0, 1000.0);
|
||||
view->getCamera()->setViewport(new osg::Viewport(0, traits->height/2, traits->width, traits->height/2));
|
||||
view->getCamera()->setGraphicsContext(gc.get());
|
||||
|
@ -366,14 +366,17 @@ struct CameraSceneStatsTextDrawCallback : public virtual osg::Drawable::DrawCall
|
||||
{
|
||||
viewStr.setf(std::ios::left, std::ios::adjustfield);
|
||||
viewStr.width(14);
|
||||
// Used fixed formatting, as scientific will switch to "...e+.." notation for
|
||||
// large numbers of vertices/drawables/etc.
|
||||
viewStr.setf(std::ios::fixed);
|
||||
viewStr.precision(0);
|
||||
|
||||
viewStr << std::setw(1) << _cameraNumber << ": ";
|
||||
viewStr << std::setw(1) << "#" << _cameraNumber << std::endl;
|
||||
|
||||
// Camera name
|
||||
if (_camera->getName().empty())
|
||||
if (!_camera->getName().empty())
|
||||
viewStr << _camera->getName();
|
||||
viewStr << std::endl;
|
||||
else
|
||||
viewStr << _camera->getName() << std::endl;
|
||||
|
||||
int frameNumber = renderInfo.getState()->getFrameStamp()->getFrameNumber();
|
||||
if (!(renderer->getGraphicsThreadDoesCull()))
|
||||
@ -383,9 +386,9 @@ struct CameraSceneStatsTextDrawCallback : public virtual osg::Drawable::DrawCall
|
||||
|
||||
#define STATS_ATTRIBUTE(str) \
|
||||
if (stats->getAttribute(frameNumber, str, value)) \
|
||||
viewStr << std::setw(7) << value << std::endl; \
|
||||
viewStr << std::setw(8) << value << std::endl; \
|
||||
else \
|
||||
viewStr << std::setw(7) << "." << std::endl; \
|
||||
viewStr << std::setw(8) << "." << std::endl; \
|
||||
|
||||
double value = 0.0;
|
||||
|
||||
@ -449,14 +452,14 @@ struct ViewSceneStatsTextDrawCallback : public virtual osg::Drawable::DrawCallba
|
||||
viewStr.clear();
|
||||
viewStr.setf(std::ios::left, std::ios::adjustfield);
|
||||
viewStr.width(20);
|
||||
viewStr.setf(std::ios::fixed);
|
||||
viewStr.precision(0);
|
||||
|
||||
viewStr << std::setw(1) << "#" << _viewNumber;
|
||||
|
||||
viewStr << std::setw(1) << _viewNumber << ": ";
|
||||
// View name
|
||||
if (_view->getName().empty())
|
||||
viewStr << std::endl;
|
||||
else
|
||||
viewStr << _view->getName() << std::endl;
|
||||
|
||||
if (!_view->getName().empty())
|
||||
viewStr << ": " << _view->getName();
|
||||
viewStr << std::endl;
|
||||
|
||||
int frameNumber = renderInfo.getState()->getFrameStamp()->getFrameNumber();
|
||||
@ -477,6 +480,9 @@ struct ViewSceneStatsTextDrawCallback : public virtual osg::Drawable::DrawCallba
|
||||
|
||||
double value = 0.0;
|
||||
|
||||
// header
|
||||
viewStr << std::setw(10) << "Unique" << std::setw(10) << "Instanced" << std::endl;
|
||||
|
||||
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")
|
||||
@ -1370,7 +1376,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
|
||||
group->addChild(geode);
|
||||
geode->addDrawable(createBackgroundRectangle(pos + osg::Vec3(-backgroundMargin, characterSize + backgroundMargin, 0),
|
||||
7 * characterSize + 2 * backgroundMargin,
|
||||
18 * characterSize + 2 * backgroundMargin,
|
||||
19 * characterSize + 2 * backgroundMargin,
|
||||
backgroundColor));
|
||||
|
||||
// Camera scene & primitive stats static text
|
||||
@ -1386,6 +1392,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
|
||||
viewStr.setf(std::ios::left, std::ios::adjustfield);
|
||||
viewStr.width(14);
|
||||
viewStr << "Camera" << std::endl;
|
||||
viewStr << "" << std::endl; // placeholder for Camera name
|
||||
viewStr << "Vertices" << std::endl;
|
||||
viewStr << "Drawables" << std::endl;
|
||||
viewStr << "Lights" << std::endl;
|
||||
@ -1409,13 +1416,13 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
|
||||
// Move camera block to the right
|
||||
pos.x() += 7 * characterSize + 2 * backgroundMargin + backgroundSpacing;
|
||||
|
||||
// add camera scene stats
|
||||
// Add camera scene stats, one block per camera
|
||||
int cameraCounter = 0;
|
||||
for(ViewerBase::Cameras::iterator citr = cameras.begin(); citr != cameras.end(); ++citr)
|
||||
{
|
||||
geode->addDrawable(createBackgroundRectangle(pos + osg::Vec3(-backgroundMargin, characterSize + backgroundMargin, 0),
|
||||
5 * characterSize + 2 * backgroundMargin,
|
||||
18 * characterSize + 2 * backgroundMargin,
|
||||
19 * characterSize + 2 * backgroundMargin,
|
||||
backgroundColor));
|
||||
|
||||
// Camera scene stats
|
||||
@ -1446,7 +1453,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
|
||||
group->addChild(geode);
|
||||
|
||||
geode->addDrawable(createBackgroundRectangle(pos + osg::Vec3(-backgroundMargin, characterSize + backgroundMargin, 0),
|
||||
5 * characterSize + 2 * backgroundMargin,
|
||||
6 * characterSize + 2 * backgroundMargin,
|
||||
12 * characterSize + 2 * backgroundMargin,
|
||||
backgroundColor));
|
||||
|
||||
@ -1463,7 +1470,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
|
||||
viewStr.setf(std::ios::left, std::ios::adjustfield);
|
||||
viewStr.width(14);
|
||||
viewStr << "View" << std::endl;
|
||||
viewStr << std::endl;
|
||||
viewStr << " " << std::endl;
|
||||
viewStr << "Stateset" << std::endl;
|
||||
viewStr << "Group" << std::endl;
|
||||
viewStr << "Transform" << std::endl;
|
||||
@ -1477,8 +1484,8 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
|
||||
viewStr.setf(std::ios::right, std::ios::adjustfield);
|
||||
camStaticText->setText(viewStr.str());
|
||||
|
||||
// Move camera block to the right
|
||||
pos.x() += 5 * characterSize + 2 * backgroundMargin + backgroundSpacing;
|
||||
// Move viewer block to the right
|
||||
pos.x() += 6 * characterSize + 2 * backgroundMargin + backgroundSpacing;
|
||||
|
||||
std::vector<osgViewer::View*> views;
|
||||
viewer->getViews(views);
|
||||
@ -1488,7 +1495,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
|
||||
for (it = views.begin(); it != views.end(); ++it)
|
||||
{
|
||||
geode->addDrawable(createBackgroundRectangle(pos + osg::Vec3(-backgroundMargin, characterSize + backgroundMargin, 0),
|
||||
6 * characterSize + 2 * backgroundMargin,
|
||||
11 * characterSize + 2 * backgroundMargin,
|
||||
12 * characterSize + 2 * backgroundMargin,
|
||||
backgroundColor));
|
||||
|
||||
@ -1502,7 +1509,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
|
||||
text->setPosition(pos);
|
||||
text->setDrawCallback(new ViewSceneStatsTextDrawCallback(*it, viewCounter));
|
||||
|
||||
pos.x() += 6 * characterSize + 2 * backgroundMargin + backgroundSpacing;
|
||||
pos.x() += 11 * characterSize + 2 * backgroundMargin + backgroundSpacing;
|
||||
viewCounter++;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user