source: git/src/gla.h @ 6e22f11

RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernlogstereowalls-datawalls-data-hanging-as-warning
Last change on this file since 6e22f11 was 1ada489, checked in by Olly Betts <olly@…>, 11 years ago

src/: Fix uses of some wx features which are deprecated in wx2.9.

  • Property mode set to 100644
File size: 7.8 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,2011,2012 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#include <string>
25#include <vector>
26
27using namespace std;
28
29#include "wx.h"
30#include "aventypes.h"
31#include "vector3.h"
32
33#include "glbitmapfont.h"
34
35class GfxCore;
36
37string GetGLSystemDescription();
38
39// #define GLA_DEBUG
40
41typedef Double glaCoord;
42
43typedef GLint glaTexCoord;
44
45// Colours for drawing.  Don't reorder these!
46enum gla_colour {
47    col_BLACK = 0,
48    col_GREY,
49    col_LIGHT_GREY,
50    col_LIGHT_GREY_2,
51    col_DARK_GREY,
52    col_WHITE,
53    col_TURQUOISE,
54    col_GREEN,
55    col_INDICATOR_1,
56    col_INDICATOR_2,
57    col_YELLOW,
58    col_RED,
59    col_BLUE,
60    col_LAST // must be the last entry here
61};
62
63class GLAPen {
64    friend class GLACanvas; // allow direct access to components
65
66    double components[3]; // red, green, blue
67
68public:
69    GLAPen();
70
71    void SetColour(double red, double green, double blue); // arguments in range 0 to 1.0
72    void Interpolate(const GLAPen&, double how_far);
73
74    double GetRed() const;
75    double GetGreen() const;
76    double GetBlue() const;
77};
78
79class GLAList {
80    GLuint gl_list;
81    unsigned int flags;
82  public:
83    GLAList() : gl_list(0), flags(0) { }
84    GLAList(GLuint gl_list_, unsigned int flags_)
85        : gl_list(gl_list_), flags(flags_) { }
86    operator bool() { return gl_list != 0; }
87    bool need_to_generate();
88    void finalise(unsigned int list_flags);
89    bool DrawList() const;
90    void invalidate_if(unsigned int mask) {
91        // If flags == NEVER_CACHE, the list won't be invalidated (unless
92        // mask is 0, which isn't a normal thing to pass).
93        if (flags & mask)
94            flags = 0;
95    }
96};
97
98class GLACanvas : public wxGLCanvas {
99    friend class GLAList; // For flag values.
100
101#ifdef GLA_DEBUG
102    int m_Vertices;
103#endif
104
105    GLdouble modelview_matrix[16];
106    GLdouble projection_matrix[16];
107    GLint viewport[4];
108
109    // Viewing volume diameter:
110    glaCoord m_VolumeDiameter;
111
112    // Parameters for plotting data:
113    Double m_Pan, m_Tilt;
114    Double m_Scale;
115    Vector3 m_Translation;
116
117    BitmapFont m_Font;
118
119    GLUquadric* m_Quadric;
120
121    GLuint m_Texture;
122    GLuint m_CrossTexture;
123
124    bool m_SmoothShading;
125    bool m_Textured;
126    bool m_Perspective;
127    bool m_Fog;
128    bool m_AntiAlias;
129    bool save_hints;
130    enum { UNKNOWN = 0, POINT = 'P', LINES = 'L', SPRITE = 'S' };
131    int blob_method;
132    int cross_method;
133
134    int x_size;
135    int y_size;
136
137    vector<GLAList> drawing_lists;
138
139    enum {
140        INVALIDATE_ON_SCALE = 1,
141        INVALIDATE_ON_X_RESIZE = 2,
142        INVALIDATE_ON_Y_RESIZE = 4,
143        NEVER_CACHE = 8,
144        CACHED = 16
145    };
146    mutable unsigned int list_flags;
147
148    wxString vendor, renderer;
149
150    bool CheckVisualFidelity(const unsigned char * target) const;
151
152public:
153    GLACanvas(wxWindow* parent, int id);
154    ~GLACanvas();
155
156    void FirstShow();
157
158    void Clear();
159    void StartDrawing();
160    void FinishDrawing();
161
162    void SetVolumeDiameter(glaCoord diameter);
163    void SetDataTransform();
164    void SetIndicatorTransform();
165
166    void DrawList(unsigned int l);
167    void DrawList2D(unsigned int l, glaCoord x, glaCoord y, Double rotation);
168    void InvalidateList(unsigned int l) {
169        if (l < drawing_lists.size()) {
170            // Invalidate any existing cached list.
171            drawing_lists[l].invalidate_if(CACHED);
172        }
173    }
174
175    virtual void GenerateList(unsigned int l) = 0;
176
177    void SetColour(const GLAPen& pen, double rgb_scale);
178    void SetColour(const GLAPen& pen);
179    void SetColour(gla_colour colour);
180
181    void DrawText(glaCoord x, glaCoord y, glaCoord z, const wxString& str);
182    void DrawIndicatorText(int x, int y, const wxString& str);
183    void GetTextExtent(const wxString& str, int * x_ext, int * y_ext);
184
185    void BeginQuadrilaterals();
186    void EndQuadrilaterals();
187    void BeginLines();
188    void EndLines();
189    void BeginTriangleStrip();
190    void EndTriangleStrip();
191    void BeginTriangles();
192    void EndTriangles();
193    void BeginPolyline();
194    void EndPolyline();
195    void BeginPolygon();
196    void EndPolygon();
197    void BeginBlobs();
198    void EndBlobs();
199    void BeginCrosses();
200    void EndCrosses();
201
202    void DrawRectangle(gla_colour edge, gla_colour fill,
203                       glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
204    void DrawShadedRectangle(const GLAPen & fill_bot, const GLAPen & fill_top,
205                             glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
206    void DrawCircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius);
207    void DrawSemicircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius, glaCoord start);
208    void DrawTriangle(gla_colour edge, gla_colour fill,
209                      const Vector3 &p0, const Vector3 &p1, const Vector3 &p2);
210
211    void DrawBlob(glaCoord x, glaCoord y, glaCoord z);
212    void DrawBlob(glaCoord x, glaCoord y);
213    void DrawCross(glaCoord x, glaCoord y, glaCoord z);
214    void DrawRing(glaCoord x, glaCoord y);
215
216    void PlaceVertex(const Vector3 & v, glaTexCoord tex_x, glaTexCoord tex_y) {
217        PlaceVertex(v.GetX(), v.GetY(), v.GetZ(), tex_x, tex_y);
218    }
219    void PlaceVertex(const Vector3 & v) {
220        PlaceVertex(v.GetX(), v.GetY(), v.GetZ());
221    }
222    void PlaceVertex(glaCoord x, glaCoord y, glaCoord z);
223    void PlaceVertex(glaCoord x, glaCoord y, glaCoord z,
224                     glaTexCoord tex_x, glaTexCoord tex_y);
225    void PlaceIndicatorVertex(glaCoord x, glaCoord y);
226
227    void PlaceNormal(const Vector3 &v);
228
229    void EnableDashedLines();
230    void DisableDashedLines();
231
232    void EnableSmoothPolygons(bool filled);
233    void DisableSmoothPolygons();
234
235    void SetRotation(double pan, double tilt) {
236        m_Pan = pan;
237        m_Tilt = tilt;
238    }
239    void SetScale(Double);
240    void SetTranslation(const Vector3 &v) {
241        m_Translation = v;
242    }
243    void AddTranslation(const Vector3 &v) {
244        m_Translation += v;
245    }
246    const Vector3 & GetTranslation() const {
247        return m_Translation;
248    }
249    void AddTranslationScreenCoordinates(int dx, int dy);
250
251    bool Transform(const Vector3 & v, double* x_out, double* y_out, double* z_out) const;
252    void ReverseTransform(Double x, Double y, double* x_out, double* y_out, double* z_out) const;
253
254    int GetFontSize() const { return m_Font.get_font_size(); }
255
256    void ToggleSmoothShading();
257    bool GetSmoothShading() const { return m_SmoothShading; }
258
259    Double SurveyUnitsAcrossViewport() const;
260
261    void ToggleTextured();
262    bool GetTextured() const { return m_Textured; }
263
264    void TogglePerspective() { m_Perspective = !m_Perspective; }
265    bool GetPerspective() const { return m_Perspective; }
266
267    void ToggleFog() { m_Fog = !m_Fog; }
268    bool GetFog() const { return m_Fog; }
269
270    void ToggleAntiAlias() { m_AntiAlias = !m_AntiAlias; }
271    bool GetAntiAlias() const { return m_AntiAlias; }
272
273    bool SaveScreenshot(const wxString & fnm, wxBitmapType type) const;
274
275    void ReadPixels(int width, int height, unsigned char * buf) const;
276
277    void PolygonOffset(bool on) const;
278
279    int GetXSize() const { list_flags |= INVALIDATE_ON_X_RESIZE; return x_size; }
280    int GetYSize() const { list_flags |= INVALIDATE_ON_Y_RESIZE; return y_size; }
281
282    void OnSize(wxSizeEvent & event);
283
284    glaCoord GetVolumeDiameter() const { return m_VolumeDiameter; }
285
286private:
287    DECLARE_EVENT_TABLE()
288};
Note: See TracBrowser for help on using the repository browser.