-wxGLCanvas::~wxGLCanvas()
-{
- GLXFBConfig * fbc = (GLXFBConfig *) m_fbc;
- if (fbc && m_canFreeFBC)
- XFree( fbc );
-
- XVisualInfo *vi = (XVisualInfo *) m_vi;
- if (vi && m_canFreeVi)
- XFree( vi );
-}
-
-void* wxGLCanvas::ChooseGLVisual(const int *attribList)
-{
- int data[512];
- GetGLAttribListFromWX( attribList, data );
-
- Display *dpy = GDK_DISPLAY();
-
- return glXChooseVisual( dpy, DefaultScreen(dpy), data );
-}
-
-void* wxGLCanvas::ChooseGLFBC(const int *attribList)
-{
- int data[512];
- GetGLAttribListFromWX( attribList, data );
-
- int returned;
- return glXChooseFBConfig( GDK_DISPLAY(), DefaultScreen(GDK_DISPLAY()),
- data, &returned );
-}
-
-
-void
-wxGLCanvas::GetGLAttribListFromWX(const int *wx_attribList, int *gl_attribList)
-{
- if ( !wx_attribList )
- {
- if (wxGLCanvas::GetGLXVersion() >= 13)
- {
- // leave GLX >= 1.3 choose the default attributes
- gl_attribList[0] = 0;
- }
- else // GLX < 1.3
- {
- int i = 0;
- // default settings if attriblist = 0
- gl_attribList[i++] = GLX_RGBA;
- gl_attribList[i++] = GLX_DOUBLEBUFFER;
- gl_attribList[i++] = GLX_DEPTH_SIZE; gl_attribList[i++] = 1;
- gl_attribList[i++] = GLX_RED_SIZE; gl_attribList[i++] = 1;
- gl_attribList[i++] = GLX_GREEN_SIZE; gl_attribList[i++] = 1;
- gl_attribList[i++] = GLX_BLUE_SIZE; gl_attribList[i++] = 1;
- gl_attribList[i++] = GLX_ALPHA_SIZE; gl_attribList[i++] = 0;
- gl_attribList[i++] = None;
- }
- }
- else // have non-default attributes
- {
- int arg=0, p=0;
- while( (wx_attribList[arg]!=0) && (p<510) )
- {
- switch( wx_attribList[arg++] )
- {
- case WX_GL_RGBA:
- if (wxGLCanvas::GetGLXVersion() <= 12)
- {
- // for GLX >= 1.3, GLX_RGBA is useless (setting this flags will crash on most opengl implm)
- gl_attribList[p++] = GLX_RGBA;
- }
- break;
- case WX_GL_BUFFER_SIZE:
- gl_attribList[p++] = GLX_BUFFER_SIZE;
- gl_attribList[p++] = wx_attribList[arg++];
- break;
- case WX_GL_LEVEL:
- gl_attribList[p++] = GLX_LEVEL;
- gl_attribList[p++] = wx_attribList[arg++];
- break;
- case WX_GL_DOUBLEBUFFER:
- gl_attribList[p++] = GLX_DOUBLEBUFFER;
- gl_attribList[p++] = 1;
- break;
- case WX_GL_STEREO:
- gl_attribList[p++] = GLX_STEREO;
- break;
- case WX_GL_AUX_BUFFERS:
- gl_attribList[p++] = GLX_AUX_BUFFERS;
- gl_attribList[p++] = wx_attribList[arg++];
- break;
- case WX_GL_MIN_RED:
- gl_attribList[p++] = GLX_RED_SIZE;
- gl_attribList[p++] = wx_attribList[arg++];
- break;
- case WX_GL_MIN_GREEN:
- gl_attribList[p++] = GLX_GREEN_SIZE;
- gl_attribList[p++] = wx_attribList[arg++];
- break;
- case WX_GL_MIN_BLUE:
- gl_attribList[p++] = GLX_BLUE_SIZE;
- gl_attribList[p++] = wx_attribList[arg++];
- break;
- case WX_GL_MIN_ALPHA:
- gl_attribList[p++] = GLX_ALPHA_SIZE;
- gl_attribList[p++] = wx_attribList[arg++];
- break;
- case WX_GL_DEPTH_SIZE:
- gl_attribList[p++] = GLX_DEPTH_SIZE;
- gl_attribList[p++] = wx_attribList[arg++];
- break;
- case WX_GL_STENCIL_SIZE:
- gl_attribList[p++] = GLX_STENCIL_SIZE;
- gl_attribList[p++] = wx_attribList[arg++];
- break;
- case WX_GL_MIN_ACCUM_RED:
- gl_attribList[p++] = GLX_ACCUM_RED_SIZE;
- gl_attribList[p++] = wx_attribList[arg++];
- break;
- case WX_GL_MIN_ACCUM_GREEN:
- gl_attribList[p++] = GLX_ACCUM_GREEN_SIZE;
- gl_attribList[p++] = wx_attribList[arg++];
- break;
- case WX_GL_MIN_ACCUM_BLUE:
- gl_attribList[p++] = GLX_ACCUM_BLUE_SIZE;
- gl_attribList[p++] = wx_attribList[arg++];
- break;
- case WX_GL_MIN_ACCUM_ALPHA:
- gl_attribList[p++] = GLX_ACCUM_ALPHA_SIZE;
- gl_attribList[p++] = wx_attribList[arg++];
- break;
- default:
- break;
- }
- }
-
- gl_attribList[p] = 0;
- }
-}
-
-/* static */
-int wxGLCanvas::GetGLXVersion()
-{
- static int s_glxVersion = 0;
- if ( s_glxVersion == 0 )
- {
- // check the GLX version
- int glxMajorVer, glxMinorVer;
- bool ok = glXQueryVersion(GDK_DISPLAY(), &glxMajorVer, &glxMinorVer);
- wxASSERT_MSG( ok, _T("GLX version not found") );
- if (!ok)
- s_glxVersion = 10; // 1.0 by default
- else
- s_glxVersion = glxMajorVer*10 + glxMinorVer;
- }
-
- return s_glxVersion;
-}
-
-void wxGLCanvas::SwapBuffers()