]> git.saurik.com Git - wxWidgets.git/blame - include/wx/glcanvas.h
We need to switch off UI elements before they are laid out. Do this via static functions.
[wxWidgets.git] / include / wx / glcanvas.h
CommitLineData
99d80019
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/glcanvas.h
3// Purpose: wxGLCanvas base header
4// Author: Julian Smart
5// Modified by:
6// Created:
7// Copyright: (c) Julian Smart
8// RCS-ID: $Id$
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
8b089c5e
JS
12#ifndef _WX_GLCANVAS_H_BASE_
13#define _WX_GLCANVAS_H_BASE_
14
a3081354
VZ
15#include "wx/defs.h"
16
17#if wxUSE_GLCANVAS
18
dc3065a5
VZ
19#include "wx/app.h"
20#include "wx/palette.h"
21#include "wx/window.h"
0643d43c 22
b5dbe15d
VS
23class WXDLLIMPEXP_FWD_GL wxGLCanvas;
24class WXDLLIMPEXP_FWD_GL wxGLContext;
dc3065a5
VZ
25
26// ----------------------------------------------------------------------------
27// Constants for attributes list
28// ----------------------------------------------------------------------------
0643d43c 29
4aa59c3d
VZ
30// Notice that not all implementation support options such as stereo, auxiliary
31// buffers, alpha channel, and accumulator buffer, use IsDisplaySupported() to
32// check for individual attributes support.
0643d43c
VZ
33enum
34{
4aa59c3d
VZ
35 WX_GL_RGBA = 1, // use true color palette (on if no attrs specified)
36 WX_GL_BUFFER_SIZE, // bits for buffer if not WX_GL_RGBA
37 WX_GL_LEVEL, // 0 for main buffer, >0 for overlay, <0 for underlay
38 WX_GL_DOUBLEBUFFER, // use double buffering (on if no attrs specified)
39 WX_GL_STEREO, // use stereoscopic display
40 WX_GL_AUX_BUFFERS, // number of auxiliary buffers
41 WX_GL_MIN_RED, // use red buffer with most bits (> MIN_RED bits)
42 WX_GL_MIN_GREEN, // use green buffer with most bits (> MIN_GREEN bits)
43 WX_GL_MIN_BLUE, // use blue buffer with most bits (> MIN_BLUE bits)
44 WX_GL_MIN_ALPHA, // use alpha buffer with most bits (> MIN_ALPHA bits)
45 WX_GL_DEPTH_SIZE, // bits for Z-buffer (0,16,32)
46 WX_GL_STENCIL_SIZE, // bits for stencil buffer
47 WX_GL_MIN_ACCUM_RED, // use red accum buffer with most bits (> MIN_ACCUM_RED bits)
48 WX_GL_MIN_ACCUM_GREEN, // use green buffer with most bits (> MIN_ACCUM_GREEN bits)
49 WX_GL_MIN_ACCUM_BLUE, // use blue buffer with most bits (> MIN_ACCUM_BLUE bits)
c39d2e0a
VZ
50 WX_GL_MIN_ACCUM_ALPHA, // use alpha buffer with most bits (> MIN_ACCUM_ALPHA bits)
51 WX_GL_SAMPLE_BUFFERS, // 1 for multisampling support (antialiasing)
d13b34d3 52 WX_GL_SAMPLES // 4 for 2x2 antialiasing supersampling on most graphics cards
0643d43c
VZ
53};
54
9a83f860 55#define wxGLCanvasName wxT("GLCanvas")
2b5f62a0 56
dc3065a5
VZ
57// ----------------------------------------------------------------------------
58// wxGLContextBase: OpenGL rendering context
59// ----------------------------------------------------------------------------
60
61class WXDLLIMPEXP_GL wxGLContextBase : public wxObject
62{
63public:
64 /*
65 The derived class should provide a ctor with this signature:
66
67 wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
68 */
69
70 // set this context as the current one
5ec69e96 71 virtual bool SetCurrent(const wxGLCanvas& win) const = 0;
dc3065a5
VZ
72};
73
74// ----------------------------------------------------------------------------
75// wxGLCanvasBase: window which can be used for OpenGL rendering
76// ----------------------------------------------------------------------------
77
78class WXDLLIMPEXP_GL wxGLCanvasBase : public wxWindow
79{
80public:
81 // default ctor doesn't initialize the window, use Create() later
15b239c0 82 wxGLCanvasBase();
dc3065a5
VZ
83
84 virtual ~wxGLCanvasBase();
85
86
87 /*
88 The derived class should provide a ctor with this signature:
89
90 wxGLCanvas(wxWindow *parent,
91 wxWindowID id = wxID_ANY,
92 int* attribList = 0,
93 const wxPoint& pos = wxDefaultPosition,
94 const wxSize& size = wxDefaultSize,
95 long style = 0,
96 const wxString& name = wxGLCanvasName,
97 const wxPalette& palette = wxNullPalette);
98 */
99
100 // operations
101 // ----------
102
103 // set the given context associated with this window as the current one
5ec69e96 104 bool SetCurrent(const wxGLContext& context) const;
dc3065a5
VZ
105
106 // flush the back buffer (if we have it)
5ec69e96 107 virtual bool SwapBuffers() = 0;
dc3065a5
VZ
108
109
110 // accessors
111 // ---------
112
3f20f7d8
VZ
113 // check if the given attributes are supported without creating a canvas
114 static bool IsDisplaySupported(const int *attribList);
115
9ce5cf09 116#if wxUSE_PALETTE
dc3065a5 117 const wxPalette *GetPalette() const { return &m_palette; }
9ce5cf09 118#endif // wxUSE_PALETTE
dc3065a5
VZ
119
120 // miscellaneous helper functions
121 // ------------------------------
122
123 // call glcolor() for the colour with the given name, return false if
124 // colour not found
35f1f4f7 125 bool SetColour(const wxString& colour);
dc3065a5 126
c39d2e0a
VZ
127 // return true if the extension with given name is supported
128 //
129 // notice that while this function is implemented for all of GLX, WGL and
130 // AGL the extensions names are usually not the same for different
131 // platforms and so the code using it still usually uses conditional
132 // compilation
133 static bool IsExtensionSupported(const char *extension);
dc3065a5
VZ
134
135 // deprecated methods using the implicit wxGLContext
136#if WXWIN_COMPATIBILITY_2_8
137 wxDEPRECATED( wxGLContext* GetContext() const );
138
139 wxDEPRECATED( void SetCurrent() );
140
141 wxDEPRECATED( void OnSize(wxSizeEvent& event) );
142#endif // WXWIN_COMPATIBILITY_2_8
143
144#ifdef __WXUNIVERSAL__
145 // resolve the conflict with wxWindowUniv::SetCurrent()
6dd0883d 146 virtual bool SetCurrent(bool doit) { return wxWindow::SetCurrent(doit); }
dc3065a5
VZ
147#endif
148
149protected:
150 // override this to implement SetColour() in GL_INDEX_MODE
151 // (currently only implemented in wxX11 and wxMotif ports)
152 virtual int GetColourIndex(const wxColour& WXUNUSED(col)) { return -1; }
153
c39d2e0a
VZ
154 // check if the given extension name is present in the space-separated list
155 // of extensions supported by the current implementation such as returned
156 // by glXQueryExtensionsString() or glGetString(GL_EXTENSIONS)
157 static bool IsExtensionInList(const char *list, const char *extension);
dc3065a5 158
9ce5cf09
VZ
159#if wxUSE_PALETTE
160 // create default palette if we're not using RGBA mode
161 // (not supported in most ports)
162 virtual wxPalette CreateDefaultPalette() { return wxNullPalette; }
163
dc3065a5 164 wxPalette m_palette;
9ce5cf09 165#endif // wxUSE_PALETTE
dc3065a5
VZ
166
167#if WXWIN_COMPATIBILITY_2_8
168 wxGLContext *m_glContext;
169#endif // WXWIN_COMPATIBILITY_2_8
170};
171
498ace9e
VZ
172// ----------------------------------------------------------------------------
173// wxGLApp: a special wxApp subclass for OpenGL applications which must be used
174// to select a visual compatible with the given attributes
175// ----------------------------------------------------------------------------
176
177class WXDLLIMPEXP_GL wxGLAppBase : public wxApp
178{
179public:
180 wxGLAppBase() : wxApp() { }
181
182 // use this in the constructor of the user-derived wxGLApp class to
183 // determine if an OpenGL rendering context with these attributes
184 // is available - returns true if so, false if not.
185 virtual bool InitGLVisual(const int *attribList) = 0;
186};
187
8b089c5e 188#if defined(__WXMSW__)
dc3065a5
VZ
189 #include "wx/msw/glcanvas.h"
190#elif defined(__WXMOTIF__) || defined(__WXX11__)
191 #include "wx/x11/glcanvas.h"
1be7a35c 192#elif defined(__WXGTK20__)
dc3065a5 193 #include "wx/gtk/glcanvas.h"
1be7a35c 194#elif defined(__WXGTK__)
dc3065a5 195 #include "wx/gtk1/glcanvas.h"
8b089c5e 196#elif defined(__WXMAC__)
ef0e9220 197 #include "wx/osx/glcanvas.h"
bd2af428 198#elif defined(__WXCOCOA__)
dc3065a5 199 #include "wx/cocoa/glcanvas.h"
2e35565a 200#else
dc3065a5 201 #error "wxGLCanvas not supported in this wxWidgets port"
8b089c5e
JS
202#endif
203
498ace9e
VZ
204// wxMac and wxMSW don't need anything extra in wxGLAppBase, so declare it here
205#ifndef wxGL_APP_DEFINED
206
207class WXDLLIMPEXP_GL wxGLApp : public wxGLAppBase
a3081354
VZ
208{
209public:
498ace9e 210 wxGLApp() : wxGLAppBase() { }
a3081354 211
498ace9e 212 virtual bool InitGLVisual(const int *attribList);
a3081354
VZ
213
214private:
215 DECLARE_DYNAMIC_CLASS(wxGLApp)
216};
217
498ace9e
VZ
218#endif // !wxGL_APP_DEFINED
219
e7ee4873
SC
220// ----------------------------------------------------------------------------
221// wxGLAPI: an API wrapper that allows the use of 'old' APIs even on OpenGL
222// platforms that don't support it natively anymore, if the APIs are available
223// it's a mere redirect
224// ----------------------------------------------------------------------------
225
226#ifndef wxUSE_OPENGL_EMULATION
227 #define wxUSE_OPENGL_EMULATION 0
228#endif
229
230class WXDLLIMPEXP_GL wxGLAPI : public wxObject
231{
232public:
233 wxGLAPI();
234 ~wxGLAPI();
235
ce00f59b 236 static void glFrustum(GLfloat left, GLfloat right, GLfloat bottom,
e203dbfe 237 GLfloat top, GLfloat zNear, GLfloat zFar);
e7ee4873
SC
238 static void glBegin(GLenum mode);
239 static void glTexCoord2f(GLfloat s, GLfloat t);
240 static void glVertex3f(GLfloat x, GLfloat y, GLfloat z);
241 static void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz);
242 static void glColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
243 static void glColor3f(GLfloat r, GLfloat g, GLfloat b);
244 static void glEnd();
245};
246
dc3065a5
VZ
247#endif // wxUSE_GLCANVAS
248
249#endif // _WX_GLCANVAS_H_BASE_