comparison src/Modules/Output/Graphics/Devices/GraphicsOutputDevicewxGLCanvas.h @ 228:82e0dc3dfd16

- All \t to two spaces (style guide compliance)
author tomwalters
date Fri, 15 Oct 2010 05:46:53 +0000
parents 73c6d61440ad
children
comparison
equal deleted inserted replaced
227:73c6d61440ad 228:82e0dc3dfd16
30 // Precompiled wxWidgets headers 30 // Precompiled wxWidgets headers
31 #include "stdwx.h" 31 #include "stdwx.h"
32 32
33 // Make sure GLCANVAS is compiled into wxWidgets 33 // Make sure GLCANVAS is compiled into wxWidgets
34 #if !wxUSE_GLCANVAS 34 #if !wxUSE_GLCANVAS
35 # error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library" 35 # error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library"
36 #endif 36 #endif
37 37
38 #if defined (_MACOSX) 38 #if defined (_MACOSX)
39 # include <OpenGL/gl.h> 39 # include <OpenGL/gl.h>
40 # include <OpenGl/glext.h> 40 # include <OpenGl/glext.h>
41 #elif defined (_WINDOWS) 41 #elif defined (_WINDOWS)
42 # include <GL/gl.h> 42 # include <GL/gl.h>
43 # define GL_GET_PROC_ADDRESS wglGetProcAddress 43 # define GL_GET_PROC_ADDRESS wglGetProcAddress
44 #else 44 #else
45 # include <GL/gl.h> 45 # include <GL/gl.h>
46 # define GL_GET_PROC_ADDRESS(x) glXGetProcAddress((const GLubyte*)x) 46 # define GL_GET_PROC_ADDRESS(x) glXGetProcAddress((const GLubyte*)x)
47 #endif 47 #endif
48 /* Define them just ourselves, easiest way to get it working cross-platform 48 /* Define them just ourselves, easiest way to get it working cross-platform
49 * and -Mesa/OpenGL-version. */ 49 * and -Mesa/OpenGL-version. */
50 #ifndef APIENTRY 50 #ifndef APIENTRY
51 # define APIENTRY 51 # define APIENTRY
52 #endif 52 #endif
53 typedef void (APIENTRY * LOCAL_PFNGLLOCKARRAYSEXTPROC) (GLint first, GLsizei count); 53 typedef void (APIENTRY * LOCAL_PFNGLLOCKARRAYSEXTPROC) (GLint first, GLsizei count);
54 typedef void (APIENTRY * LOCAL_PFNGLUNLOCKARRAYSEXTPROC) (void); 54 typedef void (APIENTRY * LOCAL_PFNGLUNLOCKARRAYSEXTPROC) (void);
55 55
56 #ifdef FTGL_SUBDIR 56 #ifdef FTGL_SUBDIR
57 # include <FTGL/FTGLBitmapFont.h> 57 # include <FTGL/FTGLBitmapFont.h>
58 #else 58 #else
59 # include <FTGLBitmapFont.h> 59 # include <FTGLBitmapFont.h>
60 #endif 60 #endif
61 61
62 #include "Output/GraphicsOutputDevice.h" 62 #include "Output/GraphicsOutputDevice.h"
63 63
64 // Use by default 64 // Use by default
74 */ 74 */
75 class GraphicsOutputDevicewxGLCanvas : public wxGLCanvas, 75 class GraphicsOutputDevicewxGLCanvas : public wxGLCanvas,
76 public GraphicsOutputDevice { 76 public GraphicsOutputDevice {
77 public: 77 public:
78 GraphicsOutputDevicewxGLCanvas(Parameters *pParam, 78 GraphicsOutputDevicewxGLCanvas(Parameters *pParam,
79 wxWindow *parent, 79 wxWindow *parent,
80 wxWindowID id = wxID_ANY, 80 wxWindowID id = wxID_ANY,
81 const wxPoint& pos = wxDefaultPosition, 81 const wxPoint& pos = wxDefaultPosition,
82 const wxSize& size = wxDefaultSize, 82 const wxSize& size = wxDefaultSize,
83 long style = 0, 83 long style = 0,
84 const wxString& name 84 const wxString& name
86 virtual ~GraphicsOutputDevicewxGLCanvas(); 86 virtual ~GraphicsOutputDevicewxGLCanvas();
87 void OnPaint(wxPaintEvent& event); 87 void OnPaint(wxPaintEvent& event);
88 void OnSize(wxSizeEvent& event); 88 void OnSize(wxSizeEvent& event);
89 void OnEraseBackground(wxEraseEvent& event); 89 void OnEraseBackground(wxEraseEvent& event);
90 90
91 /*! \param iVerticesMax Maximum number of vertices to be draw inside a gBegin()..gEnd() 91 /*! \param iVerticesMax Maximum number of vertices to be draw inside a gBegin()..gEnd()
92 * 92 *
93 * When iVerticesMax is zero, this variable will not be updated. Note that is _has_ 93 * When iVerticesMax is zero, this variable will not be updated. Note that is _has_
94 * to be set at least once before using this class. 94 * to be set at least once before using this class.
95 */ 95 */
96 bool Initialize(unsigned int iVerticesMax); 96 bool Initialize(unsigned int iVerticesMax);
97 bool Initialize(); 97 bool Initialize();
98 98
99 void Start(); 99 void Start();
100 100
101 void gGrab(); 101 void gGrab();
102 void gBeginLineStrip(); 102 void gBeginLineStrip();
103 void gBeginQuadStrip(); 103 void gBeginQuadStrip();
104 using GraphicsOutputDevice::gVertex3f; // Because we overload it 104 using GraphicsOutputDevice::gVertex3f; // Because we overload it
105 void gVertex3f(float x, float y, float z); 105 void gVertex3f(float x, float y, float z);
106 void gColor3f(float r, float g, float b); 106 void gColor3f(float r, float g, float b);
107 void gEnd(); 107 void gEnd();
108 void gText3f(float x, float y, float z, const char *sStr, bool bRotated = false); 108 void gText3f(float x, float y, float z, const char *sStr, bool bRotated = false);
109 void gRelease(); 109 void gRelease();
110 protected: 110 protected:
111 /*! \brief Smarter SetCurrent() replacement 111 /*! \brief Smarter SetCurrent() replacement
112 * \return true on success, false on error 112 * \return true on success, false on error
113 * 113 *
114 * This function tries GetContext() first. If that fails, it returns false. 114 * This function tries GetContext() first. If that fails, it returns false.
115 */ 115 */
116 bool SetCurrent(); 116 bool SetCurrent();
117 void Render(); 117 void Render();
118 118
119 /*! \brief Initialize the OpenGL environment. 119 /*! \brief Initialize the OpenGL environment.
120 * 120 *
121 * This must be called after the canvas is realized but before any other 121 * This must be called after the canvas is realized but before any other
122 * OpenGL operation is done. Make sure to run SetCurrent() beforehand. 122 * OpenGL operation is done. Make sure to run SetCurrent() beforehand.
123 * Usually only needed when m_init is false. 123 * Usually only needed when m_init is false.
124 */ 124 */
125 void InitGL(); 125 void InitGL();
126 126
127 /*! \brief Handle a resize (notify OpenGL of the new area) 127 /*! \brief Handle a resize (notify OpenGL of the new area)
128 * 128 *
129 * This is a separate function, because in multi-threading environments 129 * This is a separate function, because in multi-threading environments
130 * multiple contexts have to call it. 130 * multiple contexts have to call it.
131 */ 131 */
132 void DoResize(); 132 void DoResize();
133 133
134 /*! \brief Only need to initialize OpenGL once. 134 /*! \brief Only need to initialize OpenGL once.
135 * 135 *
136 * This is false at start and true when OpenGL has been initialized. 136 * This is false at start and true when OpenGL has been initialized.
137 * No mutex needed, since it's set once at InitGL() and only read afterwards. 137 * No mutex needed, since it's set once at InitGL() and only read afterwards.
138 */ 138 */
139 bool m_init; 139 bool m_init;
140 140
141 /*! \brief Vertex list for last drawing so it can be updated on repaint. 141 /*! \brief Vertex list for last drawing so it can be updated on repaint.
142 * 142 *
143 * No mutex needed, since it's set once at InitGL() and only read afterwards. 143 * No mutex needed, since it's set once at InitGL() and only read afterwards.
144 */ 144 */
145 GLuint m_gllist; 145 GLuint m_gllist;
146 146
147 //! \brief OpenGL context for worker thread, use when wxIsMainThread() returns false. 147 //! \brief OpenGL context for worker thread, use when wxIsMainThread() returns false.
148 wxGLContext *m_pWorkerContext; 148 wxGLContext *m_pWorkerContext;
149 149
150 //! \brief Mutex for inter-thread communication 150 //! \brief Mutex for inter-thread communication
151 wxMutex s_mutexOpenGL; 151 wxMutex s_mutexOpenGL;
152 152
153 //! \brief When true, OpenGL needs to be reinitialized (in the worker thread) 153 //! \brief When true, OpenGL needs to be reinitialized (in the worker thread)
154 bool s_bWorkerNeedsInit; 154 bool s_bWorkerNeedsInit;
155 155
156 //! \brief OpenGL attributes used for initialization. 156 //! \brief OpenGL attributes used for initialization.
157 static int GLAttrlist[]; 157 static int GLAttrlist[];
158 158
159 //! \brief Whether to use anti-aliasing or not 159 //! \brief Whether to use anti-aliasing or not
160 bool m_bAntialiasing; 160 bool m_bAntialiasing;
161 161
162 //! \brief FTGL Font class 162 //! \brief FTGL Font class
163 FTFont *m_pFont; 163 FTFont *m_pFont;
164 //! \brief Current font filename 164 //! \brief Current font filename
165 const char *m_sFontFile; 165 const char *m_sFontFile;
166 //! \brief Current font size 166 //! \brief Current font size
167 int m_iFontsize; 167 int m_iFontsize;
168 168
169 #if defined(WITH_GL_VERTEX_ARRAYS) || defined(DOXYGEN) 169 #if defined(WITH_GL_VERTEX_ARRAYS) || defined(DOXYGEN)
170 //! \brief OpenGL vertex type of the current m_pVertices, or 0xffff is outside gBegin()..gEnd() 170 //! \brief OpenGL vertex type of the current m_pVertices, or 0xffff is outside gBegin()..gEnd()
171 int m_iVertexType; 171 int m_iVertexType;
172 //! \brief Maximum number of vertices begin gBegin()..gEnd() 172 //! \brief Maximum number of vertices begin gBegin()..gEnd()
173 unsigned int m_iVerticesMax; 173 unsigned int m_iVerticesMax;
174 //! \brief Vertex array to draw at gEnd(), this becomes m_pVertices[m_iVerticesMax*3] 174 //! \brief Vertex array to draw at gEnd(), this becomes m_pVertices[m_iVerticesMax*3]
175 GLfloat *m_pVertices; 175 GLfloat *m_pVertices;
176 //! \brief The current number of vertices inside m_pVertices 176 //! \brief The current number of vertices inside m_pVertices
177 unsigned int m_iVertexCount; 177 unsigned int m_iVertexCount;
178 178
179 /*! \brief Whether to use coloring in vertex lists 179 /*! \brief Whether to use coloring in vertex lists
180 * 180 *
181 * This variable must not change after Initialize(), or the program may crash. 181 * This variable must not change after Initialize(), or the program may crash.
182 * When this variable is true, color information is stored in vertex lists. If 182 * When this variable is true, color information is stored in vertex lists. If
183 * it is false, only vertex data is stored. 183 * it is false, only vertex data is stored.
184 * 184 *
185 * This variable exists for performance reasons, but is currently only set in 185 * This variable exists for performance reasons, but is currently only set in
186 * the constructor of this object. 186 * the constructor of this object.
187 */ 187 */
188 bool m_bStaticColor; 188 bool m_bStaticColor;
189 //! \brief Current color for vertex list drawing 189 //! \brief Current color for vertex list drawing
190 float m_fCurColorR, m_fCurColorG, m_fCurColorB; 190 float m_fCurColorR, m_fCurColorG, m_fCurColorB;
191 191
192 //! \brief Whether to use vertex array locking or not 192 //! \brief Whether to use vertex array locking or not
193 bool m_bVertexArrayLock; 193 bool m_bVertexArrayLock;
194 //! \brief Pointer to vertex array locking function; can be NULL. 194 //! \brief Pointer to vertex array locking function; can be NULL.
195 LOCAL_PFNGLLOCKARRAYSEXTPROC m_glLockArraysEXT; 195 LOCAL_PFNGLLOCKARRAYSEXTPROC m_glLockArraysEXT;
196 //! \brief Pointer to vertex array unlocking function; can be NULL. 196 //! \brief Pointer to vertex array unlocking function; can be NULL.
197 LOCAL_PFNGLUNLOCKARRAYSEXTPROC m_glUnlockArraysEXT; 197 LOCAL_PFNGLUNLOCKARRAYSEXTPROC m_glUnlockArraysEXT;
198 #endif 198 #endif
199 199
200 /*! \brief wxMutexGuiEnter() / wxMutexGuiLeave() wrapper 200 /*! \brief wxMutexGuiEnter() / wxMutexGuiLeave() wrapper
201 * 201 *
202 * This is a wxMutexLocker-alike for the main gui mutex. Any method that 202 * This is a wxMutexLocker-alike for the main gui mutex. Any method that
203 * is public, can be called from within another thread and does OpenGL or 203 * is public, can be called from within another thread and does OpenGL or
204 * other gui calls must use this. Example: 204 * other gui calls must use this. Example:
205 * \code 205 * \code
206 * void DoFoo() { 206 * void DoFoo() {
207 * AimwxGuiLocker __lock__; 207 * AimwxGuiLocker __lock__;
208 * glAmazingMethod(); 208 * glAmazingMethod();
209 * } 209 * }
210 * \endcode 210 * \endcode
211 * 211 *
212 * It is mostly on X-Windows (Xorg/XFree86) that the gui mutex appears to 212 * It is mostly on X-Windows (Xorg/XFree86) that the gui mutex appears to
213 * be needed. Otherwise the error "Xlib: unexpected async reply" can occur. 213 * be needed. Otherwise the error "Xlib: unexpected async reply" can occur.
214 * 214 *
215 * On windows, the ui may occasionally lock up for a short while with these 215 * On windows, the ui may occasionally lock up for a short while with these
216 * mutexes. Since they aren't really needed on that platform, it's left out 216 * mutexes. Since they aren't really needed on that platform, it's left out
217 * alltogether. 217 * alltogether.
218 */ 218 */
219 class AimwxGuiLocker { 219 class AimwxGuiLocker {
220 public: 220 public:
221 inline AimwxGuiLocker() { 221 inline AimwxGuiLocker() {
222 #ifndef _WINDOWS 222 #ifndef _WINDOWS
223 if (!wxIsMainThread()) wxMutexGuiEnter(); 223 if (!wxIsMainThread()) wxMutexGuiEnter();
224 #endif 224 #endif
225 } 225 }
226 inline ~AimwxGuiLocker() { 226 inline ~AimwxGuiLocker() {
227 #ifndef _WINDOWS 227 #ifndef _WINDOWS
228 if (!wxIsMainThread()) wxMutexGuiLeave(); 228 if (!wxIsMainThread()) wxMutexGuiLeave();
229 #endif 229 #endif
230 } 230 }
231 }; 231 };
232 DECLARE_EVENT_TABLE() 232 DECLARE_EVENT_TABLE()
233 }; 233 };
234 #endif /* __GRAPHICS_OUTPUT_DEVICE_GL_CANVAS_H__ */ 234 #endif /* __GRAPHICS_OUTPUT_DEVICE_GL_CANVAS_H__ */