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