1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGLCanvas base header
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GLCANVAS_H_BASE_
13 #define _WX_GLCANVAS_H_BASE_
20 #include "wx/palette.h"
21 #include "wx/window.h"
23 class WXDLLIMPEXP_FWD_GL wxGLCanvas
;
24 class WXDLLIMPEXP_FWD_GL wxGLContext
;
26 // ----------------------------------------------------------------------------
27 // Constants for attributes list
28 // ----------------------------------------------------------------------------
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.
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)
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)
52 WX_GL_SAMPLES
// 4 for 2x2 antialising supersampling on most graphics cards
55 #define wxGLCanvasName wxT("GLCanvas")
57 // ----------------------------------------------------------------------------
58 // wxGLContextBase: OpenGL rendering context
59 // ----------------------------------------------------------------------------
61 class WXDLLIMPEXP_GL wxGLContextBase
: public wxObject
65 The derived class should provide a ctor with this signature:
67 wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
70 // set this context as the current one
71 virtual bool SetCurrent(const wxGLCanvas
& win
) const = 0;
74 // ----------------------------------------------------------------------------
75 // wxGLCanvasBase: window which can be used for OpenGL rendering
76 // ----------------------------------------------------------------------------
78 class WXDLLIMPEXP_GL wxGLCanvasBase
: public wxWindow
81 // default ctor doesn't initialize the window, use Create() later
84 virtual ~wxGLCanvasBase();
88 The derived class should provide a ctor with this signature:
90 wxGLCanvas(wxWindow *parent,
91 wxWindowID id = wxID_ANY,
93 const wxPoint& pos = wxDefaultPosition,
94 const wxSize& size = wxDefaultSize,
96 const wxString& name = wxGLCanvasName,
97 const wxPalette& palette = wxNullPalette);
103 // set the given context associated with this window as the current one
104 bool SetCurrent(const wxGLContext
& context
) const;
106 // flush the back buffer (if we have it)
107 virtual bool SwapBuffers() = 0;
113 // check if the given attributes are supported without creating a canvas
114 static bool IsDisplaySupported(const int *attribList
);
116 const wxPalette
*GetPalette() const { return &m_palette
; }
118 // miscellaneous helper functions
119 // ------------------------------
121 // call glcolor() for the colour with the given name, return false if
123 bool SetColour(const wxString
& colour
);
125 // return true if the extension with given name is supported
127 // notice that while this function is implemented for all of GLX, WGL and
128 // AGL the extensions names are usually not the same for different
129 // platforms and so the code using it still usually uses conditional
131 static bool IsExtensionSupported(const char *extension
);
133 // deprecated methods using the implicit wxGLContext
134 #if WXWIN_COMPATIBILITY_2_8
135 wxDEPRECATED( wxGLContext
* GetContext() const );
137 wxDEPRECATED( void SetCurrent() );
139 wxDEPRECATED( void OnSize(wxSizeEvent
& event
) );
140 #endif // WXWIN_COMPATIBILITY_2_8
142 #ifdef __WXUNIVERSAL__
143 // resolve the conflict with wxWindowUniv::SetCurrent()
144 virtual bool SetCurrent(bool doit
) { return wxWindow::SetCurrent(doit
); };
148 // override this to implement SetColour() in GL_INDEX_MODE
149 // (currently only implemented in wxX11 and wxMotif ports)
150 virtual int GetColourIndex(const wxColour
& WXUNUSED(col
)) { return -1; }
152 // create default palette if we're not using RGBA mode
153 // (not supported in most ports)
154 virtual wxPalette
CreateDefaultPalette() { return wxNullPalette
; }
156 // check if the given extension name is present in the space-separated list
157 // of extensions supported by the current implementation such as returned
158 // by glXQueryExtensionsString() or glGetString(GL_EXTENSIONS)
159 static bool IsExtensionInList(const char *list
, const char *extension
);
163 #if WXWIN_COMPATIBILITY_2_8
164 wxGLContext
*m_glContext
;
165 #endif // WXWIN_COMPATIBILITY_2_8
168 // ----------------------------------------------------------------------------
169 // wxGLApp: a special wxApp subclass for OpenGL applications which must be used
170 // to select a visual compatible with the given attributes
171 // ----------------------------------------------------------------------------
173 class WXDLLIMPEXP_GL wxGLAppBase
: public wxApp
176 wxGLAppBase() : wxApp() { }
178 // use this in the constructor of the user-derived wxGLApp class to
179 // determine if an OpenGL rendering context with these attributes
180 // is available - returns true if so, false if not.
181 virtual bool InitGLVisual(const int *attribList
) = 0;
184 #if defined(__WXMSW__)
185 #include "wx/msw/glcanvas.h"
186 #elif defined(__WXMOTIF__) || defined(__WXX11__)
187 #include "wx/x11/glcanvas.h"
188 #elif defined(__WXGTK20__)
189 #include "wx/gtk/glcanvas.h"
190 #elif defined(__WXGTK__)
191 #include "wx/gtk1/glcanvas.h"
192 #elif defined(__WXMAC__)
193 #include "wx/osx/glcanvas.h"
194 #elif defined(__WXCOCOA__)
195 #include "wx/cocoa/glcanvas.h"
197 #error "wxGLCanvas not supported in this wxWidgets port"
200 // wxMac and wxMSW don't need anything extra in wxGLAppBase, so declare it here
201 #ifndef wxGL_APP_DEFINED
203 class WXDLLIMPEXP_GL wxGLApp
: public wxGLAppBase
206 wxGLApp() : wxGLAppBase() { }
208 virtual bool InitGLVisual(const int *attribList
);
211 DECLARE_DYNAMIC_CLASS(wxGLApp
)
214 #endif // !wxGL_APP_DEFINED
216 // ----------------------------------------------------------------------------
217 // wxGLAPI: an API wrapper that allows the use of 'old' APIs even on OpenGL
218 // platforms that don't support it natively anymore, if the APIs are available
219 // it's a mere redirect
220 // ----------------------------------------------------------------------------
222 #ifndef wxUSE_OPENGL_EMULATION
223 #define wxUSE_OPENGL_EMULATION 0
226 class WXDLLIMPEXP_GL wxGLAPI
: public wxObject
232 static void glFrustum(GLfloat left
, GLfloat right
, GLfloat bottom
,
233 GLfloat top
, GLfloat zNear
, GLfloat zFar
);
234 static void glBegin(GLenum mode
);
235 static void glTexCoord2f(GLfloat s
, GLfloat t
);
236 static void glVertex3f(GLfloat x
, GLfloat y
, GLfloat z
);
237 static void glNormal3f(GLfloat nx
, GLfloat ny
, GLfloat nz
);
238 static void glColor4f(GLfloat r
, GLfloat g
, GLfloat b
, GLfloat a
);
239 static void glColor3f(GLfloat r
, GLfloat g
, GLfloat b
);
243 #endif // wxUSE_GLCANVAS
245 #endif // _WX_GLCANVAS_H_BASE_