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