diff --git a/include/osgViewer/GraphicsWindowCarbon b/include/osgViewer/GraphicsWindowCarbon index 207a6ebdb..81cbae150 100644 --- a/include/osgViewer/GraphicsWindowCarbon +++ b/include/osgViewer/GraphicsWindowCarbon @@ -43,8 +43,17 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow if (valid()) { setState( new osg::State ); - getState()->setContextID( osg::GraphicsContext::createNewContextID() ); getState()->setGraphicsContext(this); + + if (_traits.valid() && _traits->sharedContext) + { + getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); + incrementContextIDUsageCount( getState()->getContextID() ); + } + else + { + getState()->setContextID( osg::GraphicsContext::createNewContextID() ); + } } } @@ -95,6 +104,7 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow void transformMouseXY(float& x, float& y); + AGLContext& getAGLContext() { return _context; } bool _valid; bool _initialized; diff --git a/include/osgViewer/GraphicsWindowWin32 b/include/osgViewer/GraphicsWindowWin32 index ca60a200a..6688256b3 100644 --- a/include/osgViewer/GraphicsWindowWin32 +++ b/include/osgViewer/GraphicsWindowWin32 @@ -98,6 +98,8 @@ class GraphicsWindowWin32 : public osgViewer::GraphicsWindow int getScreenNumberContainingWindow( int& _screenOriginX, int& _screenOriginY ); + HGLRC& getWGLContext() { return _hglrc; } + HWND _hwnd; HDC _hdc; HGLRC _hglrc; diff --git a/include/osgViewer/GraphicsWindowX11 b/include/osgViewer/GraphicsWindowX11 index 43bb84e2a..b0097dcb3 100644 --- a/include/osgViewer/GraphicsWindowX11 +++ b/include/osgViewer/GraphicsWindowX11 @@ -116,7 +116,7 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow Display* getEventDisplay() { return _eventDisplay; } Window& getParent() { return _parent; } Window& getWindow() { return _window; } - GLXContext getGLXContext() { return _glxContext; } + GLXContext& getGLXContext() { return _glxContext; } Cursor& getDefaultCursor() { return _defaultCursor; } Cursor& getNullCursor() { return _nullCursor; } diff --git a/src/osgViewer/GraphicsWindowCarbon.cpp b/src/osgViewer/GraphicsWindowCarbon.cpp index 04b3f1afb..88501eebf 100644 --- a/src/osgViewer/GraphicsWindowCarbon.cpp +++ b/src/osgViewer/GraphicsWindowCarbon.cpp @@ -259,7 +259,9 @@ class GraphicsContextCarbon : public osg::GraphicsContext osg::notify(osg::WARN) << "GraphicsContext::realizeImplementation() aglChoosePixelFormat failed! " << aglErrorString(aglGetError()) << std::endl; return false; } + _context = aglCreateContext (pixelformat, NULL); + if (!_context) { osg::notify(osg::WARN) << "GraphicsContext::realizeImplementation() aglCreateContext failed! " << aglErrorString(aglGetError()) << std::endl; return false; @@ -621,7 +623,17 @@ bool GraphicsWindowCarbon::realizeImplementation() } // create the context - _context = aglCreateContext (_pixelFormat, NULL); + GraphicsWindowCarbon* sharedContextCarbon = dynamic_cast(_traits->sharedContext); + if (sharedContextCarbon) + { + _context = aglCreateContext (_pixelFormat, sharedContextCarbon->getAGLContext()); + } + else + { + _context = aglCreateContext (_pixelFormat, NULL); + } + + if (!_context) { osg::notify(osg::WARN) << "GraphicsWindowCarbon::realizeImplementation failed creating a context: " << aglGetError() << std::endl; return false; diff --git a/src/osgViewer/GraphicsWindowWin32.cpp b/src/osgViewer/GraphicsWindowWin32.cpp index fd7e2736d..4a60558ed 100644 --- a/src/osgViewer/GraphicsWindowWin32.cpp +++ b/src/osgViewer/GraphicsWindowWin32.cpp @@ -1005,8 +1005,17 @@ GraphicsWindowWin32::GraphicsWindowWin32( osg::GraphicsContext::Traits* traits ) if (valid()) { setState( new osg::State ); - getState()->setContextID( osg::GraphicsContext::createNewContextID() ); getState()->setGraphicsContext(this); + + if (_traits.valid() && _traits->sharedContext) + { + getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); + incrementContextIDUsageCount( getState()->getContextID() ); + } + else + { + getState()->setContextID( osg::GraphicsContext::createNewContextID() ); + } } } @@ -1401,6 +1410,16 @@ bool GraphicsWindowWin32::realizeImplementation() { init(); if (!_initialized) return false; + + if (_traits.valid && _traits->sharedContext) + { + GraphicsWindowWin32* sharedContextWin32 = dynamic_cast(_traits->sharedContext); + if (sharedContextWin32) + { + makeCurrent(); + wglShareLists( sharedContextWin32->getWGLContext(), getWGLContext() ); + } + } } // diff --git a/src/osgViewer/GraphicsWindowX11.cpp b/src/osgViewer/GraphicsWindowX11.cpp index 74ad30128..3d15a6130 100644 --- a/src/osgViewer/GraphicsWindowX11.cpp +++ b/src/osgViewer/GraphicsWindowX11.cpp @@ -422,13 +422,16 @@ void GraphicsWindowX11::init() } } - // need to pick up from traits - GLXContext sharedGLContext = 0; GraphicsWindowX11* sharedContextX11 = dynamic_cast(_traits->sharedContext); - if (sharedContextX11) sharedGLContext = sharedContextX11->getGLXContext(); - - _glxContext = glXCreateContext( _display, _visualInfo, sharedGLContext, True ); + if (sharedContextX11) + { + _glxContext = glXCreateContext( _display, _visualInfo, sharedContextX11->getGLXContext(), True ); + } + else + { + _glxContext = glXCreateContext( _display, _visualInfo, NULL, True ); + } if (!_glxContext) {