diff --git a/include/osgViewer/GraphicsWindowX11 b/include/osgViewer/GraphicsWindowX11 index 3a4092641..43bb84e2a 100644 --- a/include/osgViewer/GraphicsWindowX11 +++ b/include/osgViewer/GraphicsWindowX11 @@ -55,8 +55,18 @@ class GraphicsWindowX11 : 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() ); + } + } } @@ -106,6 +116,7 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow Display* getEventDisplay() { return _eventDisplay; } Window& getParent() { return _parent; } Window& getWindow() { return _window; } + GLXContext getGLXContext() { return _glxContext; } Cursor& getDefaultCursor() { return _defaultCursor; } Cursor& getNullCursor() { return _nullCursor; } diff --git a/src/osgViewer/GraphicsWindowX11.cpp b/src/osgViewer/GraphicsWindowX11.cpp index ca66cba0b..74ad30128 100644 --- a/src/osgViewer/GraphicsWindowX11.cpp +++ b/src/osgViewer/GraphicsWindowX11.cpp @@ -425,6 +425,9 @@ 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 (!_glxContext) @@ -576,7 +579,6 @@ bool GraphicsWindowX11::makeCurrentImplementation() return glXMakeCurrent( _display, _window, _glxContext )==True; } - bool GraphicsWindowX11::releaseContextImplementation() { if (!_realized)