diff --git a/examples/osgviewerFOX/FOX_OSG.cpp b/examples/osgviewerFOX/FOX_OSG.cpp index 039b988c7..c2c154d4f 100644 --- a/examples/osgviewerFOX/FOX_OSG.cpp +++ b/examples/osgviewerFOX/FOX_OSG.cpp @@ -48,7 +48,7 @@ void GraphicsWindowFOX::init() setState( new osg::State ); getState()->setGraphicsContext(this); - if (_traits.valid() && _traits->sharedContext) + if (_traits.valid() && _traits->sharedContext.valid()) { getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); incrementContextIDUsageCount( getState()->getContextID() ); diff --git a/examples/osgviewerWX/osgviewerWX.cpp b/examples/osgviewerWX/osgviewerWX.cpp index 6cf6ecd7e..c4a198a4d 100644 --- a/examples/osgviewerWX/osgviewerWX.cpp +++ b/examples/osgviewerWX/osgviewerWX.cpp @@ -299,7 +299,7 @@ void GraphicsWindowWX::init() setState( new osg::State ); getState()->setGraphicsContext(this); - if (_traits.valid() && _traits->sharedContext) + if (_traits.valid() && _traits->sharedContext.valid()) { getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); incrementContextIDUsageCount( getState()->getContextID() ); diff --git a/include/osg/GraphicsContext b/include/osg/GraphicsContext index d7adf6dba..cd30b2f40 100644 --- a/include/osg/GraphicsContext +++ b/include/osg/GraphicsContext @@ -128,7 +128,7 @@ class OSG_EXPORT GraphicsContext : public Object bool getContextVersion(unsigned int& major, unsigned int& minor) const; // shared context - GraphicsContext* sharedContext; + osg::observer_ptr sharedContext; osg::ref_ptr inheritedWindowData; diff --git a/include/osgViewer/GraphicsWindow b/include/osgViewer/GraphicsWindow index e8f04cc9f..6d1593e54 100644 --- a/include/osgViewer/GraphicsWindow +++ b/include/osgViewer/GraphicsWindow @@ -247,7 +247,7 @@ class GraphicsWindowEmbedded : public GraphicsWindow setState( new osg::State ); getState()->setGraphicsContext(this); - if (_traits.valid() && _traits->sharedContext) + if (_traits.valid() && _traits->sharedContext.valid()) { getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); incrementContextIDUsageCount( getState()->getContextID() ); diff --git a/include/osgViewer/api/Carbon/GraphicsWindowCarbon b/include/osgViewer/api/Carbon/GraphicsWindowCarbon index 693e53476..cc138a44b 100644 --- a/include/osgViewer/api/Carbon/GraphicsWindowCarbon +++ b/include/osgViewer/api/Carbon/GraphicsWindowCarbon @@ -48,7 +48,7 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow, public osgViewer: setState( new osg::State ); getState()->setGraphicsContext(this); - if (_traits.valid() && _traits->sharedContext) + if (_traits.valid() && _traits->sharedContext.valid()) { getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); incrementContextIDUsageCount( getState()->getContextID() ); diff --git a/include/osgViewer/api/Carbon/PixelBufferCarbon b/include/osgViewer/api/Carbon/PixelBufferCarbon index 5880450fe..60c4f51ef 100644 --- a/include/osgViewer/api/Carbon/PixelBufferCarbon +++ b/include/osgViewer/api/Carbon/PixelBufferCarbon @@ -45,7 +45,7 @@ class OSGVIEWER_EXPORT PixelBufferCarbon : public osg::GraphicsContext, public o setState( new osg::State ); getState()->setGraphicsContext(this); - if (_traits.valid() && _traits->sharedContext) + if (_traits.valid() && _traits->sharedContext.valid()) { getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); incrementContextIDUsageCount( getState()->getContextID() ); diff --git a/include/osgViewer/api/Cocoa/GraphicsWindowCocoa b/include/osgViewer/api/Cocoa/GraphicsWindowCocoa index 800e569d7..62908780b 100644 --- a/include/osgViewer/api/Cocoa/GraphicsWindowCocoa +++ b/include/osgViewer/api/Cocoa/GraphicsWindowCocoa @@ -76,7 +76,7 @@ class GraphicsWindowCocoa : public osgViewer::GraphicsWindow, public osgViewer:: setState( new osg::State ); getState()->setGraphicsContext(this); - if (_traits.valid() && _traits->sharedContext) + if (_traits.valid() && _traits->sharedContext.valid()) { getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); incrementContextIDUsageCount( getState()->getContextID() ); diff --git a/include/osgViewer/api/Cocoa/PixelBufferCocoa b/include/osgViewer/api/Cocoa/PixelBufferCocoa index 6a1a51731..e00c1135b 100644 --- a/include/osgViewer/api/Cocoa/PixelBufferCocoa +++ b/include/osgViewer/api/Cocoa/PixelBufferCocoa @@ -47,7 +47,7 @@ class OSGVIEWER_EXPORT PixelBufferCocoa : public osg::GraphicsContext, public os setState( new osg::State ); getState()->setGraphicsContext(this); - if (_traits.valid() && _traits->sharedContext) + if (_traits.valid() && _traits->sharedContext.valid()) { getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); incrementContextIDUsageCount( getState()->getContextID() ); diff --git a/include/osgViewer/api/IOS/GraphicsWindowIOS b/include/osgViewer/api/IOS/GraphicsWindowIOS index 5e7f2afc8..481bfd632 100644 --- a/include/osgViewer/api/IOS/GraphicsWindowIOS +++ b/include/osgViewer/api/IOS/GraphicsWindowIOS @@ -72,7 +72,7 @@ class GraphicsWindowIOS : public osgViewer::GraphicsWindow setState( new osg::State ); getState()->setGraphicsContext(this); - if (_traits.valid() && _traits->sharedContext) + if (_traits.valid() && _traits->sharedContext.valid()) { getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); incrementContextIDUsageCount( getState()->getContextID() ); diff --git a/include/osgViewer/api/X11/GraphicsWindowX11 b/include/osgViewer/api/X11/GraphicsWindowX11 index 47593e361..1628b0998 100644 --- a/include/osgViewer/api/X11/GraphicsWindowX11 +++ b/include/osgViewer/api/X11/GraphicsWindowX11 @@ -59,7 +59,7 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow, pub setState( new osg::State ); getState()->setGraphicsContext(this); - if (_traits.valid() && _traits->sharedContext) + if (_traits.valid() && _traits->sharedContext.valid()) { getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); incrementContextIDUsageCount( getState()->getContextID() ); diff --git a/src/osgQt/GraphicsWindowQt.cpp b/src/osgQt/GraphicsWindowQt.cpp index ecb4f8b08..df269187a 100644 --- a/src/osgQt/GraphicsWindowQt.cpp +++ b/src/osgQt/GraphicsWindowQt.cpp @@ -382,7 +382,7 @@ bool GraphicsWindowQt::init( QWidget* parent, const QGLWidget* shareWidget, Qt:: { // shareWidget if ( !shareWidget ) { - GraphicsWindowQt* sharedContextQt = dynamic_cast(_traits->sharedContext); + GraphicsWindowQt* sharedContextQt = dynamic_cast(_traits->sharedContext.get()); if ( sharedContextQt ) shareWidget = sharedContextQt->getGLWidget(); } @@ -422,7 +422,7 @@ bool GraphicsWindowQt::init( QWidget* parent, const QGLWidget* shareWidget, Qt:: getState()->setGraphicsContext(this); // initialize contextID - if ( _traits.valid() && _traits->sharedContext ) + if ( _traits.valid() && _traits->sharedContext.valid() ) { getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); incrementContextIDUsageCount( getState()->getContextID() ); diff --git a/src/osgViewer/GraphicsWindowCarbon.cpp b/src/osgViewer/GraphicsWindowCarbon.cpp index 648c0bc75..5aa55ec2f 100644 --- a/src/osgViewer/GraphicsWindowCarbon.cpp +++ b/src/osgViewer/GraphicsWindowCarbon.cpp @@ -399,7 +399,7 @@ bool GraphicsWindowCarbon::realizeImplementation() // create the context AGLContext sharedContextCarbon = NULL; - GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast(_traits->sharedContext); + GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast(_traits->sharedContext.get()); if (graphicsHandleCarbon) { sharedContextCarbon = graphicsHandleCarbon->getAGLContext(); diff --git a/src/osgViewer/GraphicsWindowCocoa.mm b/src/osgViewer/GraphicsWindowCocoa.mm index 58c718a9d..598aa590e 100644 --- a/src/osgViewer/GraphicsWindowCocoa.mm +++ b/src/osgViewer/GraphicsWindowCocoa.mm @@ -1186,7 +1186,7 @@ bool GraphicsWindowCocoa::realizeImplementation() // create the context NSOpenGLContext* sharedContext = NULL; - GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast(_traits->sharedContext); + GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast(_traits->sharedContext.get()); if (graphicsHandleCocoa) { sharedContext = graphicsHandleCocoa->getNSOpenGLContext(); diff --git a/src/osgViewer/GraphicsWindowWin32.cpp b/src/osgViewer/GraphicsWindowWin32.cpp index 06650cc91..6aacaa0d4 100644 --- a/src/osgViewer/GraphicsWindowWin32.cpp +++ b/src/osgViewer/GraphicsWindowWin32.cpp @@ -1150,7 +1150,7 @@ GraphicsWindowWin32::GraphicsWindowWin32( osg::GraphicsContext::Traits* traits ) setState( new osg::State ); getState()->setGraphicsContext(this); - if (_traits.valid() && _traits->sharedContext) + if (_traits.valid() && _traits->sharedContext.valid()) { getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); incrementContextIDUsageCount( getState()->getContextID() ); @@ -1903,7 +1903,7 @@ bool GraphicsWindowWin32::realizeImplementation() if (!_initialized) return false; } - if (_traits.valid() && (_traits->sharedContext || _traits->vsync || _traits->swapGroupEnabled)) + if (_traits.valid() && (_traits->sharedContext.valid() || _traits->vsync || _traits->swapGroupEnabled)) { // make context current so we can test capabilities and set up context sharing struct RestoreContext @@ -1932,7 +1932,7 @@ bool GraphicsWindowWin32::realizeImplementation() } // set up sharing of contexts if required - GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast(_traits->sharedContext); + GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast(_traits->sharedContext.get()); if (graphicsHandleWin32) { if (!wglShareLists(graphicsHandleWin32->getWGLContext(), getWGLContext())) diff --git a/src/osgViewer/GraphicsWindowX11.cpp b/src/osgViewer/GraphicsWindowX11.cpp index d551f36e4..ba217f173 100644 --- a/src/osgViewer/GraphicsWindowX11.cpp +++ b/src/osgViewer/GraphicsWindowX11.cpp @@ -717,7 +717,7 @@ void GraphicsWindowX11::init() } // get any shared GLX contexts - GraphicsHandleX11* graphicsHandleX11 = dynamic_cast(_traits->sharedContext); + GraphicsHandleX11* graphicsHandleX11 = dynamic_cast(_traits->sharedContext.get()); Context sharedContext = graphicsHandleX11 ? graphicsHandleX11->getContext() : 0; #ifdef OSG_USE_EGL diff --git a/src/osgViewer/PixelBufferCarbon.cpp b/src/osgViewer/PixelBufferCarbon.cpp index 61b674391..4f13d5406 100644 --- a/src/osgViewer/PixelBufferCarbon.cpp +++ b/src/osgViewer/PixelBufferCarbon.cpp @@ -81,7 +81,7 @@ bool PixelBufferCarbon::realizeImplementation() AGLContext sharedContext = NULL; // get any shared AGL contexts - GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast(_traits->sharedContext); + GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast(_traits->sharedContext.get()); if (graphicsHandleCarbon) { sharedContext = graphicsHandleCarbon->getAGLContext(); diff --git a/src/osgViewer/PixelBufferCocoa.mm b/src/osgViewer/PixelBufferCocoa.mm index ccff33be1..343840ff6 100644 --- a/src/osgViewer/PixelBufferCocoa.mm +++ b/src/osgViewer/PixelBufferCocoa.mm @@ -63,7 +63,7 @@ bool PixelBufferCocoa::realizeImplementation() // create the context NSOpenGLContext* sharedContext = NULL; - GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast(_traits->sharedContext); + GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast(_traits->sharedContext.get()); if (graphicsHandleCocoa) { sharedContext = graphicsHandleCocoa->getNSOpenGLContext(); diff --git a/src/osgViewer/PixelBufferWin32.cpp b/src/osgViewer/PixelBufferWin32.cpp index a343bd1b2..0512a85eb 100644 --- a/src/osgViewer/PixelBufferWin32.cpp +++ b/src/osgViewer/PixelBufferWin32.cpp @@ -463,7 +463,7 @@ PixelBufferWin32::PixelBufferWin32( osg::GraphicsContext::Traits* traits ): setState( new osg::State ); getState()->setGraphicsContext( this ); - if (_traits.valid() && _traits->sharedContext ) + if (_traits.valid() && _traits->sharedContext.valid() ) { getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); incrementContextIDUsageCount( getState()->getContextID() ); @@ -658,9 +658,9 @@ bool PixelBufferWin32::realizeImplementation() if (!_initialized) return false; - if ( _traits->sharedContext ) + if ( _traits->sharedContext.valid() ) { - GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast(_traits->sharedContext); + GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast(_traits->sharedContext.get()); if (graphicsHandleWin32) { if ( !wglShareLists(graphicsHandleWin32->getWGLContext(), _hglrc) ) diff --git a/src/osgViewer/PixelBufferX11.cpp b/src/osgViewer/PixelBufferX11.cpp index bec072c83..ea6e5b36d 100644 --- a/src/osgViewer/PixelBufferX11.cpp +++ b/src/osgViewer/PixelBufferX11.cpp @@ -43,7 +43,7 @@ PixelBufferX11::PixelBufferX11(osg::GraphicsContext::Traits* traits) setState( new osg::State ); getState()->setGraphicsContext(this); - if (_traits.valid() && _traits->sharedContext) + if (_traits.valid() && _traits->sharedContext.valid()) { getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); incrementContextIDUsageCount( getState()->getContextID() ); @@ -216,7 +216,7 @@ void PixelBufferX11::init() } // get any shared GLX contexts - GraphicsHandleX11* graphicsHandleX11 = dynamic_cast(_traits->sharedContext); + GraphicsHandleX11* graphicsHandleX11 = dynamic_cast(_traits->sharedContext.get()); Context sharedContext = graphicsHandleX11 ? graphicsHandleX11->getContext() : 0; _context = glXCreateContext( _display, _visualInfo, sharedContext, True );