source: git/src/gla.h

log-select
Last change on this file was ecf9e9f2, checked in by Olly Betts <olly@…>, 3 months ago

Adjust optimisation when GetContentScaleFactor?() always 1

Fixes mingw build with wx 3.2.4.

  • Property mode set to 100644
File size: 9.4 KB
RevLine 
[56da40e]1//
2//  gla.h
3//
4//  Header file for the GLA abstraction layer.
5//
6//  Copyright (C) 2002 Mark R. Shinwell.
[522e0bd]7//  Copyright (C) 2003,2004,2005,2006,2007,2011,2012,2014,2017,2018 Olly Betts
[56da40e]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
[ecbc6c18]21//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
[56da40e]22//
23
[caa5fda]24#ifndef gla_h
25#define gla_h
26
[5627cbb]27#include <string>
[bae6a7c]28#include <vector>
29
30using namespace std;
31
[56da40e]32#include "wx.h"
33#include "aventypes.h"
[08253d9]34#include "vector3.h"
[56da40e]35
[1aa3fb7]36#include "glbitmapfont.h"
[1eeb55a]37
[56da40e]38class GfxCore;
39
[5627cbb]40string GetGLSystemDescription();
[cc1a1d9]41
[d67450e]42// #define GLA_DEBUG
[1897247]43
[56da40e]44typedef Double glaCoord;
45
[ba828d4]46typedef GLfloat glaTexCoord;
[f336ab9]47
[aa048c3]48// Colours for drawing.  Don't reorder these!
49enum gla_colour {
50    col_BLACK = 0,
51    col_GREY,
52    col_LIGHT_GREY,
53    col_LIGHT_GREY_2,
54    col_DARK_GREY,
55    col_WHITE,
56    col_TURQUOISE,
57    col_GREEN,
58    col_INDICATOR_1,
59    col_INDICATOR_2,
60    col_YELLOW,
61    col_RED,
[f4c5932]62    col_BLUE,
[39b8117]63    col_MAGENTA,
[aa048c3]64    col_LAST // must be the last entry here
65};
66
[56da40e]67class GLAPen {
[aa048c3]68    friend class GLACanvas; // allow direct access to components
69
70    double components[3]; // red, green, blue
[9cf3688]71
[56da40e]72public:
73    GLAPen();
74
75    void SetColour(double red, double green, double blue); // arguments in range 0 to 1.0
[f383708]76    void Interpolate(const GLAPen&, double how_far);
[56da40e]77
[f7ea0e1]78    double GetRed() const;
79    double GetGreen() const;
80    double GetBlue() const;
[56da40e]81};
82
[db59b02]83class GLAList {
84    GLuint gl_list;
85    unsigned int flags;
86  public:
87    GLAList() : gl_list(0), flags(0) { }
88    GLAList(GLuint gl_list_, unsigned int flags_)
89        : gl_list(gl_list_), flags(flags_) { }
90    operator bool() { return gl_list != 0; }
[620c0c9]91    bool need_to_generate();
92    void finalise(unsigned int list_flags);
93    bool DrawList() const;
[b3f1bbe]94    void invalidate_if(unsigned int mask) {
95        // If flags == NEVER_CACHE, the list won't be invalidated (unless
96        // mask is 0, which isn't a normal thing to pass).
97        if (flags & mask)
98            flags = 0;
99    }
[db59b02]100};
101
[56da40e]102class GLACanvas : public wxGLCanvas {
[b3f1bbe]103    friend class GLAList; // For flag values.
[620c0c9]104
[8c048fa]105    wxGLContext ctx;
106
[203d2a7]107#ifdef GLA_DEBUG
108    int m_Vertices;
109#endif
110
[dde4fe7]111    GLdouble modelview_matrix[16];
112    GLdouble projection_matrix[16];
113    GLint viewport[4];
114
[c5fc8eb]115    // Viewing volume diameter:
116    glaCoord m_VolumeDiameter;
[56da40e]117
118    // Parameters for plotting data:
[08253d9]119    Double m_Pan, m_Tilt;
[56da40e]120    Double m_Scale;
[d67450e]121    Vector3 m_Translation;
[56da40e]122
[1aa3fb7]123    BitmapFont m_Font;
[d9b3270]124
[1b12b82]125    GLUquadric* m_Quadric;
[a517825]126
127    GLuint m_Texture;
[cab6f11]128    GLuint m_BlobTexture;
[95ce35f]129    GLuint m_CrossTexture;
[a517825]130
[4a1cede]131    Double alpha;
132
[d67450e]133    bool m_SmoothShading;
[a517825]134    bool m_Textured;
[1eeb55a]135    bool m_Perspective;
[c60062d]136    bool m_Fog;
[db452ae]137    bool m_AntiAlias;
[807f9dd]138    bool save_hints;
[fe075d7]139    enum { UNKNOWN = 0, POINT = 'P', LINES = 'L', SPRITE = 'S' };
140    int blob_method;
141    int cross_method;
[1eeb55a]142
[90430f2]143    int x_size;
144    int y_size;
145
[cf126fa]146    // wxHAS_DPI_INDEPENDENT_PIXELS is new in 3.1.6.  In older versions we just
147    // always do the scaling which is slightly less efficient for platforms
148    // where pixel coordinates don't scale with DPI.
149#if defined wxHAS_DPI_INDEPENDENT_PIXELS || \
150    !wxCHECK_VERSION(3,1,6)
151# define HAS_DPI_INDEPENDENT_PIXELS
152#endif
153
154#ifdef HAS_DPI_INDEPENDENT_PIXELS
[705adee9]155    double content_scale_factor = 1.0;
[2dacc8bd]156#else
157    static constexpr unsigned content_scale_factor = 1;
158#endif
[705adee9]159
[db59b02]160    vector<GLAList> drawing_lists;
[90430f2]161
162    enum {
163        INVALIDATE_ON_SCALE = 1,
164        INVALIDATE_ON_X_RESIZE = 2,
165        INVALIDATE_ON_Y_RESIZE = 4,
[2dacc8bd]166        INVALIDATE_ON_HIDPI = 8,
167        NEVER_CACHE = 16,
168        CACHED = 32
[90430f2]169    };
[db59b02]170    mutable unsigned int list_flags;
[bae6a7c]171
[807f9dd]172    wxString vendor, renderer;
173
174    bool CheckVisualFidelity(const unsigned char * target) const;
175
[56da40e]176public:
[84f1ed1]177    GLACanvas(wxWindow* parent, int id);
[56da40e]178    ~GLACanvas();
[2c8b64f]179
[caa5fda]180    static bool check_visual();
181
[1b12b82]182    void FirstShow();
183
[56da40e]184    void Clear();
[8a7f1c5]185    void ClearNative();
[56da40e]186    void StartDrawing();
187    void FinishDrawing();
188
[c5fc8eb]189    void SetVolumeDiameter(glaCoord diameter);
[56da40e]190    void SetDataTransform();
191    void SetIndicatorTransform();
[9cf3688]192
[d2fcc9b]193    void DrawList(unsigned int l);
[11fe902]194    void DrawListZPrepass(unsigned int l);
[76dd228]195    void DrawList2D(unsigned int l, glaCoord x, glaCoord y, Double rotation);
[b3f1bbe]196    void InvalidateList(unsigned int l) {
197        if (l < drawing_lists.size()) {
198            // Invalidate any existing cached list.
199            drawing_lists[l].invalidate_if(CACHED);
200        }
201    }
202
[d2fcc9b]203    virtual void GenerateList(unsigned int l) = 0;
[9cf3688]204
[aa048c3]205    void SetColour(const GLAPen& pen, double rgb_scale);
206    void SetColour(const GLAPen& pen);
[d1ce9bd]207    void SetColour(gla_colour colour, double rgb_scale);
[aa048c3]208    void SetColour(gla_colour colour);
[4a1cede]209    void SetAlpha(double new_alpha) { alpha = new_alpha; }
[aa048c3]210
[56da40e]211    void DrawText(glaCoord x, glaCoord y, glaCoord z, const wxString& str);
[1eeb55a]212    void DrawIndicatorText(int x, int y, const wxString& str);
[dbd50e2]213    void GetTextExtent(const wxString& str, int * x_ext, int * y_ext) const;
[9cf3688]214
[56da40e]215    void BeginQuadrilaterals();
216    void EndQuadrilaterals();
217    void BeginLines();
218    void EndLines();
[dde4fe7]219    void BeginTriangleStrip();
220    void EndTriangleStrip();
[56da40e]221    void BeginTriangles();
222    void EndTriangles();
223    void BeginPolyline();
224    void EndPolyline();
[0642381]225    void BeginPolyloop();
226    void EndPolyloop();
[45aa1d6]227    void BeginPolygon();
228    void EndPolygon();
[e633bb1]229    void BeginBlobs();
230    void EndBlobs();
[86fe6e4]231    void BeginCrosses();
232    void EndCrosses();
[9cf3688]233
[522e0bd]234    void DrawRectangle(gla_colour fill, gla_colour edge,
[d67450e]235                       glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
[aa048c3]236    void DrawShadedRectangle(const GLAPen & fill_bot, const GLAPen & fill_top,
237                             glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
238    void DrawCircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius);
239    void DrawSemicircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius, glaCoord start);
[9cf3688]240
[e633bb1]241    void DrawBlob(glaCoord x, glaCoord y, glaCoord z);
[81aea4e]242    void DrawBlob(glaCoord x, glaCoord y);
[86fe6e4]243    void DrawCross(glaCoord x, glaCoord y, glaCoord z);
[e633bb1]244    void DrawRing(glaCoord x, glaCoord y);
[9cf3688]245
[f336ab9]246    void PlaceVertex(const Vector3 & v, glaTexCoord tex_x, glaTexCoord tex_y) {
[b839829]247        PlaceVertex(v.GetX(), v.GetY(), v.GetZ(), tex_x, tex_y);
248    }
[d67450e]249    void PlaceVertex(const Vector3 & v) {
250        PlaceVertex(v.GetX(), v.GetY(), v.GetZ());
251    }
[56da40e]252    void PlaceVertex(glaCoord x, glaCoord y, glaCoord z);
[f336ab9]253    void PlaceVertex(glaCoord x, glaCoord y, glaCoord z,
254                     glaTexCoord tex_x, glaTexCoord tex_y);
[56da40e]255    void PlaceIndicatorVertex(glaCoord x, glaCoord y);
[203d2a7]256
[d67450e]257    void PlaceNormal(const Vector3 &v);
[9cf3688]258
[56da40e]259    void EnableDashedLines();
260    void DisableDashedLines();
261
[d67450e]262    void EnableSmoothPolygons(bool filled);
[1b12b82]263    void DisableSmoothPolygons();
264
[08253d9]265    void SetRotation(double pan, double tilt) {
266        m_Pan = pan;
267        m_Tilt = tilt;
268    }
[56da40e]269    void SetScale(Double);
[d67450e]270    void SetTranslation(const Vector3 &v) {
271        m_Translation = v;
272    }
273    void AddTranslation(const Vector3 &v) {
274        m_Translation += v;
275    }
276    const Vector3 & GetTranslation() const {
277        return m_Translation;
278    }
[56da40e]279    void AddTranslationScreenCoordinates(int dx, int dy);
280
[f6d8375]281    bool Transform(const Vector3 & v, double* x_out, double* y_out, double* z_out) const;
282    void ReverseTransform(Double x, Double y, double* x_out, double* y_out, double* z_out) const;
[56da40e]283
[1aa3fb7]284    int GetFontSize() const { return m_Font.get_font_size(); }
[087bc72]285
[d67450e]286    void ToggleSmoothShading();
287    bool GetSmoothShading() const { return m_SmoothShading; }
288
[e7f9e99]289    Double SurveyUnitsAcrossViewport() const;
[6abab84]290
[a517825]291    void ToggleTextured();
292    bool GetTextured() const { return m_Textured; }
293
[6abab84]294    void TogglePerspective() { m_Perspective = !m_Perspective; }
295    bool GetPerspective() const { return m_Perspective; }
[045e2af]296
[c60062d]297    void ToggleFog() { m_Fog = !m_Fog; }
298    bool GetFog() const { return m_Fog; }
299
[db452ae]300    void ToggleAntiAlias() { m_AntiAlias = !m_AntiAlias; }
301    bool GetAntiAlias() const { return m_AntiAlias; }
302
[1ada489]303    bool SaveScreenshot(const wxString & fnm, wxBitmapType type) const;
[aea4f8b]304
305    void ReadPixels(int width, int height, unsigned char * buf) const;
[f9ca87c]306
307    void PolygonOffset(bool on) const;
[90430f2]308
[2dacc8bd]309    int GetXSize() const {
310        list_flags |= INVALIDATE_ON_X_RESIZE;
311        return x_size;
312    }
313
314    int GetYSize() const {
315        list_flags |= INVALIDATE_ON_Y_RESIZE;
316        return y_size;
317    }
318
[cf126fa]319#ifdef HAS_DPI_INDEPENDENT_PIXELS
[2dacc8bd]320    double GetContentScaleFactor() const {
321        list_flags |= INVALIDATE_ON_HIDPI;
322        return content_scale_factor;
323    }
324
325    void UpdateContentScaleFactor();
326    void OnMove(wxMoveEvent & event);
327#else
328    // wxWindow::GetContentScaleFactor() will always return 1.0, so arrange
329    // things so it's a compile-time constant the compiler can optimise away.
[ecf9e9f2]330    // Use a macro so we can return unsigned instead of double without a lot
331    // of pain from trying to override a virtual method while changing the
332    // return type.
333# define GetContentScaleFactor() 1u
[2dacc8bd]334    void UpdateContentScaleFactor() { }
335#endif
[90430f2]336
337    void OnSize(wxSizeEvent & event);
[70acad9]338
339    glaCoord GetVolumeDiameter() const { return m_VolumeDiameter; }
[9071cf5]340
[705adee9]341    void ScaleMouseEvent(wxMouseEvent& e) const {
342        e.SetX(e.GetX() * content_scale_factor);
343        e.SetY(e.GetY() * content_scale_factor);
344    }
345
[9071cf5]346private:
347    DECLARE_EVENT_TABLE()
[56da40e]348};
[caa5fda]349
350#endif
Note: See TracBrowser for help on using the repository browser.