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