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#ifdef __ANDROID__
31#include <qopengl.h>
32#include <GL/gl_private.h> // this is a cut-down version of gl.h
33#include <GLES2/gl2.h>
34
35#elif defined(ocpnUSE_GL)
36#if defined(__MSVC__)
37#include "glew.h"
38
39#elif defined(__WXOSX__)
40#include <OpenGL/gl.h>
41#include <OpenGL/glu.h>
42typedef void (*_GLUfuncptr)();
43#define GL_COMPRESSED_RGB_FXT1_3DFX 0x86B0
44
45#elif defined(__WXQT__) || defined(__WXGTK__)
46#include <GL/glew.h>
47#include <GL/glu.h>
48
49#else
50#error platform not supported.
51#endif // __ANDROID__
52#endif // ocpnUSE_GL
53
54#include <wx/glcanvas.h>
55
56#include "dychart.h"
57
58#include "model/ocpn_types.h"
59#include "OCPNRegion.h"
60#include "LLRegion.h"
61#include "viewport.h"
62#include "TexFont.h"
63#include "ocpndc.h"
64#include "chcanv.h"
65
66#include <array>
67#include <unordered_map>
68
69#define FORMAT_BITS GL_RGB
70
71#ifdef __OCPN__ANDROID__
72#include <wx/qt/private/wxQtGesture.h>
73#endif
74
75class glTexFactory;
76class ChartCanvas;
77
78#define GESTURE_EVENT_TIMER 78334
79#define ZOOM_TIMER 78335
80#define GESTURE_FINISH_TIMER 78336
81
83public:
84 std::string Renderer;
85 std::string Version;
86 std::string GLSL_Version;
87
88 double dGLSL_Version;
89 GLenum TextureRectangleFormat;
90
91 bool bOldIntel;
92 bool bCanDoVBO;
93 bool bCanDoFBO;
94 bool bCanDoGLSL;
95};
96
97GLboolean QueryExtension(const char *extName);
98
100public:
101 bool m_bUseAcceleratedPanning;
116
117 bool m_bTextureCompression;
118 bool m_bTextureCompressionCaching;
119
120 int m_iTextureDimension;
121 int m_iTextureMemorySize;
122
123 bool m_GLPolygonSmoothing;
124 bool m_GLLineSmoothing;
125};
126
127class glTestCanvas : public wxGLCanvas {
128public:
129 glTestCanvas(wxWindow *parent);
130 ~glTestCanvas() {};
131};
132
133class ocpnDC;
134class emboss_data;
135class Route;
136class ChartBaseBSB;
137
143class glChartCanvas : public wxGLCanvas {
144public:
145 static bool CanClipViewport(const ViewPort &vp);
146 static ViewPort ClippedViewport(const ViewPort &vp, const LLRegion &region);
147
148 static bool HasNormalizedViewPort(const ViewPort &vp);
149 static void MultMatrixViewPort(ViewPort &vp, float lat = 0, float lon = 0);
150 static ViewPort NormalizedViewPort(const ViewPort &vp, float lat = 0,
151 float lon = 0);
152
153 static void DrawRegion(ViewPort &vp, const LLRegion &region);
154 static void SetClipRegion(ViewPort &vp, const LLRegion &region);
155 static void SetClipRect(const ViewPort &vp, const wxRect &rect,
156 bool g_clear = false);
157 static void DisableClipRegion();
158 void SetColorScheme(ColorScheme cs);
159 void RenderTextures(ocpnDC &dc, float *coords, float *uvCoords, int nVertex,
160 ViewPort *vp);
161 static void RenderSingleTexture(ocpnDC &dc, float *coords, float *uvCoords,
162 ViewPort *vp, float dx, float dy,
163 float angle);
164 void RenderColorRect(wxRect r, wxColor &color);
165
166 static bool s_b_useScissorTest;
167 static bool s_b_useStencil;
168 static bool s_b_useStencilAP;
169 static bool s_b_useFBO;
170 static std::unordered_map<wxPenStyle, std::array<wxDash, 2>> dash_map;
171
172 void SendJSONConfigMessage();
173
174 glChartCanvas(wxWindow *parent, wxGLCanvas *share = NULL);
175
177
178 void Init();
179 void SetContext(wxGLContext *pcontext) { m_pcontext = pcontext; }
180 int GetCanvasIndex() { return m_pParentCanvas->m_canvasIndex; }
181
182 int GetGLCanvasWidth() { return m_glcanvas_width; }
183 int GetGLCanvasHeight() { return m_glcanvas_height; }
184
185 void OnPaint(wxPaintEvent &event);
186 void OnEraseBG(wxEraseEvent &evt);
187 void Render();
188 void OnActivate(wxActivateEvent &event);
189 void OnSize(wxSizeEvent &event);
190 void MouseEvent(wxMouseEvent &event);
191 void FastPan(int dx, int dy);
192 void FastZoom(float factor, float cp_x, float cp_y, float post_x,
193 float post_y);
194 // void RenderCanvasBackingChart( ocpnDC dc, OCPNRegion chart_get_region);
195 // void FastZoom(float factor);
196 void RenderCanvasBackingChart(ocpnDC &dc, OCPNRegion chart_get_region);
197
198#ifdef __OCPN__ANDROID__
199 void OnEvtPanGesture(wxQT_PanGestureEvent &event);
200 void OnEvtPinchGesture(wxQT_PinchGestureEvent &event);
201 void onGestureTimerEvent(wxTimerEvent &event);
202 void onGestureFinishTimerEvent(wxTimerEvent &event);
203#else
204#ifdef HAVE_WX_GESTURE_EVENTS
205 void OnEvtPanGesture(wxPanGestureEvent &event);
206 void OnEvtZoomGesture(wxZoomGestureEvent &event);
207 void onGestureTimerEvent(wxTimerEvent &event);
208 void onGestureFinishTimerEvent(wxTimerEvent &event);
209#endif
210#endif
211
212 void onZoomTimerEvent(wxTimerEvent &event);
213
214 wxString GetRendererString() { return m_renderer; }
215 wxString GetVersionString() { return m_version; }
216 wxString GetGLSLVersionString() { return m_GLSLversion; }
217 void EnablePaint(bool b_enable) { m_b_paint_enable = b_enable; }
218
219 void Invalidate();
220 void RenderRasterChartRegionGL(ChartBase *chart, ViewPort &vp,
221 LLRegion &region);
222
223 void DrawGLOverLayObjects(void);
224 void GridDraw();
225 void FlushFBO(void);
226
227 void DrawDynamicRoutesTracksAndWaypoints(ViewPort &vp);
228 void DrawStaticRoutesTracksAndWaypoints(ViewPort &vp);
229
230 void RenderAllChartOutlines(ocpnDC &dc, ViewPort &VP);
231 void RenderChartOutline(ocpnDC &dc, int dbIndex, ViewPort &VP);
232
233 void DrawEmboss(ocpnDC &dc, emboss_data *emboss);
234 void ShipDraw(ocpnDC &dc);
235
236 void SetupCompression();
237 bool CanAcceleratePanning() { return m_b_BuiltFBO; }
238 bool UsingFBO() { return m_b_BuiltFBO; }
239
240 bool isInGesture() { return m_binGesture; }
241 void ResetGridFont() { m_gridfont.Delete(); }
242 time_t m_last_render_time;
243
244 int viewport[4];
245 double mvmatrix[16], projmatrix[16];
246
247 void SetupOpenGL();
248 ChartCanvas *m_pParentCanvas;
249 ocpnDC m_gldc;
250
251protected:
252 void RenderS57TextOverlay(ViewPort &VPoint);
253 void RenderMBTilesOverlay(ViewPort &VPoint);
254 void RenderSingleMBTileOverlay(int dbIndex, bool bOVerlay, ViewPort &VPoint,
255 OCPNRegion &screen_region,
256 LLRegion &screenLLRegion);
257 void RenderScene(bool bRenderCharts = true, bool bRenderOverlays = true);
258
259 void RenderGLAlertMessage();
260
261 void RenderQuiltViewGL(ViewPort &vp, const OCPNRegion &rect_region);
262 void RenderQuiltViewGLText(ViewPort &vp, const OCPNRegion &rect_region);
263
264 void BuildFBO();
265 bool buildFBOSize(int fboSize);
266
267 void configureShaders(ViewPort &vp);
268
269 // void ComputeRenderQuiltViewGLRegion( ViewPort &vp, OCPNRegion &Region );
270 void RenderCharts(ocpnDC &dc, const OCPNRegion &rect_region);
271 void RenderNoDTA(ViewPort &vp, const LLRegion &region,
272 int transparency = 255);
273 // void RenderNoDTA(ViewPort &vp, ChartBase *chart);
274 void RenderWorldChart(ocpnDC &dc, ViewPort &vp, wxRect &rect,
275 bool &world_view);
276
277 void DrawFloatingOverlayObjects(ocpnDC &dc);
278 void DrawGroundedOverlayObjects(ocpnDC &dc, ViewPort &vp);
279
280 void DrawChartBar(ocpnDC &dc);
281 void DrawQuiting();
282 void DrawCloseMessage(wxString msg);
283
284 void DrawGLTidesInBBox(ocpnDC &dc, LLBBox &BBox);
285 void DrawGLCurrentsInBBox(ocpnDC &dc, LLBBox &BBox);
286
287 void ZoomProject(float offset_x, float offset_y, float swidth, float sheight);
288 wxBitmap &GetTouchBackingBitmap(ViewPort &vp);
289 void CreateBackingTexture();
290
291 void RendertoTexture(GLint tex);
292
293 wxGLContext *m_pcontext;
294
295 int max_texture_dimension;
296
297 bool m_bsetup;
298
299 wxString m_renderer;
300 wxString m_version, m_GLSLversion;
301 wxString m_extensions;
302
303 ViewPort m_cache_vp;
304 ChartBase *m_cache_current_ch;
305
306 bool m_b_paint_enable;
307 int m_in_glpaint;
308
309 // For FBO(s)
310 bool m_b_DisableFBO;
311 bool m_b_BuiltFBO;
312 bool m_b_useFBOStencil;
313 GLuint m_fb0;
314 GLuint m_renderbuffer;
315
316 GLuint m_cache_tex[2];
317 GLuint m_cache_page;
318 int m_cache_tex_x;
319 int m_cache_tex_y;
320
321 GLuint ownship_tex;
322 int ownship_color;
323 wxSize ownship_size, ownship_tex_size;
324
325 GLuint m_piano_tex;
326
327 float m_fbo_offsetx;
328 float m_fbo_offsety;
329 float m_fbo_swidth;
330 float m_fbo_sheight;
331
332 float m_lastfbo_offsetx;
333 float m_lastfbo_offsety;
334 float m_lastfbo_swidth;
335 float m_lastfbo_sheight;
336
337 float m_offsetxStep, m_offsetyStep, m_swidthStep, m_sheightStep;
338 float m_runoffsetx, m_runoffsety, m_runswidth, m_runsheight;
339 float m_nStep, m_nTotal, m_nRun;
340 bool m_zoomFinal;
341 double m_zoomFinalZoom;
342 int m_zoomFinaldx, m_zoomFinaldy;
343 bool m_bforcefull;
344
345 wxTimer zoomTimer;
346
347 double m_fbo_lat, m_fbo_lon;
348 int m_cc_x, m_cc_y;
349 wxPoint m_lpinchPoint;
350
351 bool m_binPinch;
352 bool m_binPan;
353 bool m_binGesture;
354
355 wxTimer m_gestureEeventTimer;
356 wxTimer m_gestureFinishTimer;
357 bool m_bgestureGuard;
358 bool m_bpinchGuard;
359 wxPoint m_pinchStart;
360 double m_pinchlat, m_pinchlon;
361
362 OCPNRegion m_canvasregion;
363 TexFont m_gridfont;
364
365 int m_LRUtime;
366
367 GLuint m_tideTex;
368 GLuint m_currentTex;
369 int m_tideTexWidth;
370 int m_tideTexHeight;
371 int m_currentTexWidth;
372 int m_currentTexHeight;
373 int m_displayScale;
374
375 int m_glcanvas_width;
376 int m_glcanvas_height;
377
378 float m_total_zoom_val;
379 float m_final_zoom_val;
380
381 bool m_bUseGLSL;
382
383 wxBitmap m_touch_backing_bitmap;
384 unsigned int m_TouchBackingTexture;
385 int m_tex_w, m_tex_h, m_image_width, m_image_height;
386 ViewPort m_texVP;
387 float m_zoom_inc;
388
389 DECLARE_EVENT_TABLE()
390};
391
392extern void BuildCompressedCache();
393
394#include "glTextureManager.h"
395extern glTextureManager *g_glTextureManager;
396
397#endif
Base class for BSB (Maptech/NOS) format nautical charts.
Definition chartimg.h:131
Base class for all chart types.
Definition chartbase.h:119
Chart display canvas.
Definition chcanv.h:135
A wrapper class for wxRegion with additional functionality.
Definition OCPNRegion.h:56
Definition route.h:75
Represents the view port for chart display in OpenCPN.
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:64
bool m_bUseCanvasPanning
Controls OpenGL canvas hardware-accelerated panning mode.