]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/glcanvas.h
made wxHeaderCtrl::GetColumn() const to get rid of the const_cast<>s
[wxWidgets.git] / include / wx / glcanvas.h
... / ...
CommitLineData
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
23class WXDLLIMPEXP_FWD_GL wxGLCanvas;
24class WXDLLIMPEXP_FWD_GL wxGLContext;
25
26// ----------------------------------------------------------------------------
27// Constants for attributes list
28// ----------------------------------------------------------------------------
29
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.
33enum
34{
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
53};
54
55#define wxGLCanvasName _T("GLCanvas")
56
57// ----------------------------------------------------------------------------
58// wxGLContextBase: OpenGL rendering context
59// ----------------------------------------------------------------------------
60
61class WXDLLIMPEXP_GL wxGLContextBase : public wxObject
62{
63public:
64 /*
65 The derived class should provide a ctor with this signature:
66
67 wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
68 */
69
70 // set this context as the current one
71 virtual bool SetCurrent(const wxGLCanvas& win) const = 0;
72};
73
74// ----------------------------------------------------------------------------
75// wxGLCanvasBase: window which can be used for OpenGL rendering
76// ----------------------------------------------------------------------------
77
78class WXDLLIMPEXP_GL wxGLCanvasBase : public wxWindow
79{
80public:
81 // default ctor doesn't initialize the window, use Create() later
82 wxGLCanvasBase();
83
84 virtual ~wxGLCanvasBase();
85
86
87 /*
88 The derived class should provide a ctor with this signature:
89
90 wxGLCanvas(wxWindow *parent,
91 wxWindowID id = wxID_ANY,
92 int* attribList = 0,
93 const wxPoint& pos = wxDefaultPosition,
94 const wxSize& size = wxDefaultSize,
95 long style = 0,
96 const wxString& name = wxGLCanvasName,
97 const wxPalette& palette = wxNullPalette);
98 */
99
100 // operations
101 // ----------
102
103 // set the given context associated with this window as the current one
104 bool SetCurrent(const wxGLContext& context) const;
105
106 // flush the back buffer (if we have it)
107 virtual bool SwapBuffers() = 0;
108
109
110 // accessors
111 // ---------
112
113 // check if the given attributes are supported without creating a canvas
114 static bool IsDisplaySupported(const int *attribList);
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 wxString& colour);
124
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
148protected:
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 // create default palette if we're not using RGBA mode
154 // (not supported in most ports)
155 virtual wxPalette CreateDefaultPalette() { return wxNullPalette; }
156
157 // check if the given extension name is present in the space-separated list
158 // of extensions supported by the current implementation such as returned
159 // by glXQueryExtensionsString() or glGetString(GL_EXTENSIONS)
160 static bool IsExtensionInList(const char *list, const char *extension);
161
162 wxPalette m_palette;
163
164#if WXWIN_COMPATIBILITY_2_8
165 wxGLContext *m_glContext;
166#endif // WXWIN_COMPATIBILITY_2_8
167};
168
169// ----------------------------------------------------------------------------
170// wxGLApp: a special wxApp subclass for OpenGL applications which must be used
171// to select a visual compatible with the given attributes
172// ----------------------------------------------------------------------------
173
174class WXDLLIMPEXP_GL wxGLAppBase : public wxApp
175{
176public:
177 wxGLAppBase() : wxApp() { }
178
179 // use this in the constructor of the user-derived wxGLApp class to
180 // determine if an OpenGL rendering context with these attributes
181 // is available - returns true if so, false if not.
182 virtual bool InitGLVisual(const int *attribList) = 0;
183};
184
185#if defined(__WXMSW__)
186 #include "wx/msw/glcanvas.h"
187#elif defined(__WXMOTIF__) || defined(__WXX11__)
188 #include "wx/x11/glcanvas.h"
189#elif defined(__WXGTK20__)
190 #include "wx/gtk/glcanvas.h"
191#elif defined(__WXGTK__)
192 #include "wx/gtk1/glcanvas.h"
193#elif defined(__WXMAC__)
194 #include "wx/osx/glcanvas.h"
195#elif defined(__WXCOCOA__)
196 #include "wx/cocoa/glcanvas.h"
197#else
198 #error "wxGLCanvas not supported in this wxWidgets port"
199#endif
200
201// wxMac and wxMSW don't need anything extra in wxGLAppBase, so declare it here
202#ifndef wxGL_APP_DEFINED
203
204class WXDLLIMPEXP_GL wxGLApp : public wxGLAppBase
205{
206public:
207 wxGLApp() : wxGLAppBase() { }
208
209 virtual bool InitGLVisual(const int *attribList);
210
211private:
212 DECLARE_DYNAMIC_CLASS(wxGLApp)
213};
214
215#endif // !wxGL_APP_DEFINED
216
217#endif // wxUSE_GLCANVAS
218
219#endif // _WX_GLCANVAS_H_BASE_