Include wx/frame.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / gtk1 / glcanvas.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/glcanvas.cpp
3 // Purpose: wxGLCanvas, for using OpenGL/Mesa with wxWidgets and GTK
4 // Author: Robert Roebling
5 // Modified by:
6 // Created: 17/08/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #if wxUSE_GLCANVAS
16
17 #include "wx/glcanvas.h"
18
19 #ifndef WX_PRECOMP
20 #include "wx/app.h"
21 #include "wx/frame.h"
22 #endif // WX_PRECOMP
23
24 #include "wx/colour.h"
25 #include "wx/module.h"
26
27 extern "C"
28 {
29 #include "gtk/gtk.h"
30 #include "gdk/gdk.h"
31 #include "gdk/gdkx.h"
32 }
33
34 #include "wx/gtk1/win_gtk.h"
35
36 // DLL options compatibility check:
37 #include "wx/build.h"
38 WX_CHECK_BUILD_OPTIONS("wxGL")
39
40
41 //---------------------------------------------------------------------------
42 // static variables
43 //---------------------------------------------------------------------------
44 int wxGLCanvas::m_glxVersion = 0;
45
46 //---------------------------------------------------------------------------
47 // global data
48 //---------------------------------------------------------------------------
49
50 XVisualInfo *g_vi = (XVisualInfo*) NULL;
51 //-----------------------------------------------------------------------------
52 // idle system
53 //-----------------------------------------------------------------------------
54
55 extern void wxapp_install_idle_handler();
56 extern bool g_isIdle;
57
58 //---------------------------------------------------------------------------
59 // wxGLContext
60 //---------------------------------------------------------------------------
61
62 IMPLEMENT_CLASS(wxGLContext,wxObject)
63
64 wxGLContext::wxGLContext( bool WXUNUSED(isRGB), wxWindow *win, const wxPalette& WXUNUSED(palette) )
65 {
66 m_window = win;
67 m_widget = win->m_wxwindow;
68
69 wxGLCanvas *gc = (wxGLCanvas*) win;
70
71 if (wxGLCanvas::GetGLXVersion() >= 13)
72 {
73 // GLX >= 1.3
74 GLXFBConfig *fbc = gc->m_fbc;
75 wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") );
76 m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE, None, GL_TRUE );
77 }
78 else
79 {
80 // GLX <= 1.2
81 XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
82 wxCHECK_RET( vi, _T("invalid visual for OpenGl") );
83 m_glContext = glXCreateContext( GDK_DISPLAY(), vi, None, GL_TRUE );
84 }
85
86 wxCHECK_RET( m_glContext, _T("Couldn't create OpenGl context") );
87 }
88
89 wxGLContext::wxGLContext(
90 bool WXUNUSED(isRGB), wxWindow *win,
91 const wxPalette& WXUNUSED(palette),
92 const wxGLContext *other /* for sharing display lists */
93 )
94 {
95 m_window = win;
96 m_widget = win->m_wxwindow;
97
98 wxGLCanvas *gc = (wxGLCanvas*) win;
99
100 if (wxGLCanvas::GetGLXVersion() >= 13)
101 {
102 // GLX >= 1.3
103 GLXFBConfig *fbc = gc->m_fbc;
104 wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") );
105 m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE,
106 other ? other->m_glContext : None,
107 GL_TRUE );
108 }
109 else
110 {
111 // GLX <= 1.2
112 XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
113 wxCHECK_RET( vi, _T("invalid visual for OpenGl") );
114 m_glContext = glXCreateContext( GDK_DISPLAY(), vi,
115 other ? other->m_glContext : None,
116 GL_TRUE );
117 }
118
119 if ( !m_glContext )
120 {
121 wxFAIL_MSG( _T("Couldn't create OpenGl context") );
122 }
123 }
124
125 wxGLContext::~wxGLContext()
126 {
127 if (!m_glContext) return;
128
129 if (m_glContext == glXGetCurrentContext())
130 {
131 if (wxGLCanvas::GetGLXVersion() >= 13)
132 // GLX >= 1.3
133 glXMakeContextCurrent( GDK_DISPLAY(), None, None, NULL);
134 else
135 // GLX <= 1.2
136 glXMakeCurrent( GDK_DISPLAY(), None, NULL);
137 }
138
139 glXDestroyContext( GDK_DISPLAY(), m_glContext );
140 }
141
142 void wxGLContext::SwapBuffers()
143 {
144 if (m_glContext)
145 {
146 GdkWindow *window = GTK_PIZZA(m_widget)->bin_window;
147 glXSwapBuffers( GDK_DISPLAY(), GDK_WINDOW_XWINDOW( window ) );
148 }
149 }
150
151 void wxGLContext::SetCurrent()
152 {
153 if (m_glContext)
154 {
155 GdkWindow *window = GTK_PIZZA(m_widget)->bin_window;
156
157 if (wxGLCanvas::GetGLXVersion() >= 13)
158 // GLX >= 1.3
159 glXMakeContextCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window),
160 GDK_WINDOW_XWINDOW(window), m_glContext );
161 else
162 // GLX <= 1.2
163 glXMakeCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window), m_glContext );
164 }
165 }
166
167 void wxGLContext::SetColour(const wxChar *colour)
168 {
169 wxColour col = wxTheColourDatabase->Find(colour);
170 if (col.Ok())
171 {
172 float r = (float)(col.Red()/256.0);
173 float g = (float)(col.Green()/256.0);
174 float b = (float)(col.Blue()/256.0);
175 glColor3f( r, g, b);
176 }
177 }
178
179 void wxGLContext::SetupPixelFormat()
180 {
181 }
182
183 void wxGLContext::SetupPalette( const wxPalette& WXUNUSED(palette) )
184 {
185 }
186
187 wxPalette wxGLContext::CreateDefaultPalette()
188 {
189 return wxNullPalette;
190 }
191
192 //-----------------------------------------------------------------------------
193 // "realize" from m_wxwindow
194 //-----------------------------------------------------------------------------
195
196 extern "C" {
197 static gint
198 gtk_glwindow_realized_callback( GtkWidget *WXUNUSED(widget), wxGLCanvas *win )
199 {
200 if ( !win->m_glContext )
201 {
202 wxGLContext *share = win->m_sharedContext;
203 if ( !share && win->m_sharedContextOf )
204 share = win->m_sharedContextOf->GetContext();
205
206 win->m_glContext = new wxGLContext( TRUE, win, wxNullPalette, share );
207 }
208
209 return FALSE;
210 }
211 }
212
213 //-----------------------------------------------------------------------------
214 // "map" from m_wxwindow
215 //-----------------------------------------------------------------------------
216
217 extern "C" {
218 static gint
219 gtk_glwindow_map_callback( GtkWidget * WXUNUSED(widget), wxGLCanvas *win )
220 {
221 if (win->m_glContext/* && win->m_exposed*/)
222 {
223 wxPaintEvent event( win->GetId() );
224 event.SetEventObject( win );
225 win->GetEventHandler()->ProcessEvent( event );
226
227 win->m_exposed = false;
228 win->GetUpdateRegion().Clear();
229 }
230
231 return FALSE;
232 }
233 }
234
235 //-----------------------------------------------------------------------------
236 // "expose_event" of m_wxwindow
237 //-----------------------------------------------------------------------------
238
239 extern "C" {
240 static void
241 gtk_glwindow_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_event, wxGLCanvas *win )
242 {
243 if (g_isIdle)
244 wxapp_install_idle_handler();
245
246 win->m_exposed = true;
247
248 win->GetUpdateRegion().Union( gdk_event->area.x,
249 gdk_event->area.y,
250 gdk_event->area.width,
251 gdk_event->area.height );
252 }
253 }
254
255 //-----------------------------------------------------------------------------
256 // "draw" of m_wxwindow
257 //-----------------------------------------------------------------------------
258
259 extern "C" {
260 static void
261 gtk_glwindow_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxGLCanvas *win )
262 {
263 if (g_isIdle)
264 wxapp_install_idle_handler();
265
266 win->m_exposed = true;
267
268 win->GetUpdateRegion().Union( rect->x, rect->y,
269 rect->width, rect->height );
270 }
271 }
272
273 //-----------------------------------------------------------------------------
274 // "size_allocate" of m_wxwindow
275 //-----------------------------------------------------------------------------
276
277 extern "C" {
278 static void
279 gtk_glcanvas_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxGLCanvas *win )
280 {
281 if (g_isIdle)
282 wxapp_install_idle_handler();
283
284 if (!win->m_hasVMT)
285 return;
286
287 wxSizeEvent event( wxSize(win->m_width,win->m_height), win->GetId() );
288 event.SetEventObject( win );
289 win->GetEventHandler()->ProcessEvent( event );
290 }
291 }
292
293 //---------------------------------------------------------------------------
294 // wxGlCanvas
295 //---------------------------------------------------------------------------
296
297 IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
298
299 BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow)
300 EVT_SIZE(wxGLCanvas::OnSize)
301 END_EVENT_TABLE()
302
303 wxGLCanvas::wxGLCanvas( wxWindow *parent, wxWindowID id,
304 const wxPoint& pos, const wxSize& size,
305 long style, const wxString& name,
306 int *attribList,
307 const wxPalette& palette )
308 {
309 Create( parent, NULL, NULL, id, pos, size, style, name, attribList, palette );
310 }
311
312 wxGLCanvas::wxGLCanvas( wxWindow *parent,
313 const wxGLContext *shared,
314 wxWindowID id,
315 const wxPoint& pos, const wxSize& size,
316 long style, const wxString& name,
317 int *attribList,
318 const wxPalette& palette )
319 {
320 Create( parent, shared, NULL, id, pos, size, style, name, attribList, palette );
321 }
322
323 wxGLCanvas::wxGLCanvas( wxWindow *parent,
324 const wxGLCanvas *shared,
325 wxWindowID id,
326 const wxPoint& pos, const wxSize& size,
327 long style, const wxString& name,
328 int *attribList,
329 const wxPalette& palette )
330 {
331 Create( parent, NULL, shared, id, pos, size, style, name, attribList, palette );
332 }
333
334 bool wxGLCanvas::Create( wxWindow *parent,
335 const wxGLContext *shared,
336 const wxGLCanvas *shared_context_of,
337 wxWindowID id,
338 const wxPoint& pos, const wxSize& size,
339 long style, const wxString& name,
340 int *attribList,
341 const wxPalette& palette)
342 {
343 m_sharedContext = (wxGLContext*)shared; // const_cast
344 m_sharedContextOf = (wxGLCanvas*)shared_context_of; // const_cast
345 m_glContext = (wxGLContext*) NULL;
346
347 m_exposed = false;
348 m_noExpose = true;
349 m_nativeSizeEvent = true;
350 m_fbc = NULL;
351 m_vi = NULL;
352
353 // to be sure the glx version is known
354 wxGLCanvas::QueryGLXVersion();
355
356 if (wxGLCanvas::GetGLXVersion() >= 13)
357 {
358 // GLX >= 1.3 uses a GLXFBConfig
359 GLXFBConfig * fbc = NULL;
360 if (wxTheApp->m_glFBCInfo != NULL)
361 {
362 fbc = (GLXFBConfig *) wxTheApp->m_glFBCInfo;
363 m_canFreeFBC = false; // owned by wxTheApp - don't free upon destruction
364 }
365 else
366 {
367 fbc = (GLXFBConfig *) wxGLCanvas::ChooseGLFBC(attribList);
368 m_canFreeFBC = true;
369 }
370 m_fbc = fbc; // save for later use
371 wxCHECK_MSG( m_fbc, false, _T("required FBConfig couldn't be found") );
372 }
373
374 XVisualInfo *vi = NULL;
375 if (wxTheApp->m_glVisualInfo != NULL)
376 {
377 vi = (XVisualInfo *)wxTheApp->m_glVisualInfo;
378 m_canFreeVi = false; // owned by wxTheApp - don't free upon destruction
379 }
380 else
381 {
382 if (wxGLCanvas::GetGLXVersion() >= 13)
383 // GLX >= 1.3
384 vi = glXGetVisualFromFBConfig(GDK_DISPLAY(), m_fbc[0]);
385 else
386 // GLX <= 1.2
387 vi = (XVisualInfo *) ChooseGLVisual(attribList);
388
389 m_canFreeVi = true;
390 }
391
392 m_vi = vi; // save for later use
393
394 wxCHECK_MSG( m_vi, false, _T("required visual couldn't be found") );
395 GdkVisual *visual;
396 GdkColormap *colormap;
397
398 // MR: This needs a fix for lower gtk+ versions too. Might need to rethink logic (FIXME)
399 #if 0
400 if (!gtk_check_version(2,2,0))
401 {
402 wxWindow::Create( parent, id, pos, size, style, name );
403
404 m_glWidget = m_wxwindow;
405
406 GdkScreen *screen = gtk_widget_get_screen( m_glWidget );
407 colormap = gdk_screen_get_default_colormap(screen);
408 visual = gdk_colormap_get_visual(colormap);
409
410 if (GDK_VISUAL_XVISUAL(visual)->visualid != vi->visualid)
411 {
412 visual = gdk_x11_screen_lookup_visual( screen, vi->visualid );
413 colormap = gdk_colormap_new(visual, FALSE);
414 }
415
416 gtk_widget_set_colormap( m_glWidget, colormap );
417 }
418 else
419 #endif
420 {
421 visual = gdkx_visual_get( vi->visualid );
422 colormap = gdk_colormap_new( visual, TRUE );
423
424 gtk_widget_push_colormap( colormap );
425 gtk_widget_push_visual( visual );
426
427 wxWindow::Create( parent, id, pos, size, style, name );
428 m_glWidget = m_wxwindow;
429 }
430
431 gtk_pizza_set_clear( GTK_PIZZA(m_wxwindow), FALSE );
432
433 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "realize",
434 GTK_SIGNAL_FUNC(gtk_glwindow_realized_callback), (gpointer) this );
435
436 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "map",
437 GTK_SIGNAL_FUNC(gtk_glwindow_map_callback), (gpointer) this );
438
439 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event",
440 GTK_SIGNAL_FUNC(gtk_glwindow_expose_callback), (gpointer)this );
441
442 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "draw",
443 GTK_SIGNAL_FUNC(gtk_glwindow_draw_callback), (gpointer)this );
444
445 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
446 GTK_SIGNAL_FUNC(gtk_glcanvas_size_callback), (gpointer)this );
447
448 gtk_widget_pop_visual();
449 gtk_widget_pop_colormap();
450
451 // if our parent window is already visible, we had been realized before we
452 // connected to the "realize" signal and hence our m_glContext hasn't been
453 // initialized yet and we have to do it now
454 if (GTK_WIDGET_REALIZED(m_wxwindow))
455 gtk_glwindow_realized_callback( m_wxwindow, this );
456
457 if (GTK_WIDGET_MAPPED(m_wxwindow))
458 gtk_glwindow_map_callback( m_wxwindow, this );
459
460 return true;
461 }
462
463 wxGLCanvas::~wxGLCanvas()
464 {
465 GLXFBConfig * fbc = (GLXFBConfig *) m_fbc;
466 if (fbc && m_canFreeFBC)
467 XFree( fbc );
468
469 XVisualInfo *vi = (XVisualInfo *) m_vi;
470 if (vi && m_canFreeVi)
471 XFree( vi );
472
473 delete m_glContext;
474 }
475
476 void* wxGLCanvas::ChooseGLVisual(int *attribList)
477 {
478 int data[512];
479 GetGLAttribListFromWX( attribList, data );
480 attribList = (int*) data;
481
482 Display *dpy = GDK_DISPLAY();
483
484 return glXChooseVisual( dpy, DefaultScreen(dpy), attribList );
485 }
486
487 void* wxGLCanvas::ChooseGLFBC(int *attribList)
488 {
489 int data[512];
490 GetGLAttribListFromWX( attribList, data );
491 attribList = (int*) data;
492
493 int returned;
494 return glXChooseFBConfig( GDK_DISPLAY(), DefaultScreen(GDK_DISPLAY()),
495 attribList, &returned );
496 }
497
498
499 void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
500 {
501 if (!wx_attribList)
502 {
503 if (wxGLCanvas::GetGLXVersion() >= 13)
504 // leave GLX >= 1.3 choose the default attributes
505 gl_attribList[0] = 0;
506 else
507 {
508 int i = 0;
509 // default settings if attriblist = 0
510 gl_attribList[i++] = GLX_RGBA;
511 gl_attribList[i++] = GLX_DOUBLEBUFFER;
512 gl_attribList[i++] = GLX_DEPTH_SIZE; gl_attribList[i++] = 1;
513 gl_attribList[i++] = GLX_RED_SIZE; gl_attribList[i++] = 1;
514 gl_attribList[i++] = GLX_GREEN_SIZE; gl_attribList[i++] = 1;
515 gl_attribList[i++] = GLX_BLUE_SIZE; gl_attribList[i++] = 1;
516 gl_attribList[i++] = GLX_ALPHA_SIZE; gl_attribList[i++] = 0;
517 gl_attribList[i++] = None;
518 }
519 }
520 else
521 {
522 int arg=0, p=0;
523 while( (wx_attribList[arg]!=0) && (p<510) )
524 {
525 switch( wx_attribList[arg++] )
526 {
527 case WX_GL_RGBA:
528 if (wxGLCanvas::GetGLXVersion() <= 12)
529 // for GLX >= 1.3, GLX_RGBA is useless (setting this flags will crash on most opengl implm)
530 gl_attribList[p++] = GLX_RGBA;
531 break;
532 case WX_GL_BUFFER_SIZE:
533 gl_attribList[p++] = GLX_BUFFER_SIZE;
534 gl_attribList[p++] = wx_attribList[arg++];
535 break;
536 case WX_GL_LEVEL:
537 gl_attribList[p++] = GLX_LEVEL;
538 gl_attribList[p++] = wx_attribList[arg++];
539 break;
540 case WX_GL_DOUBLEBUFFER:
541 if (wxGLCanvas::GetGLXVersion() <= 12)
542 gl_attribList[p++] = GLX_DOUBLEBUFFER;
543 else
544 // for GLX >= 1.3, GLX_DOUBLEBUFFER format is different (1 <=> True)
545 // it seems this flag is useless for some hardware opengl implementation.
546 // but for Mesa 6.2.1, this flag is used so don't ignore it.
547 gl_attribList[p++] = GLX_DOUBLEBUFFER;
548 gl_attribList[p++] = 1;
549 break;
550 case WX_GL_STEREO:
551 gl_attribList[p++] = GLX_STEREO;
552 break;
553 case WX_GL_AUX_BUFFERS:
554 gl_attribList[p++] = GLX_AUX_BUFFERS;
555 gl_attribList[p++] = wx_attribList[arg++];
556 break;
557 case WX_GL_MIN_RED:
558 gl_attribList[p++] = GLX_RED_SIZE;
559 gl_attribList[p++] = wx_attribList[arg++];
560 break;
561 case WX_GL_MIN_GREEN:
562 gl_attribList[p++] = GLX_GREEN_SIZE;
563 gl_attribList[p++] = wx_attribList[arg++];
564 break;
565 case WX_GL_MIN_BLUE:
566 gl_attribList[p++] = GLX_BLUE_SIZE;
567 gl_attribList[p++] = wx_attribList[arg++];
568 break;
569 case WX_GL_MIN_ALPHA:
570 gl_attribList[p++] = GLX_ALPHA_SIZE;
571 gl_attribList[p++] = wx_attribList[arg++];
572 break;
573 case WX_GL_DEPTH_SIZE:
574 gl_attribList[p++] = GLX_DEPTH_SIZE;
575 gl_attribList[p++] = wx_attribList[arg++];
576 break;
577 case WX_GL_STENCIL_SIZE:
578 gl_attribList[p++] = GLX_STENCIL_SIZE;
579 gl_attribList[p++] = wx_attribList[arg++];
580 break;
581 case WX_GL_MIN_ACCUM_RED:
582 gl_attribList[p++] = GLX_ACCUM_RED_SIZE;
583 gl_attribList[p++] = wx_attribList[arg++];
584 break;
585 case WX_GL_MIN_ACCUM_GREEN:
586 gl_attribList[p++] = GLX_ACCUM_GREEN_SIZE;
587 gl_attribList[p++] = wx_attribList[arg++];
588 break;
589 case WX_GL_MIN_ACCUM_BLUE:
590 gl_attribList[p++] = GLX_ACCUM_BLUE_SIZE;
591 gl_attribList[p++] = wx_attribList[arg++];
592 break;
593 case WX_GL_MIN_ACCUM_ALPHA:
594 gl_attribList[p++] = GLX_ACCUM_ALPHA_SIZE;
595 gl_attribList[p++] = wx_attribList[arg++];
596 break;
597 default:
598 break;
599 }
600 }
601
602 gl_attribList[p] = 0;
603 }
604 }
605
606 void wxGLCanvas::QueryGLXVersion()
607 {
608 if (m_glxVersion == 0)
609 {
610 // check the GLX version
611 int glxMajorVer, glxMinorVer;
612 bool ok = glXQueryVersion(GDK_DISPLAY(), &glxMajorVer, &glxMinorVer);
613 wxASSERT_MSG( ok, _T("GLX version not found") );
614 if (!ok)
615 m_glxVersion = 10; // 1.0 by default
616 else
617 m_glxVersion = glxMajorVer*10 + glxMinorVer;
618 }
619 }
620
621 int wxGLCanvas::GetGLXVersion()
622 {
623 wxASSERT_MSG( m_glxVersion>0, _T("GLX version has not been initialized with wxGLCanvas::QueryGLXVersion()") );
624 return m_glxVersion;
625 }
626
627
628 void wxGLCanvas::SwapBuffers()
629 {
630 if (m_glContext)
631 m_glContext->SwapBuffers();
632 }
633
634 void wxGLCanvas::OnSize(wxSizeEvent& WXUNUSED(event))
635 {
636 }
637
638 void wxGLCanvas::SetCurrent()
639 {
640 if (m_glContext)
641 m_glContext->SetCurrent();
642 }
643
644 void wxGLCanvas::SetColour( const wxChar *colour )
645 {
646 if (m_glContext)
647 m_glContext->SetColour( colour );
648 }
649
650 void wxGLCanvas::OnInternalIdle()
651 {
652 if (m_glContext && m_exposed)
653 {
654 wxPaintEvent event( GetId() );
655 event.SetEventObject( this );
656 GetEventHandler()->ProcessEvent( event );
657
658 m_exposed = false;
659 GetUpdateRegion().Clear();
660 }
661
662 wxWindow::OnInternalIdle();
663 }
664
665
666
667 //---------------------------------------------------------------------------
668 // wxGLApp
669 //---------------------------------------------------------------------------
670
671 IMPLEMENT_CLASS(wxGLApp, wxApp)
672
673 wxGLApp::~wxGLApp()
674 {
675 if (m_glFBCInfo)
676 XFree(m_glFBCInfo);
677 if (m_glVisualInfo)
678 XFree(m_glVisualInfo);
679 }
680
681 bool wxGLApp::InitGLVisual(int *attribList)
682 {
683 wxGLCanvas::QueryGLXVersion();
684
685 if (wxGLCanvas::GetGLXVersion() >= 13)
686 {
687 // GLX >= 1.3
688 if (m_glFBCInfo)
689 XFree(m_glFBCInfo);
690 m_glFBCInfo = wxGLCanvas::ChooseGLFBC(attribList);
691
692 if (m_glFBCInfo)
693 {
694 if (m_glVisualInfo)
695 XFree(m_glVisualInfo);
696 m_glVisualInfo = glXGetVisualFromFBConfig(GDK_DISPLAY(), ((GLXFBConfig *)m_glFBCInfo)[0]);
697 }
698 return (m_glFBCInfo != NULL) && (m_glVisualInfo != NULL);
699 }
700 else
701 {
702 // GLX <= 1.2
703 if (m_glVisualInfo)
704 XFree(m_glVisualInfo);
705 m_glVisualInfo = wxGLCanvas::ChooseGLVisual(attribList);
706 return m_glVisualInfo != NULL;
707 }
708 }
709
710 #endif
711 // wxUSE_GLCANVAS