From Colin MacDonald, "In my application I have a custom graphics context class, derived from

osg::GraphicsContext, in order to give good integration with the
application's GUI toolkit.  This works really well.

However, I need to share OpenGL texture resources with the standard
osgViewer GraphicsContext implementations, in particular the
PixelBuffers.  This is essential for my application to conserve graphics
memory on low-end hardware.  Currently the standard osg implementations
will not share resources with another derived osg::GraphicsContext,
other than the pre-defined osgViewer classes e.g. PixelBufferX11 is
hardcoded to only share resources with GraphicsWindowX11 and
PixelBufferX11 objects, and no other osg::GraphicsContext object.

To address this in the cleanest way I could think of, I have moved the
OpenGL handle variables for each platform into a small utility class,
e.g. GraphicsHandleX11 for unix.  Then GraphicsWindowX11, PixelBufferX11
and any other derived osg::GraphicsContext class can inherit from
GraphicsHandleX11 to share OpenGL resources.

I have updated the X11, Win32 and Carbon implementations to use this.
The changes are minor.  I haven't touched the Cocoa implmentation as
I'm not familiar with it at all and couldn't test it - it will work
unchanged.

Without this I had some horrible hacks in my application, this greatly
simplifies things for me.  It also simplifies the osgViewer
implementations slightly.  Perhaps it may help with other users'
desires to share resources with external graphics contexts, as was
discussed on the user list recently."

Notes from Robert Osfield, adapted Colin's submission to work with the new EGL related changes.
This commit is contained in:
Robert Osfield 2009-11-21 16:41:02 +00:00
parent 40d46a8687
commit 4759cb951e
17 changed files with 315 additions and 208 deletions

View File

@ -0,0 +1,50 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGVIEWER_GRAPHICSHANDLECARBON
#define OSGVIEWER_GRAPHICSHANDLECARBON 1
#include <osgViewer/Export>
#include <Carbon/Carbon.h>
#include <AGL/agl.h>
namespace osgViewer
{
/** Class to encapsulate platform-specific OpenGL context handle variables.
* Derived osg::GraphicsContext classes can inherit from this class to
* share OpenGL resources.*/
class OSGVIEWER_EXPORT GraphicsHandleCarbon
{
public:
GraphicsHandleCarbon():
_context(0) {}
/** Set native AGL graphics context.*/
inline void setAGLContext(AGLContext context) { _context = context; }
/** Get native AGL graphics context.*/
inline AGLContext getAGLContext() const { return _context; }
protected:
AGLContext _context;
};
}
#endif

View File

