source: git/src/gla.h @ 6616cdbf

stereo
Last change on this file since 6616cdbf was 6616cdbf, checked in by Olly Betts <olly@…>, 6 years ago

Push stereo OpenGL code down to gla layer

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