]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/glcanvas.cpp
Warning fix.
[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
VZ
74 if (wxGLCanvas::GetGLXVersion() >= 13)
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 }
81 else
82 {
83 // GLX <= 1.2
84 XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
2b5f62a0 85 wxCHECK_RET( vi, _T("invalid visual for OpenGl") );
8b089c5e 86 m_glContext = glXCreateContext( GDK_DISPLAY(), vi, None, GL_TRUE );
34a34b02 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
VZ
103 if (wxGLCanvas::GetGLXVersion() >= 13)
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 }
112 else
113 {
114 // GLX <= 1.2
115 XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
2b5f62a0 116 wxCHECK_RET( vi, _T("invalid visual for OpenGl") );
2b5f62a0
VZ
117 m_glContext = glXCreateContext( GDK_DISPLAY(), vi,
118 other ? other->m_glContext : None,
119 GL_TRUE );
34a34b02 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 {
34a34b02
VZ
134 if (wxGLCanvas::GetGLXVersion() >= 13)
135 // GLX >= 1.3
136 glXMakeContextCurrent( GDK_DISPLAY(), None, None, NULL);
137 else
138 // GLX <= 1.2
8b089c5e
JS
139 glXMakeCurrent( GDK_DISPLAY(), None, NULL);
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;
34a34b02
VZ
159
160 if (wxGLCanvas::GetGLXVersion() >= 13)
161 // GLX >= 1.3
162 glXMakeContextCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window), GDK_WINDOW_XWINDOW(window), m_glContext );
163 else
164 // GLX <= 1.2
8b089c5e
JS
165 glXMakeCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window), m_glContext );
166 }
167}
168
2b5f62a0 169void wxGLContext::SetColour(const wxChar *colour)
8b089c5e 170{
564a150b
VZ
171 wxColour col = wxTheColourDatabase->Find(colour);
172 if (col.Ok())
8b089c5e 173 {
564a150b
VZ
174 float r = (float)(col.Red()/256.0);
175 float g = (float)(col.Green()/256.0);
176 float b = (float)(col.Blue()/256.0);
8b089c5e
JS
177 glColor3f( r, g, b);
178 }
179}
180
181void wxGLContext::SetupPixelFormat()
182{
183}
184
185void wxGLContext::SetupPalette( const wxPalette& WXUNUSED(palette) )
186{
187}
188
189wxPalette wxGLContext::CreateDefaultPalette()
190{
191 return wxNullPalette;
192}
193
194//-----------------------------------------------------------------------------
195// "realize" from m_wxwindow
196//-----------------------------------------------------------------------------
197
865bb325 198extern "C" {
8b089c5e 199static gint
34a34b02 200gtk_glwindow_realized_callback( GtkWidget *WXUNUSED(widget), wxGLCanvas *win )
8b089c5e 201{
4230303c
VZ
202 if ( !win->m_glContext )
203 {
204 wxGLContext *share = win->m_sharedContext;
205 if ( !share && win->m_sharedContextOf )
206 share = win->m_sharedContextOf->GetContext();
8b089c5e 207
4230303c
VZ
208 win->m_glContext = new wxGLContext( TRUE, win, wxNullPalette, share );
209 }
8b089c5e
JS
210
211 return FALSE;
212}
865bb325 213}
8b089c5e
JS
214
215//-----------------------------------------------------------------------------
216// "map" from m_wxwindow
217//-----------------------------------------------------------------------------
218
865bb325 219extern "C" {
8b089c5e
JS
220static gint
221gtk_glwindow_map_callback( GtkWidget * WXUNUSED(widget), wxGLCanvas *win )
222{
223 if (win->m_glContext/* && win->m_exposed*/)
224 {
225 wxPaintEvent event( win->GetId() );
226 event.SetEventObject( win );
227 win->GetEventHandler()->ProcessEvent( event );
228
229 win->m_exposed = FALSE;
230 win->GetUpdateRegion().Clear();
231 }
232
233 return FALSE;
234}
865bb325 235}
8b089c5e
JS
236
237//-----------------------------------------------------------------------------
238// "expose_event" of m_wxwindow
239//-----------------------------------------------------------------------------
240
865bb325 241extern "C" {
2b5f62a0 242static void
8b089c5e
JS
243gtk_glwindow_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_event, wxGLCanvas *win )
244{
2b5f62a0 245 if (g_isIdle)
8b089c5e
JS
246 wxapp_install_idle_handler();
247
248 win->m_exposed = TRUE;
249
250 win->GetUpdateRegion().Union( gdk_event->area.x,
251 gdk_event->area.y,
252 gdk_event->area.width,
253 gdk_event->area.height );
254}
865bb325 255}
8b089c5e
JS
256
257//-----------------------------------------------------------------------------
258// "draw" of m_wxwindow
259//-----------------------------------------------------------------------------
260
2b5b9325 261#ifndef __WXGTK20__
865bb325 262extern "C" {
2b5f62a0 263static void
8b089c5e
JS
264gtk_glwindow_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxGLCanvas *win )
265{
2b5f62a0 266 if (g_isIdle)
8b089c5e
JS
267 wxapp_install_idle_handler();
268
269 win->m_exposed = TRUE;
270
271 win->GetUpdateRegion().Union( rect->x, rect->y,
272 rect->width, rect->height );
273}
865bb325 274}
2b5b9325 275#endif
8b089c5e
JS
276
277//-----------------------------------------------------------------------------
278// "size_allocate" of m_wxwindow
279//-----------------------------------------------------------------------------
280
865bb325 281extern "C" {
2b5f62a0 282static void
8b089c5e
JS
283gtk_glcanvas_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxGLCanvas *win )
284{
285 if (g_isIdle)
286 wxapp_install_idle_handler();
287
288 if (!win->m_hasVMT)
289 return;
290
291 wxSizeEvent event( wxSize(win->m_width,win->m_height), win->GetId() );
292 event.SetEventObject( win );
293 win->GetEventHandler()->ProcessEvent( event );
294}
865bb325 295}
8b089c5e
JS
296
297//---------------------------------------------------------------------------
298// wxGlCanvas
299//---------------------------------------------------------------------------
300
4660d7e5 301IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
8b089c5e 302
4660d7e5 303BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow)
8b089c5e
JS
304 EVT_SIZE(wxGLCanvas::OnSize)
305END_EVENT_TABLE()
306
307wxGLCanvas::wxGLCanvas( wxWindow *parent, wxWindowID id,
2b5f62a0
VZ
308 const wxPoint& pos, const wxSize& size,
309 long style, const wxString& name,
310 int *attribList,
311 const wxPalette& palette )
8b089c5e
JS
312{
313 Create( parent, NULL, NULL, id, pos, size, style, name, attribList, palette );
314}
315
2b5f62a0 316wxGLCanvas::wxGLCanvas( wxWindow *parent,
8b089c5e
JS
317 const wxGLContext *shared,
318 wxWindowID id,
2b5f62a0
VZ
319 const wxPoint& pos, const wxSize& size,
320 long style, const wxString& name,
321 int *attribList,
322 const wxPalette& palette )
323{
8b089c5e
JS
324 Create( parent, shared, NULL, id, pos, size, style, name, attribList, palette );
325}
326
2b5f62a0 327wxGLCanvas::wxGLCanvas( wxWindow *parent,
8b089c5e
JS
328 const wxGLCanvas *shared,
329 wxWindowID id,
2b5f62a0
VZ
330 const wxPoint& pos, const wxSize& size,
331 long style, const wxString& name,
332 int *attribList,
333 const wxPalette& palette )
334{
8b089c5e
JS
335 Create( parent, NULL, shared, id, pos, size, style, name, attribList, palette );
336}
337
2b5f62a0 338bool wxGLCanvas::Create( wxWindow *parent,
8b089c5e
JS
339 const wxGLContext *shared,
340 const wxGLCanvas *shared_context_of,
341 wxWindowID id,
2b5f62a0
VZ
342 const wxPoint& pos, const wxSize& size,
343 long style, const wxString& name,
344 int *attribList,
345 const wxPalette& palette)
8b089c5e
JS
346{
347 m_sharedContext = (wxGLContext*)shared; // const_cast
348 m_sharedContextOf = (wxGLCanvas*)shared_context_of; // const_cast
349 m_glContext = (wxGLContext*) NULL;
2b5f62a0 350
8b089c5e
JS
351 m_exposed = FALSE;
352 m_noExpose = TRUE;
353 m_nativeSizeEvent = TRUE;
34a34b02
VZ
354 m_fbc = NULL;
355 m_vi = NULL;
356
357 // to be sure the glx version is known
358 wxGLCanvas::QueryGLXVersion();
359
360 if (wxGLCanvas::GetGLXVersion() >= 13)
361 {
362 // GLX >= 1.3 uses a GLXFBConfig
363 GLXFBConfig * fbc = NULL;
364 if (wxTheApp->m_glFBCInfo != NULL)
365 {
366 fbc = (GLXFBConfig *) wxTheApp->m_glFBCInfo;
367 m_canFreeFBC = FALSE; // owned by wxTheApp - don't free upon destruction
368 }
369 else
370 {
371 fbc = (GLXFBConfig *) wxGLCanvas::ChooseGLFBC(attribList);
372 m_canFreeFBC = TRUE;
373 }
374 m_fbc = fbc; // save for later use
375 wxCHECK_MSG( m_fbc, FALSE, _T("required FBConfig couldn't be found") );
376 }
2b5f62a0 377
a6f5aa49 378 XVisualInfo *vi = NULL;
2b5f62a0
VZ
379 if (wxTheApp->m_glVisualInfo != NULL)
380 {
34a34b02 381 vi = (XVisualInfo *)wxTheApp->m_glVisualInfo;
a6f5aa49 382 m_canFreeVi = FALSE; // owned by wxTheApp - don't free upon destruction
2b5f62a0
VZ
383 }
384 else
385 {
34a34b02
VZ
386 if (wxGLCanvas::GetGLXVersion() >= 13)
387 // GLX >= 1.3
388 vi = glXGetVisualFromFBConfig(GDK_DISPLAY(), m_fbc[0]);
389 else
390 // GLX <= 1.2
a6f5aa49
VZ
391 vi = (XVisualInfo *) ChooseGLVisual(attribList);
392 m_canFreeVi = TRUE;
393 }
394 m_vi = vi; // save for later use
2b5f62a0
VZ
395
396 wxCHECK_MSG( m_vi, FALSE, _T("required visual couldn't be found") );
a6f5aa49 397 GdkVisual *visual = gdkx_visual_get( vi->visualid );
645a8fab 398 GdkColormap *colormap = gdk_colormap_new( visual, TRUE );
2b5f62a0 399
a6f5aa49
VZ
400 gtk_widget_push_colormap( colormap );
401 gtk_widget_push_visual( visual );
402
4660d7e5 403 wxWindow::Create( parent, id, pos, size, style, name );
a6f5aa49
VZ
404
405 m_glWidget = m_wxwindow;
2b5f62a0 406
2b5b9325
RR
407#ifdef __WXGTK20__
408 gtk_widget_set_double_buffered( m_glWidget, FALSE );
409#endif
410
a6f5aa49 411 gtk_pizza_set_clear( GTK_PIZZA(m_wxwindow), FALSE );
2b5f62a0 412
a6f5aa49
VZ
413 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "realize",
414 GTK_SIGNAL_FUNC(gtk_glwindow_realized_callback), (gpointer) this );
415
416 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "map",
417 GTK_SIGNAL_FUNC(gtk_glwindow_map_callback), (gpointer) this );
418
419 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event",
420 GTK_SIGNAL_FUNC(gtk_glwindow_expose_callback), (gpointer)this );
421
2b5b9325 422#ifndef __WXGTK20__
a6f5aa49
VZ
423 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "draw",
424 GTK_SIGNAL_FUNC(gtk_glwindow_draw_callback), (gpointer)this );
2b5b9325 425#endif
2b5f62a0 426
a6f5aa49
VZ
427 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
428 GTK_SIGNAL_FUNC(gtk_glcanvas_size_callback), (gpointer)this );
429
430 gtk_widget_pop_visual();
431 gtk_widget_pop_colormap();
2b5f62a0 432
bc869971
VZ
433 // if our parent window is already visible, we had been realized before we
434 // connected to the "realize" signal and hence our m_glContext hasn't been
435 // initialized yet and we have to do it now
436 if (GTK_WIDGET_REALIZED(m_wxwindow))
437 gtk_glwindow_realized_callback( m_wxwindow, this );
438
439 if (GTK_WIDGET_MAPPED(m_wxwindow))
440 gtk_glwindow_map_callback( m_wxwindow, this );
441
a6f5aa49
VZ
442 return TRUE;
443}
444
445wxGLCanvas::~wxGLCanvas()
446{
34a34b02
VZ
447 GLXFBConfig * fbc = (GLXFBConfig *) m_fbc;
448 if (fbc && m_canFreeFBC) XFree( fbc );
2b5f62a0 449
34a34b02 450 XVisualInfo *vi = (XVisualInfo *) m_vi;
a6f5aa49 451 if (vi && m_canFreeVi) XFree( vi );
34a34b02 452
4230303c 453 delete m_glContext;
a6f5aa49
VZ
454}
455
456void* wxGLCanvas::ChooseGLVisual(int *attribList)
457{
458 int data[512];
34a34b02
VZ
459 GetGLAttribListFromWX( attribList, data );
460 attribList = (int*) data;
461
462 Display *dpy = GDK_DISPLAY();
463
464 return glXChooseVisual( dpy, DefaultScreen(dpy), attribList );
465}
0f8d11dc 466
34a34b02
VZ
467void* wxGLCanvas::ChooseGLFBC(int *attribList)
468{
469 int data[512];
470 GetGLAttribListFromWX( attribList, data );
2b5f62a0 471 attribList = (int*) data;
34a34b02
VZ
472
473 int returned;
474 return glXChooseFBConfig( GDK_DISPLAY(), DefaultScreen(GDK_DISPLAY()),
475 attribList, &returned );
476}
477
478
479void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
480{
481 if (!wx_attribList)
482 {
483 if (wxGLCanvas::GetGLXVersion() >= 13)
484 // leave GLX >= 1.3 choose the default attributes
485 gl_attribList[0] = 0;
486 else
487 {
488 int i = 0;
489 // default settings if attriblist = 0
490 gl_attribList[i++] = GLX_RGBA;
491 gl_attribList[i++] = GLX_DOUBLEBUFFER;
492 gl_attribList[i++] = GLX_DEPTH_SIZE; gl_attribList[i++] = 1;
493 gl_attribList[i++] = GLX_RED_SIZE; gl_attribList[i++] = 1;
494 gl_attribList[i++] = GLX_GREEN_SIZE; gl_attribList[i++] = 1;
495 gl_attribList[i++] = GLX_BLUE_SIZE; gl_attribList[i++] = 1;
496 gl_attribList[i++] = GLX_ALPHA_SIZE; gl_attribList[i++] = 0;
497 gl_attribList[i++] = None;
498 }
8b089c5e
JS
499 }
500 else
501 {
83918ccc 502 int arg=0, p=0;
34a34b02 503 while( (wx_attribList[arg]!=0) && (p<510) )
8b089c5e 504 {
34a34b02 505 switch( wx_attribList[arg++] )
8b089c5e 506 {
34a34b02
VZ
507 case WX_GL_RGBA:
508 if (wxGLCanvas::GetGLXVersion() <= 12)
509 // for GLX >= 1.3, GLX_RGBA is useless (setting this flags will crash on most opengl implm)
510 gl_attribList[p++] = GLX_RGBA;
511 break;
0f8d11dc 512 case WX_GL_BUFFER_SIZE:
34a34b02 513 gl_attribList[p++]=GLX_BUFFER_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break;
0f8d11dc 514 case WX_GL_LEVEL:
34a34b02
VZ
515 gl_attribList[p++]=GLX_LEVEL; gl_attribList[p++]=wx_attribList[arg++]; break;
516 case WX_GL_DOUBLEBUFFER:
517 if (wxGLCanvas::GetGLXVersion() <= 12)
518 gl_attribList[p++] = GLX_DOUBLEBUFFER;
519 else
520 // for GLX >= 1.3, GLX_DOUBLEBUFFER format is different (1 <=> True)
521 // it seems this flag is useless for some hardware opengl implementation.
522 // but for Mesa 6.2.1, this flag is used so don't ignore it.
523 gl_attribList[p++] = GLX_DOUBLEBUFFER; gl_attribList[p++]=1;
524 break;
525 case WX_GL_STEREO: gl_attribList[p++] = GLX_STEREO; break;
0f8d11dc 526 case WX_GL_AUX_BUFFERS:
34a34b02 527 gl_attribList[p++]=GLX_AUX_BUFFERS; gl_attribList[p++]=wx_attribList[arg++]; break;
8b089c5e 528 case WX_GL_MIN_RED:
34a34b02 529 gl_attribList[p++]=GLX_RED_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break;
8b089c5e 530 case WX_GL_MIN_GREEN:
34a34b02 531 gl_attribList[p++]=GLX_GREEN_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break;
8b089c5e 532 case WX_GL_MIN_BLUE:
34a34b02 533 gl_attribList[p++]=GLX_BLUE_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break;
0f8d11dc 534 case WX_GL_MIN_ALPHA:
34a34b02 535 gl_attribList[p++]=GLX_ALPHA_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break;
2b5f62a0 536 case WX_GL_DEPTH_SIZE:
34a34b02 537 gl_attribList[p++]=GLX_DEPTH_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break;
2b5f62a0 538 case WX_GL_STENCIL_SIZE:
34a34b02 539 gl_attribList[p++]=GLX_STENCIL_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break;
0f8d11dc 540 case WX_GL_MIN_ACCUM_RED:
34a34b02 541 gl_attribList[p++]=GLX_ACCUM_RED_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break;
0f8d11dc 542 case WX_GL_MIN_ACCUM_GREEN:
34a34b02 543 gl_attribList[p++]=GLX_ACCUM_GREEN_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break;
0f8d11dc 544 case WX_GL_MIN_ACCUM_BLUE:
34a34b02 545 gl_attribList[p++]=GLX_ACCUM_BLUE_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break;
0f8d11dc 546 case WX_GL_MIN_ACCUM_ALPHA:
34a34b02 547 gl_attribList[p++]=GLX_ACCUM_ALPHA_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break;
8b089c5e
JS
548 default:
549 break;
550 }
2b5f62a0 551 }
34a34b02 552 gl_attribList[p] = 0;
8b089c5e 553 }
34a34b02 554}
2b5f62a0 555
34a34b02
VZ
556void wxGLCanvas::QueryGLXVersion()
557{
558 if (m_glxVersion == 0)
559 {
560 // check the GLX version
561 int glxMajorVer, glxMinorVer;
562 bool ok = glXQueryVersion(GDK_DISPLAY(), &glxMajorVer, &glxMinorVer);
563 wxASSERT_MSG( ok, _T("GLX version not found") );
564 if (!ok)
565 m_glxVersion = 10; // 1.0 by default
566 else
567 m_glxVersion = glxMajorVer*10 + glxMinorVer;
568 }
569}
2b5f62a0 570
34a34b02
VZ
571int wxGLCanvas::GetGLXVersion()
572{
573 wxASSERT_MSG( m_glxVersion>0, _T("GLX version has not been initialized with wxGLCanvas::QueryGLXVersion()") );
574 return m_glxVersion;
8b089c5e
JS
575}
576
34a34b02 577
8b089c5e
JS
578void wxGLCanvas::SwapBuffers()
579{
2b5f62a0
VZ
580 if (m_glContext)
581 m_glContext->SwapBuffers();
8b089c5e
JS
582}
583
584void wxGLCanvas::OnSize(wxSizeEvent& WXUNUSED(event))
585{
8b089c5e
JS
586}
587
588void wxGLCanvas::SetCurrent()
589{
2b5f62a0
VZ
590 if (m_glContext)
591 m_glContext->SetCurrent();
8b089c5e
JS
592}
593
2b5f62a0 594void wxGLCanvas::SetColour( const wxChar *colour )
8b089c5e 595{
2b5f62a0
VZ
596 if (m_glContext)
597 m_glContext->SetColour( colour );
8b089c5e
JS
598}
599
600void wxGLCanvas::OnInternalIdle()
601{
602 if (m_glContext && m_exposed)
603 {
604 wxPaintEvent event( GetId() );
605 event.SetEventObject( this );
606 GetEventHandler()->ProcessEvent( event );
607
608 m_exposed = FALSE;
609 GetUpdateRegion().Clear();
610 }
2b5f62a0 611
8b089c5e
JS
612 wxWindow::OnInternalIdle();
613}
614
a6f5aa49
VZ
615
616
617//---------------------------------------------------------------------------
618// wxGLApp
619//---------------------------------------------------------------------------
620
621IMPLEMENT_CLASS(wxGLApp, wxApp)
2b5f62a0 622
a6f5aa49
VZ
623wxGLApp::~wxGLApp()
624{
34a34b02
VZ
625 if (m_glFBCInfo)
626 XFree(m_glFBCInfo);
2b5f62a0
VZ
627 if (m_glVisualInfo)
628 XFree(m_glVisualInfo);
a6f5aa49
VZ
629}
630
631bool wxGLApp::InitGLVisual(int *attribList)
632{
34a34b02
VZ
633 wxGLCanvas::QueryGLXVersion();
634
635 if (wxGLCanvas::GetGLXVersion() >= 13)
636 {
637 // GLX >= 1.3
638 if (m_glFBCInfo)
639 XFree(m_glFBCInfo);
640 m_glFBCInfo = wxGLCanvas::ChooseGLFBC(attribList);
641
642 if (m_glFBCInfo)
643 {
2b5f62a0
VZ
644 if (m_glVisualInfo)
645 XFree(m_glVisualInfo);
34a34b02
VZ
646 m_glVisualInfo = glXGetVisualFromFBConfig(GDK_DISPLAY(), ((GLXFBConfig *)m_glFBCInfo)[0]);
647 }
648 return (m_glFBCInfo != NULL) && (m_glVisualInfo != NULL);
649 }
650 else
651 {
652 // GLX <= 1.2
653 if (m_glVisualInfo)
654 XFree(m_glVisualInfo);
a6f5aa49 655 m_glVisualInfo = wxGLCanvas::ChooseGLVisual(attribList);
2b5f62a0 656 return m_glVisualInfo != NULL;
34a34b02 657 }
a6f5aa49
VZ
658}
659
8b089c5e
JS
660#endif
661 // wxUSE_GLCANVAS
662