Remove all lines containing cvs/svn "$Id$" keyword.
[wxWidgets.git] / include / wx / glcanvas.h
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 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_GLCANVAS_H_BASE_
12 #define _WX_GLCANVAS_H_BASE_
13
14 #include "wx/defs.h"
15
16 #if wxUSE_GLCANVAS
17
18 #include "wx/app.h"
19 #include "wx/palette.h"
20 #include "wx/window.h"
21
22 class WXDLLIMPEXP_FWD_GL wxGLCanvas;
23 class WXDLLIMPEXP_FWD_GL wxGLContext;
24
25 // ----------------------------------------------------------------------------
26 // Constants for attributes list
27 // ----------------------------------------------------------------------------
28
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.
32 enum
33 {
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)
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)
51 WX_GL_SAMPLES // 4 for 2x2 antialiasing supersampling on most graphics cards
52 };
53
54 #define wxGLCanvasName wxT("GLCanvas")
55
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
70 virtual bool SetCurrent(const wxGLCanvas& win) const = 0;
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
81 wxGLCanvasBase();
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
103 bool SetCurrent(const wxGLContext& context) const;
104
105 // flush the back buffer (if we have it)
106 virtual bool SwapBuffers() = 0;
107
108
109 // accessors
110 // ---------
111
112 // check if the given attributes are supported without creating a canvas
113 static bool IsDisplaySupported(const int *attribList);
114
115 #if wxUSE_PALETTE
116 const wxPalette *GetPalette() const { return &m_palette; }
117 #endif // wxUSE_PALETTE
118
119 // miscellaneous helper functions
120 // ------------------------------
121
122 // call glcolor() for the colour with the given name, return false if
123 // colour not found
124 bool SetColour(const wxString& colour);
125
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);
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()
145 virtual bool SetCurrent(bool doit) { return wxWindow::SetCurrent(doit); }
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
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);
157
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
163 wxPalette m_palette;
164 #endif // wxUSE_PALETTE
165
166 #if WXWIN_COMPATIBILITY_2_8
167 wxGLContext *m_glContext;
168 #endif // WXWIN_COMPATIBILITY_2_8
169 };
170
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
187 #if defined(__WXMSW__)
188 #include "wx/msw/glcanvas.h"
189 #elif defined(__WXMOTIF__) || defined(__WXX11__)
190 #include "wx/x11/glcanvas.h"
191 #elif defined(__WXGTK20__)
192 #include "wx/gtk/glcanvas.h"
193 #elif defined(__WXGTK__)
194 #include "wx/gtk1/glcanvas.h"
195 #elif defined(__WXMAC__)
196 #include "wx/osx/glcanvas.h"
197 #elif defined(__WXCOCOA__)
198 #include "wx/cocoa/glcanvas.h"
199 #else
200 #error "wxGLCanvas not supported in this wxWidgets port"
201 #endif
202
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
207 {
208 public:
209 wxGLApp() : wxGLAppBase() { }
210
211 virtual bool InitGLVisual(const int *attribList);
212
213 private:
214 DECLARE_DYNAMIC_CLASS(wxGLApp)
215 };
216
217 #endif // !wxGL_APP_DEFINED
218
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
235 static void glFrustum(GLfloat left, GLfloat right, GLfloat bottom,
236 GLfloat top, GLfloat zNear, GLfloat zFar);
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
246 #endif // wxUSE_GLCANVAS
247
248 #endif // _WX_GLCANVAS_H_BASE_