source: git/src/gla.h @ ad661cc

RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernlogstereowalls-datawalls-data-hanging-as-warning
Last change on this file since ad661cc was 8c048fa, checked in by Olly Betts <olly@…>, 11 years ago

src/gla-gl.cc,src/gla.h: Update to use wxGLContext to avoid
deprecation warnings from wx 2.9.

  • Property mode set to 100644
File size: 7.8 KB
RevLine 
[56da40e]1//
2//  gla.h
3//
4//  Header file for the GLA abstraction layer.
5//
6//  Copyright (C) 2002 Mark R. Shinwell.
[b3f1bbe]7//  Copyright (C) 2003,2004,2005,2006,2007,2011,2012 Olly Betts
[56da40e]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
[ecbc6c18]21//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
[56da40e]22//
23
[5627cbb]24#include <string>
[bae6a7c]25#include <vector>
26
27using namespace std;
28
[56da40e]29#include "wx.h"
30#include "aventypes.h"
[08253d9]31#include "vector3.h"
[56da40e]32
[1aa3fb7]33#include "glbitmapfont.h"
[1eeb55a]34
[56da40e]35class GfxCore;
36
[5627cbb]37string GetGLSystemDescription();
[cc1a1d9]38
[d67450e]39// #define GLA_DEBUG
[1897247]40
[56da40e]41typedef Double glaCoord;
42
[f336ab9]43typedef GLint glaTexCoord;
44
[aa048c3]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,
[f4c5932]59    col_BLUE,
[aa048c3]60    col_LAST // must be the last entry here
61};
62
[56da40e]63class GLAPen {
[aa048c3]64    friend class GLACanvas; // allow direct access to components
65
66    double components[3]; // red, green, blue
[9cf3688]67
[56da40e]68public:
69    GLAPen();
70
71    void SetColour(double red, double green, double blue); // arguments in range 0 to 1.0
[f383708]72    void Interpolate(const GLAPen&, double how_far);
[56da40e]73
[f7ea0e1]74    double GetRed() const;
75    double GetGreen() const;
76    double GetBlue() const;
[56da40e]77};
78
[db59b02]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; }
[620c0c9]87    bool need_to_generate();
88    void finalise(unsigned int list_flags);
89    bool DrawList() const;
[b3f1bbe]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    }
[db59b02]96};
97
[56da40e]98class GLACanvas : public wxGLCanvas {
[b3f1bbe]99    friend class GLAList; // For flag values.
[620c0c9]100
[8c048fa]101    wxGLContext ctx;
102
[203d2a7]103#ifdef GLA_DEBUG
104    int m_Vertices;
105#endif
106
[dde4fe7]107    GLdouble modelview_matrix[16];
108    GLdouble projection_matrix[16];
109    GLint viewport[4];
110
[c5fc8eb]111    // Viewing volume diameter:
112    glaCoord m_VolumeDiameter;
[56da40e]113
114    // Parameters for plotting data:
[08253d9]115    Double m_Pan, m_Tilt;
[56da40e]116    Double m_Scale;
[d67450e]117    Vector3 m_Translation;
[56da40e]118
[1aa3fb7]119    BitmapFont m_Font;
[d9b3270]120
[1b12b82]121    GLUquadric* m_Quadric;
[a517825]122
123    GLuint m_Texture;
[95ce35f]124    GLuint m_CrossTexture;
[a517825]125
[d67450e]126    bool m_SmoothShading;
[a517825]127    bool m_Textured;
[1eeb55a]128    bool m_Perspective;
[c60062d]129    bool m_Fog;
[db452ae]130    bool m_AntiAlias;
[807f9dd]131    bool save_hints;
[fe075d7]132    enum { UNKNOWN = 0, POINT = 'P', LINES = 'L', SPRITE = 'S' };
133    int blob_method;
134    int cross_method;
[1eeb55a]135
[90430f2]136    int x_size;
137    int y_size;
138
[db59b02]139    vector<GLAList> drawing_lists;
[90430f2]140
141    enum {
142        INVALIDATE_ON_SCALE = 1,
143        INVALIDATE_ON_X_RESIZE = 2,
144        INVALIDATE_ON_Y_RESIZE = 4,
[620c0c9]145        NEVER_CACHE = 8,
146        CACHED = 16
[90430f2]147    };
[db59b02]148    mutable unsigned int list_flags;
[bae6a7c]149
[807f9dd]150    wxString vendor, renderer;
151
152    bool CheckVisualFidelity(const unsigned char * target) const;
153
[56da40e]154public:
[84f1ed1]155    GLACanvas(wxWindow* parent, int id);
[56da40e]156    ~GLACanvas();
[2c8b64f]157
[1b12b82]158    void FirstShow();
159
[56da40e]160    void Clear();
161    void StartDrawing();
162    void FinishDrawing();
163
[c5fc8eb]164    void SetVolumeDiameter(glaCoord diameter);
[56da40e]165    void SetDataTransform();
166    void SetIndicatorTransform();
[9cf3688]167
[d2fcc9b]168    void DrawList(unsigned int l);
[76dd228]169    void DrawList2D(unsigned int l, glaCoord x, glaCoord y, Double rotation);
[b3f1bbe]170    void InvalidateList(unsigned int l) {
171        if (l < drawing_lists.size()) {
172            // Invalidate any existing cached list.
173            drawing_lists[l].invalidate_if(CACHED);
174        }
175    }
176
[d2fcc9b]177    virtual void GenerateList(unsigned int l) = 0;
[9cf3688]178
[aa048c3]179    void SetColour(const GLAPen& pen, double rgb_scale);
180    void SetColour(const GLAPen& pen);
181    void SetColour(gla_colour colour);
182
[56da40e]183    void DrawText(glaCoord x, glaCoord y, glaCoord z, const wxString& str);
[1eeb55a]184    void DrawIndicatorText(int x, int y, const wxString& str);
185    void GetTextExtent(const wxString& str, int * x_ext, int * y_ext);
[9cf3688]186
[56da40e]187    void BeginQuadrilaterals();
188    void EndQuadrilaterals();
189    void BeginLines();
190    void EndLines();
[dde4fe7]191    void BeginTriangleStrip();
192    void EndTriangleStrip();
[56da40e]193    void BeginTriangles();
194    void EndTriangles();
195    void BeginPolyline();
196    void EndPolyline();
[45aa1d6]197    void BeginPolygon();
198    void EndPolygon();
[e633bb1]199    void BeginBlobs();
200    void EndBlobs();
[86fe6e4]201    void BeginCrosses();
202    void EndCrosses();
[9cf3688]203
[aa048c3]204    void DrawRectangle(gla_colour edge, gla_colour fill,
[d67450e]205                       glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
[aa048c3]206    void DrawShadedRectangle(const GLAPen & fill_bot, const GLAPen & fill_top,
207                             glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
208    void DrawCircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius);
209    void DrawSemicircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius, glaCoord start);
[d67450e]210    void DrawTriangle(gla_colour edge, gla_colour fill,
211                      const Vector3 &p0, const Vector3 &p1, const Vector3 &p2);
[9cf3688]212
[e633bb1]213    void DrawBlob(glaCoord x, glaCoord y, glaCoord z);
[81aea4e]214    void DrawBlob(glaCoord x, glaCoord y);
[86fe6e4]215    void DrawCross(glaCoord x, glaCoord y, glaCoord z);
[e633bb1]216    void DrawRing(glaCoord x, glaCoord y);
[9cf3688]217
[f336ab9]218    void PlaceVertex(const Vector3 & v, glaTexCoord tex_x, glaTexCoord tex_y) {
[b839829]219        PlaceVertex(v.GetX(), v.GetY(), v.GetZ(), tex_x, tex_y);
220    }
[d67450e]221    void PlaceVertex(const Vector3 & v) {
222        PlaceVertex(v.GetX(), v.GetY(), v.GetZ());
223    }
[56da40e]224    void PlaceVertex(glaCoord x, glaCoord y, glaCoord z);
[f336ab9]225    void PlaceVertex(glaCoord x, glaCoord y, glaCoord z,
226                     glaTexCoord tex_x, glaTexCoord tex_y);
[56da40e]227    void PlaceIndicatorVertex(glaCoord x, glaCoord y);
[203d2a7]228
[d67450e]229    void PlaceNormal(const Vector3 &v);
[9cf3688]230
[56da40e]231    void EnableDashedLines();
232    void DisableDashedLines();
233
[d67450e]234    void EnableSmoothPolygons(bool filled);
[1b12b82]235    void DisableSmoothPolygons();
236
[08253d9]237    void SetRotation(double pan, double tilt) {
238        m_Pan = pan;
239        m_Tilt = tilt;
240    }
[56da40e]241    void SetScale(Double);
[d67450e]242    void SetTranslation(const Vector3 &v) {
243        m_Translation = v;
244    }
245    void AddTranslation(const Vector3 &v) {
246        m_Translation += v;
247    }
248    const Vector3 & GetTranslation() const {
249        return m_Translation;
250    }
[56da40e]251    void AddTranslationScreenCoordinates(int dx, int dy);
252
[f6d8375]253    bool Transform(const Vector3 & v, double* x_out, double* y_out, double* z_out) const;
254    void ReverseTransform(Double x, Double y, double* x_out, double* y_out, double* z_out) const;
[56da40e]255
[1aa3fb7]256    int GetFontSize() const { return m_Font.get_font_size(); }
[087bc72]257
[d67450e]258    void ToggleSmoothShading();
259    bool GetSmoothShading() const { return m_SmoothShading; }
260
[e7f9e99]261    Double SurveyUnitsAcrossViewport() const;
[6abab84]262
[a517825]263    void ToggleTextured();
264    bool GetTextured() const { return m_Textured; }
265
[6abab84]266    void TogglePerspective() { m_Perspective = !m_Perspective; }
267    bool GetPerspective() const { return m_Perspective; }
[045e2af]268
[c60062d]269    void ToggleFog() { m_Fog = !m_Fog; }
270    bool GetFog() const { return m_Fog; }
271
[db452ae]272    void ToggleAntiAlias() { m_AntiAlias = !m_AntiAlias; }
273    bool GetAntiAlias() const { return m_AntiAlias; }
274
[1ada489]275    bool SaveScreenshot(const wxString & fnm, wxBitmapType type) const;
[aea4f8b]276
277    void ReadPixels(int width, int height, unsigned char * buf) const;
[f9ca87c]278
279    void PolygonOffset(bool on) const;
[90430f2]280
281    int GetXSize() const { list_flags |= INVALIDATE_ON_X_RESIZE; return x_size; }
282    int GetYSize() const { list_flags |= INVALIDATE_ON_Y_RESIZE; return y_size; }
283
284    void OnSize(wxSizeEvent & event);
[70acad9]285
286    glaCoord GetVolumeDiameter() const { return m_VolumeDiameter; }
[9071cf5]287
288private:
289    DECLARE_EVENT_TABLE()
[56da40e]290};
Note: See TracBrowser for help on using the repository browser.