From 71b0978628ca5846f099e633762420fb673a5157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Sat, 7 Oct 2006 21:22:59 +0000 Subject: [PATCH] Separate function for finding right GLXFBConfig. svn path=/branches/work/kwin_composite/; revision=593458 --- scene_opengl.cpp | 61 +++++++++++++++++++++++++++++++++++------------- scene_opengl.h | 1 + 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/scene_opengl.cpp b/scene_opengl.cpp index ec8779fa44..00d662b9ad 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -30,6 +30,13 @@ GLXFBConfig SceneOpenGL::fbcdrawable; GLXContext SceneOpenGL::context; GLXPixmap SceneOpenGL::glxroot; +static void checkGLError( const char* txt ) + { + GLenum err = glGetError(); + if( err != GL_NO_ERROR ) + kWarning() << "GL error (" << txt << "): 0x" << QString::number( err, 16 ) << endl; + } + const int root_attrs[] = { GLX_DOUBLEBUFFER, False, @@ -42,7 +49,7 @@ const int root_attrs[] = GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT | GLX_WINDOW_BIT, None }; - + const int drawable_attrs[] = { GLX_DOUBLEBUFFER, False, @@ -56,13 +63,6 @@ const int drawable_attrs[] = None }; -static void checkGLError( const char* txt ) - { - GLenum err = glGetError(); - if( err != GL_NO_ERROR ) - kWarning() << "GL error (" << txt << "): 0x" << QString::number( err, 16 ) << endl; - } - SceneOpenGL::SceneOpenGL( Workspace* ws ) : Scene( ws ) { @@ -75,14 +75,8 @@ SceneOpenGL::SceneOpenGL( Workspace* ws ) gcroot = XCreateGC( display(), rootWindow(), GCSubwindowMode, &gcattr ); buffer = XCreatePixmap( display(), rootWindow(), displayWidth(), displayHeight(), QX11Info::appDepth()); - GLXFBConfig* fbconfigs = glXChooseFBConfig( display(), DefaultScreen( display()), - root_attrs, &dummy ); - fbcroot = fbconfigs[ 0 ]; - XFree( fbconfigs ); - fbconfigs = glXChooseFBConfig( display(), DefaultScreen( display()), - drawable_attrs, &dummy ); - fbcdrawable = fbconfigs[ 0 ]; - XFree( fbconfigs ); + findConfig( root_attrs, fbcroot ); + findConfig( drawable_attrs, fbcdrawable ); glxroot = glXCreatePixmap( display(), fbcroot, buffer, NULL ); context = glXCreateNewContext( display(), fbcroot, GLX_RGBA_TYPE, NULL, GL_FALSE ); glXMakeContextCurrent( display(), glxroot, glxroot, context ); @@ -106,6 +100,41 @@ SceneOpenGL::~SceneOpenGL() checkGLError( "Cleanup" ); } +bool SceneOpenGL::findConfig( const int* attrs, GLXFBConfig& config ) + { + int cnt; + GLXFBConfig* fbconfigs = glXChooseFBConfig( display(), DefaultScreen( display()), + attrs, &cnt ); + if( fbconfigs != NULL ) + { + config = fbconfigs[ 0 ]; + XFree( fbconfigs ); + return true; + } + static const int empty[] = { None }; + fbconfigs = glXChooseFBConfig( display(), DefaultScreen( display()), empty, &cnt ); + for( int i = 0; + i < cnt; + ++i ) + { + int pos = 0; + kDebug() << "FBCONF:" << i << endl; + while( attrs[ pos ] != (int)None ) + { + int value; + if( glXGetFBConfigAttrib( display(), fbconfigs[ i ], attrs[ pos ], &value ) + == Success ) + kDebug() << "ATTR:" << attrs[ pos ] << ":" << value + << ":" << attrs[ pos + 1 ] << endl; + else + kDebug() << "ATTR FAIL:" << attrs[ pos ] << endl; + pos += 2; + } + } + assert( false ); + return false; + } + static void quadDraw( int x, int y, int w, int h ) { glTexCoord2i( x, y ); diff --git a/scene_opengl.h b/scene_opengl.h index 414ebbaf11..ecaccbb6e0 100644 --- a/scene_opengl.h +++ b/scene_opengl.h @@ -32,6 +32,7 @@ class SceneOpenGL virtual void windowAdded( Toplevel* ); virtual void windowDeleted( Toplevel* ); private: + bool findConfig( const int* attrs, GLXFBConfig& config ); typedef GLuint Texture; GC gcroot; Pixmap buffer;