Added preliminary handling of cases where GLX version < 1.3

This commit is contained in:
Robert Osfield 2007-09-12 17:01:47 +00:00
parent 23945bb506
commit 45e98d5f18
3 changed files with 59 additions and 43 deletions

View File

@ -27,6 +27,11 @@
#include <X11/X.h> #include <X11/X.h>
#include <GL/glx.h> #include <GL/glx.h>
#ifndef GLX_VERSION_1_3
typedef XID GLXPbuffer;
#endif
namespace osgViewer namespace osgViewer
{ {
@ -34,37 +39,7 @@ class OSGVIEWER_EXPORT PixelBufferX11 : public osg::GraphicsContext
{ {
public: public:
PixelBufferX11(osg::GraphicsContext::Traits* traits): 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() );
}
}
}
virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const PixelBufferX11*>(object)!=0; } virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const PixelBufferX11*>(object)!=0; }
virtual const char* libraryName() const { return "osgViewer"; } virtual const char* libraryName() const { return "osgViewer"; }

View File

@ -516,7 +516,7 @@ void GraphicsWindowX11::init()
else else
{ {
PixelBufferX11* pixelBufferX11 = dynamic_cast<PixelBufferX11*>(_traits->sharedContext); PixelBufferX11* pixelBufferX11 = dynamic_cast<PixelBufferX11*>(_traits->sharedContext);
if (pixelBufferX11) if (pixelBufferX11 && pixelBufferX11->valid())
{ {
sharedContextGLX = pixelBufferX11->getGLXContext(); sharedContextGLX = pixelBufferX11->getGLXContext();
} }

View File

@ -25,9 +25,10 @@
using namespace osgViewer; using namespace osgViewer;
#ifdef GLX_VERSION_1_3
static GLXFBConfig getFBConfigFromVisual(::Display* dpy, XVisualInfo* visualInfo) static GLXFBConfig getFBConfigFromVisual(::Display* dpy, XVisualInfo* visualInfo)
{ {
#if defined(__APPLE__) || defined(_AIX) #if defined(__APPLE__) || defined(_AIX) || defined(__hpux)
int screen = visualInfo->screen; int screen = visualInfo->screen;
int nelements; int nelements;
GLXFBConfig *configs = glXGetFBConfigs(dpy, screen, &nelements); GLXFBConfig *configs = glXGetFBConfigs(dpy, screen, &nelements);
@ -45,12 +46,46 @@ static GLXFBConfig getFBConfigFromVisual(::Display* dpy, XVisualInfo* visualInfo
return glXGetFBConfigFromVisualSGIX( dpy, visualInfo ); return glXGetFBConfigFromVisualSGIX( dpy, visualInfo );
#endif #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() PixelBufferX11::~PixelBufferX11()
{ {
close(true); close(true);
} }
#ifdef GLX_VERSION_1_3
bool PixelBufferX11::createVisualInfo() bool PixelBufferX11::createVisualInfo()
{ {
typedef std::vector<int> Attributes; typedef std::vector<int> Attributes;
@ -93,8 +128,6 @@ void PixelBufferX11::init()
{ {
if (_initialized) return; if (_initialized) return;
#ifdef GLX_VERSION_1_3
if (!_traits) if (!_traits)
{ {
_valid = false; _valid = false;
@ -232,13 +265,23 @@ void PixelBufferX11::init()
_valid = true; _valid = true;
_initialized = 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() bool PixelBufferX11::realizeImplementation()
{ {
if (_realized) if (_realized)
@ -310,9 +353,7 @@ void PixelBufferX11::closeImplementation()
if (_pbuffer) if (_pbuffer)
{ {
#ifdef GLX_VERSION_1_3
glXDestroyPbuffer(_display, _pbuffer); glXDestroyPbuffer(_display, _pbuffer);
#endif
} }
XFlush( _display ); XFlush( _display );