diff --git a/include/osgViewer/api/X11/PixelBufferX11 b/include/osgViewer/api/X11/PixelBufferX11 index ee8f93115d7..e015e91578f 100644 --- a/include/osgViewer/api/X11/PixelBufferX11 +++ b/include/osgViewer/api/X11/PixelBufferX11 @@ -27,6 +27,11 @@ #include #include +#ifndef GLX_VERSION_1_3 + typedef XID GLXPbuffer; +#endif + + namespace osgViewer { @@ -34,37 +39,7 @@ class OSGVIEWER_EXPORT PixelBufferX11 : public osg::GraphicsContext { public: - PixelBufferX11(osg::GraphicsContext::Traits* traits): - _valid(false), - _display(0), - _parent(0), - _pbuffer(0), - _visualInfo(0), - _glxContext(0), - _initialized(false), - _realized(false) - { - _traits = traits; - - init(); - - if (valid()) - { - setState( new osg::State ); - getState()->setGraphicsContext(this); - - if (_traits.valid() && _traits->sharedContext) - { - getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); - incrementContextIDUsageCount( getState()->getContextID() ); - } - else - { - getState()->setContextID( osg::GraphicsContext::createNewContextID() ); - } - - } - } + PixelBufferX11(osg::GraphicsContext::Traits* traits); virtual bool isSameKindAs(const Object* object) const { return dynamic_cast(object)!=0; } virtual const char* libraryName() const { return "osgViewer"; } diff --git a/src/osgViewer/GraphicsWindowX11.cpp b/src/osgViewer/GraphicsWindowX11.cpp index 7c72c82b5a8..4e052778ab1 100644 --- a/src/osgViewer/GraphicsWindowX11.cpp +++ b/src/osgViewer/GraphicsWindowX11.cpp @@ -516,7 +516,7 @@ void GraphicsWindowX11::init() else { PixelBufferX11* pixelBufferX11 = dynamic_cast(_traits->sharedContext); - if (pixelBufferX11) + if (pixelBufferX11 && pixelBufferX11->valid()) { sharedContextGLX = pixelBufferX11->getGLXContext(); } diff --git a/src/osgViewer/PixelBufferX11.cpp b/src/osgViewer/PixelBufferX11.cpp index 1e2022c38ff..c743f12b547 100644 --- a/src/osgViewer/PixelBufferX11.cpp +++ b/src/osgViewer/PixelBufferX11.cpp @@ -25,9 +25,10 @@ using namespace osgViewer; +#ifdef GLX_VERSION_1_3 static GLXFBConfig getFBConfigFromVisual(::Display* dpy, XVisualInfo* visualInfo) { -#if defined(__APPLE__) || defined(_AIX) +#if defined(__APPLE__) || defined(_AIX) || defined(__hpux) int screen = visualInfo->screen; int nelements; GLXFBConfig *configs = glXGetFBConfigs(dpy, screen, &nelements); @@ -45,12 +46,46 @@ static GLXFBConfig getFBConfigFromVisual(::Display* dpy, XVisualInfo* visualInfo return glXGetFBConfigFromVisualSGIX( dpy, visualInfo ); #endif } +#endif + +PixelBufferX11::PixelBufferX11(osg::GraphicsContext::Traits* traits) + : _valid(false), + _display(0), + _parent(0), + _pbuffer(0), + _visualInfo(0), + _glxContext(0), + _initialized(false), + _realized(false) +{ + _traits = traits; + + init(); + + if (valid()) + { + setState( new osg::State ); + getState()->setGraphicsContext(this); + + if (_traits.valid() && _traits->sharedContext) + { + getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); + incrementContextIDUsageCount( getState()->getContextID() ); + } + else + { + getState()->setContextID( osg::GraphicsContext::createNewContextID() ); + } + + } +} PixelBufferX11::~PixelBufferX11() { close(true); } +#ifdef GLX_VERSION_1_3 bool PixelBufferX11::createVisualInfo() { typedef std::vector Attributes; @@ -93,8 +128,6 @@ void PixelBufferX11::init() { if (_initialized) return; -#ifdef GLX_VERSION_1_3 - if (!_traits) { _valid = false; @@ -232,13 +265,23 @@ void PixelBufferX11::init() _valid = true; _initialized = true; -#else - _valid = false; - _initialized = true; - return; -#endif } +#else + +// fallback for non GLX1.3 versions where pbuffers are not supported. +// note, this makes the rest of the pbuffer code a non op as init is false; +bool PixelBufferX11::createVisualInfo() +{ + return false; +} + +void PixelBufferX11::init() +{ +} + +#endif + bool PixelBufferX11::realizeImplementation() { if (_realized) @@ -310,9 +353,7 @@ void PixelBufferX11::closeImplementation() if (_pbuffer) { -#ifdef GLX_VERSION_1_3 glXDestroyPbuffer(_display, _pbuffer); -#endif } XFlush( _display ); @@ -347,5 +388,5 @@ void PixelBufferX11::swapBuffersImplementation() // osg::notify(osg::NOTICE)<<"PixelBufferX11::swapBuffersImplementation "<