diff --git a/include/osgViewer/api/Carbon/GraphicsHandleCarbon b/include/osgViewer/api/Carbon/GraphicsHandleCarbon new file mode 100644 index 000000000..c9b480cb5 --- /dev/null +++ b/include/osgViewer/api/Carbon/GraphicsHandleCarbon @@ -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 + +#include +#include + + +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 diff --git a/include/osgViewer/api/Carbon/GraphicsWindowCarbon b/include/osgViewer/api/Carbon/GraphicsWindowCarbon index 3a72a7890..1a7cb02ae 100644 --- a/include/osgViewer/api/Carbon/GraphicsWindowCarbon +++ b/include/osgViewer/api/Carbon/GraphicsWindowCarbon @@ -22,12 +22,12 @@ #if defined (__APPLE__) && (!__LP64__) #include -#include -#include +#include + 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; diff --git a/include/osgViewer/api/Carbon/PixelBufferCarbon b/include/osgViewer/api/Carbon/PixelBufferCarbon index ad5183314..5880450fe 100644 --- a/include/osgViewer/api/Carbon/PixelBufferCarbon +++ b/include/osgViewer/api/Carbon/PixelBufferCarbon @@ -19,16 +19,13 @@ #if defined (__APPLE__) && (!__LP64__) #include -#include - -#include -#include +#include 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; }; } diff --git a/include/osgViewer/api/Win32/GraphicsHandleWin32 b/include/osgViewer/api/Win32/GraphicsHandleWin32 new file mode 100644 index 000000000..f6ac8fa28 --- /dev/null +++ b/include/osgViewer/api/Win32/GraphicsHandleWin32 @@ -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 + +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0500 +#endif +#include + +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 diff --git a/include/osgViewer/api/Win32/GraphicsWindowWin32 b/include/osgViewer/api/Win32/GraphicsWindowWin32 index 88390a740..afcaaee65 100644 --- a/include/osgViewer/api/Win32/GraphicsWindowWin32 +++ b/include/osgViewer/api/Win32/GraphicsWindowWin32 @@ -20,16 +20,12 @@ #define OSGVIEWER_GRAPHICSWINDOWWIN32 1 #include - -#ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0500 -#endif -#include +#include 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; diff --git a/include/osgViewer/api/Win32/PixelBufferWin32 b/include/osgViewer/api/Win32/PixelBufferWin32 index 066edfa50..d82548065 100644 --- a/include/osgViewer/api/Win32/PixelBufferWin32 +++ b/include/osgViewer/api/Win32/PixelBufferWin32 @@ -19,18 +19,13 @@ #ifndef OSGVIEWER_PIXELBUFFERWIN32 #define OSGVIEWER_PIXELBUFFERWIN32 1 -#include - -#ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0500 -#endif - -#include +#include +#include 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; diff --git a/include/osgViewer/api/X11/GraphicsHandleX11 b/include/osgViewer/api/X11/GraphicsHandleX11 new file mode 100644 index 000000000..fde7bb6f6 --- /dev/null +++ b/include/osgViewer/api/X11/GraphicsHandleX11 @@ -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 + + +#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) + #define OSG_USE_EGL + #include + #include + #include + #include +#else + #define GLX_GLXEXT_PROTOTYPES 1 + #include + #include + #include + #include + #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 diff --git a/include/osgViewer/api/X11/GraphicsWindowX11 b/include/osgViewer/api/X11/GraphicsWindowX11 index d79733b16..5ce22845a 100644 --- a/include/osgViewer/api/X11/GraphicsWindowX11 +++ b/include/osgViewer/api/X11/GraphicsWindowX11 @@ -20,38 +20,23 @@ #define OSGVIEWER_GRAPHICSWINDOWX11 1 #include - -#define GLX_GLXEXT_PROTOTYPES 1 - -#include -#include -#include - -#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) - #define OSG_USE_EGL - #include -#else - #include -#endif - +#include #include 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; diff --git a/include/osgViewer/api/X11/PixelBufferX11 b/include/osgViewer/api/X11/PixelBufferX11 index 346a064f4..e4555a674 100644 --- a/include/osgViewer/api/X11/PixelBufferX11 +++ b/include/osgViewer/api/X11/PixelBufferX11 @@ -19,18 +19,13 @@ #ifndef OSGVIEWER_PIXELBUFFERX11 #define OSGVIEWER_PIXELBUFFERX11 1 -#include - -#ifndef OSG_USE_EGL - #ifndef GLX_VERSION_1_3 - typedef XID GLXPbuffer; - #endif -#endif +#include +#include 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; diff --git a/src/osgViewer/CMakeLists.txt b/src/osgViewer/CMakeLists.txt index 38779318d..53cc4305d 100644 --- a/src/osgViewer/CMakeLists.txt +++ b/src/osgViewer/CMakeLists.txt @@ -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} ) diff --git a/src/osgViewer/GraphicsWindowCarbon.cpp b/src/osgViewer/GraphicsWindowCarbon.cpp index 3cbe741d9..7afe7a0de 100644 --- a/src/osgViewer/GraphicsWindowCarbon.cpp +++ b/src/osgViewer/GraphicsWindowCarbon.cpp @@ -398,18 +398,12 @@ bool GraphicsWindowCarbon::realizeImplementation() // create the context AGLContext sharedContextCarbon = NULL; - GraphicsWindowCarbon* graphicsWindowCarbon = dynamic_cast(_traits->sharedContext); - if (graphicsWindowCarbon) + GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast(_traits->sharedContext); + if (graphicsHandleCarbon) { - sharedContextCarbon = graphicsWindowCarbon->getAGLContext(); - } - else - { - PixelBufferCarbon* pixelbuffer = dynamic_cast(_traits->sharedContext); - if (pixelbuffer) { - sharedContextCarbon = pixelbuffer->getAGLContext(); - } + sharedContextCarbon = graphicsHandleCarbon->getAGLContext(); } + _context = aglCreateContext (_pixelFormat, sharedContextCarbon); diff --git a/src/osgViewer/GraphicsWindowWin32.cpp b/src/osgViewer/GraphicsWindowWin32.cpp index 14e3d758f..6309a4f95 100644 --- a/src/osgViewer/GraphicsWindowWin32.cpp +++ b/src/osgViewer/GraphicsWindowWin32.cpp @@ -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(_traits->sharedContext); - if (sharedContextWin32) + GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast(_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; diff --git a/src/osgViewer/GraphicsWindowX11.cpp b/src/osgViewer/GraphicsWindowX11.cpp index 4e7aebec5..7e5bed95a 100644 --- a/src/osgViewer/GraphicsWindowX11.cpp +++ b/src/osgViewer/GraphicsWindowX11.cpp @@ -693,22 +693,9 @@ void GraphicsWindowX11::init() } } - Context sharedContextGLX = NULL; - - // get any shared GLX contexts - GraphicsWindowX11* graphicsWindowX11 = dynamic_cast(_traits->sharedContext); - if (graphicsWindowX11) - { - sharedContextGLX = graphicsWindowX11->getContext(); - } - else - { - PixelBufferX11* pixelBufferX11 = dynamic_cast(_traits->sharedContext); - if (pixelBufferX11 && pixelBufferX11->valid()) - { - sharedContextGLX = pixelBufferX11->getContext(); - } - } + // get any shared GLX contexts + GraphicsHandleX11* graphicsHandleX11 = dynamic_cast(_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."<(_traits->sharedContext); - if (graphicsWindowCarbon) + // get any shared AGL contexts + GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast(_traits->sharedContext); + if (graphicsHandleCarbon) { - sharedContext = graphicsWindowCarbon->getAGLContext(); - } - else - { - PixelBufferCarbon* pixelBufferCarbon = dynamic_cast(_traits->sharedContext); - if (pixelBufferCarbon) - { - sharedContext = pixelBufferCarbon->getAGLContext(); - } + sharedContext = graphicsHandleCarbon->getAGLContext(); } _context = aglCreateContext (_pixelformat, sharedContext); diff --git a/src/osgViewer/PixelBufferWin32.cpp b/src/osgViewer/PixelBufferWin32.cpp index e323a6086..3013dc672 100644 --- a/src/osgViewer/PixelBufferWin32.cpp +++ b/src/osgViewer/PixelBufferWin32.cpp @@ -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(_traits->sharedContext); - if (graphicsWindowWin32) + GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast(_traits->sharedContext); + if (graphicsHandleWin32) { - hglrc = graphicsWindowWin32->getWGLContext(); - } - else - { - PixelBufferWin32* pixelBufferWin32 = dynamic_cast(_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(readContext); - if (graphicsWindowWin32) + GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast(readContext); + if (graphicsHandleWin32) { - return wgle->wglMakeContextCurrentARB(_hdc, graphicsWindowWin32->getHDC(), _hglrc); - } - PixelBufferWin32* pixelBufferWin32 = dynamic_cast(_traits->sharedContext); - if (pixelBufferWin32) - { - return wgle->wglMakeContextCurrentARB(_hdc, pixelBufferWin32->getHDC(), _hglrc); + return wgle->wglMakeContextCurrentARB(_hdc, graphicsHandleWin32->getHDC(), _hglrc); } return false; } diff --git a/src/osgViewer/PixelBufferX11.cpp b/src/osgViewer/PixelBufferX11.cpp index 23b252e2b..fee2e3590 100644 --- a/src/osgViewer/PixelBufferX11.cpp +++ b/src/osgViewer/PixelBufferX11.cpp @@ -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(_traits->sharedContext); + Context sharedContext = graphicsHandleX11 ? graphicsHandleX11->getContext() : 0; - // get any shared GLX contexts - GraphicsWindowX11* graphicsWindowX11 = dynamic_cast(_traits->sharedContext); - if (graphicsWindowX11) - { - sharedContextGLX = graphicsWindowX11->getContext(); - } - else - { - PixelBufferX11* pixelBufferX11 = dynamic_cast(_traits->sharedContext); - if (pixelBufferX11) - { - sharedContextGLX = pixelBufferX11->getContext(); - } - } - - _context = glXCreateContext( _display, _visualInfo, sharedContextGLX, True ); + _context = glXCreateContext( _display, _visualInfo, sharedContext, True ); if (!_context) { diff --git a/src/osgViewer/ScreenCaptureHandler.cpp b/src/osgViewer/ScreenCaptureHandler.cpp index c4186de74..41c95b62c 100644 --- a/src/osgViewer/ScreenCaptureHandler.cpp +++ b/src/osgViewer/ScreenCaptureHandler.cpp @@ -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 cd = getContextData(gc);