annotate src/Modules/Output/Graphics/Devices/GraphicsOutputDevicewxGLCanvas.cc @ 656:263a05be98c4

Unify naming scheme for test data and clean up code that generates it.
author ronw@google.com
date Thu, 27 Jun 2013 20:48:27 +0000
parents af02b6addf7a
children
rev   line source
tomwalters@116 1 // Copyright 2006, Willem van Engen
tomwalters@116 2 //
tomwalters@116 3 // AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@116 4 // http://www.acousticscale.org/AIMC
tomwalters@116 5 //
tomwalters@116 6 // Licensed under the Apache License, Version 2.0 (the "License");
tomwalters@116 7 // you may not use this file except in compliance with the License.
tomwalters@116 8 // You may obtain a copy of the License at
tomwalters@116 9 //
tomwalters@116 10 // http://www.apache.org/licenses/LICENSE-2.0
tomwalters@116 11 //
tomwalters@116 12 // Unless required by applicable law or agreed to in writing, software
tomwalters@116 13 // distributed under the License is distributed on an "AS IS" BASIS,
tomwalters@116 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tomwalters@116 15 // See the License for the specific language governing permissions and
tomwalters@116 16 // limitations under the License.
tomwalters@116 17
tomwalters@116 18 /*!
tomwalters@116 19 * \file
tomwalters@116 20 * \brief Output device for output to a wxWidgets OpenGL canvas
tomwalters@116 21 *
tomwalters@116 22 * \author Willem van Engen <cnbh@willem.engen.nl>
tomwalters@116 23 * \date created 2006/09/21
tomwalters@116 24 * \version \$Id: $
tomwalters@116 25 */
tomwalters@116 26
tomwalters@116 27 #include "Support/Common.h"
tomwalters@116 28
tomwalters@116 29 /*! \class GraphicsOutputDevicewxGLCanvas
tomwalters@116 30 *
tomwalters@116 31 * Graphics output takes a large part of the application's performance at the
tomwalters@116 32 * moment when it is inline with the Process() loop. Much is gained by
tomwalters@116 33 * putting it in a separate thread, which can be done using ShotTargetThreaded.
tomwalters@116 34 *
tomwalters@116 35 * OpenGL-related documents:
tomwalters@116 36 * - http://www.opengl.org/
tomwalters@116 37 * - http://www.sgi.com/products/software/opengl/
tomwalters@116 38 * - http://developer.apple.com/graphicsimaging/opengl/
tomwalters@116 39 * - http://developer.nvidia.com/page/documentation.html
tomwalters@116 40 * - Vertex arrays
tomwalters@116 41 * - http://www.opengl.org/registry/specs/EXT/vertex_array.txt
tomwalters@116 42 * - http://www.awprofessional.com/articles/article.asp?p=461848&seqNum=2&rl=1
tomwalters@116 43 * - http://jdobry.webpark.cz/opengl/opengl_maximum_performance.html
tomwalters@116 44 * - Fonts and OpenGL
tomwalters@116 45 * - http://gltt.sourceforge.net/
tomwalters@116 46 */
tomwalters@116 47
tomwalters@116 48 // And finally our own
tomwalters@116 49 #include "Support/util.h"
tomwalters@116 50 #include "Output/GraphicsOutputDevice.h"
tomwalters@116 51 #include "Output/GraphicsOutputDevicewxGLCanvas.h"
tomwalters@116 52
tomwalters@116 53 BEGIN_EVENT_TABLE(GraphicsOutputDevicewxGLCanvas, wxGLCanvas)
tomwalters@116 54 EVT_SIZE(GraphicsOutputDevicewxGLCanvas::OnSize)
tomwalters@116 55 EVT_PAINT(GraphicsOutputDevicewxGLCanvas::OnPaint)
tomwalters@116 56 EVT_ERASE_BACKGROUND(GraphicsOutputDevicewxGLCanvas::OnEraseBackground)
tomwalters@116 57 END_EVENT_TABLE()
tomwalters@116 58
tomwalters@116 59 // wxGLCanvas attributes
tomwalters@116 60 int GraphicsOutputDevicewxGLCanvas::GLAttrlist[] = {
tomwalters@116 61 WX_GL_RGBA, 1,
tomwalters@116 62 WX_GL_DOUBLEBUFFER, 1,
tomwalters@116 63 WX_GL_MIN_RED, 5,
tomwalters@116 64 WX_GL_MIN_GREEN, 5,
tomwalters@116 65 WX_GL_MIN_BLUE, 5,
tomwalters@116 66 WX_GL_MIN_ALPHA, 3,
tomwalters@116 67 WX_GL_DEPTH_SIZE, 16,
tomwalters@116 68 0
tomwalters@116 69 };
tomwalters@116 70
tomwalters@116 71 // OpenGL get procaddress function pointer, differs across platforms
tomwalters@116 72 typedef void (*(*glGetProcAddressPtr_t)(const char*))();
tomwalters@116 73
tomwalters@116 74 GraphicsOutputDevicewxGLCanvas::GraphicsOutputDevicewxGLCanvas(Parameters *pParam,
tomwalters@228 75 wxWindow *parent,
tomwalters@116 76 wxWindowID id,
tomwalters@116 77 const wxPoint& pos,
tomwalters@116 78 const wxSize& size,
tomwalters@116 79 long style,
tomwalters@116 80 const wxString& name)
tomwalters@228 81 : wxGLCanvas(parent, (wxGLCanvas*) NULL, id, pos, size,
tomwalters@116 82 style|wxFULL_REPAINT_ON_RESIZE, name, GLAttrlist),
tomwalters@228 83 GraphicsOutputDevice(pParam) {
tomwalters@228 84 m_init = false;
tomwalters@228 85 m_gllist = 0;
tomwalters@228 86 m_pWorkerContext = NULL;
tomwalters@228 87 m_bAntialiasing = true;
tomwalters@228 88 m_pFont = NULL;
tomwalters@228 89 m_sFontFile = NULL;
tomwalters@228 90 m_iFontsize = -1;
tomwalters@116 91 #if !defined(_MACOSX)
tomwalters@228 92 s_bWorkerNeedsInit = false;
tomwalters@116 93 #endif
tomwalters@116 94
tomwalters@116 95 #ifdef WITH_GL_VERTEX_ARRAYS
tomwalters@228 96 m_iVertexType = 0xffff; // no gBegin() has happened yet
tomwalters@228 97 m_bStaticColor = false;
tomwalters@228 98 m_pVertices = NULL;
tomwalters@228 99 m_iVerticesMax = 0;
tomwalters@228 100 // Enable vertex arrays if possible
tomwalters@116 101 #ifdef _MACOSX
tomwalters@228 102 m_glLockArraysEXT = ::glLockArraysEXT;
tomwalters@228 103 m_glUnlockArraysEXT = ::glUnlockArraysEXT;
tomwalters@228 104 m_bVertexArrayLock = true;
tomwalters@116 105 #else
tomwalters@228 106 m_bVertexArrayLock = false;
tomwalters@228 107 // OpenGL command needed to fetch entry point, do it in InitGL()
tomwalters@116 108 #endif /* _MACOSX */
tomwalters@116 109 #endif /* WITH_GL_VERTEX_ARRAYS */
tomwalters@116 110 }
tomwalters@116 111
tomwalters@116 112 GraphicsOutputDevicewxGLCanvas::~GraphicsOutputDevicewxGLCanvas() {
tomwalters@228 113 // Cleanup OpenGL display list
tomwalters@228 114 if (m_init) {
tomwalters@228 115 glDeleteLists(m_gllist, 1);
tomwalters@228 116 }
tomwalters@228 117 DELETE_IF_NONNULL(m_pWorkerContext);
tomwalters@228 118 DELETE_IF_NONNULL(m_pFont);
tomwalters@116 119 #ifdef WITH_GL_VERTEX_ARRAYS
tomwalters@228 120 DELETE_ARRAY_IF_NONNULL(m_pVertices);
tomwalters@116 121 #endif
tomwalters@116 122 }
tomwalters@116 123
tomwalters@116 124 void GraphicsOutputDevicewxGLCanvas::Start() {
tomwalters@228 125 // This seems to be needed to prevent a crash on windows, but why????
tomwalters@228 126 SetCurrent();
tomwalters@228 127 return GraphicsOutputDevice::Start();
tomwalters@116 128 }
tomwalters@116 129
tomwalters@116 130 bool GraphicsOutputDevicewxGLCanvas::Initialize(unsigned int iVerticesMax) {
tomwalters@228 131 AIM_ASSERT(m_pParam);
tomwalters@228 132 // Give a chance to update anti-aliasing settings
tomwalters@228 133 if (m_bAntialiasing != m_pParam->GetBool("output.antialias")) {
tomwalters@228 134 m_bAntialiasing = m_pParam->GetBool("output.antialias");
tomwalters@228 135 if (SetCurrent()) {
tomwalters@228 136 InitGL();
tomwalters@116 137 #if !defined(_MACOSX)
tomwalters@228 138 {
tomwalters@228 139 wxMutexLocker lock(s_mutexOpenGL);
tomwalters@228 140 s_bWorkerNeedsInit = true;
tomwalters@228 141 }
tomwalters@116 142 #endif
tomwalters@228 143 }
tomwalters@228 144 }
tomwalters@116 145
tomwalters@116 146 #ifdef WITH_GL_VERTEX_ARRAYS
tomwalters@228 147 // Re-allocate vertices
tomwalters@228 148 if (iVerticesMax > m_iVerticesMax) {
tomwalters@228 149 DELETE_IF_NONNULL(m_pVertices);
tomwalters@228 150 m_iVerticesMax = iVerticesMax;
tomwalters@228 151 // If color is static, we need not store the color
tomwalters@228 152 if (m_bStaticColor)
tomwalters@228 153 m_pVertices = new GLfloat[(iVerticesMax+1)*3];
tomwalters@228 154 else
tomwalters@228 155 m_pVertices = new GLfloat[(iVerticesMax+1)*6];
tomwalters@228 156 }
tomwalters@116 157 #endif
tomwalters@116 158
tomwalters@116 159 // Change font if requested
tomwalters@228 160 const char *sFontFile = m_pParam->GetString("output.gl.fontfile");
tomwalters@228 161 unsigned int iFontsize = m_pParam->GetUInt("output.fontsize");
tomwalters@228 162 if (!m_sFontFile
tomwalters@116 163 || !strcmp(m_sFontFile,sFontFile)==0
tomwalters@116 164 || m_iFontsize!=(int)iFontsize) {
tomwalters@228 165 wxMutexLocker lock(s_mutexOpenGL);
tomwalters@228 166 DELETE_IF_NONNULL(m_pFont);
tomwalters@228 167 wxString sWorkingFontFilename = wxString::FromAscii(sFontFile);
tomwalters@228 168 if (!wxFileExists(sWorkingFontFilename)) {
tomwalters@228 169 sWorkingFontFilename = wxString::FromAscii(aimDataDir());
tomwalters@228 170 sWorkingFontFilename += _T("/");
tomwalters@228 171 sWorkingFontFilename += wxString::FromAscii(sFontFile);
tomwalters@228 172 }
tomwalters@228 173 //if (!wxFileExists(sWorkingFontFilename))
tomwalters@228 174 //sWorkingFontFilename.replace("Font:").append(sFontFile);
tomwalters@228 175 m_pFont = static_cast<FTFont*>(new FTGLBitmapFont(sWorkingFontFilename.fn_str()));
tomwalters@228 176 if (!m_pFont || m_pFont->Error()) {
tomwalters@228 177 aimERROR(_T("Couldn't load font '%s'"), sFontFile);
tomwalters@228 178 DELETE_IF_NONNULL(m_pFont);
tomwalters@228 179 } else {
tomwalters@228 180 // Display lists don't mix with our own usage :(
tomwalters@228 181 // May not be needed for a Bitmap font
tomwalters@228 182 //m_pFont->UseDisplayList(false);
tomwalters@228 183 if ( !m_pFont->FaceSize(iFontsize) ) {
tomwalters@228 184 AIM_ERROR(_T("Couldn't select font size %u on font '%s'"), iFontsize, sFontFile);
tomwalters@228 185 DELETE_IF_NONNULL(m_pFont);
tomwalters@228 186 }
tomwalters@228 187 }
tomwalters@228 188 m_sFontFile = sFontFile;
tomwalters@228 189 m_iFontsize = iFontsize;
tomwalters@228 190 }
tomwalters@228 191 return true;
tomwalters@116 192 }
tomwalters@116 193 bool GraphicsOutputDevicewxGLCanvas::Initialize() {
tomwalters@228 194 return Initialize(0);
tomwalters@116 195 }
tomwalters@116 196
tomwalters@116 197 void GraphicsOutputDevicewxGLCanvas::Render() {
tomwalters@228 198 wxPaintDC dc(this);
tomwalters@228 199 // We want to initialize first from main thread.
tomwalters@228 200 if (!m_init) {
tomwalters@228 201 if (!SetCurrent()) return;
tomwalters@228 202 InitGL();
tomwalters@228 203 }
tomwalters@228 204 // Render saved list only if not animating (redrawn anyway in that case)
tomwalters@228 205 if (!m_bRunning) {
tomwalters@228 206 if (!SetCurrent()) {
tomwalters@116 207 return;
tomwalters@116 208 }
tomwalters@228 209 glClear(GL_COLOR_BUFFER_BIT/*|GL_DEPTH_BUFFER_BIT*/);
tomwalters@228 210 glCallList(m_gllist);
tomwalters@228 211 SwapBuffers();
tomwalters@228 212 }
tomwalters@116 213 }
tomwalters@116 214
tomwalters@116 215 void GraphicsOutputDevicewxGLCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
tomwalters@116 216 Render();
tomwalters@116 217 }
tomwalters@116 218
tomwalters@116 219 void GraphicsOutputDevicewxGLCanvas::OnSize(wxSizeEvent& event) {
tomwalters@116 220 // this is also necessary to update the context on some platforms
tomwalters@116 221 wxGLCanvas::OnSize(event);
tomwalters@116 222
tomwalters@116 223 // set GL viewport
tomwalters@228 224 // (not called by wxGLCanvas::OnSize on all platforms...)
tomwalters@116 225 if (SetCurrent()) {
tomwalters@228 226 DoResize();
tomwalters@228 227 // It is only sensible to update the other thread when it's running
tomwalters@228 228 // Don't acquire the mutex when s_bWorkerNeedsInit already to avoid deadlock
tomwalters@228 229 if (/*m_bRunning &&*/ !s_bWorkerNeedsInit) {
tomwalters@228 230 wxMutexLocker lock(s_mutexOpenGL);
tomwalters@228 231 s_bWorkerNeedsInit = true;
tomwalters@228 232 }
tomwalters@228 233 }
tomwalters@116 234 }
tomwalters@116 235
tomwalters@116 236 void GraphicsOutputDevicewxGLCanvas::OnEraseBackground(wxEraseEvent& WXUNUSED(event)) {
tomwalters@116 237 }
tomwalters@116 238
tomwalters@116 239 bool GraphicsOutputDevicewxGLCanvas::SetCurrent() {
tomwalters@116 240 bool bRet=true;
tomwalters@116 241
tomwalters@116 242 #ifndef __WXMOTIF__
tomwalters@228 243 bRet = (GetContext()!=NULL);
tomwalters@228 244 if (bRet)
tomwalters@116 245 #endif
tomwalters@228 246 {
tomwalters@228 247 wxGLCanvas::SetCurrent();
tomwalters@228 248 }
tomwalters@228 249 return bRet;
tomwalters@116 250 }
tomwalters@116 251
tomwalters@116 252 void GraphicsOutputDevicewxGLCanvas::DoResize() {
tomwalters@116 253 int w, h;
tomwalters@228 254 GetClientSize(&w, &h);
tomwalters@228 255 glViewport(0, 0, (GLint)w, (GLint)h);
tomwalters@116 256 }
tomwalters@116 257
tomwalters@116 258 void GraphicsOutputDevicewxGLCanvas::InitGL() {
tomwalters@116 259 /* No SetCurrent() here, because this can be called from different GL contexts.
tomwalters@228 260 * Convenient for multi-threaded operation. */
tomwalters@116 261 //aimERROR(_T("InitGL Called"));
tomwalters@116 262 #if defined(WITH_GL_VERTEX_ARRAYS) && !defined(_MACOSX)
tomwalters@228 263 if (!m_init) {
tomwalters@228 264 /* This needs to be done here, because OpenGL commands may need SetCurrent()
tomwalters@228 265 * and an already shown window. */
tomwalters@228 266 char *extensions = (char *)glGetString(GL_EXTENSIONS);
tomwalters@228 267 if (!extensions) {
tomwalters@228 268 AIM_INFO(_T("Could not query OpenGL extensions, vertex arrays disabled"));
tomwalters@228 269 } else if (strstr(extensions, "GL_EXT_compiled_vertex_array")) {
tomwalters@228 270 m_glLockArraysEXT = (LOCAL_PFNGLLOCKARRAYSEXTPROC)GL_GET_PROC_ADDRESS("glLockArraysEXT");
tomwalters@228 271 m_glUnlockArraysEXT = (LOCAL_PFNGLUNLOCKARRAYSEXTPROC)GL_GET_PROC_ADDRESS("glUnlockArraysEXT");
tomwalters@237 272 if (!m_glLockArraysEXT || !m_glUnlockArraysEXT)
tomwalters@228 273 AIM_ERROR(_T("OpenGL error on GL_EXT_compiled_vertex_array"));
tomwalters@228 274 else
tomwalters@228 275 m_bVertexArrayLock = true;
tomwalters@228 276 }
tomwalters@228 277 }
tomwalters@116 278 #endif
tomwalters@228 279 DoResize();
tomwalters@228 280 glClearColor(0, 0, 0, 1);
tomwalters@228 281 glMatrixMode( GL_PROJECTION );
tomwalters@228 282 glLoadIdentity( );
tomwalters@116 283
tomwalters@228 284 glEnable(GL_VERTEX_ARRAY);
tomwalters@116 285
tomwalters@228 286 // Window limits in OpenGL co-ordiantes
tomwalters@228 287 //! \todo Make this configurable, or change and document fixed values
tomwalters@228 288 glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0);
tomwalters@228 289 glTranslatef(0.0, 0.0, 0.0);
tomwalters@116 290
tomwalters@228 291 if (m_bAntialiasing) {
tomwalters@228 292 glEnable(GL_LINE_SMOOTH);
tomwalters@228 293 glEnable(GL_BLEND);
tomwalters@228 294 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
tomwalters@228 295 //glBlendFunc(GL_ONE, GL_ONE);
tomwalters@228 296 glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
tomwalters@228 297 } else {
tomwalters@228 298 glDisable(GL_LINE_SMOOTH);
tomwalters@228 299 glDisable(GL_BLEND);
tomwalters@228 300 }
tomwalters@228 301 glLineWidth(1.0);
tomwalters@116 302
tomwalters@228 303 // Get a free display list only the first time
tomwalters@228 304 if (!m_init) {
tomwalters@116 305 #if !defined(_MACOSX)
tomwalters@228 306 // Windows and Linux need a separate worker context
tomwalters@228 307 aimASSERT(wxIsMainThread());
tomwalters@116 308 #if wxCHECK_VERSION(2,8,0)
tomwalters@228 309 m_pWorkerContext = new wxGLContext(this, m_glContext);
tomwalters@116 310 #else
tomwalters@228 311 m_pWorkerContext = new wxGLContext(true,
tomwalters@116 312 this,
tomwalters@116 313 wxNullPalette,
tomwalters@116 314 m_glContext);
tomwalters@116 315 #endif
tomwalters@228 316 aimASSERT(m_pWorkerContext);
tomwalters@228 317 s_bWorkerNeedsInit = true;
tomwalters@116 318 #endif
tomwalters@228 319 m_gllist = glGenLists(1);
tomwalters@228 320 aimASSERT(m_gllist);
tomwalters@228 321 // Empty window at start
tomwalters@228 322 glNewList(m_gllist, GL_COMPILE_AND_EXECUTE);
tomwalters@228 323 glEndList();
tomwalters@228 324 m_init = true;
tomwalters@228 325 }
tomwalters@116 326 }
tomwalters@116 327
tomwalters@116 328 // Call before any other render* functions
tomwalters@116 329 void GraphicsOutputDevicewxGLCanvas::gGrab() {
tomwalters@228 330 AimwxGuiLocker __lock__;
tomwalters@116 331 #if !defined(_MACOSX)
tomwalters@228 332 // Detect if we're the main thread or not.
tomwalters@228 333 if (!wxIsMainThread()) {
tomwalters@228 334 // We're called by a worker thread, make sure there's a right context
tomwalters@228 335 AIM_ASSERT(m_pWorkerContext);
tomwalters@116 336 #if wxCHECK_VERSION(2,8,0)
tomwalters@228 337 m_pWorkerContext->SetCurrent(*this);
tomwalters@116 338 #else
tomwalters@228 339 m_pWorkerContext->SetCurrent();
tomwalters@116 340 #endif
tomwalters@228 341 // Update OpenGL settings if needed
tomwalters@228 342 wxMutexLocker lock(s_mutexOpenGL);
tomwalters@228 343 if (s_bWorkerNeedsInit) {
tomwalters@228 344 InitGL();
tomwalters@228 345 s_bWorkerNeedsInit = false;
tomwalters@228 346 }
tomwalters@228 347 } else
tomwalters@116 348 #endif
tomwalters@228 349 {
tomwalters@228 350 // Either called by main thread, or we need no special worker glContext
tomwalters@228 351 if (!SetCurrent()) {
tomwalters@228 352 return;
tomwalters@228 353 }
tomwalters@228 354 // Init OpenGL once, but after SetCurrent
tomwalters@228 355 if (!m_init) {
tomwalters@228 356 InitGL();
tomwalters@228 357 }
tomwalters@228 358 }
tomwalters@228 359 glClear(GL_COLOR_BUFFER_BIT);
tomwalters@116 360
tomwalters@228 361 // Start and store in a display list for redrawing
tomwalters@228 362 glNewList(m_gllist, GL_COMPILE);
tomwalters@116 363 }
tomwalters@116 364
tomwalters@116 365 void GraphicsOutputDevicewxGLCanvas::gBeginLineStrip() {
tomwalters@116 366 #ifdef WITH_GL_VERTEX_ARRAYS
tomwalters@228 367 aimASSERT(m_iVertexType == 0xffff); // Previous gBegin*() must be gEnd()ed
tomwalters@228 368 // New lines vertex array
tomwalters@228 369 m_iVertexCount = 0;
tomwalters@228 370 m_iVertexType = GL_LINE_STRIP;
tomwalters@116 371 #else
tomwalters@228 372 AimwxGuiLocker __lock__;
tomwalters@228 373 glBegin(GL_LINE_STRIP);
tomwalters@116 374 #endif
tomwalters@116 375 }
tomwalters@116 376
tomwalters@116 377 void GraphicsOutputDevicewxGLCanvas::gBeginQuadStrip() {
tomwalters@116 378 #ifdef WITH_GL_VERTEX_ARRAYS
tomwalters@228 379 aimASSERT(m_iVertexType == 0xffff); // Previous gBegin*() must be gEnd()ed
tomwalters@228 380 // New quads vertex array
tomwalters@228 381 m_iVertexCount = 0;
tomwalters@228 382 m_iVertexType = GL_QUAD_STRIP;
tomwalters@116 383 #else
tomwalters@228 384 AimwxGuiLocker __lock__;
tomwalters@228 385 glBegin(GL_QUAD_STRIP);
tomwalters@116 386 #endif
tomwalters@116 387 }
tomwalters@116 388
tomwalters@116 389 void GraphicsOutputDevicewxGLCanvas::gVertex3f(float x, float y, float z) {
tomwalters@116 390 #ifdef WITH_GL_VERTEX_ARRAYS
tomwalters@228 391 aimASSERT(m_iVertexType != 0xffff); // Must be inside gBegin*()
tomwalters@228 392 if (m_iVertexCount>=m_iVerticesMax) {
tomwalters@228 393 static bool errShown=false;
tomwalters@228 394 if (!errShown) {
tomwalters@228 395 aimERROR(_T("Error: max vertex count reached: %d"), m_iVertexCount);
tomwalters@228 396 errShown=true;
tomwalters@228 397 }
tomwalters@228 398 return;
tomwalters@228 399 }
tomwalters@228 400 if (m_bStaticColor) {
tomwalters@228 401 m_pVertices[m_iVertexCount*3+0] = x;
tomwalters@228 402 m_pVertices[m_iVertexCount*3+1] = y;
tomwalters@228 403 m_pVertices[m_iVertexCount*3+2] = z;
tomwalters@228 404 } else {
tomwalters@228 405 m_pVertices[m_iVertexCount*6+0] = m_fCurColorR;
tomwalters@228 406 m_pVertices[m_iVertexCount*6+1] = m_fCurColorG;
tomwalters@228 407 m_pVertices[m_iVertexCount*6+2] = m_fCurColorB;
tomwalters@228 408 m_pVertices[m_iVertexCount*6+3] = x;
tomwalters@228 409 m_pVertices[m_iVertexCount*6+4] = y;
tomwalters@228 410 m_pVertices[m_iVertexCount*6+5] = z;
tomwalters@228 411 }
tomwalters@228 412 m_iVertexCount++;
tomwalters@116 413 #else
tomwalters@228 414 AimwxGuiLocker __lock__;
tomwalters@228 415 glVertex3f(x,y,z);
tomwalters@116 416 #endif
tomwalters@116 417 }
tomwalters@116 418
tomwalters@116 419 void GraphicsOutputDevicewxGLCanvas::gColor3f(float r, float g, float b) {
tomwalters@116 420 #ifdef WITH_GL_VERTEX_ARRAYS
tomwalters@228 421 if (m_iVertexType==0xffff || m_bStaticColor) {
tomwalters@228 422 // If not inside vertex array run, use the ordinary command
tomwalters@228 423 glColor3f(r, g, b);
tomwalters@228 424 }
tomwalters@228 425 if (!m_bStaticColor) {
tomwalters@228 426 // Set current color for vertex array usage
tomwalters@228 427 m_fCurColorR = r;
tomwalters@228 428 m_fCurColorG = g;
tomwalters@228 429 m_fCurColorB = b;
tomwalters@228 430 }
tomwalters@116 431 #else
tomwalters@228 432 AimwxGuiLocker __lock__;
tomwalters@116 433 glColor3f(r, g, b);
tomwalters@116 434 #endif
tomwalters@116 435 }
tomwalters@116 436
tomwalters@116 437 void GraphicsOutputDevicewxGLCanvas::gEnd() {
tomwalters@116 438 #ifdef WITH_GL_VERTEX_ARRAYS
tomwalters@228 439 aimASSERT(m_iVertexType != 0xffff); // Must be inside gBegin*()
tomwalters@228 440 AimwxGuiLocker __lock__;
tomwalters@116 441
tomwalters@228 442 // Draw the vertex array
tomwalters@228 443 glEnableClientState(GL_VERTEX_ARRAY);
tomwalters@116 444
tomwalters@228 445 // Draw vertices
tomwalters@228 446 if (m_bStaticColor)
tomwalters@228 447 glVertexPointer(3, GL_FLOAT, 0, m_pVertices);
tomwalters@228 448 else
tomwalters@228 449 glInterleavedArrays(GL_C3F_V3F, 0, m_pVertices);
tomwalters@228 450 if (m_bVertexArrayLock) m_glLockArraysEXT(0, m_iVertexCount);
tomwalters@228 451 glDrawArrays(m_iVertexType, 0, m_iVertexCount);
tomwalters@228 452 if (m_bVertexArrayLock) m_glUnlockArraysEXT();
tomwalters@116 453
tomwalters@228 454 glDisableClientState(GL_VERTEX_ARRAY);
tomwalters@116 455
tomwalters@228 456 // Remember we're outside a gBegin()..gEnd() loop
tomwalters@228 457 m_iVertexType = 0xffff;
tomwalters@116 458 #else
tomwalters@228 459 AimwxGuiLocker __lock__;
tomwalters@228 460 glEnd();
tomwalters@116 461 #endif
tomwalters@116 462 }
tomwalters@116 463
tomwalters@116 464 void GraphicsOutputDevicewxGLCanvas::gText3f(float x,
tomwalters@116 465 float y,
tomwalters@116 466 float z,
tomwalters@116 467 const char *sStr,
tomwalters@116 468 bool bRotated) {
tomwalters@116 469 #ifdef WITH_GL_VERTEX_ARRAYS
tomwalters@228 470 aimASSERT(m_iVertexType == 0xffff); // Must be outside gBegin*()
tomwalters@116 471 #endif
tomwalters@116 472
tomwalters@228 473 if (!m_pFont)
tomwalters@228 474 return;
tomwalters@116 475
tomwalters@228 476 //! \todo make rotation work
tomwalters@228 477 if (bRotated)
tomwalters@228 478 return;
tomwalters@116 479
tomwalters@228 480 {
tomwalters@228 481 AimwxGuiLocker __lock__;
tomwalters@228 482 /*
tomwalters@228 483 if (bRotated) {
tomwalters@228 484 glPushMatrix();
tomwalters@228 485 glTranslatef(x,y,z);
tomwalters@228 486 glRotatef(90.0f, 0, 0, 1.0f);
tomwalters@228 487 glRasterPos3f(0,0,0);
tomwalters@228 488 m_pFont->Render(sStr);
tomwalters@228 489 glPopMatrix();
tomwalters@228 490 } else {
tomwalters@228 491 */
tomwalters@228 492 glRasterPos3f(x, y, z);
tomwalters@228 493 m_pFont->Render(sStr);
tomwalters@228 494 }
tomwalters@116 495 }
tomwalters@116 496
tomwalters@116 497 void GraphicsOutputDevicewxGLCanvas::gRelease() {
tomwalters@116 498 #ifdef WITH_GL_VERTEX_ARRAYS
tomwalters@228 499 aimASSERT(m_iVertexType == 0xffff); // Must be gEnd()ed
tomwalters@116 500 #endif
tomwalters@228 501 AimwxGuiLocker __lock__;
tomwalters@228 502 glEndList();
tomwalters@228 503 glCallList(m_gllist);
tomwalters@228 504 //glFlush();
tomwalters@228 505 SwapBuffers(); // Doesn't matter in what context
tomwalters@116 506 }