[ci] GHA fixes
[survex.git] / src / gla.h
blobb5ce1b389bebb5f284df15bd9a7dc03daded91a4
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,2014,2017,2018 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.
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.
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
24 #ifndef gla_h
25 #define gla_h
27 #include <string>
28 #include <vector>
30 using namespace std;
32 #include "wx.h"
33 #include "aventypes.h"
34 #include "vector3.h"
36 #include "glbitmapfont.h"
38 class GfxCore;
40 string GetGLSystemDescription();
42 // #define GLA_DEBUG
44 typedef Double glaCoord;
46 typedef GLfloat glaTexCoord;
48 // Colours for drawing. Don't reorder these!
49 enum 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_MAGENTA,
64 col_LAST // must be the last entry here
67 class GLAPen {
68 friend class GLACanvas; // allow direct access to components
70 double components[3]; // red, green, blue
72 public:
73 GLAPen();
75 void SetColour(double red, double green, double blue); // arguments in range 0 to 1.0
76 void Interpolate(const GLAPen&, double how_far);
78 double GetRed() const;
79 double GetGreen() const;
80 double GetBlue() const;
83 class 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; }
91 bool need_to_generate();
92 void finalise(unsigned int list_flags);
93 bool DrawList() const;
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;
102 class GLACanvas : public wxGLCanvas {
103 friend class GLAList; // For flag values.
105 wxGLContext ctx;
107 #ifdef GLA_DEBUG
108 int m_Vertices;
109 #endif
111 GLdouble modelview_matrix[16];
112 GLdouble projection_matrix[16];
113 GLint viewport[4];
115 // Viewing volume diameter:
116 glaCoord m_VolumeDiameter;
118 // Parameters for plotting data:
119 Double m_Pan, m_Tilt;
120 Double m_Scale;
121 Vector3 m_Translation;
123 BitmapFont m_Font;
125 GLUquadric* m_Quadric;
127 GLuint m_Texture;
128 GLuint m_BlobTexture;
129 GLuint m_CrossTexture;
131 Double alpha;
133 bool m_SmoothShading;
134 bool m_Textured;
135 bool m_Perspective;
136 bool m_Fog;
137 bool m_AntiAlias;
138 bool save_hints;
139 enum { UNKNOWN = 0, POINT = 'P', LINES = 'L', SPRITE = 'S' };
140 int blob_method;
141 int cross_method;
143 int x_size;
144 int y_size;
146 vector<GLAList> drawing_lists;
148 enum {
149 INVALIDATE_ON_SCALE = 1,
150 INVALIDATE_ON_X_RESIZE = 2,
151 INVALIDATE_ON_Y_RESIZE = 4,
152 NEVER_CACHE = 8,
153 CACHED = 16
155 mutable unsigned int list_flags;
157 wxString vendor, renderer;
159 bool CheckVisualFidelity(const unsigned char * target) const;
161 public:
162 GLACanvas(wxWindow* parent, int id);
163 ~GLACanvas();
165 static bool check_visual();
167 void FirstShow();
169 void Clear();
170 void StartDrawing();
171 void FinishDrawing();
173 void SetVolumeDiameter(glaCoord diameter);
174 void SetDataTransform();
175 void SetIndicatorTransform();
177 void DrawList(unsigned int l);
178 void DrawListZPrepass(unsigned int l);
179 void DrawList2D(unsigned int l, glaCoord x, glaCoord y, Double rotation);
180 void InvalidateList(unsigned int l) {
181 if (l < drawing_lists.size()) {
182 // Invalidate any existing cached list.
183 drawing_lists[l].invalidate_if(CACHED);
187 virtual void GenerateList(unsigned int l) = 0;
189 void SetColour(const GLAPen& pen, double rgb_scale);
190 void SetColour(const GLAPen& pen);
191 void SetColour(gla_colour colour, double rgb_scale);
192 void SetColour(gla_colour colour);
193 void SetAlpha(double new_alpha) { alpha = new_alpha; }
195 void DrawText(glaCoord x, glaCoord y, glaCoord z, const wxString& str);
196 void DrawIndicatorText(int x, int y, const wxString& str);
197 void GetTextExtent(const wxString& str, int * x_ext, int * y_ext) const;
199 void BeginQuadrilaterals();
200 void EndQuadrilaterals();
201 void BeginLines();
202 void EndLines();
203 void BeginTriangleStrip();
204 void EndTriangleStrip();
205 void BeginTriangles();
206 void EndTriangles();
207 void BeginPolyline();
208 void EndPolyline();
209 void BeginPolyloop();
210 void EndPolyloop();
211 void BeginPolygon();
212 void EndPolygon();
213 void BeginBlobs();
214 void EndBlobs();
215 void BeginCrosses();
216 void EndCrosses();
218 void DrawRectangle(gla_colour fill, gla_colour edge,
219 glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
220 void DrawShadedRectangle(const GLAPen & fill_bot, const GLAPen & fill_top,
221 glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
222 void DrawCircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius);
223 void DrawSemicircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius, glaCoord start);
224 void DrawTriangle(gla_colour edge, gla_colour fill,
225 const Vector3 &p0, const Vector3 &p1, const Vector3 &p2);
227 void DrawBlob(glaCoord x, glaCoord y, glaCoord z);
228 void DrawBlob(glaCoord x, glaCoord y);
229 void DrawCross(glaCoord x, glaCoord y, glaCoord z);
230 void DrawRing(glaCoord x, glaCoord y);
232 void PlaceVertex(const Vector3 & v, glaTexCoord tex_x, glaTexCoord tex_y) {
233 PlaceVertex(v.GetX(), v.GetY(), v.GetZ(), tex_x, tex_y);
235 void PlaceVertex(const Vector3 & v) {
236 PlaceVertex(v.GetX(), v.GetY(), v.GetZ());
238 void PlaceVertex(glaCoord x, glaCoord y, glaCoord z);
239 void PlaceVertex(glaCoord x, glaCoord y, glaCoord z,
240 glaTexCoord tex_x, glaTexCoord tex_y);
241 void PlaceIndicatorVertex(glaCoord x, glaCoord y);
243 void PlaceNormal(const Vector3 &v);
245 void EnableDashedLines();
246 void DisableDashedLines();
248 void EnableSmoothPolygons(bool filled);
249 void DisableSmoothPolygons();
251 void SetRotation(double pan, double tilt) {
252 m_Pan = pan;
253 m_Tilt = tilt;
255 void SetScale(Double);
256 void SetTranslation(const Vector3 &v) {
257 m_Translation = v;
259 void AddTranslation(const Vector3 &v) {
260 m_Translation += v;
262 const Vector3 & GetTranslation() const {
263 return m_Translation;
265 void AddTranslationScreenCoordinates(int dx, int dy);
267 bool Transform(const Vector3 & v, double* x_out, double* y_out, double* z_out) const;
268 void ReverseTransform(Double x, Double y, double* x_out, double* y_out, double* z_out) const;
270 int GetFontSize() const { return m_Font.get_font_size(); }
272 void ToggleSmoothShading();
273 bool GetSmoothShading() const { return m_SmoothShading; }
275 Double SurveyUnitsAcrossViewport() const;
277 void ToggleTextured();
278 bool GetTextured() const { return m_Textured; }
280 void TogglePerspective() { m_Perspective = !m_Perspective; }
281 bool GetPerspective() const { return m_Perspective; }
283 void ToggleFog() { m_Fog = !m_Fog; }
284 bool GetFog() const { return m_Fog; }
286 void ToggleAntiAlias() { m_AntiAlias = !m_AntiAlias; }
287 bool GetAntiAlias() const { return m_AntiAlias; }
289 bool SaveScreenshot(const wxString & fnm, wxBitmapType type) const;
291 void ReadPixels(int width, int height, unsigned char * buf) const;
293 void PolygonOffset(bool on) const;
295 int GetXSize() const { list_flags |= INVALIDATE_ON_X_RESIZE; return x_size; }
296 int GetYSize() const { list_flags |= INVALIDATE_ON_Y_RESIZE; return y_size; }
298 void OnSize(wxSizeEvent & event);
300 glaCoord GetVolumeDiameter() const { return m_VolumeDiameter; }
302 private:
303 DECLARE_EVENT_TABLE()
306 #endif