1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGLCanvas base header
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GLCANVAS_H_BASE_
12 #define _WX_GLCANVAS_H_BASE_
19 #include "wx/palette.h"
20 #include "wx/window.h"
22 class WXDLLIMPEXP_FWD_GL wxGLCanvas
;
23 class WXDLLIMPEXP_FWD_GL wxGLContext
;
25 // ----------------------------------------------------------------------------
26 // Constants for attributes list
27 // ----------------------------------------------------------------------------
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.
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
54 #define wxGLCanvasName wxT("GLCanvas")
56 // ----------------------------------------------------------------------------
57 // wxGLContextBase: OpenGL rendering context
58 // ----------------------------------------------------------------------------
60 class WXDLLIMPEXP_GL wxGLContextBase
: public wxObject
64 The derived class should provide a ctor with this signature:
66 wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
69 // set this context as the current one
70 virtual bool SetCurrent(const wxGLCanvas
& win
) const = 0;
73 // ----------------------------------------------------------------------------
74 // wxGLCanvasBase: window which can be used for OpenGL rendering
75 // ----------------------------------------------------------------------------
77 class WXDLLIMPEXP_GL wxGLCanvasBase
: public wxWindow
80 // default ctor doesn't initialize the window, use Create() later
83 virtual ~wxGLCanvasBase();
87 The derived class should provide a ctor with this signature:
89 wxGLCanvas(wxWindow *parent,
90 wxWindowID id = wxID_ANY,
92 const wxPoint& pos = wxDefaultPosition,
93 const wxSize& size = wxDefaultSize,
95 const wxString& name = wxGLCanvasName,
96 const wxPalette& palette = wxNullPalette);
102 // set the given context associated with this window as the current one
103 bool SetCurrent(const wxGLContext
& context
) const;
105 // flush the back buffer (if we have it)
106 virtual bool SwapBuffers() = 0;
112 // check if the given attributes are supported without creating a canvas
113 static bool IsDisplaySupported(const int *attribList
);
116 const wxPalette
*GetPalette() const { return &m_palette
; }
117 #endif // wxUSE_PALETTE
119 // miscellaneous helper functions
120 // ------------------------------
122 // call glcolor() for the colour with the given name, return false if
124 bool SetColour(const wxString
& colour
);
126 // return true if the extension with given name is supported
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
132 static bool IsExtensionSupported(const char *extension
);
134 // deprecated methods using the implicit wxGLContext
135 #if WXWIN_COMPATIBILITY_2_8
136 wxDEPRECATED( wxGLContext
* GetContext() const );
138 wxDEPRECATED( void SetCurrent() );
140 wxDEPRECATED( void OnSize(wxSizeEvent
& event
) );
141 #endif // WXWIN_COMPATIBILITY_2_8
143 #ifdef __WXUNIVERSAL__
144 // resolve the conflict with wxWindowUniv::SetCurrent()
145 virtual bool SetCurrent(bool doit
) { return wxWindow::SetCurrent(doit
); }
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; }
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
);
159 // create default palette if we're not using RGBA mode
160 // (not supported in most ports)
161 virtual wxPalette
CreateDefaultPalette() { return wxNullPalette
; }
164 #endif // wxUSE_PALETTE
166 #if WXWIN_COMPATIBILITY_2_8
167 wxGLContext
*m_glContext
;
168 #endif // WXWIN_COMPATIBILITY_2_8
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 // ----------------------------------------------------------------------------
176 class WXDLLIMPEXP_GL wxGLAppBase
: public wxApp
179 wxGLAppBase() : wxApp() { }
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;
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"
200 #error "wxGLCanvas not supported in this wxWidgets port"
203 // wxMac and wxMSW don't need anything extra in wxGLAppBase, so declare it here
204 #ifndef wxGL_APP_DEFINED
206 class WXDLLIMPEXP_GL wxGLApp
: public wxGLAppBase
209 wxGLApp() : wxGLAppBase() { }
211 virtual bool InitGLVisual(const int *attribList
);
214 DECLARE_DYNAMIC_CLASS(wxGLApp
)
217 #endif // !wxGL_APP_DEFINED
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 // ----------------------------------------------------------------------------
225 #ifndef wxUSE_OPENGL_EMULATION
226 #define wxUSE_OPENGL_EMULATION 0
229 class WXDLLIMPEXP_GL wxGLAPI
: public wxObject
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
);
246 #endif // wxUSE_GLCANVAS
248 #endif // _WX_GLCANVAS_H_BASE_