OpenCPN Partial API docs
glChartCanvas.h
1 /******************************************************************************
2  *
3  * Project: OpenCPN
4  *
5  ***************************************************************************
6  * Copyright (C) 2013 by David S. Register *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
22  ***************************************************************************
23  */
24 
25 #ifndef __GLCHARTCANVAS_H__
26 #define __GLCHARTCANVAS_H__
27 
28 #include <wx/glcanvas.h>
29 
30 #include "dychart.h"
31 
32 #include "model/ocpn_types.h"
33 #include "OCPNRegion.h"
34 #include "LLRegion.h"
35 #include "viewport.h"
36 #include "TexFont.h"
37 #include "ocpndc.h"
38 #include "chcanv.h"
39 
40 #include <array>
41 #include <unordered_map>
42 
43 #define FORMAT_BITS GL_RGB
44 
45 #ifdef __OCPN__ANDROID__
46 #include <wx/qt/private/wxQtGesture.h>
47 #endif
48 
49 class glTexFactory;
50 class ChartCanvas;
51 
52 #define GESTURE_EVENT_TIMER 78334
53 #define ZOOM_TIMER 78335
54 #define GESTURE_FINISH_TIMER 78336
55 
56 class OCPN_GLCaps {
57 public:
58  std::string Renderer;
59  std::string Version;
60  std::string GLSL_Version;
61 
62  double dGLSL_Version;
63  GLenum TextureRectangleFormat;
64 
65  bool bOldIntel;
66  bool bCanDoVBO;
67  bool bCanDoFBO;
68  bool bCanDoGLSL;
69 
70 };
71 
72 GLboolean QueryExtension(const char *extName);
73 
75 public:
76  bool m_bUseAcceleratedPanning;
77  bool m_bUseCanvasPanning;
78 
79  bool m_bTextureCompression;
80  bool m_bTextureCompressionCaching;
81 
82  int m_iTextureDimension;
83  int m_iTextureMemorySize;
84 
85  bool m_GLPolygonSmoothing;
86  bool m_GLLineSmoothing;
87 };
88 
89 class glTestCanvas : public wxGLCanvas {
90 public:
91  glTestCanvas(wxWindow *parent);
92  ~glTestCanvas(){};
93 };
94 
95 class ocpnDC;
96 class emboss_data;
97 class Route;
98 class ChartBaseBSB;
99 
100 class glChartCanvas : public wxGLCanvas {
101 public:
102  static bool CanClipViewport(const ViewPort &vp);
103  static ViewPort ClippedViewport(const ViewPort &vp, const LLRegion &region);
104 
105  static bool HasNormalizedViewPort(const ViewPort &vp);
106  static void MultMatrixViewPort(ViewPort &vp, float lat = 0, float lon = 0);
107  static ViewPort NormalizedViewPort(const ViewPort &vp, float lat = 0,
108  float lon = 0);
109 
110  static void DrawRegion(ViewPort &vp, const LLRegion &region);
111  static void SetClipRegion(ViewPort &vp, const LLRegion &region);
112  static void SetClipRect(const ViewPort &vp, const wxRect &rect,
113  bool g_clear = false);
114  static void DisableClipRegion();
115  void SetColorScheme(ColorScheme cs);
116  void RenderTextures(ocpnDC &dc, float *coords, float *uvCoords, int nVertex,
117  ViewPort *vp);
118  static void RenderSingleTexture(ocpnDC &dc, float *coords, float *uvCoords, ViewPort *vp,
119  float dx, float dy, float angle);
120  void RenderColorRect(wxRect r, wxColor &color);
121 
122  static bool s_b_useScissorTest;
123  static bool s_b_useStencil;
124  static bool s_b_useStencilAP;
125  static bool s_b_useFBO;
126  static std::unordered_map<wxPenStyle, std::array<wxDash, 2>> dash_map;
127 
128  void SendJSONConfigMessage();
129 
130  glChartCanvas(wxWindow *parent, wxGLCanvas *share = NULL);
131 
132  ~glChartCanvas();
133 
134  void Init();
135  void SetContext(wxGLContext *pcontext) { m_pcontext = pcontext; }
136  int GetCanvasIndex() { return m_pParentCanvas->m_canvasIndex; }
137 
138  int GetGLCanvasWidth() { return m_glcanvas_width; }
139  int GetGLCanvasHeight() { return m_glcanvas_height; }
140 
141  void OnPaint(wxPaintEvent &event);
142  void OnEraseBG(wxEraseEvent &evt);
143  void Render();
144  void OnActivate(wxActivateEvent &event);
145  void OnSize(wxSizeEvent &event);
146  void MouseEvent(wxMouseEvent &event);
147  void FastPan(int dx, int dy);
148  void FastZoom(float factor, float cp_x, float cp_y, float post_x,
149  float post_y);
150  // void RenderCanvasBackingChart( ocpnDC dc, OCPNRegion chart_get_region);
151  // void FastZoom(float factor);
152  void RenderCanvasBackingChart(ocpnDC &dc, OCPNRegion chart_get_region);
153 
154 #ifdef __OCPN__ANDROID__
155  void OnEvtPanGesture(wxQT_PanGestureEvent &event);
156  void OnEvtPinchGesture(wxQT_PinchGestureEvent &event);
157  void onGestureTimerEvent(wxTimerEvent &event);
158  void onGestureFinishTimerEvent(wxTimerEvent &event);
159 #endif
160 
161  void onZoomTimerEvent(wxTimerEvent &event);
162 
163  wxString GetRendererString() { return m_renderer; }
164  wxString GetVersionString() { return m_version; }
165  wxString GetGLSLVersionString() { return m_GLSLversion; }
166  void EnablePaint(bool b_enable) { m_b_paint_enable = b_enable; }
167 
168  void Invalidate();
169  void RenderRasterChartRegionGL(ChartBase *chart, ViewPort &vp,
170  LLRegion &region);
171 
172  void DrawGLOverLayObjects(void);
173  void GridDraw();
174  void FlushFBO(void);
175 
176  void DrawDynamicRoutesTracksAndWaypoints(ViewPort &vp);
177  void DrawStaticRoutesTracksAndWaypoints(ViewPort &vp);
178 
179  void RenderAllChartOutlines(ocpnDC &dc, ViewPort &VP);
180  void RenderChartOutline(ocpnDC &dc, int dbIndex, ViewPort &VP);
181 
182  void DrawEmboss(ocpnDC &dc, emboss_data *emboss);
183  void ShipDraw(ocpnDC &dc);
184 
185  void SetupCompression();
186  bool CanAcceleratePanning() { return m_b_BuiltFBO; }
187  bool UsingFBO() { return m_b_BuiltFBO; }
188 
189  bool isInGesture() { return m_binGesture; }
190  void ResetGridFont() { m_gridfont.Delete(); }
191  time_t m_last_render_time;
192 
193  int viewport[4];
194  double mvmatrix[16], projmatrix[16];
195 
196  void SetupOpenGL();
197  ChartCanvas *m_pParentCanvas;
198  ocpnDC m_gldc;
199 
200 protected:
201  void RenderS57TextOverlay(ViewPort &VPoint);
202  void RenderMBTilesOverlay(ViewPort &VPoint);
203  void RenderScene(bool bRenderCharts = true, bool bRenderOverlays = true);
204 
205  void RenderGLAlertMessage();
206 
207  void RenderQuiltViewGL(ViewPort &vp, const OCPNRegion &rect_region);
208  void RenderQuiltViewGLText(ViewPort &vp, const OCPNRegion &rect_region);
209 
210  void BuildFBO();
211  bool buildFBOSize(int fboSize);
212 
213  void configureShaders(ViewPort &vp);
214 
215  // void ComputeRenderQuiltViewGLRegion( ViewPort &vp, OCPNRegion &Region );
216  void RenderCharts(ocpnDC &dc, const OCPNRegion &rect_region);
217  void RenderNoDTA(ViewPort &vp, const LLRegion &region,
218  int transparency = 255);
219  //void RenderNoDTA(ViewPort &vp, ChartBase *chart);
220  void RenderWorldChart(ocpnDC &dc, ViewPort &vp, wxRect &rect,
221  bool &world_view);
222 
223  void DrawFloatingOverlayObjects(ocpnDC &dc);
224  void DrawGroundedOverlayObjects(ocpnDC &dc, ViewPort &vp);
225 
226  void DrawChartBar(ocpnDC &dc);
227  void DrawQuiting();
228  void DrawCloseMessage(wxString msg);
229 
230  void DrawGLTidesInBBox(ocpnDC &dc, LLBBox &BBox);
231  void DrawGLCurrentsInBBox(ocpnDC &dc, LLBBox &BBox);
232 
233  void ZoomProject(float offset_x, float offset_y, float swidth, float sheight);
234 
235  void RendertoTexture(GLint tex);
236 
237  wxGLContext *m_pcontext;
238 
239  int max_texture_dimension;
240 
241  bool m_bsetup;
242 
243  wxString m_renderer;
244  wxString m_version, m_GLSLversion;
245  wxString m_extensions;
246 
247  ViewPort m_cache_vp;
248  ChartBase *m_cache_current_ch;
249 
250  bool m_b_paint_enable;
251  int m_in_glpaint;
252 
253  // For FBO(s)
254  bool m_b_DisableFBO;
255  bool m_b_BuiltFBO;
256  bool m_b_useFBOStencil;
257  GLuint m_fb0;
258  GLuint m_renderbuffer;
259 
260  GLuint m_cache_tex[2];
261  GLuint m_cache_page;
262  int m_cache_tex_x;
263  int m_cache_tex_y;
264 
265  GLuint ownship_tex;
266  int ownship_color;
267  wxSize ownship_size, ownship_tex_size;
268 
269  GLuint m_piano_tex;
270 
271  float m_fbo_offsetx;
272  float m_fbo_offsety;
273  float m_fbo_swidth;
274  float m_fbo_sheight;
275 
276  float m_lastfbo_offsetx;
277  float m_lastfbo_offsety;
278  float m_lastfbo_swidth;
279  float m_lastfbo_sheight;
280 
281  float m_offsetxStep, m_offsetyStep, m_swidthStep, m_sheightStep;
282  float m_runoffsetx, m_runoffsety, m_runswidth, m_runsheight;
283  float m_nStep, m_nTotal, m_nRun;
284  bool m_zoomFinal;
285  double m_zoomFinalZoom;
286  int m_zoomFinaldx, m_zoomFinaldy;
287  bool m_bforcefull;
288 
289  wxTimer zoomTimer;
290 
291  double m_fbo_lat, m_fbo_lon;
292  int m_cc_x, m_cc_y;
293  wxPoint m_lpinchPoint;
294 
295  bool m_binPinch;
296  bool m_binPan;
297  bool m_binGesture;
298 
299  wxTimer m_gestureEeventTimer;
300  wxTimer m_gestureFinishTimer;
301  bool m_bgestureGuard;
302  bool m_bpinchGuard;
303  wxPoint m_pinchStart;
304  double m_pinchlat, m_pinchlon;
305 
306  OCPNRegion m_canvasregion;
307  TexFont m_gridfont;
308 
309  int m_LRUtime;
310 
311  GLuint m_tideTex;
312  GLuint m_currentTex;
313  int m_tideTexWidth;
314  int m_tideTexHeight;
315  int m_currentTexWidth;
316  int m_currentTexHeight;
317  int m_displayScale;
318 
319  int m_glcanvas_width;
320  int m_glcanvas_height;
321 
322  bool m_bUseGLSL;
323 
324  DECLARE_EVENT_TABLE()
325 };
326 
327 extern void BuildCompressedCache();
328 
329 #include "glTextureManager.h"
330 extern glTextureManager *g_glTextureManager;
331 
332 #endif
Definition: route.h:75
Definition: ocpndc.h:58