@ -22,12 +22,12 @@
#if defined (__APPLE__) && (!__LP64__)
#include <osgViewer/GraphicsWindow>
#include <Carbon/Carbon.h>
#include <AGL/agl.h>
#include <osgViewer/api/Carbon/GraphicsHandleCarbon>
namespace osgViewer
{
class GraphicsWindowCarbon : public osgViewer::GraphicsWindow
class GraphicsWindowCarbon : public osgViewer::GraphicsWindow, public osgViewer::GraphicsHandleCarbon
{
public:
@ -137,9 +137,6 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow
/// install the standard os-eventhandler
void installEventHandler();
/// get the AGL context
AGLContext getAGLContext() { return _context; }
// get the pixelformat
AGLPixelFormat getAGLPixelFormat() { return _pixelFormat; }
@ -159,7 +156,6 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow
bool _ownsWindow;
WindowRef _window;
AGLContext _context;
AGLPixelFormat _pixelFormat;
int _windowTitleHeight;

View File

@ -19,16 +19,13 @@
#if defined (__APPLE__) && (!__LP64__)
#include <osg/GraphicsContext>
#include <osgViewer/Export>
#include <Carbon/Carbon.h>
#include <AGL/agl.h>
#include <osgViewer/api/Carbon/GraphicsHandleCarbon>
namespace osgViewer
{
class OSGVIEWER_EXPORT PixelBufferCarbon : public osg::GraphicsContext
class OSGVIEWER_EXPORT PixelBufferCarbon : public osg::GraphicsContext, public osgViewer::GraphicsHandleCarbon
{
public:
@ -37,8 +34,7 @@ class OSGVIEWER_EXPORT PixelBufferCarbon : public osg::GraphicsContext
_initialized(false),
_realized(false),
_pixelformat(0),
_pbuffer(0),
_context(0)
_pbuffer(0)
{
_traits = traits;
@ -91,10 +87,8 @@ class OSGVIEWER_EXPORT PixelBufferCarbon : public osg::GraphicsContext
/** Swap the front and back buffers.*/
virtual void swapBuffersImplementation();
static AGLPixelFormat createPixelFormat(osg::GraphicsContext::Traits* traits);
AGLContext getAGLContext() { return _context; }
public:
@ -112,9 +106,7 @@ class OSGVIEWER_EXPORT PixelBufferCarbon : public osg::GraphicsContext
bool _realized;
AGLPixelFormat _pixelformat;
AGLPbuffer _pbuffer;
AGLContext _context;
AGLPbuffer _pbuffer;
};
}

View File

@ -0,0 +1,127 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGVIEWER_GRAPHICSHANDLEWIN32
#define OSGVIEWER_GRAPHICSHANDLEWIN32 1
#include <osgViewer/Export>
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#endif
#include <windows.h>
namespace osgViewer
{
/** Class to encapsulate platform-specific OpenGL context handle variables.
* Derived osg::GraphicsContext classes can inherit from this class to
* share OpenGL resources.*/
class OSGVIEWER_EXPORT GraphicsHandleWin32
{
public:
GraphicsHandleWin32():
_hwnd(0),
_hdc(0),
_hglrc(0) {}
/** Set native window.*/
inline void setHWND(HWND hwnd) { _hwnd = hwnd; }
/** Get native window.*/
inline HWND getHWND() const { return _hwnd; }
/** Set device context.*/
inline void setHDC(HDC hdc) { _hdc = hdc; }
/** Get device context.*/
inline HDC getHDC() const { return _hdc; }
/** Set native OpenGL graphics context.*/
inline void setWGLContext(HGLRC hglrc) { _hglrc = hglrc; }
/** Get native OpenGL graphics context.*/
inline HGLRC getWGLContext() const { return _hglrc; }
protected:
HWND _hwnd;
HDC _hdc;
HGLRC _hglrc;
};
}
// Definitions required to create an OpenGL pixel format, from the WGL_ARB_pixel_format specification document.
// See http://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt
#ifndef WGL_ARB_pixel_format
#define WGL_ARB_pixel_format 1
#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
#define WGL_DRAW_TO_WINDOW_ARB 0x2001
#define WGL_DRAW_TO_BITMAP_ARB 0x2002
#define WGL_ACCELERATION_ARB 0x2003
#define WGL_NEED_PALETTE_ARB 0x2004
#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005
#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006
#define WGL_SWAP_METHOD_ARB 0x2007
#define WGL_NUMBER_OVERLAYS_ARB 0x2008
#define WGL_NUMBER_UNDERLAYS_ARB 0x2009
#define WGL_TRANSPARENT_ARB 0x200A
#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037
#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
#define WGL_SHARE_DEPTH_ARB 0x200C
#define WGL_SHARE_STENCIL_ARB 0x200D
#define WGL_SHARE_ACCUM_ARB 0x200E
#define WGL_SUPPORT_GDI_ARB 0x200F
#define WGL_SUPPORT_OPENGL_ARB 0x2010
#define WGL_DOUBLE_BUFFER_ARB 0x2011
#define WGL_STEREO_ARB 0x2012
#define WGL_PIXEL_TYPE_ARB 0x2013
#define WGL_COLOR_BITS_ARB 0x2014
#define WGL_RED_BITS_ARB 0x2015
#define WGL_RED_SHIFT_ARB 0x2016
#define WGL_GREEN_BITS_ARB 0x2017
#define WGL_GREEN_SHIFT_ARB 0x2018
#define WGL_BLUE_BITS_ARB 0x2019
#define WGL_BLUE_SHIFT_ARB 0x201A
#define WGL_ALPHA_BITS_ARB 0x201B
#define WGL_ALPHA_SHIFT_ARB 0x201C
#define WGL_ACCUM_BITS_ARB 0x201D
#define WGL_ACCUM_RED_BITS_ARB 0x201E
#define WGL_ACCUM_GREEN_BITS_ARB 0x201F
#define WGL_ACCUM_BLUE_BITS_ARB 0x2020
#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
#define WGL_DEPTH_BITS_ARB 0x2022
#define WGL_STENCIL_BITS_ARB 0x2023
#define WGL_AUX_BUFFERS_ARB 0x2024
#define WGL_NO_ACCELERATION_ARB 0x2025
#define WGL_GENERIC_ACCELERATION_ARB 0x2026
#define WGL_FULL_ACCELERATION_ARB 0x2027
#define WGL_SWAP_EXCHANGE_ARB 0x2028
#define WGL_SWAP_COPY_ARB 0x2029
#define WGL_SWAP_UNDEFINED_ARB 0x202A
#define WGL_TYPE_RGBA_ARB 0x202B
#define WGL_TYPE_COLORINDEX_ARB 0x202C
#define WGL_SAMPLE_BUFFERS_ARB 0x2041
#define WGL_SAMPLES_ARB 0x2042
#endif
#endif

View File

@ -20,16 +20,12 @@
#define OSGVIEWER_GRAPHICSWINDOWWIN32 1
#include <osgViewer/GraphicsWindow>
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#endif
#include <windows.h>
#include <osgViewer/api/Win32/GraphicsHandleWin32>
namespace osgViewer
{
class OSGVIEWER_EXPORT GraphicsWindowWin32 : public osgViewer::GraphicsWindow
class OSGVIEWER_EXPORT GraphicsWindowWin32 : public osgViewer::GraphicsWindow, public osgViewer::GraphicsHandleWin32
{
public:
@ -103,14 +99,6 @@ class OSGVIEWER_EXPORT GraphicsWindowWin32 : public osgViewer::GraphicsWindow
HWND _hwnd;
bool _installEventHandler;
};
/** Get native window.*/
HWND getHWND() const { return _hwnd; }
HDC getHDC() const { return _hdc; }
/** Get native OpenGL graphics context.*/
HGLRC getWGLContext() const { return _hglrc; }
protected:
@ -139,8 +127,7 @@ class OSGVIEWER_EXPORT GraphicsWindowWin32 : public osgViewer::GraphicsWindow
unsigned int& extendedStyle );
bool setPixelFormat();
HGLRC createContextImplementation();
void adaptKey( WPARAM wParam, LPARAM lParam, int& keySymbol, unsigned int& modifierMask );
void transformMouseXY(float& x, float& y);
@ -149,9 +136,6 @@ class OSGVIEWER_EXPORT GraphicsWindowWin32 : public osgViewer::GraphicsWindow
HCURSOR getOrCreateCursor(MouseCursor mouseShape);
HWND _hwnd;
HDC _hdc;
HGLRC _hglrc;
HCURSOR _currentCursor;
WNDPROC _windowProcedure;

View File

@ -19,18 +19,13 @@
#ifndef OSGVIEWER_PIXELBUFFERWIN32
#define OSGVIEWER_PIXELBUFFERWIN32 1
#include <osgViewer/GraphicsWindow>
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#endif
#include <windows.h>
#include <osg/GraphicsContext>
#include <osgViewer/api/Win32/GraphicsHandleWin32>
namespace osgViewer
{
class OSGVIEWER_EXPORT PixelBufferWin32 : public osg::GraphicsContext
class OSGVIEWER_EXPORT PixelBufferWin32 : public osg::GraphicsContext, public osgViewer::GraphicsHandleWin32
{
public:
@ -62,24 +57,12 @@ class OSGVIEWER_EXPORT PixelBufferWin32 : public osg::GraphicsContext
/** Swap the front and back buffers.*/
virtual void swapBuffersImplementation();
/** Get native window.*/
HWND getHWND() const { return _hwnd; }
HDC getHDC() const { return _hdc; }
/** Get native OpenGL graphics context.*/
HGLRC getWGLContext() const { return _hglrc; }
virtual void bindPBufferToTextureImplementation( GLenum /*buffer*/ );
protected:
void init();
HWND _hwnd;
HDC _hdc;
HGLRC _hglrc;
bool _initialized;
bool _valid;

View File

@ -0,0 +1,80 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGVIEWER_GRAPHICSHANDLEX11
#define OSGVIEWER_GRAPHICSHANDLEX11 1
#include <osgViewer/Export>
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
#define OSG_USE_EGL
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <EGL/egl.h>
#else
#define GLX_GLXEXT_PROTOTYPES 1
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <GL/glx.h>
#ifndef GLX_VERSION_1_3
typedef XID GLXPbuffer;
#endif
#endif
namespace osgViewer
{
/** Class to encapsulate platform-specific OpenGL context handle variables.
* Derived osg::GraphicsContext classes can inherit from this class to
* share OpenGL resources.*/
class OSGVIEWER_EXPORT GraphicsHandleX11
{
public:
GraphicsHandleX11():
_display(0),
_context(0) {}
/** Set X11 display.*/
inline void setDisplay(Display* display) { _display = display; }
/** Get X11 display.*/
inline Display* getDisplay() const { return _display; }
#ifdef OSG_USE_EGL
typedef EGLContext Context;
typedef EGLSurface Pbuffer;
#else
typedef GLXContext Context;
typedef GLXPbuffer Pbuffer;
#endif
/** Set native OpenGL graphics context.*/
inline void setContext(Context context) { _context = context; }
/** Get native OpenGL graphics context.*/
inline Context getContext() const { return _context; }
protected:
Display* _display;
Context _context;
};
}
#endif

View File

@ -20,38 +20,23 @@
#define OSGVIEWER_GRAPHICSWINDOWX11 1
#include <osgViewer/GraphicsWindow>
#define GLX_GLXEXT_PROTOTYPES 1
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
#define OSG_USE_EGL
#include <EGL/egl.h>
#else
#include <GL/glx.h>
#endif
#include <osgViewer/api/X11/GraphicsHandleX11>
#include <string.h>
namespace osgViewer
{
class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow
class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow, public osgViewer::GraphicsHandleX11
{
public:
GraphicsWindowX11(osg::GraphicsContext::Traits* traits):
_valid(false),
_display(0),
_eventDisplay(0),
_parent(0),
_window(0),
_visualInfo(0),
_context(0),
#ifdef OSG_USE_EGL
_eglDisplay(0),
_eglSurface(0),
@ -151,7 +136,6 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow
// X11 specific aces functions
Display* getDisplay() const { return _display; }
Display* getEventDisplay() const { return _eventDisplay; }
Display* getDisplayToUse() const ;
@ -159,15 +143,6 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow
Window& getParent() { return _parent; }
Window& getWindow() { return _window; }
#ifdef OSG_USE_EGL
typedef EGLContext Context;
#else
typedef GLXContext Context;
#endif
Context& getContext() { return _context; }
Cursor getCurrentCursor() { return _currentCursor; }
protected:
@ -197,12 +172,10 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow
void flushKeyEvents();
bool _valid;
Display* _display;
Display* _eventDisplay;
Window _parent;
Window _window;
XVisualInfo* _visualInfo;
Context _context;
#ifdef OSG_USE_EGL
EGLDisplay _eglDisplay;

View File

@ -19,18 +19,13 @@
#ifndef OSGVIEWER_PIXELBUFFERX11
#define OSGVIEWER_PIXELBUFFERX11 1
#include <osgViewer/api/X11/GraphicsWindowX11>
#ifndef OSG_USE_EGL
#ifndef GLX_VERSION_1_3
typedef XID GLXPbuffer;
#endif
#endif
#include <osg/GraphicsContext>
#include <osgViewer/api/X11/GraphicsHandleX11>
namespace osgViewer
{
class OSGVIEWER_EXPORT PixelBufferX11 : public osg::GraphicsContext
class OSGVIEWER_EXPORT PixelBufferX11 : public osg::GraphicsContext, public osgViewer::GraphicsHandleX11
{
public:
@ -69,19 +64,8 @@ class OSGVIEWER_EXPORT PixelBufferX11 : public osg::GraphicsContext
public:
// X11 specific aces functions
Display* getDisplay() const { return _display; }
#ifdef OSG_USE_EGL
typedef EGLContext Context;
typedef EGLSurface Pbuffer;
#else
typedef GLXContext Context;
typedef GLXPbuffer Pbuffer;
#endif
Pbuffer& getPbuffer() { return _pbuffer; }
Context& getContext() { return _context; }
protected:
@ -92,10 +76,8 @@ class OSGVIEWER_EXPORT PixelBufferX11 : public osg::GraphicsContext
void init();
bool _valid;
Display* _display;
Pbuffer _pbuffer;
XVisualInfo* _visualInfo;
Context _context;
bool _initialized;
bool _realized;

View File

@ -53,6 +53,7 @@ IF(WIN32)
ENDIF()
SET(LIB_PUBLIC_HEADERS ${LIB_PUBLIC_HEADERS}
${HEADER_PATH}/api/Win32/GraphicsHandleWin32
${HEADER_PATH}/api/Win32/GraphicsWindowWin32
${HEADER_PATH}/api/Win32/PixelBufferWin32
)
@ -84,6 +85,7 @@ ELSE()
ELSEIF(${OSG_WINDOWING_SYSTEM} STREQUAL "Carbon")
ADD_DEFINITIONS(-DUSE_DARWIN_CARBON_IMPLEMENTATION)
SET(LIB_PUBLIC_HEADERS ${LIB_PUBLIC_HEADERS}
${HEADER_PATH}/api/Carbon/GraphicsHandleCarbon
${HEADER_PATH}/api/Carbon/GraphicsWindowCarbon
${HEADER_PATH}/api/Carbon/PixelBufferCarbon
)
@ -109,6 +111,7 @@ ELSE()
ENDIF()
SET(LIB_PUBLIC_HEADERS ${LIB_PUBLIC_HEADERS}
${HEADER_PATH}/api/X11/GraphicsHandleX11
${HEADER_PATH}/api/X11/GraphicsWindowX11
${HEADER_PATH}/api/X11/PixelBufferX11
)
@ -117,7 +120,7 @@ ELSE()
GraphicsWindowX11.cpp
PixelBufferX11.cpp
)
IF(OSGVIEWER_USE_XRANDR)
ADD_DEFINITIONS(-DOSGVIEWER_USE_XRANDR)
SET(LIB_PRIVATE_HEADERS ${LIB_PRIVATE_HEADERS} ${XRANDR_INCLUDE_DIRS} )

View File

@ -398,18 +398,12 @@ bool GraphicsWindowCarbon::realizeImplementation()
// create the context
AGLContext sharedContextCarbon = NULL;
GraphicsWindowCarbon* graphicsWindowCarbon = dynamic_cast<GraphicsWindowCarbon*>(_traits->sharedContext);
if (graphicsWindowCarbon)
GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast<GraphicsHandleCarbon*>(_traits->sharedContext);
if (graphicsHandleCarbon)
{
sharedContextCarbon = graphicsWindowCarbon->getAGLContext();
}
else
{
PixelBufferCarbon* pixelbuffer = dynamic_cast<PixelBufferCarbon*>(_traits->sharedContext);
if (pixelbuffer) {
sharedContextCarbon = pixelbuffer->getAGLContext();
}
sharedContextCarbon = graphicsHandleCarbon->getAGLContext();
}
_context = aglCreateContext (_pixelFormat, sharedContextCarbon);

View File

@ -1029,10 +1029,7 @@ osgViewer::GraphicsWindowWin32* Win32WindowingSystem::getGraphicsWindowFor( HWND
//////////////////////////////////////////////////////////////////////////////
GraphicsWindowWin32::GraphicsWindowWin32( osg::GraphicsContext::Traits* traits )
: _hwnd(0),
_hdc(0),
_hglrc(0),
_currentCursor(0),
: _currentCursor(0),
_windowProcedure(0),
_timeOfLastCheckEvents(-1.0),
_screenOriginX(0),
@ -1783,8 +1780,8 @@ bool GraphicsWindowWin32::realizeImplementation()
if (_traits.valid() && _traits->sharedContext)
{
GraphicsWindowWin32* sharedContextWin32 = dynamic_cast<GraphicsWindowWin32*>(_traits->sharedContext);
if (sharedContextWin32)
GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast<GraphicsHandleWin32*>(_traits->sharedContext);
if (graphicsHandleWin32)
{
struct RestoreContext
{
@ -1804,7 +1801,7 @@ bool GraphicsWindowWin32::realizeImplementation()
HDC _hdc;
HGLRC _hglrc;
} restoreContext;
_realized = true;
bool result = makeCurrent();
_realized = false;
@ -1813,7 +1810,7 @@ bool GraphicsWindowWin32::realizeImplementation()
{
return false;
}
if (!wglShareLists(sharedContextWin32->getWGLContext(), getWGLContext()))
if (!wglShareLists(graphicsHandleWin32->getWGLContext(), getWGLContext()))
{
reportErrorForScreen("GraphicsWindowWin32::realizeImplementation() - Unable to share OpenGL context", _traits->screenNum, ::GetLastError());
return false;

View File

@ -693,22 +693,9 @@ void GraphicsWindowX11::init()
}
}
Context sharedContextGLX = NULL;
// get any shared GLX contexts
GraphicsWindowX11* graphicsWindowX11 = dynamic_cast<GraphicsWindowX11*>(_traits->sharedContext);
if (graphicsWindowX11)
{
sharedContextGLX = graphicsWindowX11->getContext();
}
else
{
PixelBufferX11* pixelBufferX11 = dynamic_cast<PixelBufferX11*>(_traits->sharedContext);
if (pixelBufferX11 && pixelBufferX11->valid())
{
sharedContextGLX = pixelBufferX11->getContext();
}
}
// get any shared GLX contexts
GraphicsHandleX11* graphicsHandleX11 = dynamic_cast<GraphicsHandleX11*>(_traits->sharedContext);
Context sharedContext = graphicsHandleX11 ? graphicsHandleX11->getContext() : 0;
#ifdef OSG_USE_EGL
@ -774,7 +761,7 @@ void GraphicsWindowX11::init()
};
#endif
_context = eglCreateContext(_eglDisplay, eglConfig, NULL, contextAttribs);
_context = eglCreateContext(_eglDisplay, eglConfig, sharedContext, contextAttribs);
if (_context == EGL_NO_CONTEXT)
{
osg::notify(osg::NOTICE)<<"GraphicsWindowX11::init() - eglCreateContext(..) failed."<<std::endl;
@ -790,7 +777,7 @@ void GraphicsWindowX11::init()
#else
_context = glXCreateContext( _display, _visualInfo, sharedContextGLX, True );
_context = glXCreateContext( _display, _visualInfo, sharedContext, True );
if (!_context)
{
@ -989,7 +976,6 @@ bool GraphicsWindowX11::makeCurrentImplementation()
#ifdef OSG_USE_EGL
bool result = eglMakeCurrent(_eglDisplay, _eglSurface, _eglSurface, _context)==EGL_TRUE;
checkEGLError("after eglMakeCurrent()");
return result;
#else
return glXMakeCurrent( _display, _window, _context )==True;
@ -1005,8 +991,9 @@ bool GraphicsWindowX11::releaseContextImplementation()
}
#ifdef OSG_USE_EGL
return eglMakeCurrent( _eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT )==EGL_TRUE;
bool result = eglMakeCurrent( _eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT )==EGL_TRUE;
checkEGLError("after eglMakeCurrent() release");
return result;
#else
return glXMakeCurrent( _display, None, NULL )==True;
#endif

View File

@ -80,19 +80,11 @@ bool PixelBufferCarbon::realizeImplementation()
AGLContext sharedContext = NULL;
// get any shared GLX contexts
GraphicsWindowCarbon* graphicsWindowCarbon = dynamic_cast<GraphicsWindowCarbon*>(_traits->sharedContext);
if (graphicsWindowCarbon)
// get any shared AGL contexts
GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast<GraphicsHandleCarbon*>(_traits->sharedContext);
if (graphicsHandleCarbon)
{
sharedContext = graphicsWindowCarbon->getAGLContext();
}
else
{
PixelBufferCarbon* pixelBufferCarbon = dynamic_cast<PixelBufferCarbon*>(_traits->sharedContext);
if (pixelBufferCarbon)
{
sharedContext = pixelBufferCarbon->getAGLContext();
}
sharedContext = graphicsHandleCarbon->getAGLContext();
}
_context = aglCreateContext (_pixelformat, sharedContext);

View File

@ -445,9 +445,6 @@ using namespace osgViewer;
PixelBufferWin32::PixelBufferWin32( osg::GraphicsContext::Traits* traits ):
_hwnd(0),
_hdc(0),
_hglrc(0),
_initialized(false),
_valid(false),
_realized(false),
@ -657,27 +654,15 @@ bool PixelBufferWin32::realizeImplementation()
makeCurrentImplementation();
if (_traits->sharedContext)
if ( _traits->sharedContext )
{
HGLRC hglrc = 0;
GraphicsWindowWin32* graphicsWindowWin32 = dynamic_cast<GraphicsWindowWin32*>(_traits->sharedContext);
if (graphicsWindowWin32)
GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast<GraphicsHandleWin32*>(_traits->sharedContext);
if (graphicsHandleWin32)
{
hglrc = graphicsWindowWin32->getWGLContext();
}
else
{
PixelBufferWin32* pixelBufferWin32 = dynamic_cast<PixelBufferWin32*>(_traits->sharedContext);
if (pixelBufferWin32)
if ( !wglShareLists(graphicsHandleWin32->getWGLContext(), _hglrc) )
{
hglrc = pixelBufferWin32->getWGLContext();
}
}
if ( !wglShareLists(hglrc, _hglrc) )
{
osg::notify(osg::NOTICE) << "PixelBufferWin32::realizeImplementation, wglShareLists error: " << sysError() << std::endl;
}
}
}
@ -757,15 +742,10 @@ bool PixelBufferWin32::makeContextCurrentImplementation( GraphicsContext* readCo
return false;
}
GraphicsWindowWin32* graphicsWindowWin32 = dynamic_cast<GraphicsWindowWin32*>(readContext);
if (graphicsWindowWin32)
GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast<GraphicsHandleWin32*>(readContext);
if (graphicsHandleWin32)
{
return wgle->wglMakeContextCurrentARB(_hdc, graphicsWindowWin32->getHDC(), _hglrc);
}
PixelBufferWin32* pixelBufferWin32 = dynamic_cast<PixelBufferWin32*>(_traits->sharedContext);
if (pixelBufferWin32)
{
return wgle->wglMakeContextCurrentARB(_hdc, pixelBufferWin32->getHDC(), _hglrc);
return wgle->wglMakeContextCurrentARB(_hdc, graphicsHandleWin32->getHDC(), _hglrc);
}
return false;
}

View File

@ -28,10 +28,8 @@ using namespace osgViewer;
PixelBufferX11::PixelBufferX11(osg::GraphicsContext::Traits* traits)
: _valid(false),
_display(0),
_pbuffer(0),
_visualInfo(0),
_context(0),
_initialized(false),
_realized(false),
_useGLX1_3(false)
@ -217,24 +215,11 @@ void PixelBufferX11::init()
}
}
GLXContext sharedContextGLX = NULL;
// get any shared GLX contexts
GraphicsHandleX11* graphicsHandleX11 = dynamic_cast<GraphicsHandleX11*>(_traits->sharedContext);
Context sharedContext = graphicsHandleX11 ? graphicsHandleX11->getContext() : 0;
// get any shared GLX contexts
GraphicsWindowX11* graphicsWindowX11 = dynamic_cast<GraphicsWindowX11*>(_traits->sharedContext);
if (graphicsWindowX11)
{
sharedContextGLX = graphicsWindowX11->getContext();
}
else
{
PixelBufferX11* pixelBufferX11 = dynamic_cast<PixelBufferX11*>(_traits->sharedContext);
if (pixelBufferX11)
{
sharedContextGLX = pixelBufferX11->getContext();
}
}
_context = glXCreateContext( _display, _visualInfo, sharedContextGLX, True );
_context = glXCreateContext( _display, _visualInfo, sharedContext, True );
if (!_context)
{

View File

@ -490,7 +490,9 @@ void WindowCaptureCallback::setCaptureOperation(ScreenCaptureHandler::CaptureOpe
void WindowCaptureCallback::operator () (osg::RenderInfo& renderInfo) const
{
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE)
glReadBuffer(_readBuffer);
#endif
osg::GraphicsContext* gc = renderInfo.getState()->getGraphicsContext();
osg::ref_ptr<ContextData> cd = getContextData(gc);