From 3de205ec4564f27397380ab40be6cad239ef886b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 6 Feb 2007 14:38:08 +0000 Subject: [PATCH] Added new Viewer threading model options --- applications/osgviewer/osgviewer.cpp | 22 ++++-- examples/osgcamera/osgcamera.cpp | 27 ++++--- include/osgViewer/Viewer | 9 ++- src/osgViewer/Viewer.cpp | 102 ++++++++++++++++++++------- 4 files changed, 118 insertions(+), 42 deletions(-) diff --git a/applications/osgviewer/osgviewer.cpp b/applications/osgviewer/osgviewer.cpp index 2a768e5db..4e2b92304 100644 --- a/applications/osgviewer/osgviewer.cpp +++ b/applications/osgviewer/osgviewer.cpp @@ -49,16 +49,24 @@ public: switch(viewer->getThreadingModel()) { case(osgViewer::Viewer::SingleThreaded): - viewer->setThreadingModel(osgViewer::Viewer::ThreadPerContext); - osg::notify(osg::NOTICE)<<"Threading model 'ThreadPerContext' selected."<setThreadingModel(osgViewer::Viewer::CullDrawThreadPerContext); + osg::notify(osg::NOTICE)<<"Threading model 'CullDrawThreadPerContext' selected."<setThreadingModel(osgViewer::Viewer::ThreadPerCamera); - osg::notify(osg::NOTICE)<<"Threading model 'ThreadPerCamera' selected."<setThreadingModel(osgViewer::Viewer::DrawThreadPerContext); + osg::notify(osg::NOTICE)<<"Threading model 'DrawThreadPerContext' selected."<setThreadingModel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext); + osg::notify(osg::NOTICE)<<"Threading model 'CullThreadPerCameraDrawThreadPerContext' selected."<setThreadingModel(osgViewer::Viewer::SingleThreaded); - osg::notify(osg::NOTICE)<<"Threading model 'SingleTheaded' selected."<setThreadingModel(viewer->suggestBestThreadingModel()); + osg::notify(osg::NOTICE)<<"Threading model 'AutomaticSelection' selected."<getThreadingModel()) { case(osgViewer::Viewer::SingleThreaded): - viewer->setThreadingModel(osgViewer::Viewer::ThreadPerContext); - osg::notify(osg::NOTICE)<<"Threading model 'ThreadPerContext' selected."<setThreadingModel(osgViewer::Viewer::CullDrawThreadPerContext); + osg::notify(osg::NOTICE)<<"Threading model 'CullDrawThreadPerContext' selected."<setThreadingModel(osgViewer::Viewer::ThreadPerCamera); - osg::notify(osg::NOTICE)<<"Threading model 'ThreadPerCamera' selected."<setThreadingModel(osgViewer::Viewer::DrawThreadPerContext); + osg::notify(osg::NOTICE)<<"Threading model 'DrawThreadPerContext' selected."<setThreadingModel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext); + osg::notify(osg::NOTICE)<<"Threading model 'CullThreadPerCameraDrawThreadPerContext' selected."<setThreadingModel(osgViewer::Viewer::SingleThreaded); - osg::notify(osg::NOTICE)<<"Threading model 'SingleTheaded' selected."<setThreadingModel(viewer->suggestBestThreadingModel()); + osg::notify(osg::NOTICE)<<"Threading model 'AutomaticSelection' selected."<= static_cast(cameras.size()+contexts.size())) + { + return CullThreadPerCameraDrawThreadPerContext; + } + +#if 1 + return DrawThreadPerContext; +#else + return CullDrawThreadPerContext; +#endif +} + unsigned int Viewer::computeNumberOfThreadsIncludingMainRequired() { unsigned int numThreadsOnBarrier = 1; - switch(_threadingModel) + + ThreadingModel threadingModel = _threadingModel==AutomaticSelection ? suggestBestThreadingModel() : _threadingModel; + + switch(threadingModel) { case(SingleThreaded): numThreadsOnBarrier = 1; break; - case(ThreadPerContext): + case(CullDrawThreadPerContext): { Contexts contexts; getContexts(contexts); numThreadsOnBarrier = contexts.size()+1; break; - } - case(ThreadPerCamera): + } + case(DrawThreadPerContext): + numThreadsOnBarrier = 1; + break; + case(CullThreadPerCameraDrawThreadPerContext): { Cameras cameras; getCameras(cameras); numThreadsOnBarrier = _useMainThreadForRenderingTraversal ? cameras.size() : cameras.size()+1; break; } + default: + osg::notify(osg::NOTICE)<<"Error: Threading model not selected"<resizeGLObjectBuffers(osg::DisplaySettings::instance()->getMaxNumberOfGraphicsContexts()); } - osg::notify(osg::NOTICE)<<"_numThreadsOnBarrier = "<<_numThreadsOnBarrier<