source: git/src/gla.h @ aea4f8b

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

src/gfxcore.cc,src/gla-gl.cc,src/gla.h: Eliminate glReadPixels() call
from src/gfxcore.cc.

git-svn-id: file:///home/survex-svn/survex/trunk@3739 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 7.1 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 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// Use texture mapped fonts (lots faster, at least with hardware 3d)
25#define USE_FNT
26
27#include <string>
28#include <vector>
29
30using namespace std;
31
32#include "wx.h"
33#include "aventypes.h"
34#include "vector3.h"
35
36#ifdef USE_FNT
37#include "fnt.h"
38#endif
39
40class GfxCore;
41
42string GetGLSystemDescription();
43
44// #define GLA_DEBUG
45
46typedef Double glaCoord;
47
48// Colours for drawing.  Don't reorder these!
49enum 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_LAST // must be the last entry here
64};
65
66class GLAPen {
67    friend class GLACanvas; // allow direct access to components
68
69    double components[3]; // red, green, blue
70
71public:
72    GLAPen();
73    ~GLAPen();
74
75    void SetColour(double red, double green, double blue); // arguments in range 0 to 1.0
76    void Interpolate(const GLAPen&, double how_far);
77
78    double GetRed() const;
79    double GetGreen() const;
80    double GetBlue() const;
81};
82
83const unsigned int INVALIDATE_ON_SCALE = 1;
84const unsigned int NEVER_CACHE = 2;
85
86class GLAList {
87    GLuint gl_list;
88    unsigned int flags;
89  public:
90    GLAList() : gl_list(0), flags(0) { }
91    GLAList(GLuint gl_list_, unsigned int flags_)
92        : gl_list(gl_list_), flags(flags_) { }
93    bool test_flag(unsigned int mask) const { return flags & mask; }
94    operator bool() { return gl_list != 0; }
95    void DrawList() const;
96    void InvalidateList();
97};
98
99class GLACanvas : public wxGLCanvas {
100#ifdef GLA_DEBUG
101    int m_Vertices;
102#endif
103
104    GLdouble modelview_matrix[16];
105    GLdouble projection_matrix[16];
106    GLint viewport[4];
107
108    // Viewing volume diameter:
109    glaCoord m_VolumeDiameter;
110
111    // Parameters for plotting data:
112    Double m_Pan, m_Tilt;
113    Double m_Scale;
114    Vector3 m_Translation;
115
116#ifdef USE_FNT
117    fntTexFont m_Font;
118#else
119    static void * const m_Font;
120    static const int m_FontSize;
121#endif
122
123    GLUquadric* m_Quadric;
124
125    GLuint m_Texture;
126    GLuint m_CrossTexture;
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    vector<GLAList> drawing_lists;
139    mutable unsigned int list_flags;
140
141    wxString vendor, renderer;
142
143    bool CheckVisualFidelity(const unsigned char * target) const;
144
145public:
146    GLACanvas(wxWindow* parent, int id);
147    ~GLACanvas();
148
149    void FirstShow();
150
151    void Clear();
152    void StartDrawing();
153    void FinishDrawing();
154
155    void SetVolumeDiameter(glaCoord diameter);
156    void SetDataTransform();
157    void SetIndicatorTransform();
158
159    void DrawList(unsigned int l);
160    void DrawList2D(unsigned int l, glaCoord x, glaCoord y, Double rotation);
161    void InvalidateList(unsigned int l);
162    virtual void GenerateList(unsigned int l) = 0;
163
164    void SetBackgroundColour(float red, float green, float blue);
165    void SetColour(const GLAPen& pen, double rgb_scale);
166    void SetColour(const GLAPen& pen);
167    void SetColour(gla_colour colour);
168
169    void DrawText(glaCoord x, glaCoord y, glaCoord z, const wxString& str);
170    void DrawIndicatorText(int x, int y, const wxString& str);
171    void GetTextExtent(const wxString& str, int * x_ext, int * y_ext);
172
173    void BeginQuadrilaterals();
174    void EndQuadrilaterals();
175    void BeginLines();
176    void EndLines();
177    void BeginTriangleStrip();
178    void EndTriangleStrip();
179    void BeginTriangles();
180    void EndTriangles();
181    void BeginPolyline();
182    void EndPolyline();
183    void BeginPolygon();
184    void EndPolygon();
185    void BeginBlobs();
186    void EndBlobs();
187    void BeginCrosses();
188    void EndCrosses();
189
190    void DrawRectangle(gla_colour edge, gla_colour fill,
191                       glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
192    void DrawShadedRectangle(const GLAPen & fill_bot, const GLAPen & fill_top,
193                             glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
194    void DrawCircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius);
195    void DrawSemicircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius, glaCoord start);
196    void DrawTriangle(gla_colour edge, gla_colour fill,
197                      const Vector3 &p0, const Vector3 &p1, const Vector3 &p2);
198
199    void DrawBlob(glaCoord x, glaCoord y, glaCoord z);
200    void DrawBlob(glaCoord x, glaCoord y);
201    void DrawCross(glaCoord x, glaCoord y, glaCoord z);
202    void DrawRing(glaCoord x, glaCoord y);
203
204    void PlaceVertex(const Vector3 & v) {
205        PlaceVertex(v.GetX(), v.GetY(), v.GetZ());
206    }
207    void PlaceVertex(glaCoord x, glaCoord y, glaCoord z);
208    void PlaceIndicatorVertex(glaCoord x, glaCoord y);
209
210    void PlaceNormal(const Vector3 &v);
211
212    void EnableDashedLines();
213    void DisableDashedLines();
214
215    void EnableSmoothPolygons(bool filled);
216    void DisableSmoothPolygons();
217
218    void SetRotation(double pan, double tilt) {
219        m_Pan = pan;
220        m_Tilt = tilt;
221    }
222    void SetScale(Double);
223    void SetTranslation(const Vector3 &v) {
224        m_Translation = v;
225    }
226    void AddTranslation(const Vector3 &v) {
227        m_Translation += v;
228    }
229    const Vector3 & GetTranslation() const {
230        return m_Translation;
231    }
232    void AddTranslationScreenCoordinates(int dx, int dy);
233
234    bool Transform(const Vector3 & v, double* x_out, double* y_out, double* z_out) const;
235    void ReverseTransform(Double x, Double y, double* x_out, double* y_out, double* z_out) const;
236
237#ifdef USE_FNT
238    int GetFontSize() const { return m_Font.getFontSize(); }
239#else
240    int GetFontSize() const { return m_FontSize; }
241#endif
242
243    void ToggleSmoothShading();
244    bool GetSmoothShading() const { return m_SmoothShading; }
245
246    Double SurveyUnitsAcrossViewport() const;
247
248    void ToggleTextured();
249    bool GetTextured() const { return m_Textured; }
250
251    void TogglePerspective() { m_Perspective = !m_Perspective; }
252    bool GetPerspective() const { return m_Perspective; }
253
254    void ToggleFog() { m_Fog = !m_Fog; }
255    bool GetFog() const { return m_Fog; }
256
257    void ToggleAntiAlias() { m_AntiAlias = !m_AntiAlias; }
258    bool GetAntiAlias() const { return m_AntiAlias; }
259
260    bool SaveScreenshot(const wxString & fnm, int type) const;
261
262    void ReadPixels(int width, int height, unsigned char * buf) const;
263};
Note: See TracBrowser for help on using the repository browser.