- XVisualInfo *vi, vi_templ;
- XWindowAttributes xwa;
- int val, n;
-
- m_sharedContext = (wxGLContext*)shared; // const_cast
- m_sharedContextOf = (wxGLCanvas*)shared_context_of; // const_cast
- m_glContext = (wxGLContext*) NULL;
-
- Display* display = (Display*) wxGetDisplay();
-
- // Check for the presence of the GLX extension
- if(!glXQueryExtension(display, NULL, NULL)) {
- wxLogDebug(wxT("wxGLCanvas: GLX extension is missing\n"));
- return FALSE;
- }
-
- if(attribList) {
- int data[512], arg=0, p=0;
-
- while( (attribList[arg]!=0) && (p<512) )
- {
- switch( attribList[arg++] )
- {
- case WX_GL_RGBA: data[p++] = GLX_RGBA; break;
- case WX_GL_BUFFER_SIZE:
- data[p++]=GLX_BUFFER_SIZE; data[p++]=attribList[arg++]; break;
- case WX_GL_LEVEL:
- data[p++]=GLX_LEVEL; data[p++]=attribList[arg++]; break;
- case WX_GL_DOUBLEBUFFER: data[p++] = GLX_DOUBLEBUFFER; break;
- case WX_GL_STEREO: data[p++] = GLX_STEREO; break;
- case WX_GL_AUX_BUFFERS:
- data[p++]=GLX_AUX_BUFFERS; data[p++]=attribList[arg++]; break;
- case WX_GL_MIN_RED:
- data[p++]=GLX_RED_SIZE; data[p++]=attribList[arg++]; break;
- case WX_GL_MIN_GREEN:
- data[p++]=GLX_GREEN_SIZE; data[p++]=attribList[arg++]; break;
- case WX_GL_MIN_BLUE:
- data[p++]=GLX_BLUE_SIZE; data[p++]=attribList[arg++]; break;
- case WX_GL_MIN_ALPHA:
- data[p++]=GLX_ALPHA_SIZE; data[p++]=attribList[arg++]; break;
- case WX_GL_DEPTH_SIZE:
- data[p++]=GLX_DEPTH_SIZE; data[p++]=attribList[arg++]; break;
- case WX_GL_STENCIL_SIZE:
- data[p++]=GLX_STENCIL_SIZE; data[p++]=attribList[arg++]; break;
- case WX_GL_MIN_ACCUM_RED:
- data[p++]=GLX_ACCUM_RED_SIZE; data[p++]=attribList[arg++]; break;
- case WX_GL_MIN_ACCUM_GREEN:
- data[p++]=GLX_ACCUM_GREEN_SIZE; data[p++]=attribList[arg++]; break;
- case WX_GL_MIN_ACCUM_BLUE:
- data[p++]=GLX_ACCUM_BLUE_SIZE; data[p++]=attribList[arg++]; break;
- case WX_GL_MIN_ACCUM_ALPHA:
- data[p++]=GLX_ACCUM_ALPHA_SIZE; data[p++]=attribList[arg++]; break;
- default:
- break;
- }
- }
- data[p] = 0;
-
- attribList = (int*) data;
- // Get an appropriate visual
- vi = glXChooseVisual(display, DefaultScreen(display), attribList);
- if(!vi) return FALSE;
-
- // Here we should make sure that vi is the same visual as the
- // one used by the xwindow drawable in wxCanvas. However,
- // there is currently no mechanism for this in wx_canvs.cc.
- } else {
- // By default, we use the visual of xwindow
- // NI: is this really senseful ? opengl in e.g. color index mode ?
- XGetWindowAttributes(display, (Window)wxGetClientAreaWindow(this), &xwa);
- vi_templ.visualid = XVisualIDFromVisual(xwa.visual);
- vi = XGetVisualInfo(display, VisualIDMask, &vi_templ, &n);
- if(!vi) return FALSE;
- glXGetConfig(display, vi, GLX_USE_GL, &val);
- if(!val) return FALSE;
- // Basically, this is it. It should be possible to use vi
- // in glXCreateContext() below. But this fails with Mesa.
- // I notified the Mesa author about it; there may be a fix.
-#ifdef OLD_MESA
- // Construct an attribute list matching the visual
- int a_list[32];
- n = 0;
- if(vi->c_class==TrueColor || vi->c_class==DirectColor) { // RGBA visual
- a_list[n++] = GLX_RGBA;
- a_list[n++] = GLX_RED_SIZE;
- a_list[n++] = bitcount(vi->red_mask);
- a_list[n++] = GLX_GREEN_SIZE;
- a_list[n++] = bitcount(vi->green_mask);
- a_list[n++] = GLX_BLUE_SIZE;
- a_list[n++] = bitcount(vi->blue_mask);
- glXGetConfig(display, vi, GLX_ALPHA_SIZE, &val);
- a_list[n++] = GLX_ALPHA_SIZE;
- a_list[n++] = val;
- } else { // Color index visual
- glXGetConfig(display, vi, GLX_BUFFER_SIZE, &val);
- a_list[n++] = GLX_BUFFER_SIZE;
- a_list[n++] = val;
- }
- a_list[n] = None;
- // XFree(vi);
- vi = glXChooseVisual(display, DefaultScreen(display), a_list);
- if(!vi) return FALSE;
-#endif /* OLD_MESA */
- }
-
- m_vi = vi; // safe for later use
-
- wxCHECK_MSG( m_vi, FALSE, wxT("required visual couldn't be found") );
-
- // Create the GLX context and make it current
-
- wxGLContext *share= m_sharedContext;
- if (share==NULL && m_sharedContextOf)
- share = m_sharedContextOf->GetContext();