source: git/src/gla-gl.cc @ 04078a7

walls-datawalls-data-hanging-as-warning
Last change on this file since 04078a7 was cf126fa, checked in by Olly Betts <olly@…>, 10 months ago

Fix OpenGL scaling on hidpi with wx3.0

Reported by Philip Balister.

  • Property mode set to 100644
File size: 49.5 KB
Line 
1//
2//  gla-gl.cc
3//
4//  OpenGL implementation for the GLA abstraction layer.
5//
6//  Copyright (C) 2002-2003,2005 Mark R. Shinwell
7//  Copyright (C) 2003-2022 Olly Betts
8//
9//  This program is free software; you can redistribute it and/or modify
10//  it under the terms of the GNU General Public License as published by
11//  the Free Software Foundation; either version 2 of the License, or
12//  (at your option) any later version.
13//
14//  This program is distributed in the hope that it will be useful,
15//  but WITHOUT ANY WARRANTY; without even the implied warranty of
16//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17//  GNU General Public License for more details.
18//
19//  You should have received a copy of the GNU General Public License
20//  along with this program; if not, write to the Free Software
21//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22//
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <wx/confbase.h>
29#include <wx/image.h>
30
31#include <algorithm>
32
33#include "aven.h"
34#include "gla.h"
35#include "gllogerror.h"
36#include "message.h"
37#include "useful.h"
38
39#ifdef HAVE_GL_GL_H
40# include <GL/gl.h>
41#elif defined HAVE_OPENGL_GL_H
42# include <OpenGL/gl.h>
43#endif
44
45#ifdef HAVE_GL_GLEXT_H
46# include <GL/glext.h>
47#elif defined HAVE_OPENGL_GLEXT_H
48# include <OpenGL/glext.h>
49#endif
50
51#ifndef GL_POINT_SIZE_MAX
52#define GL_POINT_SIZE_MAX 0x8127
53#endif
54#ifndef GL_POINT_SPRITE
55#define GL_POINT_SPRITE 0x8861
56#endif
57#ifndef GL_COORD_REPLACE
58#define GL_COORD_REPLACE 0x8862
59#endif
60// GL_POINT_SIZE_RANGE is deprecated in OpenGL 1.2 and later, and replaced by
61// GL_SMOOTH_POINT_SIZE_RANGE.
62#ifndef GL_SMOOTH_POINT_SIZE_RANGE
63#define GL_SMOOTH_POINT_SIZE_RANGE GL_POINT_SIZE_RANGE
64#endif
65// GL_POINT_SIZE_GRANULARITY is deprecated in OpenGL 1.2 and later, and
66// replaced by GL_SMOOTH_POINT_SIZE_GRANULARITY.
67#ifndef GL_SMOOTH_POINT_SIZE_GRANULARITY
68#define GL_SMOOTH_POINT_SIZE_GRANULARITY GL_POINT_SIZE_GRANULARITY
69#endif
70// GL_ALIASED_POINT_SIZE_RANGE was added in OpenGL 1.2.
71#ifndef GL_ALIASED_POINT_SIZE_RANGE
72#define GL_ALIASED_POINT_SIZE_RANGE 0x846D
73#endif
74
75using namespace std;
76
77const int BLOB_DIAMETER = 5;
78
79#define BLOB_TEXTURE \
80            o, o, o, o, o, o, o, o,\
81            o, o, o, o, o, o, o, o,\
82            o, o, I, I, I, o, o, o,\
83            o, I, I, I, I, I, o, o,\
84            o, I, I, I, I, I, o, o,\
85            o, I, I, I, I, I, o, o,\
86            o, o, I, I, I, o, o, o,\
87            o, o, o, o, o, o, o, o
88
89#define CROSS_TEXTURE \
90            o, o, o, o, o, o, o, o,\
91            I, o, o, o, o, o, I, o,\
92            o, I, o, o, o, I, o, o,\
93            o, o, I, o, I, o, o, o,\
94            o, o, o, I, o, o, o, o,\
95            o, o, I, o, I, o, o, o,\
96            o, I, o, o, o, I, o, o,\
97            I, o, o, o, o, o, I, o
98
99// Declared in gllogerror.h.
100bool opengl_initialised = false;
101
102static bool double_buffered = false;
103
104static const int* wx_gl_attribs = NULL;
105
106bool
107GLACanvas::check_visual()
108{
109    static const int wx_gl_attribs_full[] = {
110        WX_GL_DOUBLEBUFFER,
111        WX_GL_RGBA,
112        WX_GL_DEPTH_SIZE, 16,
113        0
114    };
115
116    // Use a double-buffered visual if available, as it will give much smoother
117    // animation.
118    double_buffered = true;
119    wx_gl_attribs = wx_gl_attribs_full;
120    if (!IsDisplaySupported(wx_gl_attribs)) {
121        ++wx_gl_attribs;
122        if (!IsDisplaySupported(wx_gl_attribs)) {
123            return false;
124        }
125        double_buffered = false;
126    }
127    return true;
128}
129
130string GetGLSystemDescription()
131{
132    // If OpenGL isn't initialised we may get a SEGV from glGetString.
133    if (!opengl_initialised)
134        return "No OpenGL information available yet - try opening a file.";
135    const char *p = (const char*)glGetString(GL_VERSION);
136    if (!p)
137        return "Couldn't read OpenGL version!";
138
139    string info;
140    info += "OpenGL ";
141    info += p;
142    info += '\n';
143    info += (const char*)glGetString(GL_VENDOR);
144    info += '\n';
145    info += (const char*)glGetString(GL_RENDERER);
146#if !(wxUSE_GLCANVAS_EGL-0) && \
147    (defined __WXGTK__ || defined __WXX11__ || defined __WXMOTIF__)
148    info += string_format("\nGLX %0.1f\n", wxGLCanvas::GetGLXVersion() * 0.1);
149#else
150    info += '\n';
151#endif
152
153    GLint red, green, blue;
154    glGetIntegerv(GL_RED_BITS, &red);
155    glGetIntegerv(GL_GREEN_BITS, &green);
156    glGetIntegerv(GL_BLUE_BITS, &blue);
157    GLint max_texture_size;
158    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
159    GLint max_viewport[2];
160    glGetIntegerv(GL_MAX_VIEWPORT_DIMS, max_viewport);
161    GLdouble point_size_range[2];
162    glGetDoublev(GL_SMOOTH_POINT_SIZE_RANGE, point_size_range);
163    GLdouble point_size_granularity;
164    glGetDoublev(GL_SMOOTH_POINT_SIZE_GRANULARITY, &point_size_granularity);
165    info += string_format("R%dG%dB%d\n"
166             "Max Texture size: %dx%d\n"
167             "Max Viewport size: %dx%d\n"
168             "Smooth Point Size %.3f-%.3f (granularity %.3f)",
169             (int)red, (int)green, (int)blue,
170             (int)max_texture_size, (int)max_texture_size,
171             (int)max_viewport[0], (int)max_viewport[1],
172             point_size_range[0], point_size_range[1],
173             point_size_granularity);
174    glGetDoublev(GL_ALIASED_POINT_SIZE_RANGE, point_size_range);
175    if (glGetError() != GL_INVALID_ENUM) {
176        info += string_format("\nAliased point size %.3f-%.3f",
177                              point_size_range[0], point_size_range[1]);
178    }
179
180    info += "\nDouble buffered: ";
181    if (double_buffered)
182        info += "true";
183    else
184        info += "false";
185
186    const GLubyte* gl_extensions = glGetString(GL_EXTENSIONS);
187    if (*gl_extensions) {
188        info += '\n';
189        info += (const char*)gl_extensions;
190    }
191    return info;
192}
193
194static bool
195glpoint_sprite_works()
196{
197    // Point sprites provide an easy, fast way for us to draw crosses by
198    // texture mapping GL points.
199    //
200    // If we have OpenGL >= 2.0 then we definitely have GL_POINT_SPRITE.
201    // Otherwise see if we have the GL_ARB_point_sprite or GL_NV_point_sprite
202    // extensions.
203    //
204    // The symbolic constants GL_POINT_SPRITE, GL_POINT_SPRITE_ARB, and
205    // GL_POINT_SPRITE_NV all give the same number so it doesn't matter
206    // which we use.
207    static bool glpoint_sprite = false;
208    static bool checked = false;
209    if (!checked) {
210        float maxSize = 0.0f;
211        glGetFloatv(GL_POINT_SIZE_MAX, &maxSize);
212        if (maxSize >= 8) {
213            glpoint_sprite = (atoi((const char *)glGetString(GL_VERSION)) >= 2);
214            if (!glpoint_sprite) {
215                const char * p = (const char *)glGetString(GL_EXTENSIONS);
216                while (true) {
217                    size_t l = 0;
218                    if (memcmp(p, "GL_ARB_point_sprite", 19) == 0) {
219                        l = 19;
220                    } else if (memcmp(p, "GL_NV_point_sprite", 18) == 0) {
221                        l = 18;
222                    }
223                    if (l) {
224                        p += l;
225                        if (*p == '\0' || *p == ' ') {
226                            glpoint_sprite = true;
227                            break;
228                        }
229                    }
230                    p = strchr(p + 1, ' ');
231                    if (!p) break;
232                    ++p;
233                }
234            }
235        }
236        checked = true;
237    }
238    return glpoint_sprite;
239}
240
241void
242log_gl_error(const wxChar * str, GLenum error_code)
243{
244    wxString msg;
245    switch (error_code) {
246        case GL_INVALID_ENUM:
247            msg = "Invalid OpenGL enumerated value";
248            break;
249        case GL_INVALID_VALUE:
250            msg = "Invalid OpenGL numeric argument value";
251            break;
252        case GL_INVALID_OPERATION:
253            msg = "Invalid OpenGL operation";
254            break;
255        case GL_INVALID_FRAMEBUFFER_OPERATION:
256            msg = "Invalid OpenGL framebuffer operation";
257            break;
258        case GL_OUT_OF_MEMORY:
259            msg = wmsg(/*Out of memory*/389);
260            break;
261        case GL_STACK_UNDERFLOW:
262            msg = "OpenGL stack underflow";
263            break;
264        case GL_STACK_OVERFLOW:
265            msg = "OpenGL stack overflow";
266            break;
267        default:
268            msg.Format("Unknown OpenGL error code: %d", int(error_code));
269            break;
270    }
271    wxLogError(str, msg);
272}
273
274//
275//  GLAPen
276//
277
278GLAPen::GLAPen()
279{
280    components[0] = components[1] = components[2] = 0.0;
281}
282
283void GLAPen::SetColour(double red, double green, double blue)
284{
285    components[0] = red;
286    components[1] = green;
287    components[2] = blue;
288}
289
290double GLAPen::GetRed() const
291{
292    return components[0];
293}
294
295double GLAPen::GetGreen() const
296{
297    return components[1];
298}
299
300double GLAPen::GetBlue() const
301{
302    return components[2];
303}
304
305void GLAPen::Interpolate(const GLAPen& pen, double how_far)
306{
307    components[0] += how_far * (pen.GetRed() - components[0]);
308    components[1] += how_far * (pen.GetGreen() - components[1]);
309    components[2] += how_far * (pen.GetBlue() - components[2]);
310}
311
312struct ColourTriple {
313    // RGB triple: values are from 0-255 inclusive for each component.
314    unsigned char r, g, b;
315};
316
317// Order must match that in enum gla_colour[] in gla.h.
318static const ColourTriple COLOURS[] = {
319    { 0, 0, 0 },       // black
320    { 100, 100, 100 }, // grey
321    { 180, 180, 180 }, // light grey
322    { 140, 140, 140 }, // light grey 2
323    { 90, 90, 90 },    // dark grey
324    { 255, 255, 255 }, // white
325    { 0, 100, 255},    // turquoise
326    { 0, 255, 40 },    // green
327    { 150, 205, 224 }, // indicator 1
328    { 114, 149, 160 }, // indicator 2
329    { 255, 255, 0 },   // yellow
330    { 255, 0, 0 },     // red
331    { 40, 40, 255 },   // blue
332    { 255, 0, 255 },   // magenta
333};
334
335bool GLAList::need_to_generate() {
336    // Bail out if the list is already cached, or can't usefully be cached.
337    if (flags & (GLACanvas::CACHED|GLACanvas::NEVER_CACHE))
338        return false;
339
340    // Create a new OpenGL list to hold this sequence of drawing
341    // operations.
342    if (gl_list == 0) {
343        gl_list = glGenLists(1);
344        CHECK_GL_ERROR("GLAList::need_to_generate", "glGenLists");
345#ifdef GLA_DEBUG
346        printf("glGenLists(1) returned %u\n", (unsigned)gl_list);
347#endif
348        if (gl_list == 0) {
349            // If we can't create a list for any reason, fall back to just
350            // drawing directly, and flag the list as NEVER_CACHE as there's
351            // unlikely to be much point calling glGenLists() again.
352            flags = GLACanvas::NEVER_CACHE;
353            return false;
354        }
355
356        // We should have 256 lists for font drawing and a dozen or so for 2D
357        // and 3D lists.  So something is amiss if we've generated 1000 lists,
358        // probably a infinite loop in the lazy list mechanism.
359        assert(gl_list < 1000);
360    }
361    // https://www.opengl.org/resources/faq/technical/displaylist.htm advises:
362    //
363    // "Stay away from GL_COMPILE_AND_EXECUTE mode. Instead, create the
364    // list using GL_COMPILE mode, then execute it with glCallList()."
365    glNewList(gl_list, GL_COMPILE);
366    CHECK_GL_ERROR("GLAList::need_to_generate", "glNewList");
367    return true;
368}
369
370void GLAList::finalise(unsigned int list_flags)
371{
372    glEndList();
373    CHECK_GL_ERROR("GLAList::finalise", "glEndList");
374    if (list_flags & GLACanvas::NEVER_CACHE) {
375        glDeleteLists(gl_list, 1);
376        CHECK_GL_ERROR("GLAList::finalise", "glDeleteLists");
377        gl_list = 0;
378        flags = GLACanvas::NEVER_CACHE;
379    } else {
380        flags = list_flags | GLACanvas::CACHED;
381    }
382}
383
384bool GLAList::DrawList() const {
385    if ((flags & GLACanvas::CACHED) == 0)
386        return false;
387    glCallList(gl_list);
388    CHECK_GL_ERROR("GLAList::DrawList", "glCallList");
389    return true;
390}
391
392//
393//  GLACanvas
394//
395
396BEGIN_EVENT_TABLE(GLACanvas, wxGLCanvas)
397    EVT_SIZE(GLACanvas::OnSize)
398#ifdef HAS_DPI_INDEPENDENT_PIXELS
399    EVT_MOVE(GLACanvas::OnMove)
400#endif
401END_EVENT_TABLE()
402
403// Pass wxWANTS_CHARS so that the window gets cursor keys on MS Windows.
404GLACanvas::GLACanvas(wxWindow* parent, int id)
405    : wxGLCanvas(parent, id, wx_gl_attribs, wxDefaultPosition,
406                 wxDefaultSize, wxWANTS_CHARS),
407      ctx(this), m_Translation(), blob_method(UNKNOWN), cross_method(UNKNOWN),
408      x_size(0), y_size(0)
409{
410    // Constructor.
411
412    m_Quadric = NULL;
413    m_Pan = 0.0;
414    m_Tilt = 0.0;
415    m_Scale = 0.0;
416    m_VolumeDiameter = 1.0;
417    m_SmoothShading = false;
418    m_Texture = 0;
419    m_Textured = false;
420    m_Perspective = false;
421    m_Fog = false;
422    m_AntiAlias = false;
423    list_flags = 0;
424    alpha = 1.0;
425}
426
427GLACanvas::~GLACanvas()
428{
429    // Destructor.
430
431    if (m_Quadric) {
432        gluDeleteQuadric(m_Quadric);
433        CHECK_GL_ERROR("~GLACanvas", "gluDeleteQuadric");
434    }
435}
436
437void GLACanvas::FirstShow()
438{
439#ifdef HAS_DPI_INDEPENDENT_PIXELS
440    content_scale_factor = wxGLCanvas::GetContentScaleFactor();
441#endif
442
443    // Update our record of the client area size and centre.
444    GetClientSize(&x_size, &y_size);
445    x_size *= content_scale_factor;
446    y_size *= content_scale_factor;
447    if (x_size < 1) x_size = 1;
448    if (y_size < 1) y_size = 1;
449
450    ctx.SetCurrent(*this);
451    opengl_initialised = true;
452
453    // Set the background colour of the canvas to black.
454    glClearColor(0.0, 0.0, 0.0, 1.0);
455    CHECK_GL_ERROR("FirstShow", "glClearColor");
456
457    // Set viewport.
458    glViewport(0, 0, x_size, y_size);
459    CHECK_GL_ERROR("FirstShow", "glViewport");
460
461    save_hints = false;
462
463    vendor = wxString((const char *)glGetString(GL_VENDOR), wxConvUTF8);
464    renderer = wxString((const char *)glGetString(GL_RENDERER), wxConvUTF8);
465    {
466        wxConfigBase * cfg = wxConfigBase::Get();
467        wxString s;
468        if (cfg->Read(wxT("opengl_survex"), &s, wxString()) && s == wxT(VERSION) &&
469            cfg->Read(wxT("opengl_vendor"), &s, wxString()) && s == vendor &&
470            cfg->Read(wxT("opengl_renderer"), &s, wxString()) && s == renderer) {
471            // The survex version, vendor and renderer are the same as those
472            // we cached hints for, so use those hints.
473            int v;
474            if (cfg->Read(wxT("blob_method"), &v, 0) &&
475                (v == SPRITE || v == POINT || v == LINES)) {
476                // How to draw blobs.
477                blob_method = v;
478            }
479            if (cfg->Read(wxT("cross_method"), &v, 0) &&
480                (v == SPRITE || v == LINES)) {
481                // How to draw crosses.
482                cross_method = v;
483            }
484        }
485    }
486
487    if (m_Quadric) return;
488    // One time initialisation follows.
489
490    m_Quadric = gluNewQuadric();
491    CHECK_GL_ERROR("FirstShow", "gluNewQuadric");
492    if (!m_Quadric) {
493        abort(); // FIXME need to cope somehow
494    }
495
496    glShadeModel(GL_FLAT);
497    CHECK_GL_ERROR("FirstShow", "glShadeModel");
498    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // So text works.
499    CHECK_GL_ERROR("FirstShow", "glPolygonMode");
500    //glAlphaFunc(GL_GREATER, 0.5f);
501    //CHECK_GL_ERROR("FirstShow", "glAlphaFunc");
502
503    // We want glReadPixels() to read from the front buffer (which is the
504    // default for single-buffered displays).
505    if (double_buffered) {
506        glReadBuffer(GL_FRONT);
507        CHECK_GL_ERROR("FirstShow", "glReadBuffer");
508    }
509
510    // Grey fog effect.
511    GLfloat fogcolour[4] = { 0.5, 0.5, 0.5, 1.0 };
512    glFogfv(GL_FOG_COLOR, fogcolour);
513    CHECK_GL_ERROR("FirstShow", "glFogfv");
514
515    // Linear fogging.
516    glFogi(GL_FOG_MODE, GL_LINEAR);
517    CHECK_GL_ERROR("FirstShow", "glFogi");
518
519    // Optimise for speed (compute fog per vertex).
520    glHint(GL_FOG_HINT, GL_FASTEST);
521    CHECK_GL_ERROR("FirstShow", "glHint");
522
523    // No padding on pixel packing and unpacking (default is to pad each
524    // line to a multiple of 4 bytes).
525    glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // For setting texture maps.
526    CHECK_GL_ERROR("FirstShow", "glPixelStorei GL_UNPACK_ALIGNMENT");
527    glPixelStorei(GL_PACK_ALIGNMENT, 1); // For screengrabs and movies.
528    CHECK_GL_ERROR("FirstShow", "glPixelStorei GL_PACK_ALIGNMENT");
529
530    // Load font
531    wxString path = wmsg_cfgpth();
532    path += wxCONFIG_PATH_SEPARATOR;
533    path += wxT("unifont.pixelfont");
534    if (!m_Font.load(path, content_scale_factor >= 2)) {
535        // FIXME: do something better.
536        // We have this message available: Error in format of font file “%s”
537        fprintf(stderr, "Failed to parse compiled-in font data\n");
538        exit(1);
539    }
540
541    if (blob_method == UNKNOWN) {
542        // Check if we can use GL_POINTS to plot blobs at stations.
543        GLdouble point_size_range[2];
544        glGetDoublev(GL_SMOOTH_POINT_SIZE_RANGE, point_size_range);
545        CHECK_GL_ERROR("FirstShow", "glGetDoublev GL_SMOOTH_POINT_SIZE_RANGE");
546        if (point_size_range[0] <= BLOB_DIAMETER &&
547            point_size_range[1] >= BLOB_DIAMETER) {
548            blob_method = POINT;
549        } else {
550            blob_method = glpoint_sprite_works() ? SPRITE : LINES;
551        }
552        save_hints = true;
553    }
554
555    if (blob_method == POINT) {
556        glPointSize(BLOB_DIAMETER);
557        CHECK_GL_ERROR("FirstShow", "glPointSize");
558    }
559
560    if (cross_method == UNKNOWN) {
561        cross_method = glpoint_sprite_works() ? SPRITE : LINES;
562        save_hints = true;
563    }
564
565    if (cross_method == SPRITE) {
566        glGenTextures(1, &m_CrossTexture);
567        CHECK_GL_ERROR("FirstShow", "glGenTextures");
568        glBindTexture(GL_TEXTURE_2D, m_CrossTexture);
569        CHECK_GL_ERROR("FirstShow", "glBindTexture");
570        // Cross image for drawing crosses using texture mapped point sprites.
571        const unsigned char crossteximage[128] = {
572#define o 0,0
573#define I 255,255
574            CROSS_TEXTURE
575#undef o
576#undef I
577        };
578        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
579        CHECK_GL_ERROR("FirstShow", "glPixelStorei");
580        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
581        CHECK_GL_ERROR("FirstShow", "glTexEnvi");
582        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
583        CHECK_GL_ERROR("FirstShow", "glTexParameteri GL_TEXTURE_WRAP_S");
584        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
585        CHECK_GL_ERROR("FirstShow", "glTexParameteri GL_TEXTURE_WRAP_T");
586        glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 8, 8, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, (GLvoid *)crossteximage);
587        CHECK_GL_ERROR("FirstShow", "glTexImage2D");
588        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
589        CHECK_GL_ERROR("FirstShow", "glTexParameteri GL_TEXTURE_MAG_FILTER");
590        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
591        CHECK_GL_ERROR("FirstShow", "glTexParameteri GL_TEXTURE_MIN_FILTER");
592    }
593
594    if (blob_method == SPRITE) {
595        glGenTextures(1, &m_BlobTexture);
596        CHECK_GL_ERROR("FirstShow", "glGenTextures");
597        glBindTexture(GL_TEXTURE_2D, m_BlobTexture);
598        CHECK_GL_ERROR("FirstShow", "glBindTexture");
599        // Image for drawing blobs using texture mapped point sprites.
600        const unsigned char blobteximage[128] = {
601#define o 0,0
602#define I 255,255
603            BLOB_TEXTURE
604#undef o
605#undef I
606        };
607        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
608        CHECK_GL_ERROR("FirstShow", "glPixelStorei");
609        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
610        CHECK_GL_ERROR("FirstShow", "glTexEnvi");
611        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
612        CHECK_GL_ERROR("FirstShow", "glTexParameteri GL_TEXTURE_WRAP_S");
613        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
614        CHECK_GL_ERROR("FirstShow", "glTexParameteri GL_TEXTURE_WRAP_T");
615        glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 8, 8, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, (GLvoid *)blobteximage);
616        CHECK_GL_ERROR("FirstShow", "glTexImage2D");
617        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
618        CHECK_GL_ERROR("FirstShow", "glTexParameteri GL_TEXTURE_MAG_FILTER");
619        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
620        CHECK_GL_ERROR("FirstShow", "glTexParameteri GL_TEXTURE_MIN_FILTER");
621    }
622}
623
624void GLACanvas::Clear()
625{
626    // Clear the canvas.
627
628    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
629    CHECK_GL_ERROR("Clear", "glClear");
630}
631
632void GLACanvas::ClearNative()
633{
634    // Clear the canvas to the native background colour.
635
636    wxColour background_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWFRAME);
637    glClearColor(background_colour.Red() / 255.,
638                 background_colour.Green() / 255.,
639                 background_colour.Blue() / 255.,
640                 1.0);
641    CHECK_GL_ERROR("ClearNative", "glClearColor");
642    glClear(GL_COLOR_BUFFER_BIT);
643    CHECK_GL_ERROR("ClearNative", "glClear");
644    glClearColor(0.0, 0.0, 0.0, 1.0);
645    CHECK_GL_ERROR("ClearNative", "glClearColor (2)");
646}
647
648void GLACanvas::SetScale(Double scale)
649{
650    if (scale != m_Scale) {
651        for (auto & i : drawing_lists) {
652            i.invalidate_if(INVALIDATE_ON_SCALE);
653        }
654
655        m_Scale = scale;
656    }
657}
658
659#ifdef HAS_DPI_INDEPENDENT_PIXELS
660void GLACanvas::UpdateContentScaleFactor()
661{
662    double new_content_scale_factor = wxGLCanvas::GetContentScaleFactor();
663    if (new_content_scale_factor == content_scale_factor) return;
664
665    content_scale_factor = new_content_scale_factor;
666    for (auto& i : drawing_lists) {
667        i.invalidate_if(INVALIDATE_ON_HIDPI);
668    }
669}
670
671void GLACanvas::OnMove(wxMoveEvent & event)
672{
673    UpdateContentScaleFactor();
674    event.Skip();
675}
676#endif
677
678void GLACanvas::OnSize(wxSizeEvent & event)
679{
680    UpdateContentScaleFactor();
681
682    wxSize size = event.GetSize();
683
684    auto new_w = size.GetWidth() * content_scale_factor;
685    auto new_h = size.GetHeight() * content_scale_factor;
686    // The width and height go to zero when the panel is dragged right
687    // across so we clamp them to be at least 1 to avoid problems.
688    if (new_w < 1) new_w = 1;
689    if (new_h < 1) new_h = 1;
690    unsigned int mask = 0;
691    if (new_w != x_size) mask |= INVALIDATE_ON_X_RESIZE;
692    if (new_h != y_size) mask |= INVALIDATE_ON_Y_RESIZE;
693    if (mask) {
694        x_size = new_w;
695        y_size = new_h;
696        for (auto& i : drawing_lists) {
697            i.invalidate_if(mask);
698        }
699    }
700
701    event.Skip();
702
703    if (!opengl_initialised) return;
704
705    // Set viewport.
706    glViewport(0, 0, x_size, y_size);
707    CHECK_GL_ERROR("OnSize", "glViewport");
708}
709
710void GLACanvas::AddTranslationScreenCoordinates(int dx, int dy)
711{
712    // Translate the data by a given amount, specified in screen coordinates.
713
714    // Find out how far the translation takes us in data coordinates.
715    SetDataTransform();
716
717    double x0, y0, z0;
718    double x, y, z;
719    gluUnProject(0.0, 0.0, 0.0, modelview_matrix, projection_matrix, viewport,
720                 &x0, &y0, &z0);
721    CHECK_GL_ERROR("AddTranslationScreenCoordinates", "gluUnProject");
722    gluUnProject(dx, -dy, 0.0, modelview_matrix, projection_matrix, viewport,
723                 &x, &y, &z);
724    CHECK_GL_ERROR("AddTranslationScreenCoordinates", "gluUnProject (2)");
725
726    // Apply the translation.
727    AddTranslation(Vector3(x - x0, y - y0, z - z0));
728}
729
730void GLACanvas::SetVolumeDiameter(glaCoord diameter)
731{
732    // Set the size of the data drawing volume by giving the diameter of the
733    // smallest sphere containing it.
734
735    m_VolumeDiameter = max(glaCoord(1.0), diameter);
736}
737
738void GLACanvas::StartDrawing()
739{
740    // Prepare for a redraw operation.
741
742    ctx.SetCurrent(*this);
743    glDepthMask(GL_TRUE);
744
745    if (!save_hints) return;
746
747    // We want to check on the second redraw.
748    static int draw_count = 2;
749    if (--draw_count != 0) return;
750
751    if (cross_method != LINES) {
752        SetColour(col_WHITE);
753        Clear();
754        SetDataTransform();
755        BeginCrosses();
756        DrawCross(-m_Translation.GetX(), -m_Translation.GetY(), -m_Translation.GetZ());
757        EndCrosses();
758        static const unsigned char expected_cross[64 * 3] = {
759#define o 0,0,0
760#define I 255,255,255
761            CROSS_TEXTURE
762#undef o
763#undef I
764        };
765        if (!CheckVisualFidelity(expected_cross)) {
766            cross_method = LINES;
767            save_hints = true;
768        }
769    }
770
771    if (blob_method != LINES) {
772        SetColour(col_WHITE);
773        Clear();
774        SetDataTransform();
775        BeginBlobs();
776        DrawBlob(-m_Translation.GetX(), -m_Translation.GetY(), -m_Translation.GetZ());
777        EndBlobs();
778        static const unsigned char expected_blob[64 * 3] = {
779#define o 0,0,0
780#define I 255,255,255
781            BLOB_TEXTURE
782#undef o
783#undef I
784        };
785        if (!CheckVisualFidelity(expected_blob)) {
786            blob_method = LINES;
787            save_hints = true;
788        }
789    }
790
791    wxConfigBase * cfg = wxConfigBase::Get();
792    cfg->Write(wxT("opengl_survex"), wxT(VERSION));
793    cfg->Write(wxT("opengl_vendor"), vendor);
794    cfg->Write(wxT("opengl_renderer"), renderer);
795    cfg->Write(wxT("blob_method"), blob_method);
796    cfg->Write(wxT("cross_method"), cross_method);
797    cfg->Flush();
798    save_hints = false;
799}
800
801void GLACanvas::EnableSmoothPolygons(bool filled)
802{
803    // Prepare for drawing smoothly-shaded polygons.
804    // Only use this when required (in particular lines in lists may not be
805    // coloured correctly when this is enabled).
806
807    glPushAttrib(GL_ENABLE_BIT|GL_LIGHTING_BIT|GL_POLYGON_BIT);
808    if (filled) {
809        glShadeModel(GL_SMOOTH);
810        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
811    } else {
812        glDisable(GL_LINE_SMOOTH);
813        glDisable(GL_TEXTURE_2D);
814        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
815    }
816    CHECK_GL_ERROR("EnableSmoothPolygons", "glPolygonMode");
817
818    if (filled && m_SmoothShading) {
819        static const GLfloat mat_specular[] = { 0.2, 0.2, 0.2, 1.0 };
820        static const GLfloat light_position[] = { -1.0, -1.0, -1.0, 0.0 };
821        static const GLfloat light_ambient[] = { 0.3, 0.3, 0.3, 1.0 };
822        static const GLfloat light_diffuse[] = { 0.7, 0.7, 0.7, 1.0 };
823        glEnable(GL_COLOR_MATERIAL);
824        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
825        glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 10.0);
826        glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
827        glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
828        glLightfv(GL_LIGHT0, GL_POSITION, light_position);
829        glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
830        glEnable(GL_LIGHTING);
831        glEnable(GL_LIGHT0);
832    }
833}
834
835void GLACanvas::DisableSmoothPolygons()
836{
837    glPopAttrib();
838}
839
840void GLACanvas::PlaceNormal(const Vector3 &v)
841{
842    // Add a normal (for polygons etc.)
843
844    glNormal3d(v.GetX(), v.GetY(), v.GetZ());
845}
846
847void GLACanvas::SetDataTransform()
848{
849    // Set projection.
850    glMatrixMode(GL_PROJECTION);
851    CHECK_GL_ERROR("SetDataTransform", "glMatrixMode");
852    glLoadIdentity();
853    CHECK_GL_ERROR("SetDataTransform", "glLoadIdentity");
854
855    double aspect = double(y_size) / double(x_size);
856
857    Double near_plane = 1.0;
858    if (m_Perspective) {
859        Double lr = near_plane * tan(rad(25.0));
860        Double far_plane = m_VolumeDiameter * 5 + near_plane; // FIXME: work out properly
861        Double tb = lr * aspect;
862        glFrustum(-lr, lr, -tb, tb, near_plane, far_plane);
863        CHECK_GL_ERROR("SetViewportAndProjection", "glFrustum");
864    } else {
865        near_plane = 0.0;
866        assert(m_Scale != 0.0);
867        Double lr = m_VolumeDiameter / m_Scale * 0.5;
868        Double far_plane = m_VolumeDiameter + near_plane;
869        Double tb = lr;
870        if (aspect >= 1.0) {
871            tb *= aspect;
872        } else {
873            lr /= aspect;
874        }
875        glOrtho(-lr, lr, -tb, tb, near_plane, far_plane);
876        CHECK_GL_ERROR("SetViewportAndProjection", "glOrtho");
877    }
878
879    // Set the modelview transform for drawing data.
880    glMatrixMode(GL_MODELVIEW);
881    CHECK_GL_ERROR("SetDataTransform", "glMatrixMode");
882    glLoadIdentity();
883    CHECK_GL_ERROR("SetDataTransform", "glLoadIdentity");
884    if (m_Perspective) {
885        glTranslated(0.0, 0.0, -near_plane);
886    } else {
887        glTranslated(0.0, 0.0, -0.5 * m_VolumeDiameter);
888    }
889    CHECK_GL_ERROR("SetDataTransform", "glTranslated");
890    // Get axes the correct way around (z upwards, y into screen)
891    glRotated(-90.0, 1.0, 0.0, 0.0);
892    CHECK_GL_ERROR("SetDataTransform", "glRotated");
893    glRotated(-m_Tilt, 1.0, 0.0, 0.0);
894    CHECK_GL_ERROR("SetDataTransform", "glRotated");
895    glRotated(m_Pan, 0.0, 0.0, 1.0);
896    CHECK_GL_ERROR("SetDataTransform", "CopyToOpenGL");
897    if (m_Perspective) {
898        glTranslated(m_Translation.GetX(),
899                     m_Translation.GetY(),
900                     m_Translation.GetZ());
901        CHECK_GL_ERROR("SetDataTransform", "glTranslated");
902    }
903
904    // Save projection matrix.
905    glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix);
906    CHECK_GL_ERROR("SetDataTransform", "glGetDoublev");
907
908    // Save viewport coordinates.
909    glGetIntegerv(GL_VIEWPORT, viewport);
910    CHECK_GL_ERROR("SetDataTransform", "glGetIntegerv");
911
912    // Save modelview matrix.
913    glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix);
914    CHECK_GL_ERROR("SetDataTransform", "glGetDoublev");
915
916    if (!m_Perspective) {
917        // Adjust the translation so we don't change the Z position of the model
918        double X, Y, Z;
919        gluProject(m_Translation.GetX(),
920                   m_Translation.GetY(),
921                   m_Translation.GetZ(),
922                   modelview_matrix, projection_matrix, viewport,
923                   &X, &Y, &Z);
924        double Tx, Ty, Tz;
925        gluUnProject(X, Y, 0.5, modelview_matrix, projection_matrix, viewport,
926                     &Tx, &Ty, &Tz);
927        glTranslated(Tx, Ty, Tz);
928        CHECK_GL_ERROR("SetDataTransform", "glTranslated");
929        glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix);
930    }
931
932    glEnable(GL_DEPTH_TEST);
933    CHECK_GL_ERROR("SetDataTransform", "glEnable GL_DEPTH_TEST");
934
935    if (m_Textured) {
936        glBindTexture(GL_TEXTURE_2D, m_Texture);
937        glEnable(GL_TEXTURE_2D);
938        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
939        CHECK_GL_ERROR("ToggleTextured", "glTexParameteri GL_TEXTURE_WRAP_S");
940        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
941        CHECK_GL_ERROR("ToggleTextured", "glTexParameteri GL_TEXTURE_WRAP_T");
942        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
943        CHECK_GL_ERROR("ToggleTextured", "glTexParameteri GL_TEXTURE_MAG_FILTER");
944        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
945                        GL_LINEAR_MIPMAP_LINEAR);
946        CHECK_GL_ERROR("ToggleTextured", "glTexParameteri GL_TEXTURE_MIN_FILTER");
947        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
948    } else {
949        glDisable(GL_TEXTURE_2D);
950    }
951    if (m_Fog) {
952        glFogf(GL_FOG_START, near_plane);
953        glFogf(GL_FOG_END, near_plane + m_VolumeDiameter);
954        glEnable(GL_FOG);
955    } else {
956        glDisable(GL_FOG);
957    }
958
959    glEnable(GL_BLEND);
960    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
961    if (m_AntiAlias) {
962        glEnable(GL_LINE_SMOOTH);
963    } else {
964        glDisable(GL_LINE_SMOOTH);
965    }
966}
967
968void GLACanvas::SetIndicatorTransform()
969{
970    list_flags |= NEVER_CACHE;
971
972    // Set the modelview transform and projection for drawing indicators.
973
974    glDisable(GL_DEPTH_TEST);
975    CHECK_GL_ERROR("SetIndicatorTransform", "glDisable GL_DEPTH_TEST");
976    glDisable(GL_FOG);
977    CHECK_GL_ERROR("SetIndicatorTransform", "glDisable GL_FOG");
978
979    // Just a simple 2D projection.
980    glMatrixMode(GL_PROJECTION);
981    CHECK_GL_ERROR("SetIndicatorTransform", "glMatrixMode");
982    glLoadIdentity();
983    CHECK_GL_ERROR("SetIndicatorTransform", "glLoadIdentity (2)");
984    gluOrtho2D(0, x_size, 0, y_size);
985    CHECK_GL_ERROR("SetIndicatorTransform", "gluOrtho2D");
986
987    // No modelview transform.
988    glMatrixMode(GL_MODELVIEW);
989    CHECK_GL_ERROR("SetIndicatorTransform", "glMatrixMode");
990    glLoadIdentity();
991    CHECK_GL_ERROR("SetIndicatorTransform", "glLoadIdentity");
992
993    glDisable(GL_TEXTURE_2D);
994    CHECK_GL_ERROR("SetIndicatorTransform", "glDisable GL_TEXTURE_2D");
995    glDisable(GL_BLEND);
996    CHECK_GL_ERROR("SetIndicatorTransform", "glDisable GL_BLEND");
997    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
998    CHECK_GL_ERROR("SetIndicatorTransform", "glTexParameteri GL_TEXTURE_WRAP_S");
999    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
1000    CHECK_GL_ERROR("SetIndicatorTransform", "glTexParameteri GL_TEXTURE_WRAP_T");
1001    glAlphaFunc(GL_GREATER, 0.5f);
1002    CHECK_GL_ERROR("SetIndicatorTransform", "glAlphaFunc");
1003    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1004    CHECK_GL_ERROR("SetIndicatorTransform", "glTexParameteri GL_TEXTURE_MAG_FILTER");
1005    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1006    CHECK_GL_ERROR("SetIndicatorTransform", "glTexParameteri GL_TEXTURE_MIN_FILTER");
1007    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
1008    CHECK_GL_ERROR("SetIndicatorTransform", "glHint");
1009}
1010
1011void GLACanvas::FinishDrawing()
1012{
1013    // Complete a redraw operation.
1014
1015    if (double_buffered) {
1016        SwapBuffers();
1017    } else {
1018        glFlush();
1019        CHECK_GL_ERROR("FinishDrawing", "glFlush");
1020    }
1021}
1022
1023void GLACanvas::DrawList(unsigned int l)
1024{
1025    // FIXME: uncomment to disable use of lists for debugging:
1026    // GenerateList(l); return;
1027    if (l >= drawing_lists.size()) drawing_lists.resize(l + 1);
1028
1029    // We generate the OpenGL lists lazily to minimise delays on startup.
1030    // So check if we need to generate the OpenGL list now.
1031    if (drawing_lists[l].need_to_generate()) {
1032        // Clear list_flags so that we can note what conditions to invalidate
1033        // the cached OpenGL list on.
1034        list_flags = 0;
1035
1036#ifdef GLA_DEBUG
1037        printf("generating list #%u... ", l);
1038        m_Vertices = 0;
1039#endif
1040        GenerateList(l);
1041#ifdef GLA_DEBUG
1042        printf("done (%d vertices)\n", m_Vertices);
1043#endif
1044        drawing_lists[l].finalise(list_flags);
1045    }
1046
1047    if (!drawing_lists[l].DrawList()) {
1048        // That list isn't cached (which means it probably can't usefully be
1049        // cached).
1050        GenerateList(l);
1051    }
1052}
1053
1054void GLACanvas::DrawListZPrepass(unsigned int l)
1055{
1056    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
1057    DrawList(l);
1058    glDepthMask(GL_FALSE);
1059    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1060    glDepthFunc(GL_EQUAL);
1061    DrawList(l);
1062    glDepthMask(GL_TRUE);
1063    glDepthFunc(GL_LESS);
1064}
1065
1066void GLACanvas::DrawList2D(unsigned int l, glaCoord x, glaCoord y, Double rotation)
1067{
1068    glMatrixMode(GL_PROJECTION);
1069    CHECK_GL_ERROR("DrawList2D", "glMatrixMode");
1070    glPushMatrix();
1071    CHECK_GL_ERROR("DrawList2D", "glPushMatrix");
1072    glTranslated(x, y, 0);
1073    CHECK_GL_ERROR("DrawList2D", "glTranslated");
1074    if (rotation != 0.0) {
1075        glRotated(rotation, 0, 0, -1);
1076        CHECK_GL_ERROR("DrawList2D", "glRotated");
1077    }
1078    DrawList(l);
1079    glMatrixMode(GL_PROJECTION);
1080    CHECK_GL_ERROR("DrawList2D", "glMatrixMode 2");
1081    glPopMatrix();
1082    CHECK_GL_ERROR("DrawList2D", "glPopMatrix");
1083}
1084
1085void GLACanvas::SetColour(const GLAPen& pen, double rgb_scale)
1086{
1087    // Set the colour for subsequent operations.
1088    glColor4f(pen.GetRed() * rgb_scale, pen.GetGreen() * rgb_scale,
1089              pen.GetBlue() * rgb_scale, alpha);
1090}
1091
1092void GLACanvas::SetColour(const GLAPen& pen)
1093{
1094    // Set the colour for subsequent operations.
1095    glColor4d(pen.components[0], pen.components[1], pen.components[2], alpha);
1096}
1097
1098void GLACanvas::SetColour(gla_colour colour, double rgb_scale)
1099{
1100    // Set the colour for subsequent operations.
1101    rgb_scale /= 255.0;
1102    glColor4f(COLOURS[colour].r * rgb_scale,
1103              COLOURS[colour].g * rgb_scale,
1104              COLOURS[colour].b * rgb_scale,
1105              alpha);
1106}
1107
1108void GLACanvas::SetColour(gla_colour colour)
1109{
1110    // Set the colour for subsequent operations.
1111    if (alpha == 1.0) {
1112        glColor3ubv(&COLOURS[colour].r);
1113    } else {
1114        glColor4ub(COLOURS[colour].r,
1115                   COLOURS[colour].g,
1116                   COLOURS[colour].b,
1117                   (unsigned char)(255 * alpha));
1118    }
1119}
1120
1121void GLACanvas::DrawText(glaCoord x, glaCoord y, glaCoord z, const wxString& str)
1122{
1123    // Draw a text string on the current buffer in the current font.
1124    glRasterPos3d(x, y, z);
1125    CHECK_GL_ERROR("DrawText", "glRasterPos3d");
1126    m_Font.write_string(str.data(), str.size());
1127}
1128
1129void GLACanvas::DrawIndicatorText(int x, int y, const wxString& str)
1130{
1131    glRasterPos2d(x, y);
1132    CHECK_GL_ERROR("DrawIndicatorText", "glRasterPos2d");
1133    m_Font.write_string(str.data(), str.size());
1134}
1135
1136void GLACanvas::GetTextExtent(const wxString& str, int * x_ext, int * y_ext) const
1137{
1138    m_Font.get_text_extent(str.data(), str.size(), x_ext, y_ext);
1139}
1140
1141void GLACanvas::BeginQuadrilaterals()
1142{
1143    // Commence drawing of quadrilaterals.
1144
1145    glBegin(GL_QUADS);
1146}
1147
1148void GLACanvas::EndQuadrilaterals()
1149{
1150    // Finish drawing of quadrilaterals.
1151
1152    glEnd();
1153    CHECK_GL_ERROR("EndQuadrilaterals", "glEnd GL_QUADS");
1154}
1155
1156void GLACanvas::BeginLines()
1157{
1158    // Commence drawing of a set of lines.
1159
1160    glBegin(GL_LINES);
1161}
1162
1163void GLACanvas::EndLines()
1164{
1165    // Finish drawing of a set of lines.
1166
1167    glEnd();
1168    CHECK_GL_ERROR("EndLines", "glEnd GL_LINES");
1169}
1170
1171void GLACanvas::BeginTriangles()
1172{
1173    // Commence drawing of a set of triangles.
1174
1175    glBegin(GL_TRIANGLES);
1176}
1177
1178void GLACanvas::EndTriangles()
1179{
1180    // Finish drawing of a set of triangles.
1181
1182    glEnd();
1183    CHECK_GL_ERROR("EndTriangles", "glEnd GL_TRIANGLES");
1184}
1185
1186void GLACanvas::BeginTriangleStrip()
1187{
1188    // Commence drawing of a triangle strip.
1189
1190    glBegin(GL_TRIANGLE_STRIP);
1191}
1192
1193void GLACanvas::EndTriangleStrip()
1194{
1195    // Finish drawing of a triangle strip.
1196
1197    glEnd();
1198    CHECK_GL_ERROR("EndTriangleStrip", "glEnd GL_TRIANGLE_STRIP");
1199}
1200
1201void GLACanvas::BeginPolyline()
1202{
1203    // Commence drawing of a polyline.
1204
1205    glBegin(GL_LINE_STRIP);
1206}
1207
1208void GLACanvas::EndPolyline()
1209{
1210    // Finish drawing of a polyline.
1211
1212    glEnd();
1213    CHECK_GL_ERROR("EndPolyline", "glEnd GL_LINE_STRIP");
1214}
1215
1216void GLACanvas::BeginPolyloop()
1217{
1218    // Commence drawing of a polyloop.
1219
1220    glBegin(GL_LINE_LOOP);
1221}
1222
1223void GLACanvas::EndPolyloop()
1224{
1225    // Finish drawing of a polyloop.
1226
1227    glEnd();
1228    CHECK_GL_ERROR("EndPolyloop", "glEnd GL_LINE_LOOP");
1229}
1230
1231void GLACanvas::BeginPolygon()
1232{
1233    // Commence drawing of a polygon.
1234
1235    glBegin(GL_POLYGON);
1236}
1237
1238void GLACanvas::EndPolygon()
1239{
1240    // Finish drawing of a polygon.
1241
1242    glEnd();
1243    CHECK_GL_ERROR("EndPolygon", "glEnd GL_POLYGON");
1244}
1245
1246void GLACanvas::PlaceVertex(glaCoord x, glaCoord y, glaCoord z)
1247{
1248    // Place a vertex for the current object being drawn.
1249
1250#ifdef GLA_DEBUG
1251    m_Vertices++;
1252#endif
1253    glVertex3d(x, y, z);
1254}
1255
1256void GLACanvas::PlaceVertex(glaCoord x, glaCoord y, glaCoord z,
1257                            glaTexCoord tex_x, glaTexCoord tex_y)
1258{
1259    // Place a vertex for the current object being drawn.
1260
1261#ifdef GLA_DEBUG
1262    m_Vertices++;
1263#endif
1264    glTexCoord2f(tex_x, tex_y);
1265    glVertex3d(x, y, z);
1266}
1267
1268void GLACanvas::PlaceIndicatorVertex(glaCoord x, glaCoord y)
1269{
1270    // Place a vertex for the current indicator object being drawn.
1271
1272    PlaceVertex(x, y, 0.0);
1273}
1274
1275void GLACanvas::BeginBlobs()
1276{
1277    // Commence drawing of a set of blobs.
1278    if (blob_method == SPRITE) {
1279        glPushAttrib(GL_ENABLE_BIT|GL_POINT_BIT);
1280        CHECK_GL_ERROR("BeginBlobs", "glPushAttrib");
1281        glBindTexture(GL_TEXTURE_2D, m_BlobTexture);
1282        CHECK_GL_ERROR("BeginBlobs", "glBindTexture");
1283        glEnable(GL_ALPHA_TEST);
1284        CHECK_GL_ERROR("BeginBlobs", "glEnable GL_ALPHA_TEST");
1285        glPointSize(8);
1286        CHECK_GL_ERROR("BeginBlobs", "glPointSize");
1287        glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
1288        CHECK_GL_ERROR("BeginBlobs", "glTexEnvi GL_POINT_SPRITE");
1289        glEnable(GL_TEXTURE_2D);
1290        CHECK_GL_ERROR("BeginBlobs", "glEnable GL_TEXTURE_2D");
1291        glEnable(GL_POINT_SPRITE);
1292        CHECK_GL_ERROR("BeginBlobs", "glEnable GL_POINT_SPRITE");
1293        glBegin(GL_POINTS);
1294    } else if (blob_method == POINT) {
1295        glPushAttrib(GL_ENABLE_BIT);
1296        CHECK_GL_ERROR("BeginBlobs", "glPushAttrib");
1297        glEnable(GL_ALPHA_TEST);
1298        CHECK_GL_ERROR("BeginBlobs", "glEnable GL_ALPHA_TEST");
1299        glEnable(GL_POINT_SMOOTH);
1300        CHECK_GL_ERROR("BeginBlobs", "glEnable GL_POINT_SMOOTH");
1301        glBegin(GL_POINTS);
1302    } else {
1303        glPushAttrib(GL_TRANSFORM_BIT|GL_VIEWPORT_BIT|GL_ENABLE_BIT);
1304        CHECK_GL_ERROR("BeginBlobs", "glPushAttrib");
1305        SetIndicatorTransform();
1306        glEnable(GL_DEPTH_TEST);
1307        CHECK_GL_ERROR("BeginBlobs", "glEnable GL_DEPTH_TEST");
1308        glBegin(GL_LINES);
1309    }
1310}
1311
1312void GLACanvas::EndBlobs()
1313{
1314    // Finish drawing of a set of blobs.
1315    glEnd();
1316    if (blob_method != LINES) {
1317        CHECK_GL_ERROR("EndBlobs", "glEnd GL_POINTS");
1318    } else {
1319        CHECK_GL_ERROR("EndBlobs", "glEnd GL_LINES");
1320    }
1321    glPopAttrib();
1322    CHECK_GL_ERROR("EndBlobs", "glPopAttrib");
1323}
1324
1325void GLACanvas::DrawBlob(glaCoord x, glaCoord y, glaCoord z)
1326{
1327    if (blob_method != LINES) {
1328        // Draw a marker.
1329        PlaceVertex(x, y, z);
1330    } else {
1331        double X, Y, Z;
1332        if (!Transform(Vector3(x, y, z), &X, &Y, &Z)) {
1333            printf("bad transform\n");
1334            return;
1335        }
1336        // Stuff behind us (in perspective view) will get clipped,
1337        // but we can save effort with a cheap check here.
1338        if (Z <= 0) return;
1339
1340        X -= BLOB_DIAMETER * 0.5;
1341        Y -= BLOB_DIAMETER * 0.5;
1342
1343        PlaceVertex(X, Y + 1, Z);
1344        PlaceVertex(X, Y + (BLOB_DIAMETER - 1), Z);
1345
1346        for (int i = 1; i < (BLOB_DIAMETER - 1); ++i) {
1347            PlaceVertex(X + i, Y, Z);
1348            PlaceVertex(X + i, Y + BLOB_DIAMETER, Z);
1349        }
1350
1351        PlaceVertex(X + (BLOB_DIAMETER - 1), Y + 1, Z);
1352        PlaceVertex(X + (BLOB_DIAMETER - 1), Y + (BLOB_DIAMETER - 1), Z);
1353    }
1354#ifdef GLA_DEBUG
1355    m_Vertices++;
1356#endif
1357}
1358
1359void GLACanvas::DrawBlob(glaCoord x, glaCoord y)
1360{
1361    if (blob_method != LINES) {
1362        // Draw a marker.
1363        PlaceVertex(x, y, 0);
1364    } else {
1365        x -= BLOB_DIAMETER * 0.5;
1366        y -= BLOB_DIAMETER * 0.5;
1367
1368        PlaceVertex(x, y + 1, 0);
1369        PlaceVertex(x, y + (BLOB_DIAMETER - 1), 0);
1370
1371        for (int i = 1; i < (BLOB_DIAMETER - 1); ++i) {
1372            PlaceVertex(x + i, y, 0);
1373            PlaceVertex(x + i, y + BLOB_DIAMETER, 0);
1374        }
1375
1376        PlaceVertex(x + (BLOB_DIAMETER - 1), y + 1, 0);
1377        PlaceVertex(x + (BLOB_DIAMETER - 1), y + (BLOB_DIAMETER - 1), 0);
1378    }
1379#ifdef GLA_DEBUG
1380    m_Vertices++;
1381#endif
1382}
1383
1384void GLACanvas::BeginCrosses()
1385{
1386    // Plot crosses.
1387    if (cross_method == SPRITE) {
1388        list_flags |= NEVER_CACHE;
1389        SetDataTransform();
1390        glPushAttrib(GL_ENABLE_BIT|GL_POINT_BIT);
1391        CHECK_GL_ERROR("BeginCrosses", "glPushAttrib");
1392        glBindTexture(GL_TEXTURE_2D, m_CrossTexture);
1393        CHECK_GL_ERROR("BeginCrosses", "glBindTexture");
1394        glEnable(GL_ALPHA_TEST);
1395        CHECK_GL_ERROR("BeginCrosses", "glEnable GL_ALPHA_TEST");
1396        glPointSize(8);
1397        CHECK_GL_ERROR("BeginCrosses", "glPointSize");
1398        glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
1399        CHECK_GL_ERROR("BeginCrosses", "glTexEnvi GL_POINT_SPRITE");
1400        glEnable(GL_TEXTURE_2D);
1401        CHECK_GL_ERROR("BeginCrosses", "glEnable GL_TEXTURE_2D");
1402        glEnable(GL_POINT_SPRITE);
1403        CHECK_GL_ERROR("BeginCrosses", "glEnable GL_POINT_SPRITE");
1404        glBegin(GL_POINTS);
1405    } else {
1406        // To get the crosses to appear at a constant size and orientation on
1407        // screen, we plot them in the Indicator transform coordinates (which
1408        // unfortunately means they can't be usefully put in an opengl display
1409        // list).
1410        glPushAttrib(GL_TRANSFORM_BIT|GL_VIEWPORT_BIT|GL_ENABLE_BIT);
1411        CHECK_GL_ERROR("BeginCrosses", "glPushAttrib 2");
1412        SetIndicatorTransform();
1413        // Align line drawing to pixel centres to get pixel-perfect rendering
1414        // (graphics card and driver bugs aside).
1415        glTranslated(-0.5, -0.5, 0);
1416        CHECK_GL_ERROR("BeginCrosses", "glTranslated");
1417        glEnable(GL_DEPTH_TEST);
1418        CHECK_GL_ERROR("BeginCrosses", "glEnable GL_DEPTH_TEST");
1419        glBegin(GL_LINES);
1420    }
1421}
1422
1423void GLACanvas::EndCrosses()
1424{
1425    glEnd();
1426    if (cross_method == SPRITE) {
1427        CHECK_GL_ERROR("EndCrosses", "glEnd GL_POINTS");
1428    } else {
1429        CHECK_GL_ERROR("EndCrosses", "glEnd GL_LINES");
1430    }
1431    glPopAttrib();
1432    CHECK_GL_ERROR("EndCrosses", "glPopAttrib");
1433}
1434
1435void GLACanvas::DrawCross(glaCoord x, glaCoord y, glaCoord z)
1436{
1437    if (cross_method == SPRITE) {
1438        // Draw a marker.
1439        PlaceVertex(x, y, z);
1440    } else {
1441        double X, Y, Z;
1442        if (!Transform(Vector3(x, y, z), &X, &Y, &Z)) {
1443            printf("bad transform\n");
1444            return;
1445        }
1446        // Stuff behind us (in perspective view) will get clipped,
1447        // but we can save effort with a cheap check here.
1448        if (Z <= 0) return;
1449
1450        // Round to integers before adding on the offsets for the
1451        // cross arms to avoid uneven crosses.
1452        X = rint(X);
1453        Y = rint(Y);
1454        // Need to extend lines by an extra pixel (which shouldn't get drawn by
1455        // the diamond-exit rule).
1456        PlaceVertex(X - 3, Y - 3, Z);
1457        PlaceVertex(X + 4, Y + 4, Z);
1458        PlaceVertex(X - 3, Y + 3, Z);
1459        PlaceVertex(X + 4, Y - 4, Z);
1460    }
1461#ifdef GLA_DEBUG
1462    m_Vertices++;
1463#endif
1464}
1465
1466void GLACanvas::DrawRing(glaCoord x, glaCoord y)
1467{
1468    // Draw an unfilled circle of radius 4
1469
1470    // Round to integers to get an even ring.
1471    x = rint(x);
1472    y = rint(y);
1473
1474    glBegin(GL_LINE_LOOP);
1475    PlaceIndicatorVertex(x + 3.5, y - 1.5);
1476    PlaceIndicatorVertex(x + 1.5, y - 3.5);
1477    PlaceIndicatorVertex(x - 1.5, y - 3.5);
1478    PlaceIndicatorVertex(x - 3.5, y - 1.5);
1479    PlaceIndicatorVertex(x - 3.5, y + 1.5);
1480    PlaceIndicatorVertex(x - 1.5, y + 3.5);
1481    PlaceIndicatorVertex(x + 1.5, y + 3.5);
1482    PlaceIndicatorVertex(x + 3.5, y + 1.5);
1483    glEnd();
1484    CHECK_GL_ERROR("DrawRing", "glEnd GL_LINE_LOOP");
1485}
1486
1487void GLACanvas::DrawRectangle(gla_colour fill, gla_colour edge,
1488                              glaCoord x0, glaCoord y0, glaCoord w, glaCoord h)
1489{
1490    // Draw a filled rectangle with an edge in the indicator plane.
1491    // (x0, y0) specify the bottom-left corner of the rectangle and (w, h) the
1492    // size.
1493
1494    SetColour(fill);
1495    BeginQuadrilaterals();
1496    PlaceIndicatorVertex(x0, y0);
1497    PlaceIndicatorVertex(x0 + w, y0);
1498    PlaceIndicatorVertex(x0 + w, y0 + h);
1499    PlaceIndicatorVertex(x0, y0 + h);
1500    EndQuadrilaterals();
1501
1502    if (edge != fill) {
1503        SetColour(edge);
1504        BeginPolyline();
1505        PlaceIndicatorVertex(x0, y0);
1506        PlaceIndicatorVertex(x0 + w, y0);
1507        PlaceIndicatorVertex(x0 + w, y0 + h);
1508        PlaceIndicatorVertex(x0, y0 + h);
1509        PlaceIndicatorVertex(x0, y0);
1510        EndPolyline();
1511    }
1512}
1513
1514void
1515GLACanvas::DrawShadedRectangle(const GLAPen & fill_bot, const GLAPen & fill_top,
1516                               glaCoord x0, glaCoord y0,
1517                               glaCoord w, glaCoord h)
1518{
1519    // Draw a graduated filled rectangle in the indicator plane.
1520    // (x0, y0) specify the bottom-left corner of the rectangle and (w, h) the
1521    // size.
1522
1523    glShadeModel(GL_SMOOTH);
1524    CHECK_GL_ERROR("DrawShadedRectangle", "glShadeModel GL_SMOOTH");
1525    BeginQuadrilaterals();
1526    SetColour(fill_bot);
1527    PlaceIndicatorVertex(x0, y0);
1528    PlaceIndicatorVertex(x0 + w, y0);
1529    SetColour(fill_top);
1530    PlaceIndicatorVertex(x0 + w, y0 + h);
1531    PlaceIndicatorVertex(x0, y0 + h);
1532    EndQuadrilaterals();
1533    glShadeModel(GL_FLAT);
1534    CHECK_GL_ERROR("DrawShadedRectangle", "glShadeModel GL_FLAT");
1535}
1536
1537void GLACanvas::DrawCircle(gla_colour edge, gla_colour fill,
1538                           glaCoord cx, glaCoord cy, glaCoord radius)
1539{
1540    // Draw a filled circle with an edge.
1541    SetColour(fill);
1542    glMatrixMode(GL_MODELVIEW);
1543    CHECK_GL_ERROR("DrawCircle", "glMatrixMode");
1544    glPushMatrix();
1545    CHECK_GL_ERROR("DrawCircle", "glPushMatrix");
1546    glTranslated(cx, cy, 0.0);
1547    CHECK_GL_ERROR("DrawCircle", "glTranslated");
1548    assert(m_Quadric);
1549    gluDisk(m_Quadric, 0.0, radius, 36, 1);
1550    CHECK_GL_ERROR("DrawCircle", "gluDisk");
1551    SetColour(edge);
1552    gluDisk(m_Quadric, radius - 1.0, radius, 36, 1);
1553    CHECK_GL_ERROR("DrawCircle", "gluDisk (2)");
1554    glPopMatrix();
1555    CHECK_GL_ERROR("DrawCircle", "glPopMatrix");
1556}
1557
1558void GLACanvas::DrawSemicircle(gla_colour edge, gla_colour fill,
1559                               glaCoord cx, glaCoord cy,
1560                               glaCoord radius, glaCoord start)
1561{
1562    // Draw a filled semicircle with an edge.
1563    // The semicircle extends from "start" deg to "start"+180 deg (increasing
1564    // clockwise, 0 deg upwards).
1565    SetColour(fill);
1566    glMatrixMode(GL_MODELVIEW);
1567    CHECK_GL_ERROR("DrawSemicircle", "glMatrixMode");
1568    glPushMatrix();
1569    CHECK_GL_ERROR("DrawSemicircle", "glPushMatrix");
1570    glTranslated(cx, cy, 0.0);
1571    CHECK_GL_ERROR("DrawSemicircle", "glTranslated");
1572    assert(m_Quadric);
1573    gluPartialDisk(m_Quadric, 0.0, radius, 36, 1, start, 180.0);
1574    CHECK_GL_ERROR("DrawSemicircle", "gluPartialDisk");
1575    SetColour(edge);
1576    gluPartialDisk(m_Quadric, radius - 1.0, radius, 36, 1, start, 180.0);
1577    CHECK_GL_ERROR("DrawSemicircle", "gluPartialDisk (2)");
1578    glPopMatrix();
1579    CHECK_GL_ERROR("DrawSemicircle", "glPopMatrix");
1580}
1581
1582void GLACanvas::EnableDashedLines()
1583{
1584    // Enable dashed lines, and start drawing in them.
1585
1586    glLineStipple(1, 0x3333);
1587    CHECK_GL_ERROR("EnableDashedLines", "glLineStipple");
1588    glEnable(GL_LINE_STIPPLE);
1589    CHECK_GL_ERROR("EnableDashedLines", "glEnable GL_LINE_STIPPLE");
1590}
1591
1592void GLACanvas::DisableDashedLines()
1593{
1594    glDisable(GL_LINE_STIPPLE);
1595    CHECK_GL_ERROR("DisableDashedLines", "glDisable GL_LINE_STIPPLE");
1596}
1597
1598bool GLACanvas::Transform(const Vector3 & v,
1599                          double* x_out, double* y_out, double* z_out) const
1600{
1601    // Convert from data coordinates to screen coordinates.
1602
1603    // Perform the projection.
1604    return gluProject(v.GetX(), v.GetY(), v.GetZ(),
1605                      modelview_matrix, projection_matrix, viewport,
1606                      x_out, y_out, z_out);
1607}
1608
1609void GLACanvas::ReverseTransform(Double x, Double y,
1610                                 double* x_out, double* y_out, double* z_out) const
1611{
1612    // Convert from screen coordinates to data coordinates.
1613
1614    // Perform the projection.
1615    gluUnProject(x, y, 0.0, modelview_matrix, projection_matrix, viewport,
1616                 x_out, y_out, z_out);
1617    CHECK_GL_ERROR("ReverseTransform", "gluUnProject");
1618}
1619
1620Double GLACanvas::SurveyUnitsAcrossViewport() const
1621{
1622    // Measure the current viewport in survey units, taking into account the
1623    // current display scale.
1624
1625    assert(m_Scale != 0.0);
1626    list_flags |= INVALIDATE_ON_SCALE;
1627    Double result = m_VolumeDiameter / m_Scale;
1628    if (y_size < x_size) {
1629        result = result * x_size / y_size;
1630    }
1631    return result;
1632}
1633
1634void GLACanvas::ToggleSmoothShading()
1635{
1636    m_SmoothShading = !m_SmoothShading;
1637}
1638
1639void GLACanvas::ToggleTextured()
1640{
1641    m_Textured = !m_Textured;
1642    if (m_Textured && m_Texture == 0) {
1643        glGenTextures(1, &m_Texture);
1644        CHECK_GL_ERROR("ToggleTextured", "glGenTextures");
1645
1646        glBindTexture(GL_TEXTURE_2D, m_Texture);
1647        CHECK_GL_ERROR("ToggleTextured", "glBindTexture");
1648
1649        ::wxInitAllImageHandlers();
1650
1651        wxImage img;
1652        wxString texture(wmsg_cfgpth());
1653        texture += wxCONFIG_PATH_SEPARATOR;
1654        texture += wxT("images");
1655        texture += wxCONFIG_PATH_SEPARATOR;
1656        texture += wxT("texture.png");
1657        if (!img.LoadFile(texture, wxBITMAP_TYPE_PNG)) {
1658            // FIXME
1659            fprintf(stderr, "Couldn't load image.\n");
1660            exit(1);
1661        }
1662
1663        // Generate mipmaps.
1664        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, // was GL_LUMINANCE
1665                          img.GetWidth(), img.GetHeight(),
1666                          GL_RGB, GL_UNSIGNED_BYTE, img.GetData());
1667        CHECK_GL_ERROR("ToggleTextured", "gluBuild2DMipmaps");
1668
1669        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1670        CHECK_GL_ERROR("ToggleTextured", "glTexEnvi");
1671    }
1672}
1673
1674bool GLACanvas::SaveScreenshot(const wxString & fnm, wxBitmapType type) const
1675{
1676    const int width = x_size;
1677    const int height = y_size;
1678    unsigned char *pixels = (unsigned char *)malloc(3 * width * (height + 1));
1679    if (!pixels) return false;
1680    glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *)pixels);
1681    CHECK_GL_ERROR("SaveScreenshot", "glReadPixels");
1682    unsigned char * tmp_row = pixels + 3 * width * height;
1683    // We need to flip the image vertically - this approach should be more
1684    // efficient than using wxImage::Mirror(false) as that creates a new
1685    // wxImage object.
1686    for (int y = height / 2 - 1; y >= 0; --y) {
1687        unsigned char * upper = pixels + 3 * width * y;
1688        unsigned char * lower = pixels + 3 * width * (height - y - 1);
1689        memcpy(tmp_row, upper, 3 * width);
1690        memcpy(upper, lower, 3 * width);
1691        memcpy(lower, tmp_row, 3 * width);
1692    }
1693    // NB wxImage constructor calls free(pixels) for us.
1694    wxImage grab(width, height, pixels);
1695    return grab.SaveFile(fnm, type);
1696}
1697
1698bool GLACanvas::CheckVisualFidelity(const unsigned char * target) const
1699{
1700    unsigned char pixels[3 * 8 * 8];
1701    if (double_buffered) {
1702        glReadBuffer(GL_BACK);
1703        CHECK_GL_ERROR("FirstShow", "glReadBuffer");
1704    }
1705    glReadPixels(x_size / 2 - 4, y_size / 2 - 5, 8, 8,
1706                 GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *)pixels);
1707    CHECK_GL_ERROR("CheckVisualFidelity", "glReadPixels");
1708    if (double_buffered) {
1709        glReadBuffer(GL_FRONT);
1710        CHECK_GL_ERROR("FirstShow", "glReadBuffer");
1711    }
1712#if 0
1713    // Show what got drawn and what was expected for debugging.
1714    for (int y = 0; y < 8; ++y) {
1715        for (int x = 0; x < 8; ++x) {
1716            int o = (y * 8 + x) * 3;
1717            printf("%c", pixels[o] ? 'X' : '.');
1718        }
1719        printf(" ");
1720        for (int x = 0; x < 8; ++x) {
1721            int o = (y * 8 + x) * 3;
1722            printf("%c", target[o] ? 'X' : '.');
1723        }
1724        printf("\n");
1725    }
1726#endif
1727    return (memcmp(pixels, target, sizeof(pixels)) == 0);
1728}
1729
1730void GLACanvas::ReadPixels(int width, int height, unsigned char * buf) const
1731{
1732    CHECK_GL_ERROR("ReadPixels", "glReadPixels");
1733    glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *)buf);
1734}
1735
1736void GLACanvas::PolygonOffset(bool on) const
1737{
1738    if (on) {
1739        glPolygonOffset(1.0, 1.0);
1740        glEnable(GL_POLYGON_OFFSET_FILL);
1741    } else {
1742        glDisable(GL_POLYGON_OFFSET_FILL);
1743    }
1744}
Note: See TracBrowser for help on using the repository browser.