From b47ef11d7421427a30c36d280da0ea8f784b3428 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 21 Jan 2007 18:24:54 +0000 Subject: [PATCH] Initial on screen stats support --- Make/makedirdefs | 42 +- VisualStudio/OpenSceneGraph.dsw | 28 +- .../osgviewer/osgviewerapplication.dsp | 4 +- applications/osgviewer/GNUmakefile | 2 +- applications/osgviewer/GNUmakefile.inst | 2 +- applications/osgviewer/osgviewer.cpp | 408 ++++++++++++------ include/osg/View | 2 +- src/osg/Stats.cpp | 2 +- src/osg/View.cpp | 9 + src/osgUtil/SceneView.cpp | 5 +- src/osgViewer/CompositeViewer.cpp | 55 ++- src/osgViewer/Viewer.cpp | 71 ++- 12 files changed, 444 insertions(+), 186 deletions(-) diff --git a/Make/makedirdefs b/Make/makedirdefs index 3a85a93d2..444d28907 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -184,25 +184,22 @@ endif APPLICATION_DIRS = \ osgversion +APPLICATION_DIRS += osgarchive \ + osgconv \ + osgviewer \ + +ifeq ($(GDAL_INSTALLED),yes) + APPLICATION_DIRS += osgdem +endif + ifeq ($(PRODUCER_INSTALLED),yes) - APPLICATION_DIRS += osgarchive \ - osgconv \ - osgviewer \ - - ifeq ($(GDAL_INSTALLED),yes) - APPLICATION_DIRS += osgdem - endif + APPLICATION_DIRS += osgproducerviewer endif - -EXAMPLE_DIRS = - - -ifeq ($(PRODUCER_INSTALLED),yes) - - EXAMPLE_DIRS += osganimate \ +EXAMPLE_DIRS = \ + osganimate \ osgautotransform \ osgbillboard \ osgblendequation \ @@ -276,17 +273,16 @@ ifeq ($(PRODUCER_INSTALLED),yes) osgvolume \ osgwindows \ - ifeq ($(COMPILE_INTROSPECTION),yes) - EXAMPLE_DIRS += osgintrospection - endif - ifeq ($(GDAL_INSTALLED),yes) - EXAMPLE_DIRS += osgphotoalbum - EXAMPLE_DIRS += osgbluemarble - EXAMPLE_DIRS += osgsimulation - EXAMPLE_DIRS += osgfadetext - endif +ifeq ($(COMPILE_INTROSPECTION),yes) + EXAMPLE_DIRS += osgintrospection +endif +ifeq ($(GDAL_INSTALLED),yes) + EXAMPLE_DIRS += osgphotoalbum + EXAMPLE_DIRS += osgbluemarble + EXAMPLE_DIRS += osgsimulation + EXAMPLE_DIRS += osgfadetext endif ifeq ($(GLUT_INSTALLED),yes) diff --git a/VisualStudio/OpenSceneGraph.dsw b/VisualStudio/OpenSceneGraph.dsw index 59661a304..68dcaff74 100644 --- a/VisualStudio/OpenSceneGraph.dsw +++ b/VisualStudio/OpenSceneGraph.dsw @@ -366,10 +366,34 @@ Package=<4> Project_Dep_Name Core osgGA End Project Dependency Begin Project Dependency - Project_Dep_Name Core osgProducer + Project_Dep_Name Core osgViewer End Project Dependency Begin Project Dependency - Project_Dep_Name Core osgViewer + Project_Dep_Name Core osgUtil + End Project Dependency +}}} + +############################################################################### + +Project: "Application osgproducerviewer"=.\applications\osgproducerviewer\osgproducerviewer.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name Core osg + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgDB + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgGA + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgProducer End Project Dependency Begin Project Dependency Project_Dep_Name Core osgUtil diff --git a/VisualStudio/applications/osgviewer/osgviewerapplication.dsp b/VisualStudio/applications/osgviewer/osgviewerapplication.dsp index 2cc7fecb0..e269f8878 100644 --- a/VisualStudio/applications/osgviewer/osgviewerapplication.dsp +++ b/VisualStudio/applications/osgviewer/osgviewerapplication.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Target_Dir "" MTL=midl.exe # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../Producer/include" /I "../../../../3rdParty/include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "_CRT_SECURE_NO_DEPRECATE" /YX /FD /Zm200 /c +# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../3rdParty/include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "_CRT_SECURE_NO_DEPRECATE" /YX /FD /Zm200 /c # ADD BASE RSC /l 0x809 /d "NDEBUG" # ADD RSC /l 0x809 /d "NDEBUG" BSC32=bscmake.exe @@ -68,7 +68,7 @@ LINK32=link.exe # PROP Target_Dir "" MTL=midl.exe # ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /Zi /Od /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../Producer/include" /I "../../../../3rdParty/include" /D "_CONSOLE" /D "_MBCS" /D "FL_DLL" /D "WIN32" /D "_DEBUG" /D "_CRT_SECURE_NO_DEPRECATE" /FR /YX /FD /Zm200 /c +# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /Zi /Od /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../3rdParty/include" /D "_CONSOLE" /D "_MBCS" /D "FL_DLL" /D "WIN32" /D "_DEBUG" /D "_CRT_SECURE_NO_DEPRECATE" /FR /YX /FD /Zm200 /c # ADD BASE RSC /l 0x809 /d "_DEBUG" # ADD RSC /l 0x809 /d "_DEBUG" BSC32=bscmake.exe diff --git a/applications/osgviewer/GNUmakefile b/applications/osgviewer/GNUmakefile index cd327bb67..3c4db770e 100644 --- a/applications/osgviewer/GNUmakefile +++ b/applications/osgviewer/GNUmakefile @@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs CXXFILES =\ osgviewer.cpp\ -LIBS += -losgViewer -losgProducer -lProducer -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) +LIBS += -losgViewer -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) INSTFILES = \ $(CXXFILES)\ diff --git a/applications/osgviewer/GNUmakefile.inst b/applications/osgviewer/GNUmakefile.inst index 74794f7a9..2bb519bd6 100644 --- a/applications/osgviewer/GNUmakefile.inst +++ b/applications/osgviewer/GNUmakefile.inst @@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs CXXFILES =\ osgviewer.cpp\ -LIBS += -losgViewer -losgProducer -lProducer -losgDB -losgText -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) +LIBS += -losgViewer -losgDB -losgText -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) EXEC = osgviewer diff --git a/applications/osgviewer/osgviewer.cpp b/applications/osgviewer/osgviewer.cpp index 71fadae47..e5e04ecef 100644 --- a/applications/osgviewer/osgviewer.cpp +++ b/applications/osgviewer/osgviewer.cpp @@ -12,127 +12,12 @@ #include #include #include -#include -/////////////////////////////////////////////////////////////////////////// -// -// osgProducer version (see osgViewer version in next section below) - -#include -int main_osgProducer(osg::ArgumentParser& arguments) -{ - // set up the usage document, in case we need to print out how to use this program. - arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); - arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models."); - arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); - arguments.getApplicationUsage()->addCommandLineOption("--image ","Load an image and render it on a quad"); - arguments.getApplicationUsage()->addCommandLineOption("--dem ","Load an image/DEM and render it on a HeightField"); - arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line parameters"); - arguments.getApplicationUsage()->addCommandLineOption("--help-env","Display environmental variables available"); - arguments.getApplicationUsage()->addCommandLineOption("--help-keys","Display keyboard & mouse bindings available"); - arguments.getApplicationUsage()->addCommandLineOption("--help-all","Display all command line, env vars and keyboard & mouse bindings."); - - - // construct the viewer. - osgProducer::Viewer viewer(arguments); - - // set up the value with sensible default event handlers. - viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); - - // get details on keyboard and mouse bindings used by the viewer. - viewer.getUsage(*arguments.getApplicationUsage()); - - // if user request help write it out to cout. - bool helpAll = arguments.read("--help-all"); - unsigned int helpType = ((helpAll || arguments.read("-h") || arguments.read("--help"))? osg::ApplicationUsage::COMMAND_LINE_OPTION : 0 ) | - ((helpAll || arguments.read("--help-env"))? osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE : 0 ) | - ((helpAll || arguments.read("--help-keys"))? osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING : 0 ); - if (helpType) - { - arguments.getApplicationUsage()->write(std::cout, helpType); - return 1; - } - - // report any errors if they have occurred when parsing the program arguments. - if (arguments.errors()) - { - arguments.writeErrorMessages(std::cout); - return 1; - } - - if (arguments.argc()<=1) - { - arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); - return 1; - } - - osg::Timer_t start_tick = osg::Timer::instance()->tick(); - - // read the scene from the list of file specified command line args. - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); - - // if no model has been successfully loaded report failure. - if (!loadedModel) - { - std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; - return 1; - } - - // any option left unread are converted into errors to write out later. - arguments.reportRemainingOptionsAsUnrecognized(); - - // report any errors if they have occurred when parsing the program arguments. - if (arguments.errors()) - { - arguments.writeErrorMessages(std::cout); - } - - osg::Timer_t end_tick = osg::Timer::instance()->tick(); - - std::cout << "Time to load = "<delta_s(start_tick,end_tick)< +#include #include + #include #include #include @@ -141,6 +26,8 @@ int main_osgProducer(osg::ArgumentParser& arguments) #include #include +#include + class ThreadingHandler : public osgGA::GUIEventHandler { public: @@ -204,7 +91,20 @@ class StatsHandler : public osgGA::GUIEventHandler { public: - StatsHandler() {} + StatsHandler(): + _statsType(NO_STATS), + _frameRateChildNum(0), + _viewerChildNum(0), + _sceneChildNum(0) {} + + enum StatsType + { + NO_STATS = 0, + FRAME_RATE = 1, + VIEWER_STATS = 2, + SCENE_STATS = 3, + LAST = 4 + }; bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) { @@ -216,6 +116,54 @@ public: case(osgGA::GUIEventAdapter::KEYDOWN): { if (ea.getKey()=='s') + { + if (viewer->getStats()) + { + if (!_camera.valid()) + { + setUpCamera(viewer); + setUpScene(viewer); + } + + ++_statsType; + + if (_statsType==LAST) _statsType = NO_STATS; + + switch(_statsType) + { + case(NO_STATS): + { + _camera->setNodeMask(0x0); + _switch->setAllChildrenOff(); + break; + } + case(FRAME_RATE): + { + _camera->setNodeMask(0xffffffff); + _switch->setValue(_frameRateChildNum, true); + break; + } + case(VIEWER_STATS): + { + _camera->setNodeMask(0xffffffff); + _switch->setValue(_viewerChildNum, true); + break; + } + case(SCENE_STATS): + { + _switch->setValue(_sceneChildNum, true); + _camera->setNodeMask(0xffffffff); + break; + } + default: + break; + } + + + } + return true; + } + if (ea.getKey()=='S') { if (viewer->getStats()) { @@ -224,17 +172,218 @@ public: return true; } } + case(osgGA::GUIEventAdapter::FRAME): + { + update(viewer); + return true; + } default: break; } return false; + + } + + void setUpCamera(osgViewer::Viewer* viewer) + { + osgViewer::Viewer::Windows windows; + viewer->getWindows(windows); + + if (windows.empty()) return; + + osgViewer::GraphicsWindow* window = windows.front(); + + _camera = new osg::Camera; + _camera->setGraphicsContext(window); + _camera->setViewport(0, 0, window->getTraits()->width, window->getTraits()->height); + + _camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024)); + _camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); + _camera->setViewMatrix(osg::Matrix::identity()); + + // only clear the depth buffer + _camera->setClearMask(0); + + viewer->setUpRenderingSupport(); } - bool _done; + struct TextDrawCallback : public virtual osg::Drawable::DrawCallback + { + TextDrawCallback(osg::Stats* stats, const std::string name, int frameDelta): + _stats(stats), + _attributeName(name), + _frameDelta(frameDelta) {} + + /** do customized draw code.*/ + virtual void drawImplementation(osg::RenderInfo& renderInfo,const osg::Drawable* drawable) const + { + osgText::Text* text = (osgText::Text*)drawable; + + int frameNumber = renderInfo.getState()->getFrameStamp()->getFrameNumber(); + + double value; + if (_stats->getAttribute( frameNumber+_frameDelta, _attributeName, value)) + { + sprintf(_tmpText,"%4.2f",value); + text->setText(_tmpText); + } + + text->drawImplementation(renderInfo); + } + + osg::Stats* _stats; + std::string _attributeName; + int _frameDelta; + mutable char _tmpText[128]; + }; + + void setUpScene(osgViewer::Viewer* viewer) + { + _switch = new osg::Switch; + _camera->addChild(_switch.get()); + + osg::StateSet* stateset = _switch->getOrCreateStateSet(); + stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); + stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); + + std::string font("fonts/arial.ttf"); + + float leftPos = 10.0f; + float characterSize = 20.0f; + + osg::Vec3 pos(leftPos,1000.0f,0.0f); + + osg::Vec4 colorFR(1.0f,1.0f,1.0f,1.0f); + osg::Vec4 colorUpdate( 0.0f,1.0f,0.0f,1.0f); + osg::Vec4 colorCull( 0.0f,1.0f,1.0f,1.0f); + osg::Vec4 colorDraw( 1.0f,1.0f,0.0f,1.0f); + osg::Vec4 colorGPU( 1.0f,0.5f,0.0f,1.0f); + + + // frame rate stats + { + osg::Geode* geode = new osg::Geode(); + + std::string font("fonts/arial.ttf"); + + // turn lighting off for the text and disable depth test to ensure its always ontop. + + { + _frameRateLabel = new osgText::Text; + geode->addDrawable( _frameRateLabel.get() ); + + _frameRateLabel->setColor(colorFR); + _frameRateLabel->setFont(font); + _frameRateLabel->setCharacterSize(characterSize); + _frameRateLabel->setPosition(pos); + _frameRateLabel->setText("Frame Rate: "); + + pos.x() = _frameRateLabel->getBound().xMax(); + + _frameRateValue = new osgText::Text; + geode->addDrawable( _frameRateValue.get() ); + + _frameRateValue->setColor(colorFR); + _frameRateValue->setFont(font); + _frameRateValue->setCharacterSize(characterSize); + _frameRateValue->setPosition(pos); + _frameRateValue->setText("0.0"); + + _frameRateValue->setDrawCallback(new TextDrawCallback(viewer->getStats(),"Frame rate",-1)); + + pos.y() -= characterSize*1.5f; +; + } + + _frameRateChildNum = _switch->getNumChildren(); + _switch->addChild(geode, false); + } + + + // viewer stats + { + pos.x() = leftPos; + + osg::Geode* geode = new osg::Geode(); + + { + osgText::Text* text = new osgText::Text; + geode->addDrawable( text ); + + text->setFont(font); + text->setPosition(pos); + text->setText("Viewer Stats "); + + pos.y() -= characterSize*1.5f; + } + + _viewerChildNum = _switch->getNumChildren(); + _switch->addChild(geode, false); + } + + // scene stats + { + pos.x() = leftPos; + + osg::Geode* geode = new osg::Geode(); + + { + osgText::Text* text = new osgText::Text; + geode->addDrawable( text ); + + text->setFont(font); + text->setPosition(pos); + text->setText("Scene Stats "); + + pos.y() -= characterSize*1.5f; + } + + _sceneChildNum = _switch->getNumChildren(); + _switch->addChild(geode, false); + } + } + + void update(osgViewer::Viewer* viewer) + { + return ; + + osg::Stats* stats = viewer->getStats(); + if (!stats || _statsType==NO_STATS) return; + + int frameNumber = viewer->getFrameStamp()->getFrameNumber(); + + char tmpText[128]; + double frameRate = 0.0; + + osg::Timer_t startTick = osg::Timer::instance()->tick(); + if (stats->getAttribute(frameNumber-1, "Frame rate", frameRate)) + { + sprintf(tmpText,"%4.2f",frameRate); + _frameRateValue->setText(tmpText); + } + + } + + + int _statsType; + osg::ref_ptr _camera; + osg::ref_ptr _switch; + + unsigned int _frameRateChildNum; + osg::ref_ptr _frameRateLabel; + osg::ref_ptr _frameRateValue; + + unsigned int _viewerChildNum; + + unsigned int _sceneChildNum; + }; -int main_osgViewer(osg::ArgumentParser& arguments) +int main(int argc, char** argv) { + // use an ArgumentParser object to manage the program arguments. + osg::ArgumentParser arguments(&argc,argv); + arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); @@ -338,20 +487,3 @@ int main_osgViewer(osg::ArgumentParser& arguments) return viewer.run(); } - -int main( int argc, char **argv ) -{ - // use an ArgumentParser object to manage the program arguments. - osg::ArgumentParser arguments(&argc,argv); - - if (arguments.read("--osgProducer")) - { - return main_osgProducer(arguments); - } - else - { - return main_osgViewer(arguments); - } - -} - diff --git a/include/osg/View b/include/osg/View index 24ecd5111..71457827b 100644 --- a/include/osg/View +++ b/include/osg/View @@ -43,7 +43,7 @@ class OSG_EXPORT View : public virtual osg::Referenced /** Set the master camera of the view. */ - void setCamera(osg::Camera* camera) { _camera = camera; } + void setCamera(osg::Camera* camera); /** Get the master camera of the view. */ osg::Camera* getCamera() { return _camera.get(); } diff --git a/src/osg/Stats.cpp b/src/osg/Stats.cpp index b16d0b0c0..00cdf0ebb 100644 --- a/src/osg/Stats.cpp +++ b/src/osg/Stats.cpp @@ -74,7 +74,7 @@ bool Stats::getAttribute(int frameNumber, const std::string& attributeName, doub const AttributeMap& attributeMap = _attributeMapList[index]; AttributeMap::const_iterator itr = attributeMap.find(attributeName); - if (itr != attributeMap.end()) return false; + if (itr == attributeMap.end()) return false; value = itr->second; return true; diff --git a/src/osg/View.cpp b/src/osg/View.cpp index 061b814f5..e5c4951ae 100644 --- a/src/osg/View.cpp +++ b/src/osg/View.cpp @@ -53,6 +53,15 @@ View::~View() } +void View::setCamera(osg::Camera* camera) +{ + if (_camera.valid()) _camera->setView(0); + + _camera = camera; + + if (_camera.valid()) _camera->setView(this); +} + void View::updateSlaves() { for(unsigned int i=0; i<_slaves.size(); ++i) diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index e88c29392..fbe5c6c87 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -477,6 +477,8 @@ osg::Matrixd SceneView::computeRightEyeViewImplementation(const osg::Matrixd& vi void SceneView::cull() { + if (_camera->getNodeMask()==0) return; + _renderInfo.setView(_camera->getView()); // update the active uniforms @@ -693,7 +695,7 @@ void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod renderStage->setViewport(getViewport()); renderStage->setClearColor(getClearColor()); - + renderStage->setClearMask(_camera->getClearMask()); switch(_lightingMode) { @@ -812,6 +814,7 @@ void SceneView::flushDeletedGLObjects(double& availableTime) void SceneView::draw() { + if (_camera->getNodeMask()==0) return; osg::State* state = _renderInfo.getState(); diff --git a/src/osgViewer/CompositeViewer.cpp b/src/osgViewer/CompositeViewer.cpp index ae50e4990..d26899459 100644 --- a/src/osgViewer/CompositeViewer.cpp +++ b/src/osgViewer/CompositeViewer.cpp @@ -533,6 +533,57 @@ struct CompositeViewerRenderingOperation : public osg::GraphicsOperation void CompositeViewer::setUpRenderingSupport() { +#if 1 + _cameraSceneViewMap.clear(); + + Contexts contexts; + getContexts(contexts); + + osg::FrameStamp* frameStamp = getFrameStamp(); + + for(Contexts::iterator gcitr = contexts.begin(); + gcitr != contexts.end(); + ++gcitr) + { + (*gcitr)->removeAllOperations(); + + osg::GraphicsContext* gc = *gcitr; + osg::GraphicsContext::Cameras& cameras = gc->getCameras(); + osg::State* state = gc->getState(); + + for(osg::GraphicsContext::Cameras::iterator citr = cameras.begin(); + citr != cameras.end(); + ++citr) + { + osg::Camera* camera = *citr; + osgViewer::View* view = dynamic_cast(camera->getView()); + osgViewer::Scene* scene = view ? view->getScene() : 0; + + osg::DisplaySettings* ds = view ? view->getDisplaySettings() : 0; + if (!ds) ds = osg::DisplaySettings::instance(); + + osgDB::DatabasePager* dp = scene ? scene->getDatabasePager() : 0; + + camera->setStats(new osg::Stats("Camera")); + + osgUtil::SceneView* sceneView = new osgUtil::SceneView; + _cameraSceneViewMap[camera] = sceneView; + + sceneView->setGlobalStateSet(view ? view->getCamera()->getStateSet() : 0); + sceneView->setDefaults(); + sceneView->setDisplaySettings(ds); + sceneView->setCamera(camera); + sceneView->setState(state); + sceneView->setFrameStamp(frameStamp); + + if (dp) dp->setCompileGLObjectsForContextID(state->getContextID(), true); + + gc->add(new CompositeViewerRenderingOperation(sceneView, dp)); + + } + } + +#else osg::FrameStamp* frameStamp = getFrameStamp(); // what should we do with the old sceneViews? @@ -549,8 +600,6 @@ void CompositeViewer::setUpRenderingSupport() (*citr)->removeAllOperations(); } - - for(Views::iterator itr = _views.begin(); itr != _views.end(); ++itr) @@ -601,7 +650,7 @@ void CompositeViewer::setUpRenderingSupport() } } - +#endif } diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index 0b290cfed..fd41c4ae9 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -533,28 +533,72 @@ struct ViewerRenderingOperation : public osg::GraphicsOperation void Viewer::setUpRenderingSupport() { - osg::FrameStamp* frameStamp = getFrameStamp(); - - // what should we do with the old sceneViews? +#if 1 _cameraSceneViewMap.clear(); Contexts contexts; getContexts(contexts); - - // clear out all the previously assigned operations - for(Contexts::iterator citr = contexts.begin(); - citr != contexts.end(); - ++citr) - { - (*citr)->removeAllOperations(); - } - + + osg::FrameStamp* frameStamp = getFrameStamp(); osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance(); osgDB::DatabasePager* dp = _scene.valid() ? _scene->getDatabasePager() : 0; + for(Contexts::iterator gcitr = contexts.begin(); + gcitr != contexts.end(); + ++gcitr) + { + (*gcitr)->removeAllOperations(); + + osg::GraphicsContext* gc = *gcitr; + osg::GraphicsContext::Cameras& cameras = gc->getCameras(); + osg::State* state = gc->getState(); + + for(osg::GraphicsContext::Cameras::iterator citr = cameras.begin(); + citr != cameras.end(); + ++citr) + { + osg::Camera* camera = *citr; + + camera->setStats(new osg::Stats("Camera")); + + osgUtil::SceneView* sceneView = new osgUtil::SceneView; + _cameraSceneViewMap[camera] = sceneView; + + sceneView->setGlobalStateSet(_camera->getStateSet()); + sceneView->setDefaults(); + sceneView->setDisplaySettings(ds); + sceneView->setCamera(camera); + sceneView->setState(state); + sceneView->setFrameStamp(frameStamp); + + if (dp) dp->setCompileGLObjectsForContextID(state->getContextID(), true); + + gc->add(new ViewerRenderingOperation(sceneView, dp)); + + } + } + +#else + _cameraSceneViewMap.clear(); + + Contexts contexts; + getContexts(contexts); + + osg::FrameStamp* frameStamp = getFrameStamp(); + osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance(); + osgDB::DatabasePager* dp = _scene.valid() ? _scene->getDatabasePager() : 0; + + // clear out all the previously assigned operations + for(Contexts::iterator gcitr = contexts.begin(); + gcitr != contexts.end(); + ++gcitr) + { + (*gcitr)->removeAllOperations(); + } + if (_camera.valid() && _camera->getGraphicsContext()) { - _camera->setStats(new osg::Stats("Viewer")); + _camera->setStats(new osg::Stats("Camera")); osgUtil::SceneView* sceneView = new osgUtil::SceneView; _cameraSceneViewMap[_camera] = sceneView; @@ -595,6 +639,7 @@ void Viewer::setUpRenderingSupport() slave._camera->getGraphicsContext()->add(new ViewerRenderingOperation(sceneView, dp)); } } +#endif }