diff options
-rw-r--r-- | include/vcl/opengl/OpenGLContext.hxx | 2 | ||||
-rw-r--r-- | vcl/source/opengl/OpenGLContext.cxx | 89 |
2 files changed, 91 insertions, 0 deletions
diff --git a/include/vcl/opengl/OpenGLContext.hxx b/include/vcl/opengl/OpenGLContext.hxx index 559fbab40ca2..b01e8fd352a1 100644 --- a/include/vcl/opengl/OpenGLContext.hxx +++ b/include/vcl/opengl/OpenGLContext.hxx @@ -157,6 +157,8 @@ public: return mbInitialized; } + static SystemWindowData generateWinData(Window* pParent); + private: SAL_DLLPRIVATE bool initWindow(); diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx index 4b420182d2c1..4d5e59515cd2 100644 --- a/vcl/source/opengl/OpenGLContext.cxx +++ b/vcl/source/opengl/OpenGLContext.cxx @@ -684,4 +684,93 @@ bool OpenGLContext::initWindow() #endif +#if defined( WNT ) || defined( MACOSX ) || defined( IOS) || defined( ANDROID ) + +SystemWindowData OpenGLContext::generateWinData(Window* /*pParent*/) +{ + SystemWindowData aWinData; + aWinData.nSize = sizeof(aWinData); + return aWinData; +} + +#elif defined( UNX ) + +SystemWindowData OpenGLContext::generateWinData(Window* pParent) +{ + SystemWindowData aWinData; + aWinData.nSize = sizeof(aWinData); + + const SystemEnvData* sysData(pParent->GetSystemData()); + + Display *dpy = reinterpret_cast<Display*>(sysData->pDisplay); + + if( !glXQueryExtension( dpy, NULL, NULL ) ) + return aWinData; + + XLIB_Window win = sysData->aWindow; + + SAL_INFO("vcl.opengl", "parent window: " << win); + + XWindowAttributes xattr; + XGetWindowAttributes( dpy, win, &xattr ); + + int screen = XScreenNumberOfScreen( xattr.screen ); + + static int visual_attribs[] = + { + GLX_RED_SIZE, 8, + GLX_GREEN_SIZE, 8, + GLX_BLUE_SIZE, 8, + GLX_ALPHA_SIZE, 8, + GLX_DEPTH_SIZE, 24, + GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, + None + }; + + initOpenGLFunctionPointers(); + + int fbCount = 0; + GLXFBConfig* pFBC = glXChooseFBConfig( dpy, + screen, + visual_attribs, &fbCount ); + + if(!pFBC) + { + SAL_WARN("vcl.opengl", "no suitable fb format found"); + return aWinData; + } + + int best_fbc = -1, best_num_samp = -1; + for(int i = 0; i < fbCount; ++i) + { + XVisualInfo* pVi = glXGetVisualFromFBConfig( dpy, pFBC[i] ); + if(pVi) + { + // pick the one with the most samples per pixel + int nSampleBuf = 0; + int nSamples = 0; + glXGetFBConfigAttrib( dpy, pFBC[i], GLX_SAMPLE_BUFFERS, &nSampleBuf ); + glXGetFBConfigAttrib( dpy, pFBC[i], GLX_SAMPLES , &nSamples ); + + if ( best_fbc < 0 || (nSampleBuf && ( nSamples > best_num_samp )) ) + { + best_fbc = i; + best_num_samp = nSamples; + } + } + XFree( pVi ); + } + + XVisualInfo* vi = glXGetVisualFromFBConfig( dpy, pFBC[best_fbc] ); + if( vi ) + { + SAL_INFO("vcl.opengl", "using VisualID " << vi->visualid); + aWinData.pVisual = (void*)(vi->visual); + } + + return aWinData; +} + +#endif + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |