diff --git a/include/osgProducer/ViewerEventHandler b/include/osgProducer/ViewerEventHandler index 6c699f14e..9c217f9c8 100644 --- a/include/osgProducer/ViewerEventHandler +++ b/include/osgProducer/ViewerEventHandler @@ -49,7 +49,8 @@ class OSGPRODUCER_EXPORT ViewerEventHandler : public osgGA::GUIEventHandler { NO_STATS = 0, FRAME_RATE = 1, - CAMERA_STATS = 2 + CAMERA_STATS = 2, + SCENE_STATS = 3 }; void setFrameStatsMode(FrameStatsMode mode); diff --git a/include/osgUtil/SceneView b/include/osgUtil/SceneView index d770302e3..471116f52 100644 --- a/include/osgUtil/SceneView +++ b/include/osgUtil/SceneView @@ -455,6 +455,9 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced, public osg::CullSetting /** Flush deleted OpenGL objects, such as texture objects, display lists etc within specified available time.*/ virtual void flushDeletedGLObjects(double& availableTime); + /** Extract stats for current draw list. */ + bool getStats(Statistics* primStats); + protected: virtual ~SceneView(); diff --git a/src/osgProducer/ViewerEventHandler.cpp b/src/osgProducer/ViewerEventHandler.cpp index ee9300a2c..b2e854c25 100644 --- a/src/osgProducer/ViewerEventHandler.cpp +++ b/src/osgProducer/ViewerEventHandler.cpp @@ -4,6 +4,8 @@ #include #include #include +#include + #include #include @@ -144,6 +146,12 @@ protected: osg::ref_ptr _positionText; osg::ref_ptr _orientationText; osg::ref_ptr _speedText; + + TextList _sceneStatsLabelList; + osg::ref_ptr _numVerticesText; + osg::ref_ptr _numPrimitivesText; + osg::ref_ptr _numDrawablesText; + std::vector _fs; unsigned int _index; @@ -165,7 +173,6 @@ void ViewerEventHandler::StatsAndHelpDrawCallback::operator()( const Producer::C osgUtil::SceneView* sv = osh->getSceneView(); osg::State& state = *(sv->getState()); - state.applyProjectionMatrix(_projection.get()); state.applyModelViewMatrix(_modelview.get()); @@ -379,6 +386,8 @@ void ViewerEventHandler::StatsAndHelpDrawCallback::displayStats() OsgSceneHandler* osh = _veh->getOsgCameraGroup()->getSceneHandlerList()[_cameraNumber].get(); osgUtil::SceneView* sv = osh->getSceneView(); + char tmpText[128]; + // render graphs if (_veh->getFrameStatsMode()>=ViewerEventHandler::CAMERA_STATS) { @@ -387,7 +396,7 @@ void ViewerEventHandler::StatsAndHelpDrawCallback::displayStats() glMatrixMode( GL_PROJECTION ); glPushMatrix(); glLoadIdentity(); - glOrtho( -.025, .128, 600.0, -10.0, -1.0, 1.0 ); + glOrtho( -.03, .128, 600.0, -20.0, -1.0, 1.0 ); unsigned int lindex = (_index + 1) % _fs.size(); @@ -486,10 +495,8 @@ void ViewerEventHandler::StatsAndHelpDrawCallback::displayStats() { // update and draw the frame rate text. - char tmpText[128]; _frameRateLabelText->draw(*(sv->getState())); - if (_fs.size()>1) { unsigned int lindex = (_index + 1) % _fs.size(); @@ -554,6 +561,44 @@ void ViewerEventHandler::StatsAndHelpDrawCallback::displayStats() } } + if (_veh->getFrameStatsMode()>=ViewerEventHandler::SCENE_STATS) + { + osgUtil::Statistics stats; + + for(osgProducer::OsgCameraGroup::SceneHandlerList::iterator shitr = _veh->getOsgCameraGroup()->getSceneHandlerList().begin(); + shitr != _veh->getOsgCameraGroup()->getSceneHandlerList().end(); + ++shitr) + { + (*shitr)->getSceneView()->getStats(&stats); + } + + unsigned int primitives = 0; + for(osgUtil::Statistics::PrimitiveCountMap::iterator pcmitr = stats.GetPrimitivesBegin(); + pcmitr != stats.GetPrimitivesEnd(); + ++pcmitr) + { + primitives += pcmitr->second; + } + + for(TextList::iterator itr = _sceneStatsLabelList.begin(); + itr != _sceneStatsLabelList.end(); + ++itr) + { + (*itr)->draw(*(sv->getState())); + } + + sprintf(tmpText,"%d",stats._vertexCount); + _numVerticesText->setText(tmpText); + _numVerticesText->draw(*(sv->getState())); + + sprintf(tmpText,"%d",primitives); + _numPrimitivesText->setText(tmpText); + _numPrimitivesText->draw(*(sv->getState())); + + sprintf(tmpText,"%d",stats.numDrawables); + _numDrawablesText->setText(tmpText); + _numDrawablesText->draw(*(sv->getState())); + } } } @@ -593,7 +638,7 @@ void ViewerEventHandler::StatsAndHelpDrawCallback::createStatsText() pos.x() = leftPos; - pos.y() -= characterSize; + pos.y() -= characterSize*1.5f; { osgText::Text* text = new osgText::Text; @@ -693,7 +738,91 @@ void ViewerEventHandler::StatsAndHelpDrawCallback::createStatsText() pos.y() -= characterSize; } + pos.y() -= characterSize*0.5f; + // scene stats section + { + pos.x() = leftPos; + + // num drawables + osgText::Text* drawLabel = new osgText::Text; + drawLabel->setFont("fonts/arial.ttf"); + drawLabel->setColor(colorDraw); + drawLabel->setFontResolution((unsigned int)characterSize,(unsigned int)characterSize); + drawLabel->setCharacterSize(characterSize); + drawLabel->setPosition(pos); + drawLabel->setAlignment(osgText::Text::BASE_LINE); + drawLabel->setText("Number of Drawables: "); + + _sceneStatsLabelList.push_back(drawLabel); + + pos.x() = drawLabel->getBound().xMax(); + + _numDrawablesText = new osgText::Text; + _numDrawablesText->setFont("fonts/arial.ttf"); + _numDrawablesText->setColor(colorDraw); + _numDrawablesText->setFontResolution((unsigned int)characterSize,(unsigned int)characterSize); + _numDrawablesText->setCharacterSize(characterSize); + _numDrawablesText->setPosition(pos); + _numDrawablesText->setAlignment(osgText::Text::BASE_LINE); + _numDrawablesText->setText("100000 "); + + pos.x() = _numDrawablesText->getBound().xMax(); + + // num vertices + drawLabel = new osgText::Text; + drawLabel->setFont("fonts/arial.ttf"); + drawLabel->setColor(colorDraw); + drawLabel->setFontResolution((unsigned int)characterSize,(unsigned int)characterSize); + drawLabel->setCharacterSize(characterSize); + drawLabel->setPosition(pos); + drawLabel->setAlignment(osgText::Text::BASE_LINE); + drawLabel->setText("Number of Vertices: "); + + _sceneStatsLabelList.push_back(drawLabel); + + pos.x() = drawLabel->getBound().xMax(); + + _numVerticesText = new osgText::Text; + _numVerticesText->setFont("fonts/arial.ttf"); + _numVerticesText->setColor(colorDraw); + _numVerticesText->setFontResolution((unsigned int)characterSize,(unsigned int)characterSize); + _numVerticesText->setCharacterSize(characterSize); + _numVerticesText->setPosition(pos); + _numVerticesText->setAlignment(osgText::Text::BASE_LINE); + _numVerticesText->setText("1000000 "); + + pos.x() = _numVerticesText->getBound().xMax(); + + + // num primitives + drawLabel = new osgText::Text; + drawLabel->setFont("fonts/arial.ttf"); + drawLabel->setColor(colorDraw); + drawLabel->setFontResolution((unsigned int)characterSize,(unsigned int)characterSize); + drawLabel->setCharacterSize(characterSize); + drawLabel->setPosition(pos); + drawLabel->setAlignment(osgText::Text::BASE_LINE); + drawLabel->setText("Number of Primitives: "); + + _sceneStatsLabelList.push_back(drawLabel); + + pos.x() = drawLabel->getBound().xMax(); + + _numPrimitivesText = new osgText::Text; + _numPrimitivesText->setFont("fonts/arial.ttf"); + _numPrimitivesText->setColor(colorDraw); + _numPrimitivesText->setFontResolution((unsigned int)characterSize,(unsigned int)characterSize); + _numPrimitivesText->setCharacterSize(characterSize); + _numPrimitivesText->setPosition(pos); + _numPrimitivesText->setAlignment(osgText::Text::BASE_LINE); + _numPrimitivesText->setText("1000000 "); + + pos.x() = _numPrimitivesText->getBound().xMax(); + + + + } } void ViewerEventHandler::StatsAndHelpDrawCallback::displayInfo() @@ -792,7 +921,7 @@ bool ViewerEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActio { case 's' : { - FrameStatsMode newFrameStatsMode = (FrameStatsMode)((_frameStatsMode+1)%3); + FrameStatsMode newFrameStatsMode = (FrameStatsMode)((_frameStatsMode+1)%4); setFrameStatsMode(newFrameStatsMode); return true; } diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index c8028ace6..5d4a21086 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -1361,3 +1361,32 @@ void SceneView::getViewMatrixAsLookAt(Vec3& eye,Vec3& center,Vec3& up,float look { getViewMatrix().getLookAt(eye,center,up,lookDistance); } + +bool SceneView::getStats(Statistics* primStats) +{ + if (_displaySettings.valid() && _displaySettings->getStereo()) + { + switch(_displaySettings->getStereoMode()) + { + case(osg::DisplaySettings::QUAD_BUFFER): + case(osg::DisplaySettings::ANAGLYPHIC): + case(osg::DisplaySettings::HORIZONTAL_SPLIT): + case(osg::DisplaySettings::VERTICAL_SPLIT): + case(osg::DisplaySettings::VERTICAL_INTERLACE): + case(osg::DisplaySettings::HORIZONTAL_INTERLACE): + { + bool resultLeft = _renderStageLeft->getStats(primStats); + bool resultRight = _renderStageRight->getStats(primStats); + return resultLeft && resultRight; + } + case(osg::DisplaySettings::RIGHT_EYE): + case(osg::DisplaySettings::LEFT_EYE): + default: + return _renderStage->getStats(primStats); + } + } + else + { + return _renderStage->getStats(primStats); + } +} diff --git a/src/osgWrappers/osgProducer/ViewerEventHandler.cpp b/src/osgWrappers/osgProducer/ViewerEventHandler.cpp index 16dc00bed..775601689 100644 --- a/src/osgWrappers/osgProducer/ViewerEventHandler.cpp +++ b/src/osgWrappers/osgProducer/ViewerEventHandler.cpp @@ -28,6 +28,7 @@ BEGIN_ENUM_REFLECTOR(osgProducer::ViewerEventHandler::FrameStatsMode) I_EnumLabel(osgProducer::ViewerEventHandler::NO_STATS); I_EnumLabel(osgProducer::ViewerEventHandler::FRAME_RATE); I_EnumLabel(osgProducer::ViewerEventHandler::CAMERA_STATS); + I_EnumLabel(osgProducer::ViewerEventHandler::SCENE_STATS); END_REFLECTOR BEGIN_OBJECT_REFLECTOR(osgProducer::ViewerEventHandler) diff --git a/src/osgWrappers/osgUtil/SceneView.cpp b/src/osgWrappers/osgUtil/SceneView.cpp index e13176de1..f28d815a9 100644 --- a/src/osgWrappers/osgUtil/SceneView.cpp +++ b/src/osgWrappers/osgUtil/SceneView.cpp @@ -27,6 +27,7 @@ #include #include #include +#include // Must undefine IN and OUT macros defined in Windows headers #ifdef IN @@ -185,6 +186,7 @@ BEGIN_OBJECT_REFLECTOR(osgUtil::SceneView) I_Method0(void, releaseAllGLObjects); I_Method0(void, flushAllDeletedGLObjects); I_Method1(void, flushDeletedGLObjects, IN, double &, availableTime); + I_Method1(bool, getStats, IN, osgUtil::Statistics *, primStats); I_Property(int, ActiveUniforms); I_Property(osg::CameraNode *, Camera); I_Property(const osg::Vec4 &, ClearColor);