Skip to content

Commit

Permalink
Added preliminary handling of cases where GLX version < 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
robertosfield committed Sep 12, 2007
1 parent 23945bb commit 45e98d5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 43 deletions.
37 changes: 6 additions & 31 deletions include/osgViewer/api/X11/PixelBufferX11
Expand Up @@ -27,44 +27,19 @@
#include <X11/X.h>
#include <GL/glx.h>

#ifndef GLX_VERSION_1_3
typedef XID GLXPbuffer;
#endif


namespace osgViewer
{

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<const PixelBufferX11*>(object)!=0; }
virtual const char* libraryName() const { return "osgViewer"; }
Expand Down
2 changes: 1 addition & 1 deletion src/osgViewer/GraphicsWindowX11.cpp
Expand Up @@ -516,7 +516,7 @@ void GraphicsWindowX11::init()
else
{
PixelBufferX11* pixelBufferX11 = dynamic_cast<PixelBufferX11*>(_traits->sharedContext);
if (pixelBufferX11)
if (pixelBufferX11 && pixelBufferX11->valid())
{
sharedContextGLX = pixelBufferX11->getGLXContext();
}
Expand Down
63 changes: 52 additions & 11 deletions src/osgViewer/PixelBufferX11.cpp
Expand Up @@ -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);
Expand All @@ -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<int> Attributes;
Expand Down Expand Up @@ -93,8 +128,6 @@ void PixelBufferX11::init()
{
if (_initialized) return;

#ifdef GLX_VERSION_1_3

if (!_traits)
{
_valid = false;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -310,9 +353,7 @@ void PixelBufferX11::closeImplementation()

if (_pbuffer)
{
#ifdef GLX_VERSION_1_3
glXDestroyPbuffer(_display, _pbuffer);
#endif
}

XFlush( _display );
Expand Down Expand Up @@ -347,5 +388,5 @@ void PixelBufferX11::swapBuffersImplementation()

// osg::notify(osg::NOTICE)<<"PixelBufferX11::swapBuffersImplementation "<<this<<" "<<OpenThreads::Thread::CurrentThread()<<std::endl;

glXSwapBuffers(_display, _pbuffer);
glXSwapBuffers(_display, _pbuffer);
}

0 comments on commit 45e98d5

Please sign in to comment.