]> git.saurik.com Git - wxWidgets.git/blob - include/wx/glcanvas.h
compilation
[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 // RCS-ID: $Id$
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GLCANVAS_H_BASE_
13 #define _WX_GLCANVAS_H_BASE_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_GLCANVAS
18
19 #include "wx/app.h"
20 #include "wx/palette.h"
21 #include "wx/window.h"
22
23 class WXDLLIMPEXP_FWD_GL wxGLCanvas;
24 class WXDLLIMPEXP_FWD_GL wxGLContext;
25
26 // ----------------------------------------------------------------------------
27 // Constants for attributes list
28 // ----------------------------------------------------------------------------
29
30 // The generic OpenGL implementation doesn't support most of these options,
31 // such as stereo, auxiliary buffers, alpha channel, and accumulator buffer.
32 // Other implementations may actually support them.
33 enum
34 {
35 WX_GL_RGBA=1, /* use true color palette */
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 doublebuffer */
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 };
52
53 #define wxGLCanvasName _T("GLCanvas")
54
55 // ----------------------------------------------------------------------------
56 // wxGLContextBase: OpenGL rendering context
57 // ----------------------------------------------------------------------------
58
59 class WXDLLIMPEXP_GL wxGLContextBase : public wxObject
60 {
61 public:
62 /*
63 The derived class should provide a ctor with this signature:
64
65 wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
66 */
67
68 // set this context as the current one
69 virtual void SetCurrent(const wxGLCanvas& win) const = 0;
70 };
71
72 // ----------------------------------------------------------------------------
73 // wxGLCanvasBase: window which can be used for OpenGL rendering
74 // ----------------------------------------------------------------------------
75
76 class WXDLLIMPEXP_GL wxGLCanvasBase : public wxWindow
77 {
78 public:
79 // default ctor doesn't initialize the window, use Create() later
80 wxGLCanvasBase();
81
82 virtual ~wxGLCanvasBase();
83
84
85 /*
86 The derived class should provide a ctor with this signature:
87
88 wxGLCanvas(wxWindow *parent,
89 wxWindowID id = wxID_ANY,
90 int* attribList = 0,
91 const wxPoint& pos = wxDefaultPosition,
92 const wxSize& size = wxDefaultSize,
93 long style = 0,
94 const wxString& name = wxGLCanvasName,
95 const wxPalette& palette = wxNullPalette);
96 */
97
98 // operations
99 // ----------
100
101 // set the given context associated with this window as the current one
102 void SetCurrent(const wxGLContext& context) const;
103
104 // flush the back buffer (if we have it)
105 virtual void SwapBuffers() = 0;
106
107
108 // accessors
109 // ---------
110
111 const wxPalette *GetPalette() const { return &m_palette; }
112
113 // miscellaneous helper functions
114 // ------------------------------
115
116 // call glcolor() for the colour with the given name, return false if
117 // colour not found
118 bool SetColour(const wxString& colour);
119
120
121
122 // deprecated methods using the implicit wxGLContext
123 #if WXWIN_COMPATIBILITY_2_8
124 wxDEPRECATED( wxGLContext* GetContext() const );
125
126 wxDEPRECATED( void SetCurrent() );
127
128 wxDEPRECATED( void OnSize(wxSizeEvent& event) );
129 #endif // WXWIN_COMPATIBILITY_2_8
130
131 #ifdef __WXUNIVERSAL__
132 // resolve the conflict with wxWindowUniv::SetCurrent()
133 virtual bool SetCurrent(bool doit) { return wxWindow::SetCurrent(doit); };
134 #endif
135
136 protected:
137 // override this to implement SetColour() in GL_INDEX_MODE
138 // (currently only implemented in wxX11 and wxMotif ports)
139 virtual int GetColourIndex(const wxColour& WXUNUSED(col)) { return -1; }
140
141 // create default palette if we're not using RGBA mode
142 // (not supported in most ports)
143 virtual wxPalette CreateDefaultPalette() { return wxNullPalette; }
144
145
146 wxPalette m_palette;
147
148 #if WXWIN_COMPATIBILITY_2_8
149 wxGLContext *m_glContext;
150 #endif // WXWIN_COMPATIBILITY_2_8
151 };
152
153 // ----------------------------------------------------------------------------
154 // wxGLApp: a special wxApp subclass for OpenGL applications which must be used
155 // to select a visual compatible with the given attributes
156 // ----------------------------------------------------------------------------
157
158 class WXDLLIMPEXP_GL wxGLAppBase : public wxApp
159 {
160 public:
161 wxGLAppBase() : wxApp() { }
162
163 // use this in the constructor of the user-derived wxGLApp class to
164 // determine if an OpenGL rendering context with these attributes
165 // is available - returns true if so, false if not.
166 virtual bool InitGLVisual(const int *attribList) = 0;
167 };
168
169 #if defined(__WXMSW__)
170 #include "wx/msw/glcanvas.h"
171 #elif defined(__WXMOTIF__) || defined(__WXX11__)
172 #include "wx/x11/glcanvas.h"
173 #elif defined(__WXGTK20__)
174 #include "wx/gtk/glcanvas.h"
175 #elif defined(__WXGTK__)
176 #include "wx/gtk1/glcanvas.h"
177 #elif defined(__WXMAC__)
178 #include "wx/mac/glcanvas.h"
179 #elif defined(__WXCOCOA__)
180 #include "wx/cocoa/glcanvas.h"
181 #else
182 #error "wxGLCanvas not supported in this wxWidgets port"
183 #endif
184
185 // wxMac and wxMSW don't need anything extra in wxGLAppBase, so declare it here
186 #ifndef wxGL_APP_DEFINED
187
188 class WXDLLIMPEXP_GL wxGLApp : public wxGLAppBase
189 {
190 public:
191 wxGLApp() : wxGLAppBase() { }
192
193 virtual bool InitGLVisual(const int *attribList);
194
195 private:
196 DECLARE_DYNAMIC_CLASS(wxGLApp)
197 };
198
199 #endif // !wxGL_APP_DEFINED
200
201 #endif // wxUSE_GLCANVAS
202
203 #endif // _WX_GLCANVAS_H_BASE_