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