4 // Header file for the GLA abstraction layer.
6 // Copyright (C) 2002 Mark R. Shinwell.
7 // Copyright (C) 2003,2004,2005,2006,2007,2011,2012,2014,2017,2018 Olly Betts
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
33 #include "aventypes.h"
36 #include "glbitmapfont.h"
40 string
GetGLSystemDescription();
44 typedef Double glaCoord
;
46 typedef GLfloat glaTexCoord
;
48 // Colours for drawing. Don't reorder these!
63 col_LAST
// must be the last entry here
67 friend class GLACanvas
; // allow direct access to components
69 double components
[3]; // red, green, blue
74 void SetColour(double red
, double green
, double blue
); // arguments in range 0 to 1.0
75 void Interpolate(const GLAPen
&, double how_far
);
77 double GetRed() const;
78 double GetGreen() const;
79 double GetBlue() const;
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; }
90 bool need_to_generate();
91 void finalise(unsigned int list_flags
);
92 bool DrawList() const;
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).
101 class GLACanvas
: public wxGLCanvas
{
102 friend class GLAList
; // For flag values.
110 GLdouble modelview_matrix
[16];
111 GLdouble projection_matrix
[16];
114 // Viewing volume diameter:
115 glaCoord m_VolumeDiameter
;
117 // Parameters for plotting data:
118 Double m_Pan
, m_Tilt
;
120 Vector3 m_Translation
;
124 GLUquadric
* m_Quadric
;
127 GLuint m_BlobTexture
;
128 GLuint m_CrossTexture
;
132 bool m_SmoothShading
;
138 enum { UNKNOWN
= 0, POINT
= 'P', LINES
= 'L', SPRITE
= 'S' };
145 vector
<GLAList
> drawing_lists
;
148 INVALIDATE_ON_SCALE
= 1,
149 INVALIDATE_ON_X_RESIZE
= 2,
150 INVALIDATE_ON_Y_RESIZE
= 4,
154 mutable unsigned int list_flags
;
156 wxString vendor
, renderer
;
158 bool CheckVisualFidelity(const unsigned char * target
) const;
161 GLACanvas(wxWindow
* parent
, int id
);
164 static bool check_visual();
170 void FinishDrawing();
172 void SetVolumeDiameter(glaCoord diameter
);
173 void SetDataTransform();
174 void SetIndicatorTransform();
176 void DrawList(unsigned int l
);
177 void DrawListZPrepass(unsigned int l
);
178 void DrawList2D(unsigned int l
, glaCoord x
, glaCoord y
, Double rotation
);
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
);
186 virtual void GenerateList(unsigned int l
) = 0;
188 void SetColour(const GLAPen
& pen
, double rgb_scale
);
189 void SetColour(const GLAPen
& pen
);
190 void SetColour(gla_colour colour
, double rgb_scale
);
191 void SetColour(gla_colour colour
);
192 void SetAlpha(double new_alpha
) { alpha
= new_alpha
; }
194 void DrawText(glaCoord x
, glaCoord y
, glaCoord z
, const wxString
& str
);
195 void DrawIndicatorText(int x
, int y
, const wxString
& str
);
196 void GetTextExtent(const wxString
& str
, int * x_ext
, int * y_ext
) const;
198 void BeginQuadrilaterals();
199 void EndQuadrilaterals();
202 void BeginTriangleStrip();
203 void EndTriangleStrip();
204 void BeginTriangles();
206 void BeginPolyline();
208 void BeginPolyloop();
217 void DrawRectangle(gla_colour fill
, gla_colour edge
,
218 glaCoord x0
, glaCoord y0
, glaCoord w
, glaCoord h
);
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
);
223 void DrawTriangle(gla_colour edge
, gla_colour fill
,
224 const Vector3
&p0
, const Vector3
&p1
, const Vector3
&p2
);
226 void DrawBlob(glaCoord x
, glaCoord y
, glaCoord z
);
227 void DrawBlob(glaCoord x
, glaCoord y
);
228 void DrawCross(glaCoord x
, glaCoord y
, glaCoord z
);
229 void DrawRing(glaCoord x
, glaCoord y
);
231 void PlaceVertex(const Vector3
& v
, glaTexCoord tex_x
, glaTexCoord tex_y
) {
232 PlaceVertex(v
.GetX(), v
.GetY(), v
.GetZ(), tex_x
, tex_y
);
234 void PlaceVertex(const Vector3
& v
) {
235 PlaceVertex(v
.GetX(), v
.GetY(), v
.GetZ());
237 void PlaceVertex(glaCoord x
, glaCoord y
, glaCoord z
);
238 void PlaceVertex(glaCoord x
, glaCoord y
, glaCoord z
,
239 glaTexCoord tex_x
, glaTexCoord tex_y
);
240 void PlaceIndicatorVertex(glaCoord x
, glaCoord y
);
242 void PlaceNormal(const Vector3
&v
);
244 void EnableDashedLines();
245 void DisableDashedLines();
247 void EnableSmoothPolygons(bool filled
);
248 void DisableSmoothPolygons();
250 void SetRotation(double pan
, double tilt
) {
254 void SetScale(Double
);
255 void SetTranslation(const Vector3
&v
) {
258 void AddTranslation(const Vector3
&v
) {
261 const Vector3
& GetTranslation() const {
262 return m_Translation
;
264 void AddTranslationScreenCoordinates(int dx
, int dy
);
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;
269 int GetFontSize() const { return m_Font
.get_font_size(); }
271 void ToggleSmoothShading();
272 bool GetSmoothShading() const { return m_SmoothShading
; }
274 Double
SurveyUnitsAcrossViewport() const;
276 void ToggleTextured();
277 bool GetTextured() const { return m_Textured
; }
279 void TogglePerspective() { m_Perspective
= !m_Perspective
; }
280 bool GetPerspective() const { return m_Perspective
; }
282 void ToggleFog() { m_Fog
= !m_Fog
; }
283 bool GetFog() const { return m_Fog
; }
285 void ToggleAntiAlias() { m_AntiAlias
= !m_AntiAlias
; }
286 bool GetAntiAlias() const { return m_AntiAlias
; }
288 bool SaveScreenshot(const wxString
& fnm
, wxBitmapType type
) const;
290 void ReadPixels(int width
, int height
, unsigned char * buf
) const;
292 void PolygonOffset(bool on
) const;
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
; }
297 void OnSize(wxSizeEvent
& event
);
299 glaCoord
GetVolumeDiameter() const { return m_VolumeDiameter
; }
302 DECLARE_EVENT_TABLE()