]>
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 | |
8 | // RCS-ID: $Id$ | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
8b089c5e JS |
12 | #ifndef _WX_GLCANVAS_H_BASE_ |
13 | #define _WX_GLCANVAS_H_BASE_ | |
14 | ||
a3081354 VZ |
15 | #include "wx/defs.h" |
16 | ||
17 | #if wxUSE_GLCANVAS | |
18 | ||
dc3065a5 VZ |
19 | #include "wx/app.h" |
20 | #include "wx/palette.h" | |
21 | #include "wx/window.h" | |
0643d43c | 22 | |
dc3065a5 VZ |
23 | class WXDLLIMPEXP_GL wxGLCanvas; |
24 | class WXDLLIMPEXP_GL wxGLContext; | |
25 | ||
26 | // ---------------------------------------------------------------------------- | |
27 | // Constants for attributes list | |
28 | // ---------------------------------------------------------------------------- | |
0643d43c | 29 | |
dc3065a5 VZ |
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. | |
0643d43c VZ |
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) */ | |
f5318dd5 | 44 | WX_GL_MIN_ALPHA, /* use alpha buffer with most bits (> MIN_ALPHA bits) */ |
0643d43c VZ |
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) */ | |
f5318dd5 | 50 | WX_GL_MIN_ACCUM_ALPHA /* use alpha buffer with most bits (> MIN_ACCUM_ALPHA bits) */ |
0643d43c VZ |
51 | }; |
52 | ||
2b5f62a0 VZ |
53 | #define wxGLCanvasName _T("GLCanvas") |
54 | ||
dc3065a5 VZ |
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 | #if WXWIN_COMPATIBILITY_2_8 | |
83 | m_glContext = NULL; | |
84 | #endif | |
85 | } | |
86 | ||
87 | virtual ~wxGLCanvasBase(); | |
88 | ||
89 | ||
90 | /* | |
91 | The derived class should provide a ctor with this signature: | |
92 | ||
93 | wxGLCanvas(wxWindow *parent, | |
94 | wxWindowID id = wxID_ANY, | |
95 | int* attribList = 0, | |
96 | const wxPoint& pos = wxDefaultPosition, | |
97 | const wxSize& size = wxDefaultSize, | |
98 | long style = 0, | |
99 | const wxString& name = wxGLCanvasName, | |
100 | const wxPalette& palette = wxNullPalette); | |
101 | */ | |
102 | ||
103 | // operations | |
104 | // ---------- | |
105 | ||
106 | // set the given context associated with this window as the current one | |
107 | void SetCurrent(const wxGLContext& context) const; | |
108 | ||
109 | // flush the back buffer (if we have it) | |
110 | virtual void SwapBuffers() = 0; | |
111 | ||
112 | ||
113 | // accessors | |
114 | // --------- | |
115 | ||
116 | const wxPalette *GetPalette() const { return &m_palette; } | |
117 | ||
118 | // miscellaneous helper functions | |
119 | // ------------------------------ | |
120 | ||
121 | // call glcolor() for the colour with the given name, return false if | |
122 | // colour not found | |
123 | bool SetColour(const wxChar *colour); | |
124 | ||
125 | ||
126 | ||
127 | // deprecated methods using the implicit wxGLContext | |
128 | #if WXWIN_COMPATIBILITY_2_8 | |
129 | wxDEPRECATED( wxGLContext* GetContext() const ); | |
130 | ||
131 | wxDEPRECATED( void SetCurrent() ); | |
132 | ||
133 | wxDEPRECATED( void OnSize(wxSizeEvent& event) ); | |
134 | #endif // WXWIN_COMPATIBILITY_2_8 | |
135 | ||
136 | #ifdef __WXUNIVERSAL__ | |
137 | // resolve the conflict with wxWindowUniv::SetCurrent() | |
138 | virtual bool SetCurrent(bool doit) { return wxWindow::SetCurrent(doit); }; | |
139 | #endif | |
140 | ||
141 | protected: | |
142 | // override this to implement SetColour() in GL_INDEX_MODE | |
143 | // (currently only implemented in wxX11 and wxMotif ports) | |
144 | virtual int GetColourIndex(const wxColour& WXUNUSED(col)) { return -1; } | |
145 | ||
146 | // create default palette if we're not using RGBA mode | |
147 | // (not supported in most ports) | |
148 | virtual wxPalette CreateDefaultPalette() { return wxNullPalette; } | |
149 | ||
150 | ||
151 | wxPalette m_palette; | |
152 | ||
153 | #if WXWIN_COMPATIBILITY_2_8 | |
154 | wxGLContext *m_glContext; | |
155 | #endif // WXWIN_COMPATIBILITY_2_8 | |
156 | }; | |
157 | ||
8b089c5e | 158 | #if defined(__WXMSW__) |
dc3065a5 VZ |
159 | #include "wx/msw/glcanvas.h" |
160 | #elif defined(__WXMOTIF__) || defined(__WXX11__) | |
161 | #include "wx/x11/glcanvas.h" | |
1be7a35c | 162 | #elif defined(__WXGTK20__) |
dc3065a5 | 163 | #include "wx/gtk/glcanvas.h" |
1be7a35c | 164 | #elif defined(__WXGTK__) |
dc3065a5 | 165 | #include "wx/gtk1/glcanvas.h" |
8b089c5e | 166 | #elif defined(__WXMAC__) |
dc3065a5 | 167 | #include "wx/mac/glcanvas.h" |
bd2af428 | 168 | #elif defined(__WXCOCOA__) |
dc3065a5 | 169 | #include "wx/cocoa/glcanvas.h" |
2e35565a | 170 | #else |
dc3065a5 | 171 | #error "wxGLCanvas not supported in this wxWidgets port" |
8b089c5e JS |
172 | #endif |
173 | ||
d8290dd0 | 174 | class WXDLLIMPEXP_GL wxGLApp : public wxApp |
a3081354 VZ |
175 | { |
176 | public: | |
177 | wxGLApp() : wxApp() { } | |
a3081354 VZ |
178 | |
179 | // use this in the constructor of the user-derived wxGLApp class to | |
180 | // determine if an OpenGL rendering context with these attributes | |
5d3e7b52 | 181 | // is available - returns true if so, false if not. |
dc3065a5 | 182 | bool InitGLVisual(const int *attribList); |
a3081354 VZ |
183 | |
184 | private: | |
185 | DECLARE_DYNAMIC_CLASS(wxGLApp) | |
186 | }; | |
187 | ||
dc3065a5 VZ |
188 | #endif // wxUSE_GLCANVAS |
189 | ||
190 | #endif // _WX_GLCANVAS_H_BASE_ |