]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk/glcanvas.h
renamed GlobalPtr to GlobalPtrLock
[wxWidgets.git] / include / wx / gtk / glcanvas.h
CommitLineData
8b089c5e
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: glcanvas.h
77ffb593 3// Purpose: wxGLCanvas, for using OpenGL/Mesa with wxWidgets and GTK
8b089c5e
JS
4// Author: Robert Roebling
5// Modified by:
6// Created: 17/8/98
7// RCS-ID: $Id$
8// Copyright: (c) Robert Roebling
65571936 9// Licence: wxWindows licence
8b089c5e
JS
10/////////////////////////////////////////////////////////////////////////////
11
db4c39a9
VZ
12#ifndef _WX_GLCANVAS_H_
13#define _WX_GLCANVAS_H_
14
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
8b089c5e
JS
16#pragma interface "glcanvas.h"
17#endif
18
a6f5aa49
VZ
19#include "wx/scrolwin.h"
20#include "wx/app.h"
8b089c5e
JS
21
22extern "C" {
a6f5aa49
VZ
23#include <GL/gl.h>
24#include <GL/glx.h>
25#include <GL/glu.h>
8b089c5e
JS
26}
27
28//---------------------------------------------------------------------------
29// Constants for attriblist
30//---------------------------------------------------------------------------
31
32enum
33{
34 WX_GL_RGBA=1, /* use true color palette */
f48d169c
UN
35 WX_GL_BUFFER_SIZE, /* bits for buffer if not WX_GL_RGBA */
36 WX_GL_LEVEL, /* 0 for main buffer, >0 for overlay, <0 for underlay */
8b089c5e 37 WX_GL_DOUBLEBUFFER, /* use doublebuffer */
f48d169c
UN
38 WX_GL_STEREO, /* use stereoscopic display */
39 WX_GL_AUX_BUFFERS, /* number of auxiliary buffers */
8b089c5e
JS
40 WX_GL_MIN_RED, /* use red buffer with most bits (> MIN_RED bits) */
41 WX_GL_MIN_GREEN, /* use green buffer with most bits (> MIN_GREEN bits) */
f48d169c
UN
42 WX_GL_MIN_BLUE, /* use blue buffer with most bits (> MIN_BLUE bits) */
43 WX_GL_MIN_ALPHA, /* use blue buffer with most bits (> MIN_ALPHA bits) */
44 WX_GL_DEPTH_SIZE, /* bits for Z-buffer (0,16,32) */
45 WX_GL_STENCIL_SIZE, /* bits for stencil buffer */
46 WX_GL_MIN_ACCUM_RED, /* use red accum buffer with most bits (> MIN_ACCUM_RED bits) */
47 WX_GL_MIN_ACCUM_GREEN, /* use green buffer with most bits (> MIN_ACCUM_GREEN bits) */
48 WX_GL_MIN_ACCUM_BLUE, /* use blue buffer with most bits (> MIN_ACCUM_BLUE bits) */
49 WX_GL_MIN_ACCUM_ALPHA /* use blue buffer with most bits (> MIN_ACCUM_ALPHA bits) */
8b089c5e
JS
50};
51
52//---------------------------------------------------------------------------
53// classes
54//---------------------------------------------------------------------------
55
56class WXDLLEXPORT wxGLContext;
57class WXDLLEXPORT wxGLCanvas;
58
59//---------------------------------------------------------------------------
60// wxGLContext
61//---------------------------------------------------------------------------
62
63
64class WXDLLEXPORT wxGLContext: public wxObject
65{
66public:
67 wxGLContext( bool isRGB, wxWindow *win, const wxPalette& palette = wxNullPalette );
2b5f62a0
VZ
68 wxGLContext(
69 bool WXUNUSED(isRGB), wxWindow *win,
8b089c5e
JS
70 const wxPalette& WXUNUSED(palette),
71 const wxGLContext *other /* for sharing display lists */
72 );
73 ~wxGLContext();
74
75 void SetCurrent();
2b5f62a0 76 void SetColour(const wxChar *colour);
8b089c5e
JS
77 void SwapBuffers();
78
79 void SetupPixelFormat();
80 void SetupPalette(const wxPalette& palette);
81 wxPalette CreateDefaultPalette();
82
83 inline wxPalette* GetPalette() const { return (wxPalette*) & m_palette; }
84 inline wxWindow* GetWindow() const { return m_window; }
85 inline GtkWidget* GetWidget() const { return m_widget; }
86 inline GLXContext GetContext() const { return m_glContext; }
87
88public:
89 GLXContext m_glContext;
90
91 GtkWidget *m_widget;
92 wxPalette m_palette;
93 wxWindow* m_window;
2b5f62a0 94
8b089c5e
JS
95private:
96 DECLARE_CLASS(wxGLContext)
97};
98
99//---------------------------------------------------------------------------
a6f5aa49 100// wxGLCanvas
8b089c5e
JS
101//---------------------------------------------------------------------------
102
4660d7e5 103class WXDLLEXPORT wxGLCanvas: public wxWindow
8b089c5e
JS
104{
105public:
106 inline wxGLCanvas() {
107 m_glContext = (wxGLContext*) NULL;
108 m_sharedContext = (wxGLContext*) NULL;
109 m_glWidget = (GtkWidget*) NULL;
110 m_vi = (void*) NULL;
111 m_exposed = FALSE;
112 }
2b5f62a0 113 wxGLCanvas( wxWindow *parent, wxWindowID id = -1,
8b089c5e 114 const wxPoint& pos = wxDefaultPosition,
2b5f62a0
VZ
115 const wxSize& size = wxDefaultSize,
116 long style = 0, const wxString& name = wxGLCanvasName,
117 int *attribList = (int*) NULL,
8b089c5e 118 const wxPalette& palette = wxNullPalette );
a0573e8e 119 wxGLCanvas( wxWindow *parent, const wxGLContext *shared,
2b5f62a0 120 wxWindowID id = -1,
8b089c5e 121 const wxPoint& pos = wxDefaultPosition,
2b5f62a0
VZ
122 const wxSize& size = wxDefaultSize,
123 long style = 0, const wxString& name = wxGLCanvasName,
124 int *attribList = (int*) NULL,
8b089c5e 125 const wxPalette& palette = wxNullPalette );
a0573e8e 126 wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared,
2b5f62a0 127 wxWindowID id = -1,
8b089c5e 128 const wxPoint& pos = wxDefaultPosition,
2b5f62a0
VZ
129 const wxSize& size = wxDefaultSize,
130 long style = 0, const wxString& name = wxGLCanvasName,
131 int *attribList = (int*) NULL,
8b089c5e
JS
132 const wxPalette& palette = wxNullPalette );
133
2b5f62a0
VZ
134 bool Create( wxWindow *parent,
135 const wxGLContext *shared = (wxGLContext*)NULL,
136 const wxGLCanvas *shared_context_of = (wxGLCanvas*)NULL,
137 wxWindowID id = -1,
138 const wxPoint& pos = wxDefaultPosition,
139 const wxSize& size = wxDefaultSize,
140 long style = 0,
141 const wxString& name = wxGLCanvasName,
142 int *attribList = (int*) NULL,
143 const wxPalette& palette = wxNullPalette );
144
8b089c5e
JS
145 ~wxGLCanvas();
146
147 void SetCurrent();
2b5f62a0 148 void SetColour(const wxChar *colour);
8b089c5e
JS
149 void SwapBuffers();
150
151 void OnSize(wxSizeEvent& event);
2b5f62a0 152
8b089c5e
JS
153 void OnInternalIdle();
154
2b5f62a0 155 inline wxGLContext* GetContext() const { return m_glContext; }
8b089c5e
JS
156
157 // implementation
2b5f62a0 158
8b089c5e
JS
159 wxGLContext *m_glContext,
160 *m_sharedContext;
161 wxGLCanvas *m_sharedContextOf;
a6f5aa49 162 void *m_vi; // actually an XVisualInfo*
34a34b02 163 GLXFBConfig *m_fbc;
a6f5aa49 164 bool m_canFreeVi;
34a34b02 165 bool m_canFreeFBC;
8b089c5e
JS
166 GtkWidget *m_glWidget;
167 bool m_exposed;
2b5f62a0 168
a6f5aa49
VZ
169 // returns an XVisualInfo* based on desired GL attributes;
170 // returns NULL if an appropriate visual is not found. The
2b5f62a0 171 // caller is reponsible for using XFree() to deallocate
a6f5aa49
VZ
172 // the returned structure.
173 static void* ChooseGLVisual(int *attribList);
34a34b02
VZ
174 static void* ChooseGLFBC(int *attribList);
175 static void GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList );
8b089c5e 176
34a34b02
VZ
177 static void QueryGLXVersion();
178 static int GetGLXVersion();
179 static int m_glxVersion;
8b089c5e
JS
180private:
181 DECLARE_EVENT_TABLE()
182 DECLARE_CLASS(wxGLCanvas)
183};
184
8b089c5e
JS
185#endif
186 // _WX_GLCANVAS_H_
187