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 "OCPNRegion.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
213protected:
214 void RenderS57TextOverlay(ViewPort &VPoint);
215 void RenderMBTilesOverlay(ViewPort &VPoint);
216 void RenderSingleMBTileOverlay(int dbIndex, bool bOVerlay, ViewPort &VPoint,
217 OCPNRegion &screen_region,
218 LLRegion &screenLLRegion);
219 void RenderScene(bool bRenderCharts = true, bool bRenderOverlays = true);
220
221 void RenderGLAlertMessage();
222
223 void RenderQuiltViewGL(ViewPort &vp, const OCPNRegion &rect_region);
224 void RenderQuiltViewGLText(ViewPort &vp, const OCPNRegion &rect_region);
225
226 void BuildFBO();
227 bool buildFBOSize(int fboSize);
228
229 void configureShaders(ViewPort &vp);
230
231 // void ComputeRenderQuiltViewGLRegion( ViewPort &vp, OCPNRegion &Region );
232 void RenderCharts(ocpnDC &dc, const OCPNRegion &rect_region);
233 void RenderNoDTA(ViewPort &vp, const LLRegion &region,
234 int transparency = 255);
235 // void RenderNoDTA(ViewPort &vp, ChartBase *chart);
236 void RenderWorldChart(ocpnDC &dc, ViewPort &vp, wxRect &rect,
237 bool &world_view);
238
239 void DrawFloatingOverlayObjects(ocpnDC &dc);
240 void DrawGroundedOverlayObjects(ocpnDC &dc, ViewPort &vp);
241
242 void DrawChartBar(ocpnDC &dc);
243 void DrawQuiting();
244 void DrawCloseMessage(wxString msg);
245
246 void DrawGLTidesInBBox(ocpnDC &dc, LLBBox &BBox);
247 void DrawGLCurrentsInBBox(ocpnDC &dc, LLBBox &BBox);
248
249 void ZoomProject(float offset_x, float offset_y, float swidth, float sheight);
250 wxBitmap &GetTouchBackingBitmap(ViewPort &vp);
251 void CreateBackingTexture();
252
253 void RendertoTexture(GLint tex);
254
255 wxGLContext *m_pcontext;
256
257 int max_texture_dimension;
258
259 bool m_bsetup;
260
261 wxString m_renderer;
262 wxString m_version, m_GLSLversion;
263 wxString m_extensions;
264
265 ViewPort m_cache_vp;
266 ChartBase *m_cache_current_ch;
267
268 bool m_b_paint_enable;
269 int m_in_glpaint;
270
271 // For FBO(s)
272 bool m_b_DisableFBO;
273 bool m_b_BuiltFBO;
274 bool m_b_useFBOStencil;
275 GLuint m_fb0;
276 GLuint m_renderbuffer;
277
278 GLuint m_cache_tex[2];
279 GLuint m_cache_page;
280 int m_cache_tex_x;
281 int m_cache_tex_y;
282
283 GLuint ownship_tex;
284 int ownship_color;
285 wxSize ownship_size, ownship_tex_size;
286
287 GLuint m_piano_tex;
288
289 float m_fbo_offsetx;
290 float m_fbo_offsety;
291 float m_fbo_swidth;
292 float m_fbo_sheight;
293
294 float m_lastfbo_offsetx;
295 float m_lastfbo_offsety;
296 float m_lastfbo_swidth;
297 float m_lastfbo_sheight;
298
299 float m_offsetxStep, m_offsetyStep, m_swidthStep, m_sheightStep;
300 float m_runoffsetx, m_runoffsety, m_runswidth, m_runsheight;
301 float m_nStep, m_nTotal, m_nRun;
302 bool m_zoomFinal;
303 double m_zoomFinalZoom;
304 int m_zoomFinaldx, m_zoomFinaldy;
305 bool m_bforcefull;
306
307 wxTimer zoomTimer;
308
309 double m_fbo_lat, m_fbo_lon;
310 int m_cc_x, m_cc_y;
311 wxPoint m_lpinchPoint;
312
313 bool m_binPinch;
314 bool m_binPan;
315 bool m_binGesture;
316
317 wxTimer m_gestureEeventTimer;
318 wxTimer m_gestureFinishTimer;
319 bool m_bgestureGuard;
320 bool m_bpinchGuard;
321 wxPoint m_pinchStart;
322 double m_pinchlat, m_pinchlon;
323
324 OCPNRegion m_canvasregion;
325 TexFont m_gridfont;
326
327 int m_LRUtime;
328
329 GLuint m_tideTex;
330 GLuint m_currentTex;
331 int m_tideTexWidth;
332 int m_tideTexHeight;
333 int m_currentTexWidth;
334 int m_currentTexHeight;
335 int m_displayScale;
336
337 int m_glcanvas_width;
338 int m_glcanvas_height;
339
340 float m_total_zoom_val;
341 float m_final_zoom_val;
342
343 bool m_bUseGLSL;
344
345 wxBitmap m_touch_backing_bitmap;
346 unsigned int m_TouchBackingTexture;
347 int m_tex_w, m_tex_h, m_image_width, m_image_height;
348 ViewPort m_texVP;
349 float m_zoom_inc;
350
351 DECLARE_EVENT_TABLE()
352};
353
354#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:151
A wrapper class for wxRegion with additional functionality.
Definition OCPNRegion.h:56
ViewPort - Core geographic projection and coordinate transformation engine.
Definition viewport.h:84
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.
Class ocpnGLOptions – OpenGL runtime options.