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