source: git/src/gla.h @ 53496ab3

RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-data
Last change on this file since 53496ab3 was 4a1cede, checked in by Olly Betts <olly@…>, 11 years ago

Use OpenGL alpha to draw faded splay legs

  • Property mode set to 100644
File size: 7.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,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    wxGLContext ctx;
102
103#ifdef GLA_DEBUG
104    int m_Vertices;
105#endif
106
107    GLdouble modelview_matrix[16];
108    GLdouble projection_matrix[16];
109    GLint viewport[4];
110
111    // Viewing volume diameter:
112    glaCoord m_VolumeDiameter;
113
114    // Parameters for plotting data:
115    Double m_Pan, m_Tilt;
116    Double m_Scale;
117    Vector3 m_Translation;
118
119    BitmapFont m_Font;
120
121    GLUquadric* m_Quadric;
122
123    GLuint m_Texture;
124    GLuint m_CrossTexture;
125
126    Double alpha;
127
128    bool m_SmoothShading;
129    bool m_Textured;
130    bool m_Perspective;
131    bool m_Fog;
132    bool m_AntiAlias;
133    bool save_hints;
134    enum { UNKNOWN = 0, POINT = 'P', LINES = 'L', SPRITE = 'S' };
135    int blob_method;
136    int cross_method;
137
138    int x_size;
139    int y_size;
140
141    vector<GLAList> drawing_lists;
142
143    enum {
144        INVALIDATE_ON_SCALE = 1,
145        INVALIDATE_ON_X_RESIZE = 2,
146        INVALIDATE_ON_Y_RESIZE = 4,
147        NEVER_CACHE = 8,
148        CACHED = 16
149    };
150    mutable unsigned int list_flags;
151
152    wxString vendor, renderer;
153
154    bool CheckVisualFidelity(const unsigned char * target) const;
155
156public:
157    GLACanvas(wxWindow* parent, int id);
158    ~GLACanvas();
159
160    void FirstShow();
161
162    void Clear();
163    void StartDrawing();
164    void FinishDrawing();
165
166    void SetVolumeDiameter(glaCoord diameter);
167    void SetDataTransform();
168    void SetIndicatorTransform();
169
170    void DrawList(unsigned int l);
171    void DrawList2D(unsigned int l, glaCoord x, glaCoord y, Double rotation);
172    void InvalidateList(unsigned int l) {
173        if (l < drawing_lists.size()) {
174            // Invalidate any existing cached list.
175            drawing_lists[l].invalidate_if(CACHED);
176        }
177    }
178
179    virtual void GenerateList(unsigned int l) = 0;
180
181    void SetColour(const GLAPen& pen, double rgb_scale);
182    void SetColour(const GLAPen& pen);
183    void SetColour(gla_colour colour);
184    void SetAlpha(double new_alpha) { alpha = new_alpha; }
185
186    void DrawText(glaCoord x, glaCoord y, glaCoord z, const wxString& str);
187    void DrawIndicatorText(int x, int y, const wxString& str);
188    void GetTextExtent(const wxString& str, int * x_ext, int * y_ext);
189
190    void BeginQuadrilaterals();
191    void EndQuadrilaterals();
192    void BeginLines();
193    void EndLines();
194    void BeginTriangleStrip();
195    void EndTriangleStrip();
196    void BeginTriangles();
197    void EndTriangles();
198    void BeginPolyline();
199    void EndPolyline();
200    void BeginPolygon();
201    void EndPolygon();
202    void BeginBlobs();
203    void EndBlobs();
204    void BeginCrosses();
205    void EndCrosses();
206
207    void DrawRectangle(gla_colour edge, gla_colour fill,
208                       glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
209    void DrawShadedRectangle(const GLAPen & fill_bot, const GLAPen & fill_top,
210                             glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
211    void DrawCircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius);
212    void DrawSemicircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius, glaCoord start);
213    void DrawTriangle(gla_colour edge, gla_colour fill,
214                      const Vector3 &p0, const Vector3 &p1, const Vector3 &p2);
215
216    void DrawBlob(glaCoord x, glaCoord y, glaCoord z);
217    void DrawBlob(glaCoord x, glaCoord y);
218    void DrawCross(glaCoord x, glaCoord y, glaCoord z);
219    void DrawRing(glaCoord x, glaCoord y);
220
221    void PlaceVertex(const Vector3 & v, glaTexCoord tex_x, glaTexCoord tex_y) {
222        PlaceVertex(v.GetX(), v.GetY(), v.GetZ(), tex_x, tex_y);
223    }
224    void PlaceVertex(const Vector3 & v) {
225        PlaceVertex(v.GetX(), v.GetY(), v.GetZ());
226    }
227    void PlaceVertex(glaCoord x, glaCoord y, glaCoord z);
228    void PlaceVertex(glaCoord x, glaCoord y, glaCoord z,
229                     glaTexCoord tex_x, glaTexCoord tex_y);
230    void PlaceIndicatorVertex(glaCoord x, glaCoord y);
231
232    void PlaceNormal(const Vector3 &v);
233
234    void EnableDashedLines();
235    void DisableDashedLines();
236
237    void EnableSmoothPolygons(bool filled);
238    void DisableSmoothPolygons();
239
240    void SetRotation(double pan, double tilt) {
241        m_Pan = pan;
242        m_Tilt = tilt;
243    }
244    void SetScale(Double);
245    void SetTranslation(const Vector3 &v) {
246        m_Translation = v;
247    }
248    void AddTranslation(const Vector3 &v) {
249        m_Translation += v;
250    }
251    const Vector3 & GetTranslation() const {
252        return m_Translation;
253    }
254    void AddTranslationScreenCoordinates(int dx, int dy);
255
256    bool Transform(const Vector3 & v, double* x_out, double* y_out, double* z_out) const;
257    void ReverseTransform(Double x, Double y, double* x_out, double* y_out, double* z_out) const;
258
259    int GetFontSize() const { return m_Font.get_font_size(); }
260
261    void ToggleSmoothShading();
262    bool GetSmoothShading() const { return m_SmoothShading; }
263
264    Double SurveyUnitsAcrossViewport() const;
265
266    void ToggleTextured();
267    bool GetTextured() const { return m_Textured; }
268
269    void TogglePerspective() { m_Perspective = !m_Perspective; }
270    bool GetPerspective() const { return m_Perspective; }
271
272    void ToggleFog() { m_Fog = !m_Fog; }
273    bool GetFog() const { return m_Fog; }
274
275    void ToggleAntiAlias() { m_AntiAlias = !m_AntiAlias; }
276    bool GetAntiAlias() const { return m_AntiAlias; }
277
278    bool SaveScreenshot(const wxString & fnm, wxBitmapType type) const;
279
280    void ReadPixels(int width, int height, unsigned char * buf) const;
281
282    void PolygonOffset(bool on) const;
283
284    int GetXSize() const { list_flags |= INVALIDATE_ON_X_RESIZE; return x_size; }
285    int GetYSize() const { list_flags |= INVALIDATE_ON_Y_RESIZE; return y_size; }
286
287    void OnSize(wxSizeEvent & event);
288
289    glaCoord GetVolumeDiameter() const { return m_VolumeDiameter; }
290
291private:
292    DECLARE_EVENT_TABLE()
293};
Note: See TracBrowser for help on using the repository browser.