source: git/src/gla.h @ 9fcc81a

RELEASE/1.2debug-cidebug-ci-sanitiserswalls-datawalls-data-hanging-as-warning
Last change on this file since 9fcc81a was 0642381, checked in by Olly Betts <olly@…>, 6 years ago

Highlight surveys on survey tree mouseover

This is cleaner than running a search to highlight them, and means
we can restore "double-click survey in tree to zoom".

  • Property mode set to 100644
File size: 8.2 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,
[aa048c3]63    col_LAST // must be the last entry here
64};
65
[56da40e]66class GLAPen {
[aa048c3]67    friend class GLACanvas; // allow direct access to components
68
69    double components[3]; // red, green, blue
[9cf3688]70
[56da40e]71public:
72    GLAPen();
73
74    void SetColour(double red, double green, double blue); // arguments in range 0 to 1.0
[f383708]75    void Interpolate(const GLAPen&, double how_far);
[56da40e]76
[f7ea0e1]77    double GetRed() const;
78    double GetGreen() const;
79    double GetBlue() const;
[56da40e]80};
81
[db59b02]82class GLAList {
83    GLuint gl_list;
84    unsigned int flags;
85  public:
86    GLAList() : gl_list(0), flags(0) { }
87    GLAList(GLuint gl_list_, unsigned int flags_)
88        : gl_list(gl_list_), flags(flags_) { }
89    operator bool() { return gl_list != 0; }
[620c0c9]90    bool need_to_generate();
91    void finalise(unsigned int list_flags);
92    bool DrawList() const;
[b3f1bbe]93    void invalidate_if(unsigned int mask) {
94        // If flags == NEVER_CACHE, the list won't be invalidated (unless
95        // mask is 0, which isn't a normal thing to pass).
96        if (flags & mask)
97            flags = 0;
98    }
[db59b02]99};
100
[56da40e]101class GLACanvas : public wxGLCanvas {
[b3f1bbe]102    friend class GLAList; // For flag values.
[620c0c9]103
[8c048fa]104    wxGLContext ctx;
105
[203d2a7]106#ifdef GLA_DEBUG
107    int m_Vertices;
108#endif
109
[dde4fe7]110    GLdouble modelview_matrix[16];
111    GLdouble projection_matrix[16];
112    GLint viewport[4];
113
[c5fc8eb]114    // Viewing volume diameter:
115    glaCoord m_VolumeDiameter;
[56da40e]116
117    // Parameters for plotting data:
[08253d9]118    Double m_Pan, m_Tilt;
[56da40e]119    Double m_Scale;
[d67450e]120    Vector3 m_Translation;
[56da40e]121
[1aa3fb7]122    BitmapFont m_Font;
[d9b3270]123
[1b12b82]124    GLUquadric* m_Quadric;
[a517825]125
126    GLuint m_Texture;
[cab6f11]127    GLuint m_BlobTexture;
[95ce35f]128    GLuint m_CrossTexture;
[a517825]129
[4a1cede]130    Double alpha;
131
[d67450e]132    bool m_SmoothShading;
[a517825]133    bool m_Textured;
[1eeb55a]134    bool m_Perspective;
[c60062d]135    bool m_Fog;
[db452ae]136    bool m_AntiAlias;
[807f9dd]137    bool save_hints;
[fe075d7]138    enum { UNKNOWN = 0, POINT = 'P', LINES = 'L', SPRITE = 'S' };
139    int blob_method;
140    int cross_method;
[1eeb55a]141
[90430f2]142    int x_size;
143    int y_size;
144
[db59b02]145    vector<GLAList> drawing_lists;
[90430f2]146
147    enum {
148        INVALIDATE_ON_SCALE = 1,
149        INVALIDATE_ON_X_RESIZE = 2,
150        INVALIDATE_ON_Y_RESIZE = 4,
[620c0c9]151        NEVER_CACHE = 8,
152        CACHED = 16
[90430f2]153    };
[db59b02]154    mutable unsigned int list_flags;
[bae6a7c]155
[807f9dd]156    wxString vendor, renderer;
157
158    bool CheckVisualFidelity(const unsigned char * target) const;
159
[56da40e]160public:
[84f1ed1]161    GLACanvas(wxWindow* parent, int id);
[56da40e]162    ~GLACanvas();
[2c8b64f]163
[caa5fda]164    static bool check_visual();
165
[1b12b82]166    void FirstShow();
167
[56da40e]168    void Clear();
169    void StartDrawing();
170    void FinishDrawing();
171
[c5fc8eb]172    void SetVolumeDiameter(glaCoord diameter);
[56da40e]173    void SetDataTransform();
174    void SetIndicatorTransform();
[9cf3688]175
[d2fcc9b]176    void DrawList(unsigned int l);
[11fe902]177    void DrawListZPrepass(unsigned int l);
[76dd228]178    void DrawList2D(unsigned int l, glaCoord x, glaCoord y, Double rotation);
[b3f1bbe]179    void InvalidateList(unsigned int l) {
180        if (l < drawing_lists.size()) {
181            // Invalidate any existing cached list.
182            drawing_lists[l].invalidate_if(CACHED);
183        }
184    }
185
[d2fcc9b]186    virtual void GenerateList(unsigned int l) = 0;
[9cf3688]187
[aa048c3]188    void SetColour(const GLAPen& pen, double rgb_scale);
189    void SetColour(const GLAPen& pen);
[d1ce9bd]190    void SetColour(gla_colour colour, double rgb_scale);
[aa048c3]191    void SetColour(gla_colour colour);
[4a1cede]192    void SetAlpha(double new_alpha) { alpha = new_alpha; }
[aa048c3]193
[56da40e]194    void DrawText(glaCoord x, glaCoord y, glaCoord z, const wxString& str);
[1eeb55a]195    void DrawIndicatorText(int x, int y, const wxString& str);
[dbd50e2]196    void GetTextExtent(const wxString& str, int * x_ext, int * y_ext) const;
[9cf3688]197
[56da40e]198    void BeginQuadrilaterals();
199    void EndQuadrilaterals();
200    void BeginLines();
201    void EndLines();
[dde4fe7]202    void BeginTriangleStrip();
203    void EndTriangleStrip();
[56da40e]204    void BeginTriangles();
205    void EndTriangles();
206    void BeginPolyline();
207    void EndPolyline();
[0642381]208    void BeginPolyloop();
209    void EndPolyloop();
[45aa1d6]210    void BeginPolygon();
211    void EndPolygon();
[e633bb1]212    void BeginBlobs();
213    void EndBlobs();
[86fe6e4]214    void BeginCrosses();
215    void EndCrosses();
[9cf3688]216
[522e0bd]217    void DrawRectangle(gla_colour fill, gla_colour edge,
[d67450e]218                       glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
[aa048c3]219    void DrawShadedRectangle(const GLAPen & fill_bot, const GLAPen & fill_top,
220                             glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
221    void DrawCircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius);
222    void DrawSemicircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius, glaCoord start);
[d67450e]223    void DrawTriangle(gla_colour edge, gla_colour fill,
224                      const Vector3 &p0, const Vector3 &p1, const Vector3 &p2);
[9cf3688]225
[e633bb1]226    void DrawBlob(glaCoord x, glaCoord y, glaCoord z);
[81aea4e]227    void DrawBlob(glaCoord x, glaCoord y);
[86fe6e4]228    void DrawCross(glaCoord x, glaCoord y, glaCoord z);
[e633bb1]229    void DrawRing(glaCoord x, glaCoord y);
[9cf3688]230
[f336ab9]231    void PlaceVertex(const Vector3 & v, glaTexCoord tex_x, glaTexCoord tex_y) {
[b839829]232        PlaceVertex(v.GetX(), v.GetY(), v.GetZ(), tex_x, tex_y);
233    }
[d67450e]234    void PlaceVertex(const Vector3 & v) {
235        PlaceVertex(v.GetX(), v.GetY(), v.GetZ());
236    }
[56da40e]237    void PlaceVertex(glaCoord x, glaCoord y, glaCoord z);
[f336ab9]238    void PlaceVertex(glaCoord x, glaCoord y, glaCoord z,
239                     glaTexCoord tex_x, glaTexCoord tex_y);
[56da40e]240    void PlaceIndicatorVertex(glaCoord x, glaCoord y);
[203d2a7]241
[d67450e]242    void PlaceNormal(const Vector3 &v);
[9cf3688]243
[56da40e]244    void EnableDashedLines();
245    void DisableDashedLines();
246
[d67450e]247    void EnableSmoothPolygons(bool filled);
[1b12b82]248    void DisableSmoothPolygons();
249
[08253d9]250    void SetRotation(double pan, double tilt) {
251        m_Pan = pan;
252        m_Tilt = tilt;
253    }
[56da40e]254    void SetScale(Double);
[d67450e]255    void SetTranslation(const Vector3 &v) {
256        m_Translation = v;
257    }
258    void AddTranslation(const Vector3 &v) {
259        m_Translation += v;
260    }
261    const Vector3 & GetTranslation() const {
262        return m_Translation;
263    }
[56da40e]264    void AddTranslationScreenCoordinates(int dx, int dy);
265
[f6d8375]266    bool Transform(const Vector3 & v, double* x_out, double* y_out, double* z_out) const;
267    void ReverseTransform(Double x, Double y, double* x_out, double* y_out, double* z_out) const;
[56da40e]268
[1aa3fb7]269    int GetFontSize() const { return m_Font.get_font_size(); }
[087bc72]270
[d67450e]271    void ToggleSmoothShading();
272    bool GetSmoothShading() const { return m_SmoothShading; }
273
[e7f9e99]274    Double SurveyUnitsAcrossViewport() const;
[6abab84]275
[a517825]276    void ToggleTextured();
277    bool GetTextured() const { return m_Textured; }
278
[6abab84]279    void TogglePerspective() { m_Perspective = !m_Perspective; }
280    bool GetPerspective() const { return m_Perspective; }
[045e2af]281
[c60062d]282    void ToggleFog() { m_Fog = !m_Fog; }
283    bool GetFog() const { return m_Fog; }
284
[db452ae]285    void ToggleAntiAlias() { m_AntiAlias = !m_AntiAlias; }
286    bool GetAntiAlias() const { return m_AntiAlias; }
287
[1ada489]288    bool SaveScreenshot(const wxString & fnm, wxBitmapType type) const;
[aea4f8b]289
290    void ReadPixels(int width, int height, unsigned char * buf) const;
[f9ca87c]291
292    void PolygonOffset(bool on) const;
[90430f2]293
294    int GetXSize() const { list_flags |= INVALIDATE_ON_X_RESIZE; return x_size; }
295    int GetYSize() const { list_flags |= INVALIDATE_ON_Y_RESIZE; return y_size; }
296
297    void OnSize(wxSizeEvent & event);
[70acad9]298
299    glaCoord GetVolumeDiameter() const { return m_VolumeDiameter; }
[9071cf5]300
301private:
302    DECLARE_EVENT_TABLE()
[56da40e]303};
[caa5fda]304
305#endif
Note: See TracBrowser for help on using the repository browser.