OpenCPN Partial API docs
Loading...
Searching...
No Matches
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// We need to set up our openGL environment before including
29// glcanvas.h which includes GL/gl.h
30#include "gl_headers.h"
31
32#include <wx/glcanvas.h>
33
34#include "dychart.h"
35
36#include "model/ocpn_types.h"
37#include "OCPNRegion.h"
38#include "LLRegion.h"
39#include "viewport.h"
40#include "TexFont.h"
41#include "ocpndc.h"
42#include "chcanv.h"
43#include "ocpn_gl_options.h"
44
45#include <array>
46#include <unordered_map>
47
48#define FORMAT_BITS GL_RGB
49
50#ifdef __OCPN__ANDROID__
51#include <wx/qt/private/wxQtGesture.h>
52#endif
53
54class glTexFactory;
55class ChartCanvas;
56
57#define GESTURE_EVENT_TIMER 78334
58#define ZOOM_TIMER 78335
59#define GESTURE_FINISH_TIMER 78336
60
62public:
63 std::string Renderer;
64 std::string Version;
65 std::string GLSL_Version;
66
67 double dGLSL_Version;
68 GLenum TextureRectangleFormat;
69
70 bool bOldIntel;
71 bool bCanDoVBO;
72 bool bCanDoFBO;
73 bool bCanDoGLSL;
74};
75
76GLboolean QueryExtension(const char *extName);
77
78class glTestCanvas : public wxGLCanvas {
79public:
80 glTestCanvas(wxWindow *parent);
81 ~glTestCanvas() {};
82};
83
84class ocpnDC;
85class emboss_data;
86class Route;
87class ChartBaseBSB;
88
94class glChartCanvas : public wxGLCanvas {
95public:
96 static bool CanClipViewport(const ViewPort &vp);
97 static ViewPort ClippedViewport(const ViewPort &vp, const LLRegion &region);
98
99 static bool HasNormalizedViewPort(const ViewPort &vp);
100 static void MultMatrixViewPort(ViewPort &vp, float lat = 0, float lon = 0);
101 static ViewPort NormalizedViewPort(const ViewPort &vp, float lat = 0,
102 float lon = 0);
103
104 static void DrawRegion(ViewPort &vp, const LLRegion &region);
105 static void SetClipRegion(ViewPort &vp, const LLRegion &region);
106 static void SetClipRect(const ViewPort &vp, const wxRect &rect,
107 bool g_clear = false);
108 static void DisableClipRegion();
109 void SetColorScheme(ColorScheme cs);
110 void RenderTextures(ocpnDC &dc, float *coords, float *uvCoords, int nVertex,
111 ViewPort *vp);
112 static void RenderSingleTexture(ocpnDC &dc, float *coords, float *uvCoords,
113 ViewPort *vp, float dx, float dy,
114 float angle);
115 void RenderColorRect(wxRect r, wxColor &color);
116
117 static bool s_b_useScissorTest;
118 static bool s_b_useStencil;
119 static bool s_b_useStencilAP;
120 static bool s_b_useFBO;
121 static std::unordered_map<wxPenStyle, std::array<wxDash, 2>> dash_map;
122
123 void SendJSONConfigMessage();
124
125 glChartCanvas(wxWindow *parent, wxGLCanvas *share = NULL);
126
128
129 void Init();
130 void SetContext(wxGLContext *pcontext) { m_pcontext = pcontext; }
131 int GetCanvasIndex() { return m_pParentCanvas->m_canvasIndex; }
132
133 int GetGLCanvasWidth() { return m_glcanvas_width; }
134 int GetGLCanvasHeight() { return m_glcanvas_height; }
135
136 void OnPaint(wxPaintEvent &event);
137 void OnEraseBG(wxEraseEvent &evt);
138 void Render();
139 void OnActivate(wxActivateEvent &event);
140 void OnSize(wxSizeEvent &event);
141 void MouseEvent(wxMouseEvent &event);
142 void FastPan(int dx, int dy);
143 void FastZoom(float factor, float cp_x, float cp_y, float post_x,
144 float post_y);
145 // void RenderCanvasBackingChart( ocpnDC dc, OCPNRegion chart_get_region);
146 // void FastZoom(float factor);
147 void RenderCanvasBackingChart(ocpnDC &dc, OCPNRegion chart_get_region);
148
149#ifdef __OCPN__ANDROID__
150 void OnEvtPanGesture(wxQT_PanGestureEvent &event);
151 void OnEvtPinchGesture(wxQT_PinchGestureEvent &event);
152 void onGestureTimerEvent(wxTimerEvent &event);
153 void onGestureFinishTimerEvent(wxTimerEvent &event);
154#else
155#ifdef HAVE_WX_GESTURE_EVENTS
156 void OnEvtPanGesture(wxPanGestureEvent &event);
157 void OnEvtZoomGesture(wxZoomGestureEvent &event);
158 void onGestureTimerEvent(wxTimerEvent &event);
159 void onGestureFinishTimerEvent(wxTimerEvent &event);
160#endif
161#endif
162
163 void onZoomTimerEvent(wxTimerEvent &event);
164
165 wxString GetRendererString() { return m_renderer; }
166 wxString GetVersionString() { return m_version; }
167 wxString GetGLSLVersionString() { return m_GLSLversion; }
168 void EnablePaint(bool b_enable) { m_b_paint_enable = b_enable; }
169
170 void Invalidate();
171 void RenderRasterChartRegionGL(ChartBase *chart, ViewPort &vp,
172 LLRegion &region);
173
174 void DrawGLOverLayObjects(void);
175 void GridDraw();
176 void FlushFBO(void);
177
178 void DrawDynamicRoutesTracksAndWaypoints(ViewPort &vp);
179 void DrawStaticRoutesTracksAndWaypoints(ViewPort &vp);
180
181 void RenderAllChartOutlines(ocpnDC &dc, ViewPort &VP);
182 void RenderChartOutline(ocpnDC &dc, int dbIndex, ViewPort &VP);
183
184 void DrawEmboss(ocpnDC &dc, emboss_data *emboss);
185 void ShipDraw(ocpnDC &dc);
186
187 void SetupCompression();
188 bool CanAcceleratePanning() { return m_b_BuiltFBO; }
189 bool UsingFBO() { return m_b_BuiltFBO; }
190
191 bool isInGesture() { return m_binGesture; }
192 void ResetGridFont() { m_gridfont.Delete(); }
193 time_t m_last_render_time;
194
195 int viewport[4];
196 double mvmatrix[16], projmatrix[16];
197
198 void SetupOpenGL();
199 ChartCanvas *m_pParentCanvas;
200 ocpnDC m_gldc;
201
202protected:
203 void RenderS57TextOverlay(ViewPort &VPoint);
204 void RenderMBTilesOverlay(ViewPort &VPoint);
205 void RenderSingleMBTileOverlay(int dbIndex, bool bOVerlay, ViewPort &VPoint,
206 OCPNRegion &screen_region,
207 LLRegion &screenLLRegion);
208 void RenderScene(bool bRenderCharts = true, bool bRenderOverlays = true);
209
210 void RenderGLAlertMessage();
211
212 void RenderQuiltViewGL(ViewPort &vp, const OCPNRegion &rect_region);
213 void RenderQuiltViewGLText(ViewPort &vp, const OCPNRegion &rect_region);
214
215 void BuildFBO();
216 bool buildFBOSize(int fboSize);
217
218 void configureShaders(ViewPort &vp);
219
220 // void ComputeRenderQuiltViewGLRegion( ViewPort &vp, OCPNRegion &Region );
221 void RenderCharts(ocpnDC &dc, const OCPNRegion &rect_region);
222 void RenderNoDTA(ViewPort &vp, const LLRegion &region,
223 int transparency = 255);
224 // void RenderNoDTA(ViewPort &vp, ChartBase *chart);
225 void RenderWorldChart(ocpnDC &dc, ViewPort &vp, wxRect &rect,
226 bool &world_view);
227
228 void DrawFloatingOverlayObjects(ocpnDC &dc);
229 void DrawGroundedOverlayObjects(ocpnDC &dc, ViewPort &vp);
230
231 void DrawChartBar(ocpnDC &dc);
232 void DrawQuiting();
233 void DrawCloseMessage(wxString msg);
234
235 void DrawGLTidesInBBox(ocpnDC &dc, LLBBox &BBox);
236 void DrawGLCurrentsInBBox(ocpnDC &dc, LLBBox &BBox);
237
238 void ZoomProject(float offset_x, float offset_y, float swidth, float sheight);
239 wxBitmap &GetTouchBackingBitmap(ViewPort &vp);
240 void CreateBackingTexture();
241
242 void RendertoTexture(GLint tex);
243
244 wxGLContext *m_pcontext;
245
246 int max_texture_dimension;
247
248 bool m_bsetup;
249
250 wxString m_renderer;
251 wxString m_version, m_GLSLversion;
252 wxString m_extensions;
253
254 ViewPort m_cache_vp;
255 ChartBase *m_cache_current_ch;
256
257 bool m_b_paint_enable;
258 int m_in_glpaint;
259
260 // For FBO(s)
261 bool m_b_DisableFBO;
262 bool m_b_BuiltFBO;
263 bool m_b_useFBOStencil;
264 GLuint m_fb0;
265 GLuint m_renderbuffer;
266
267 GLuint m_cache_tex[2];
268 GLuint m_cache_page;
269 int m_cache_tex_x;
270 int m_cache_tex_y;
271
272 GLuint ownship_tex;
273 int ownship_color;
274 wxSize ownship_size, ownship_tex_size;
275
276 GLuint m_piano_tex;
277
278 float m_fbo_offsetx;
279 float m_fbo_offsety;
280 float m_fbo_swidth;
281 float m_fbo_sheight;
282
283 float m_lastfbo_offsetx;
284 float m_lastfbo_offsety;
285 float m_lastfbo_swidth;
286 float m_lastfbo_sheight;
287
288 float m_offsetxStep, m_offsetyStep, m_swidthStep, m_sheightStep;
289 float m_runoffsetx, m_runoffsety, m_runswidth, m_runsheight;
290 float m_nStep, m_nTotal, m_nRun;
291 bool m_zoomFinal;
292 double m_zoomFinalZoom;
293 int m_zoomFinaldx, m_zoomFinaldy;
294 bool m_bforcefull;
295
296 wxTimer zoomTimer;
297
298 double m_fbo_lat, m_fbo_lon;
299 int m_cc_x, m_cc_y;
300 wxPoint m_lpinchPoint;
301
302 bool m_binPinch;
303 bool m_binPan;
304 bool m_binGesture;
305
306 wxTimer m_gestureEeventTimer;
307 wxTimer m_gestureFinishTimer;
308 bool m_bgestureGuard;
309 bool m_bpinchGuard;
310 wxPoint m_pinchStart;
311 double m_pinchlat, m_pinchlon;
312
313 OCPNRegion m_canvasregion;
314 TexFont m_gridfont;
315
316 int m_LRUtime;
317
318 GLuint m_tideTex;
319 GLuint m_currentTex;
320 int m_tideTexWidth;
321 int m_tideTexHeight;
322 int m_currentTexWidth;
323 int m_currentTexHeight;
324 int m_displayScale;
325
326 int m_glcanvas_width;
327 int m_glcanvas_height;
328
329 float m_total_zoom_val;
330 float m_final_zoom_val;
331
332 bool m_bUseGLSL;
333
334 wxBitmap m_touch_backing_bitmap;
335 unsigned int m_TouchBackingTexture;
336 int m_tex_w, m_tex_h, m_image_width, m_image_height;
337 ViewPort m_texVP;
338 float m_zoom_inc;
339
340 DECLARE_EVENT_TABLE()
341};
342
343extern void BuildCompressedCache();
344
345#include "glTextureManager.h"
346extern glTextureManager *g_glTextureManager;
347
348#endif
Generic Chart canvas base.
Base class for BSB (Maptech/NOS) format nautical charts.
Definition chartimg.h:127
Base class for all chart types.
Definition chartbase.h:125
ChartCanvas - Main chart display and interaction component.
Definition chcanv.h:151
A wrapper class for wxRegion with additional functionality.
Definition OCPNRegion.h:56
Represents a navigational route in the navigation system.
Definition route.h:98
ViewPort - Core geographic projection and coordinate transformation engine.
Definition viewport.h:84
Stores emboss effect data for textures.
Definition emboss_data.h:35
OpenGL chart rendering canvas.
Device context class that can use either wxDC or OpenGL for drawing.
Definition ocpndc.h:60
Platform independent GL includes.
Class ocpnGLOptions – OpenGL runtime options.