From c6c4dd95edbe45100707c38f751c727cecd24517 Mon Sep 17 00:00:00 2001 From: san Date: Mon, 12 Apr 2010 13:39:49 +0000 Subject: [PATCH] Helper methods for choosing X visual suitable for 3D visualization added --- src/Qtx/Qtx.cxx | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ src/Qtx/Qtx.h | 5 ++++ 2 files changed, 73 insertions(+) diff --git a/src/Qtx/Qtx.cxx b/src/Qtx/Qtx.cxx index a9163e978..27e9c929d 100755 --- a/src/Qtx/Qtx.cxx +++ b/src/Qtx/Qtx.cxx @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -1381,3 +1382,70 @@ bool Qtx::stringToConicalGradient( const QString& str, QConicalGradient& gradien } return success; } + +#ifndef WIN32 + +#include +#include + +/*! + \brief Open the default X display and returns pointer to it. + This method is available on Linux only. + \return Pointer to X display. + \sa getVisual() +*/ +void* Qtx::getDisplay() +{ + static Display* pDisplay = NULL; + if ( !pDisplay ) + pDisplay = XOpenDisplay( NULL ); + return pDisplay; +} + +/*! + \brief Returns pointer to X visual suitable for 3D rendering. + This method is available on Linux only. + \return Pointer to X visual. + \sa getDisplay() +*/ +Qt::HANDLE Qtx::getVisual() +{ + Qt::HANDLE res = NULL; + + Display* pDisplay = (Display*)getDisplay(); + if ( !pDisplay ) + return res; + + int errorBase; + int eventBase; + + // Make sure OpenGL's GLX extension supported + if( !glXQueryExtension( pDisplay, &errorBase, &eventBase ) ){ + qCritical( "Could not find glx extension" ); + return res; + } + + // Find an appropriate visual + + int doubleBufferVisual[] = { + GLX_RGBA, // Needs to support OpenGL + GLX_DEPTH_SIZE, 16, // Needs to support a 16 bit depth buffer + GLX_DOUBLEBUFFER, // Needs to support double-buffering + None // end of list + }; + + // Try for the double-bufferd visual first + XVisualInfo *visualInfo = NULL; + visualInfo = glXChooseVisual( pDisplay, DefaultScreen(pDisplay), doubleBufferVisual ); + + if( visualInfo == NULL ){ + qCritical( "Could not find matching glx visual" ); + return res; + } + + qDebug() << "Picked visual 0x" << hex << XVisualIDFromVisual( visualInfo->visual ); + res = (Qt::HANDLE)( visualInfo->visual ); + + return res; +} +#endif // WIN32 diff --git a/src/Qtx/Qtx.h b/src/Qtx/Qtx.h index b5dd9f2ef..2077ea987 100755 --- a/src/Qtx/Qtx.h +++ b/src/Qtx/Qtx.h @@ -167,6 +167,11 @@ public: static bool stringToLinearGradient( const QString&, QLinearGradient& ); static bool stringToRadialGradient( const QString&, QRadialGradient& ); static bool stringToConicalGradient( const QString&, QConicalGradient& ); + +#ifndef WIN32 + static void* getDisplay(); + static Qt::HANDLE getVisual(); +#endif }; #endif -- 2.39.2