source: git/src/gla.h @ fe075d7

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

src/gla-gl.cc,src/gla.h: Cache the best method for drawing blobs
and crosses, and recheck automatically if the graphics hardware
or drivers are changed or upgraded.

git-svn-id: file:///home/survex-svn/survex/trunk@3531 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 6.9 KB
Line 
1//
2//  gla.h
3//
4//  Header file for the GLA abstraction layer.
5//
6//  Copyright (C) 2002 Mark R. Shinwell.
7//  Copyright (C) 2003,2004,2005,2006,2007 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// Use texture mapped fonts (lots faster, at least with hardware 3d)
25#define USE_FNT
26
27#include <string>
28#include <vector>
29
30using namespace std;
31
32#include "wx.h"
33#include "aventypes.h"
34#include "vector3.h"
35
36#ifdef USE_FNT
37#include "fnt.h"
38#endif
39
40class GfxCore;
41
42string GetGLSystemDescription();
43
44// #define GLA_DEBUG
45
46typedef Double glaCoord;
47
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,
62    col_BLUE,
63    col_LAST // must be the last entry here
64};
65
66class GLAPen {
67    friend class GLACanvas; // allow direct access to components
68
69    double components[3]; // red, green, blue
70
71public:
72    GLAPen();
73    ~GLAPen();
74
75    void SetColour(double red, double green, double blue); // arguments in range 0 to 1.0
76    void Interpolate(const GLAPen&, double how_far);
77
78    double GetRed() const;
79    double GetGreen() const;
80    double GetBlue() const;
81};
82
83const unsigned int INVALIDATE_ON_SCALE = 1;
84const unsigned int NEVER_CACHE = 2;
85
86class GLAList {
87    GLuint gl_list;
88    unsigned int flags;
89  public:
90    GLAList() : gl_list(0), flags(0) { }
91    GLAList(GLuint gl_list_, unsigned int flags_)
92        : gl_list(gl_list_), flags(flags_) { }
93    bool test_flag(unsigned int mask) const { return flags & mask; }
94    operator bool() { return gl_list != 0; }
95    void DrawList() const;
96    void InvalidateList();
97};
98
99class GLACanvas : public wxGLCanvas {
100#ifdef GLA_DEBUG
101    int m_Vertices;
102#endif
103
104    GLdouble modelview_matrix[16];
105    GLdouble projection_matrix[16];
106    GLint viewport[4];
107
108    // Viewing volume diameter:
109    glaCoord m_VolumeDiameter;
110
111    // Parameters for plotting data:
112    Double m_Pan, m_Tilt;
113    Double m_Scale;
114    Vector3 m_Translation;
115
116#ifdef USE_FNT
117    fntTexFont m_Font;
118#else
119    static void * const m_Font;
120    static const int m_FontSize;
121#endif
122
123    GLUquadric* m_Quadric;
124
125    GLuint m_Texture;
126    GLuint m_CrossTexture;
127
128    bool m_SmoothShading;
129    bool m_Textured;
130    bool m_Perspective;
131    bool m_Fog;
132    bool m_AntiAlias;
133    enum { UNKNOWN = 0, POINT = 'P', LINES = 'L', SPRITE = 'S' };
134    int blob_method;
135    int cross_method;
136
137    vector<GLAList> drawing_lists;
138    mutable unsigned int list_flags;
139
140public:
141    GLACanvas(wxWindow* parent, int id);
142    ~GLACanvas();
143
144    void FirstShow();
145
146    void Clear();
147    void StartDrawing();
148    void FinishDrawing();
149
150    void SetVolumeDiameter(glaCoord diameter);
151    void SetDataTransform();
152    void SetIndicatorTransform();
153
154    void DrawList(unsigned int l);
155    void DrawList2D(unsigned int l, glaCoord x, glaCoord y, Double rotation);
156    void InvalidateList(unsigned int l);
157    virtual void GenerateList(unsigned int l) = 0;
158
159    void SetBackgroundColour(float red, float green, float blue);
160    void SetColour(const GLAPen& pen, double rgb_scale);
161    void SetColour(const GLAPen& pen);
162    void SetColour(gla_colour colour);
163
164    void DrawText(glaCoord x, glaCoord y, glaCoord z, const wxString& str);
165    void DrawIndicatorText(int x, int y, const wxString& str);
166    void GetTextExtent(const wxString& str, int * x_ext, int * y_ext);
167
168    void BeginQuadrilaterals();
169    void EndQuadrilaterals();
170    void BeginLines();
171    void EndLines();
172    void BeginTriangleStrip();
173    void EndTriangleStrip();
174    void BeginTriangles();
175    void EndTriangles();
176    void BeginPolyline();
177    void EndPolyline();
178    void BeginPolygon();
179    void EndPolygon();
180    void BeginBlobs();
181    void EndBlobs();
182    void BeginCrosses();
183    void EndCrosses();
184
185    void DrawRectangle(gla_colour edge, gla_colour fill,
186                       glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
187    void DrawShadedRectangle(const GLAPen & fill_bot, const GLAPen & fill_top,
188                             glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
189    void DrawCircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius);
190    void DrawSemicircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius, glaCoord start);
191    void DrawTriangle(gla_colour edge, gla_colour fill,
192                      const Vector3 &p0, const Vector3 &p1, const Vector3 &p2);
193
194    void DrawBlob(glaCoord x, glaCoord y, glaCoord z);
195    void DrawBlob(glaCoord x, glaCoord y);
196    void DrawCross(glaCoord x, glaCoord y, glaCoord z);
197    void DrawRing(glaCoord x, glaCoord y);
198
199    void PlaceVertex(const Vector3 & v) {
200        PlaceVertex(v.GetX(), v.GetY(), v.GetZ());
201    }
202    void PlaceVertex(glaCoord x, glaCoord y, glaCoord z);
203    void PlaceIndicatorVertex(glaCoord x, glaCoord y);
204
205    void PlaceNormal(const Vector3 &v);
206
207    void EnableDashedLines();
208    void DisableDashedLines();
209
210    void EnableSmoothPolygons(bool filled);
211    void DisableSmoothPolygons();
212
213    void SetRotation(double pan, double tilt) {
214        m_Pan = pan;
215        m_Tilt = tilt;
216    }
217    void SetScale(Double);
218    void SetTranslation(const Vector3 &v) {
219        m_Translation = v;
220    }
221    void AddTranslation(const Vector3 &v) {
222        m_Translation += v;
223    }
224    const Vector3 & GetTranslation() const {
225        return m_Translation;
226    }
227    void AddTranslationScreenCoordinates(int dx, int dy);
228
229    bool Transform(const Vector3 & v, double* x_out, double* y_out, double* z_out) const;
230    void ReverseTransform(Double x, Double y, double* x_out, double* y_out, double* z_out) const;
231
232#ifdef USE_FNT
233    int GetFontSize() const { return m_Font.getFontSize(); }
234#else
235    int GetFontSize() const { return m_FontSize; }
236#endif
237
238    void ToggleSmoothShading();
239    bool GetSmoothShading() const { return m_SmoothShading; }
240
241    Double SurveyUnitsAcrossViewport() const;
242
243    void ToggleTextured();
244    bool GetTextured() const { return m_Textured; }
245
246    void TogglePerspective() { m_Perspective = !m_Perspective; }
247    bool GetPerspective() const { return m_Perspective; }
248
249    void ToggleFog() { m_Fog = !m_Fog; }
250    bool GetFog() const { return m_Fog; }
251
252    void ToggleAntiAlias() { m_AntiAlias = !m_AntiAlias; }
253    bool GetAntiAlias() const { return m_AntiAlias; }
254
255    bool SaveScreenshot(const wxString & fnm, int type) const;
256};
Note: See TracBrowser for help on using the repository browser.