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