diff --git a/include/osgViewer/CompositeViewer b/include/osgViewer/CompositeViewer index 94e538713..7023fae10 100644 --- a/include/osgViewer/CompositeViewer +++ b/include/osgViewer/CompositeViewer @@ -95,8 +95,6 @@ class OSGVIEWER_EXPORT CompositeViewer : public ViewerBase, public virtual osg:: virtual void getContexts(Contexts& contexts, bool onlyValid=true); - virtual void getWindows(Windows& windows, bool onlyValid=true); - virtual void getAllThreads(Threads& threads, bool onlyActive=true); virtual void getOperationThreads(OperationThreads& threads, bool onlyActive=true); diff --git a/include/osgViewer/Viewer b/include/osgViewer/Viewer index dc2296516..645e4255c 100644 --- a/include/osgViewer/Viewer +++ b/include/osgViewer/Viewer @@ -88,8 +88,6 @@ class OSGVIEWER_EXPORT Viewer : public ViewerBase, public osgViewer::View virtual void getContexts(Contexts& contexts, bool onlyValid=true); - virtual void getWindows(Windows& windows, bool onlyValid=true); - virtual void getAllThreads(Threads& threads, bool onlyActive=true); virtual void getOperationThreads(OperationThreads& threads, bool onlyActive=true); diff --git a/include/osgViewer/ViewerBase b/include/osgViewer/ViewerBase index 0a17a9717..f6126e79e 100644 --- a/include/osgViewer/ViewerBase +++ b/include/osgViewer/ViewerBase @@ -217,7 +217,7 @@ class OSGVIEWER_EXPORT ViewerBase : public virtual osg::Object virtual void getContexts(Contexts& contexts, bool onlyValid=true) = 0; typedef std::vector Windows; - virtual void getWindows(Windows& windows, bool onlyValid=true) = 0; + virtual void getWindows(Windows& windows, bool onlyValid=true); typedef std::vector Threads; virtual void getAllThreads(Threads& threads, bool onlyActive=true) = 0; diff --git a/src/osgViewer/CompositeViewer.cpp b/src/osgViewer/CompositeViewer.cpp index c8ad1025c..b1692a089 100644 --- a/src/osgViewer/CompositeViewer.cpp +++ b/src/osgViewer/CompositeViewer.cpp @@ -276,39 +276,37 @@ void CompositeViewer::getContexts(Contexts& contexts, bool onlyValid) typedef std::set ContextSet; ContextSet contextSet; + contexts.clear(); + for(RefViews::iterator vitr = _views.begin(); vitr != _views.end(); ++vitr) { osgViewer::View* view = vitr->get(); - if (view->getCamera() && - view->getCamera()->getGraphicsContext() && - (view->getCamera()->getGraphicsContext()->valid() || !onlyValid)) + osg::GraphicsContext* gc = view->getCamera() ? view->getCamera()->getGraphicsContext() : 0; + if (gc && (gc->valid() || !onlyValid)) { - contextSet.insert(view->getCamera()->getGraphicsContext()); + if (contextSet.count(gc)==0) + { + contextSet.insert(gc); + contexts.push_back(gc); + } } for(unsigned int i=0; igetNumSlaves(); ++i) { View::Slave& slave = view->getSlave(i); - if (slave._camera.valid() && - slave._camera->getGraphicsContext() && - (slave._camera->getGraphicsContext()->valid() || !onlyValid)) + osg::GraphicsContext* sgc = slave._camera.valid() ? slave._camera->getGraphicsContext() : 0; + if (sgc && (sgc->valid() || !onlyValid)) { - contextSet.insert(slave._camera->getGraphicsContext()); + if (contextSet.count(sgc)==0) + { + contextSet.insert(sgc); + contexts.push_back(sgc); + } } } } - - contexts.clear(); - contexts.reserve(contextSet.size()); - - for(ContextSet::iterator itr = contextSet.begin(); - itr != contextSet.end(); - ++itr) - { - contexts.push_back(const_cast(*itr)); - } } void CompositeViewer::getCameras(Cameras& cameras, bool onlyActive) @@ -334,22 +332,6 @@ void CompositeViewer::getCameras(Cameras& cameras, bool onlyActive) } } -void CompositeViewer::getWindows(Windows& windows, bool onlyValid) -{ - windows.clear(); - - Contexts contexts; - getContexts(contexts, onlyValid); - - for(Contexts::iterator itr = contexts.begin(); - itr != contexts.end(); - ++itr) - { - osgViewer::GraphicsWindow* gw = dynamic_cast(*itr); - if (gw) windows.push_back(gw); - } -} - void CompositeViewer::getScenes(Scenes& scenes, bool onlyValid) { typedef std::set SceneSet; @@ -362,16 +344,13 @@ void CompositeViewer::getScenes(Scenes& scenes, bool onlyValid) osgViewer::View* view = vitr->get(); if (view->getScene() && (!onlyValid || view->getScene()->getSceneData())) { - sceneSet.insert(view->getScene()); + if (sceneSet.count(view->getScene())==0) + { + sceneSet.insert(view->getScene()); + scenes.push_back(view->getScene()); + } } } - - for(SceneSet::iterator sitr = sceneSet.begin(); - sitr != sceneSet.end(); - ++sitr) - { - scenes.push_back(const_cast(*sitr)); - } } void CompositeViewer::getViews(Views& views, bool onlyValid) diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index f83fbf15f..f0179f5f7 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -951,23 +951,6 @@ void Viewer::getViews(Views& views, bool onlyValid) views.push_back(this); } -void Viewer::getWindows(Windows& windows, bool onlyValid) -{ - windows.clear(); - - Contexts contexts; - getContexts(contexts, onlyValid); - - for(Contexts::iterator itr = contexts.begin(); - itr != contexts.end(); - ++itr) - { - osgViewer::GraphicsWindow* gw = dynamic_cast(*itr); - if (gw) windows.push_back(gw); - } -} - - void Viewer::getAllThreads(Threads& threads, bool onlyActive) { OperationThreads operationThreads; @@ -1033,68 +1016,34 @@ void Viewer::getOperationThreads(OperationThreads& threads, bool onlyActive) } -struct LessGraphicsContext -{ - bool operator () (const osg::GraphicsContext* lhs, const osg::GraphicsContext* rhs) const - { - int screenLeft = lhs->getTraits()? lhs->getTraits()->screenNum : 0; - int screenRight = rhs->getTraits()? rhs->getTraits()->screenNum : 0; - if (screenLeft < screenRight) return true; - if (screenLeft > screenRight) return false; - - screenLeft = lhs->getTraits()? lhs->getTraits()->x : 0; - screenRight = rhs->getTraits()? rhs->getTraits()->x : 0; - if (screenLeft < screenRight) return true; - if (screenLeft > screenRight) return false; - - screenLeft = lhs->getTraits()? lhs->getTraits()->y : 0; - screenRight = rhs->getTraits()? rhs->getTraits()->y : 0; - if (screenLeft < screenRight) return true; - if (screenLeft > screenRight) return false; - - return lhs < rhs; - } -}; - - - void Viewer::getContexts(Contexts& contexts, bool onlyValid) { typedef std::set ContextSet; ContextSet contextSet; + contexts.clear(); + if (_camera.valid() && _camera->getGraphicsContext() && (_camera->getGraphicsContext()->valid() || !onlyValid)) { contextSet.insert(_camera->getGraphicsContext()); + contexts.push_back(_camera->getGraphicsContext()); } for(unsigned int i=0; igetGraphicsContext() && - (slave._camera->getGraphicsContext()->valid() || !onlyValid)) + osg::GraphicsContext* sgc = slave._camera.valid() ? slave._camera->getGraphicsContext() : 0; + if (sgc && (sgc->valid() || !onlyValid)) { - contextSet.insert(slave._camera->getGraphicsContext()); + if (contextSet.count(sgc)==0) + { + contextSet.insert(sgc); + contexts.push_back(sgc); + } } } - - contexts.clear(); - contexts.reserve(contextSet.size()); - - for(ContextSet::iterator itr = contextSet.begin(); - itr != contextSet.end(); - ++itr) - { - contexts.push_back(const_cast(*itr)); - } - - if (contexts.size()>=2) - { - std::sort(contexts.begin(), contexts.end(), LessGraphicsContext()); - } } void Viewer::getCameras(Cameras& cameras, bool onlyActive) diff --git a/src/osgViewer/ViewerBase.cpp b/src/osgViewer/ViewerBase.cpp index ff5f85e45..1c57ca52f 100644 --- a/src/osgViewer/ViewerBase.cpp +++ b/src/osgViewer/ViewerBase.cpp @@ -501,6 +501,22 @@ void ViewerBase::startThreading() osg::notify(osg::INFO)<<"Set up threading"<(*itr); + if (gw) windows.push_back(gw); + } +} + void ViewerBase::checkWindowStatus() { Contexts contexts;