diff --git a/include/osgViewer/api/X11/PixelBufferX11 b/include/osgViewer/api/X11/PixelBufferX11 index e4555a674..9e815f8a3 100644 --- a/include/osgViewer/api/X11/PixelBufferX11 +++ b/include/osgViewer/api/X11/PixelBufferX11 @@ -83,6 +83,17 @@ class OSGVIEWER_EXPORT PixelBufferX11 : public osg::GraphicsContext, public osgV bool _realized; bool _useGLX1_3; + bool _useSGIX; + + typedef Pbuffer ( *GLXCreateGLXPbufferSGIX_FuncPtr) (Display *dpy, GLXFBConfig config, unsigned int, unsigned height, int* attrib_list); + typedef void ( *GLXDestroyGLXPbufferSGIX_FuncPtr) (Display *dpy, Pbuffer pbuf); + typedef int ( *GLXQueryGLXPbufferSGIX_FuncCPtr) (Display *dpy, Pbuffer pbuf, int attribute, unsigned int *value); + typedef GLXFBConfig ( *GLXGetFBConfigFromVisualSGIX_FuncPtr) (Display *dpy, XVisualInfo *vis); + + GLXCreateGLXPbufferSGIX_FuncPtr _glXCreateGLXPbufferSGIX; + GLXDestroyGLXPbufferSGIX_FuncPtr _glXDestroyGLXPbufferSGIX; + GLXQueryGLXPbufferSGIX_FuncCPtr _glXQueryGLXPbufferSGIX; + GLXGetFBConfigFromVisualSGIX_FuncPtr _glXGetFBConfigFromVisualSGIX; }; } diff --git a/src/osgViewer/PixelBufferX11.cpp b/src/osgViewer/PixelBufferX11.cpp index c835828db..8661af14e 100644 --- a/src/osgViewer/PixelBufferX11.cpp +++ b/src/osgViewer/PixelBufferX11.cpp @@ -32,7 +32,12 @@ PixelBufferX11::PixelBufferX11(osg::GraphicsContext::Traits* traits) _visualInfo(0), _initialized(false), _realized(false), - _useGLX1_3(false) + _useGLX1_3(false), + _useSGIX(false), + _glXCreateGLXPbufferSGIX(NULL), + _glXDestroyGLXPbufferSGIX(NULL), + _glXQueryGLXPbufferSGIX(NULL), + _glXGetFBConfigFromVisualSGIX(NULL) { _traits = traits; @@ -181,6 +186,20 @@ void PixelBufferX11::init() const char *extensions = glXQueryExtensionsString(_display, screen); haveSGIX_pbuffer = osg::isExtensionInExtensionString("GLX_SGIX_pbuffer", extensions) && osg::isExtensionInExtensionString("GLX_SGIX_fbconfig", extensions); + + if (haveSGIX_pbuffer) + { + osg::setGLExtensionFuncPtr(_glXCreateGLXPbufferSGIX, "glXDestroyGLXPbufferSGIX"); + osg::setGLExtensionFuncPtr(_glXDestroyGLXPbufferSGIX, "glXDestroyGLXPbufferSGIX"); + osg::setGLExtensionFuncPtr(_glXQueryGLXPbufferSGIX, "glXDestroyGLXPbufferSGIX"); + osg::setGLExtensionFuncPtr(_glXGetFBConfigFromVisualSGIX, "glXGetFBConfigFromVisualSGIX"); + if (_glXCreateGLXPbufferSGIX == NULL || + _glXDestroyGLXPbufferSGIX == NULL || + _glXQueryGLXPbufferSGIX == NULL || + _glXGetFBConfigFromVisualSGIX == NULL) { + haveSGIX_pbuffer = false; + } + } } #endif @@ -283,7 +302,7 @@ void PixelBufferX11::init() // If we still have no pbuffer but a capable display with the SGIX extension, try to use that if (!_pbuffer && haveSGIX_pbuffer) { - GLXFBConfigSGIX fbconfig = glXGetFBConfigFromVisualSGIX( _display, _visualInfo ); + GLXFBConfigSGIX fbconfig = _glXGetFBConfigFromVisualSGIX( _display, _visualInfo ); typedef std::vector AttributeList; AttributeList attributes; @@ -291,14 +310,15 @@ void PixelBufferX11::init() attributes.push_back( GL_TRUE ); attributes.push_back( 0L ); - _pbuffer = glXCreateGLXPbufferSGIX(_display, fbconfig, _traits->width, _traits->height, &attributes.front() ); + _pbuffer = _glXCreateGLXPbufferSGIX(_display, fbconfig, _traits->width, _traits->height, &attributes.front() ); if (_pbuffer) { + _useSGIX = true; int iWidth = 0; int iHeight = 0; - glXQueryGLXPbufferSGIX(_display, _pbuffer, GLX_WIDTH_SGIX , (unsigned int *)&iWidth); - glXQueryGLXPbufferSGIX(_display, _pbuffer, GLX_HEIGHT_SGIX, (unsigned int *)&iHeight); - + _glXQueryGLXPbufferSGIX(_display, _pbuffer, GLX_WIDTH_SGIX , (unsigned int *)&iWidth); + _glXQueryGLXPbufferSGIX(_display, _pbuffer, GLX_HEIGHT_SGIX, (unsigned int *)&iHeight); + if (_traits->width != iWidth || _traits->height != iHeight) { OSG_NOTICE << "PixelBufferX11::init(), SGIX_pbuffer created with different size then requsted" << std::endl; @@ -351,7 +371,10 @@ void PixelBufferX11::closeImplementation() else { #ifdef GLX_SGIX_pbuffer - glXDestroyGLXPbufferSGIX(_display, _pbuffer); + if (_useSGIX) + { + _glXDestroyGLXPbufferSGIX(_display, _pbuffer); + } #endif } }