From 78b6ada7435f4611af884659f8d4895a2a6c8781 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 20 Jun 2007 11:59:27 +0000 Subject: [PATCH] Completed implementation of PixelBufferX11. --- include/osgViewer/api/X11/PixelBufferX11 | 6 +- src/osgViewer/PixelBufferX11.cpp | 92 ++++++++++++++---------- 2 files changed, 59 insertions(+), 39 deletions(-) diff --git a/include/osgViewer/api/X11/PixelBufferX11 b/include/osgViewer/api/X11/PixelBufferX11 index cfd75e5f9..ee8f93115 100644 --- a/include/osgViewer/api/X11/PixelBufferX11 +++ b/include/osgViewer/api/X11/PixelBufferX11 @@ -38,7 +38,7 @@ class OSGVIEWER_EXPORT PixelBufferX11 : public osg::GraphicsContext _valid(false), _display(0), _parent(0), - _window(0), + _pbuffer(0), _visualInfo(0), _glxContext(0), _initialized(false), @@ -103,7 +103,7 @@ class OSGVIEWER_EXPORT PixelBufferX11 : public osg::GraphicsContext Display* getDisplay() const { return _display; } Window& getParent() { return _parent; } - Window& getWindow() { return _window; } + GLXPbuffer& getPbuffer() { return _pbuffer; } GLXContext& getGLXContext() { return _glxContext; } protected: @@ -117,7 +117,7 @@ class OSGVIEWER_EXPORT PixelBufferX11 : public osg::GraphicsContext bool _valid; Display* _display; Window _parent; - Window _window; + GLXPbuffer _pbuffer; XVisualInfo* _visualInfo; GLXContext _glxContext; diff --git a/src/osgViewer/PixelBufferX11.cpp b/src/osgViewer/PixelBufferX11.cpp index 15a0036f4..02b46065e 100644 --- a/src/osgViewer/PixelBufferX11.cpp +++ b/src/osgViewer/PixelBufferX11.cpp @@ -25,6 +25,27 @@ using namespace osgViewer; +static GLXFBConfig getFBConfigFromVisual(::Display* dpy, XVisualInfo* visualInfo) +{ +#if defined(__APPLE__) || defined(_AIX) + int screen = visualInfo->screen; + int nelements; + GLXFBConfig *configs = glXGetFBConfigs(dpy, screen, &nelements); + for( int i = 0; i < nelements; i++ ) + { + int visual_id; + if( glXGetFBConfigAttrib( dpy, configs[i], GLX_VISUAL_ID, &visual_id ) == 0 ) + { + if( (unsigned int)visual_id == visualInfo->visualid ) + return configs[i]; + } + } + return NULL; +#else + return glXGetFBConfigFromVisualSGIX( dpy, visualInfo ); +#endif +} + PixelBufferX11::~PixelBufferX11() { close(true); @@ -72,6 +93,8 @@ void PixelBufferX11::init() { if (_initialized) return; +#ifdef GLX_VERSION_1_3 + if (!_traits) { _valid = false; @@ -180,14 +203,20 @@ void PixelBufferX11::init() mask |= CWOverrideRedirect; } - _window = XCreateWindow( _display, _parent, - _traits->x, - _traits->y, - _traits->width, _traits->height, 0, - _visualInfo->depth, InputOutput, - _visualInfo->visual, mask, &swatt ); + GLXFBConfig fbconfig = getFBConfigFromVisual( _display, _visualInfo ); + + typedef std::vector AttributeList; + + AttributeList attributes; + attributes.push_back( GLX_PBUFFER_WIDTH ); + attributes.push_back( _traits->width ); + attributes.push_back( GLX_PBUFFER_HEIGHT ); + attributes.push_back( _traits->height ); + attributes.push_back( 0L ); + + _pbuffer = glXCreatePbuffer(_display, fbconfig, &attributes.front() ); - if (!_window) + if (!_pbuffer) { osg::notify(osg::NOTICE)<<"Error: Unable to create Window."<width != watt.width && _traits->height != watt.height) - { - resized( _traits->x, _traits->y, _traits->width, _traits->height ); - } - - _valid = true; _initialized = true; +#else + _valid = false; + _initialized = true; + return; +#endif } bool PixelBufferX11::realizeImplementation() @@ -226,12 +250,7 @@ bool PixelBufferX11::realizeImplementation() if (!_initialized) init(); if (!_initialized) return false; - - XMapWindow( _display, _window ); - -// Window temp = _window; -// XSetWMColormapWindows( _display, _window, &temp, 1); - + _realized = true; return true; @@ -245,15 +264,15 @@ bool PixelBufferX11::makeCurrentImplementation() return false; } - osg::notify(osg::NOTICE)<<"PixelBufferX11::makeCurrentImplementation "<