diff --git a/include/osgViewer/CompositeViewer b/include/osgViewer/CompositeViewer index f5ca58f76..b1f7a5482 100644 --- a/include/osgViewer/CompositeViewer +++ b/include/osgViewer/CompositeViewer @@ -138,11 +138,21 @@ class OSGVIEWER_EXPORT CompositeViewer : public osg::Referenced typedef std::vector Scenes; void getScenes(Scenes& scenes, bool onlyValid=true); - void stopThreading(); - void startThreading(); - void setUpRenderingSupport(); - public: + /** Set the graphics operation to call on realization of the viewers graphics windows.*/ + void setRealizeOperation(osg::GraphicsOperation* op) { _realizeOperation = op; } + + /** Get the graphics operation to call on realization of the viewers graphics windows.*/ + osg::GraphicsOperation* getRealizeOperation() { return _realizeOperation.get(); } + + /** Stop any threads begin run by viewer.*/ + void stopThreading(); + + /** Start any threads required by the viewer, as per viewers ThreadingModel.*/ + void startThreading(); + + /** Set up the GraphicsOperations to render the various viewer cameras on the viewers graphics windows.*/ + void setUpRenderingSupport(); protected: @@ -180,6 +190,8 @@ class OSGVIEWER_EXPORT CompositeViewer : public osg::Referenced osg::ref_ptr _eventQueue; osg::ref_ptr _eventVisitor; + + osg::ref_ptr _realizeOperation; }; diff --git a/include/osgViewer/Viewer b/include/osgViewer/Viewer index cce614c4d..64e22c5f9 100644 --- a/include/osgViewer/Viewer +++ b/include/osgViewer/Viewer @@ -123,8 +123,19 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View typedef std::vector Windows; void getWindows(Windows& windows, bool onlyValid=true); + /** Set the graphics operation to call on realization of the viewers graphics windows.*/ + void setRealizeOperation(osg::GraphicsOperation* op) { _realizeOperation = op; } + + /** Get the graphics operation to call on realization of the viewers graphics windows.*/ + osg::GraphicsOperation* getRealizeOperation() { return _realizeOperation.get(); } + + /** Stop any threads begin run by viewer.*/ void stopThreading(); + + /** Start any threads required by the viewer, as per viewers ThreadingModel.*/ void startThreading(); + + /** Set up the GraphicsOperations to render the various viewer cameras on the viewers graphics windows.*/ void setUpRenderingSupport(); protected: @@ -156,6 +167,8 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View osg::observer_ptr _cameraWithFocus; osg::ref_ptr _eventVisitor; + + osg::ref_ptr _realizeOperation; }; diff --git a/src/osgViewer/CompositeViewer.cpp b/src/osgViewer/CompositeViewer.cpp index 9841c6f81..a119c64a4 100644 --- a/src/osgViewer/CompositeViewer.cpp +++ b/src/osgViewer/CompositeViewer.cpp @@ -694,7 +694,17 @@ void CompositeViewer::realize() citr != contexts.end(); ++citr) { - (*citr)->realize(); + osg::GraphicsContext* gc = *citr; + gc->realize(); + + if (_realizeOperation.valid()) + { + gc->makeCurrent(); + + (*_realizeOperation)(gc); + + gc->releaseContext(); + } } bool grabFocus = true; diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index 3b1e4e334..40ea37830 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -756,7 +756,17 @@ void Viewer::realize() citr != contexts.end(); ++citr) { - (*citr)->realize(); + osg::GraphicsContext* gc = *citr; + gc->realize(); + + if (_realizeOperation.valid()) + { + gc->makeCurrent(); + + (*_realizeOperation)(gc); + + gc->releaseContext(); + } } bool grabFocus = true; @@ -774,14 +784,14 @@ void Viewer::realize() } } - - startThreading(); - // initialize the global timer to be relative to the current time. osg::Timer::instance()->setStartTick(); // pass on the start tick to all the associated eventqueues setStartTick(osg::Timer::instance()->getStartTick()); + + startThreading(); + }