Added context sharing support.

This commit is contained in:
Robert Osfield
2007-02-15 12:24:04 +00:00
parent 4f2474ece8
commit 3fe4be6e70
6 changed files with 55 additions and 9 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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; }

View File

@@ -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<GraphicsWindowCarbon*>(_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;

View File

@@ -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<GraphicsWindowWin32*>(_traits->sharedContext);
if (sharedContextWin32)
{
makeCurrent();
wglShareLists( sharedContextWin32->getWGLContext(), getWGLContext() );
}
}
}
//

View File

@@ -422,13 +422,16 @@ void GraphicsWindowX11::init()
}
}
// need to pick up from traits
GLXContext sharedGLContext = 0;
GraphicsWindowX11* sharedContextX11 = dynamic_cast<GraphicsWindowX11*>(_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)
{