From: san Date: Mon, 12 Apr 2010 13:39:49 +0000 (+0000) Subject: Helper methods for choosing X visual suitable for 3D visualization added X-Git-Tag: V5_1_4a1~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c6c4dd95edbe45100707c38f751c727cecd24517;p=modules%2Fgui.git Helper methods for choosing X visual suitable for 3D visualization added --- 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