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 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
30 #include "aventypes.h"
33 #include "glbitmapfont.h"
37 string
GetGLSystemDescription();
41 typedef Double glaCoord
;
43 typedef GLfloat glaTexCoord
;
45 // Colours for drawing. Don't reorder these!
60 col_LAST
// must be the last entry here
64 friend class GLACanvas
; // allow direct access to components
66 double components
[3]; // red, green, blue
71 void SetColour(double red
, double green
, double blue
); // arguments in range 0 to 1.0
72 void Interpolate(const GLAPen
&, double how_far
);
74 double GetRed() const;
75 double GetGreen() const;
76 double GetBlue() const;
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).
98 class GLACanvas
: public wxGLCanvas
{
99 friend class GLAList
; // For flag values.
107 GLdouble modelview_matrix
[16];
108 GLdouble projection_matrix
[16];
111 // Viewing volume diameter:
112 glaCoord m_VolumeDiameter
;
114 // Parameters for plotting data:
115 Double m_Pan
, m_Tilt
;
117 Vector3 m_Translation
;
121 GLUquadric
* m_Quadric
;
124 GLuint m_BlobTexture
;
125 GLuint m_CrossTexture
;
129 bool m_SmoothShading
;
135 enum { UNKNOWN
= 0, POINT
= 'P', LINES
= 'L', SPRITE
= 'S' };
142 vector
<GLAList
> drawing_lists
;
145 INVALIDATE_ON_SCALE
= 1,
146 INVALIDATE_ON_X_RESIZE
= 2,
147 INVALIDATE_ON_Y_RESIZE
= 4,
151 mutable unsigned int list_flags
;
153 wxString vendor
, renderer
;
155 bool CheckVisualFidelity(const unsigned char * target
) const;
158 GLACanvas(wxWindow
* parent
, int id
);
165 void FinishDrawing();
167 void SetVolumeDiameter(glaCoord diameter
);
168 void SetDataTransform();
169 void SetIndicatorTransform();
171 void DrawList(unsigned int l
);
172 void DrawListZPrepass(unsigned int l
);
173 void DrawList2D(unsigned int l
, glaCoord x
, glaCoord y
, Double rotation
);
174 void InvalidateList(unsigned int l
) {
175 if (l
< drawing_lists
.size()) {
176 // Invalidate any existing cached list.
177 drawing_lists
[l
].invalidate_if(CACHED
);
181 virtual void GenerateList(unsigned int l
) = 0;
183 void SetColour(const GLAPen
& pen
, double rgb_scale
);
184 void SetColour(const GLAPen
& pen
);
185 void SetColour(gla_colour colour
, double rgb_scale
);
186 void SetColour(gla_colour colour
);
187 void SetAlpha(double new_alpha
) { alpha
= new_alpha
; }
189 void DrawText(glaCoord x
, glaCoord y
, glaCoord z
, const wxString
& str
);
190 void DrawIndicatorText(int x
, int y
, const wxString
& str
);
191 void GetTextExtent(const wxString
& str
, int * x_ext
, int * y_ext
) const;
193 void BeginQuadrilaterals();
194 void EndQuadrilaterals();
197 void BeginTriangleStrip();
198 void EndTriangleStrip();
199 void BeginTriangles();
201 void BeginPolyline();
210 void DrawRectangle(gla_colour edge
, gla_colour fill
,
211 glaCoord x0
, glaCoord y0
, glaCoord w
, glaCoord h
);
212 void DrawShadedRectangle(const GLAPen
& fill_bot
, const GLAPen
& fill_top
,
213 glaCoord x0
, glaCoord y0
, glaCoord w
, glaCoord h
);
214 void DrawCircle(gla_colour edge
, gla_colour fill
, glaCoord cx
, glaCoord cy
, glaCoord radius
);
215 void DrawSemicircle(gla_colour edge
, gla_colour fill
, glaCoord cx
, glaCoord cy
, glaCoord radius
, glaCoord start
);
216 void DrawTriangle(gla_colour edge
, gla_colour fill
,
217 const Vector3
&p0
, const Vector3
&p1
, const Vector3
&p2
);
219 void DrawBlob(glaCoord x
, glaCoord y
, glaCoord z
);
220 void DrawBlob(glaCoord x
, glaCoord y
);
221 void DrawCross(glaCoord x
, glaCoord y
, glaCoord z
);
222 void DrawRing(glaCoord x
, glaCoord y
);
224 void PlaceVertex(const Vector3
& v
, glaTexCoord tex_x
, glaTexCoord tex_y
) {
225 PlaceVertex(v
.GetX(), v
.GetY(), v
.GetZ(), tex_x
, tex_y
);
227 void PlaceVertex(const Vector3
& v
) {
228 PlaceVertex(v
.GetX(), v
.GetY(), v
.GetZ());
230 void PlaceVertex(glaCoord x
, glaCoord y
, glaCoord z
);
231 void PlaceVertex(glaCoord x
, glaCoord y
, glaCoord z
,
232 glaTexCoord tex_x
, glaTexCoord tex_y
);
233 void PlaceIndicatorVertex(glaCoord x
, glaCoord y
);
235 void PlaceNormal(const Vector3
&v
);
237 void EnableDashedLines();
238 void DisableDashedLines();
240 void EnableSmoothPolygons(bool filled
);
241 void DisableSmoothPolygons();
243 void SetRotation(double pan
, double tilt
) {
247 void SetScale(Double
);
248 void SetTranslation(const Vector3
&v
) {
251 void AddTranslation(const Vector3
&v
) {
254 const Vector3
& GetTranslation() const {
255 return m_Translation
;
257 void AddTranslationScreenCoordinates(int dx
, int dy
);
259 bool Transform(const Vector3
& v
, double* x_out
, double* y_out
, double* z_out
) const;
260 void ReverseTransform(Double x
, Double y
, double* x_out
, double* y_out
, double* z_out
) const;
262 int GetFontSize() const { return m_Font
.get_font_size(); }
264 void ToggleSmoothShading();
265 bool GetSmoothShading() const { return m_SmoothShading
; }
267 Double
SurveyUnitsAcrossViewport() const;
269 void ToggleTextured();
270 bool GetTextured() const { return m_Textured
; }
272 void TogglePerspective() { m_Perspective
= !m_Perspective
; }
273 bool GetPerspective() const { return m_Perspective
; }
275 void ToggleFog() { m_Fog
= !m_Fog
; }
276 bool GetFog() const { return m_Fog
; }
278 void ToggleAntiAlias() { m_AntiAlias
= !m_AntiAlias
; }
279 bool GetAntiAlias() const { return m_AntiAlias
; }
281 bool SaveScreenshot(const wxString
& fnm
, wxBitmapType type
) const;
283 void ReadPixels(int width
, int height
, unsigned char * buf
) const;
285 void PolygonOffset(bool on
) const;
287 int GetXSize() const { list_flags
|= INVALIDATE_ON_X_RESIZE
; return x_size
; }
288 int GetYSize() const { list_flags
|= INVALIDATE_ON_Y_RESIZE
; return y_size
; }
290 void OnSize(wxSizeEvent
& event
);
292 glaCoord
GetVolumeDiameter() const { return m_VolumeDiameter
; }
295 DECLARE_EVENT_TABLE()