OpenCPN Partial API docs
Loading...
Searching...
No Matches
ocpndc.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2011 by Sean D'Epagnier *
3 * sean at depagnier dot com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
25#ifndef __OCPNDC_H__
26#define __OCPNDC_H__
27
28#ifdef ocpnUSE_GL
29#include "gl_headers.h"
30#include "shaders.h"
31#endif
32
33#include <wx/brush.h>
34#include <wx/colour.h>
35#include <wx/font.h>
36#include <wx/glcanvas.h>
37#include <wx/pen.h>
38#include <wx/string.h>
39
40#include "linmath.h"
41
42#include "TexFont.h"
43#include "viewport.h"
44
45class glChartCanvas; // Circular
46
47static void DrawGLThickLine(float x1, float y1, float x2, float y2, wxPen pen,
48 bool b_hiqual);
49
50//----------------------------------------------------------------------------
51// ocpnDC
52//----------------------------------------------------------------------------
53
60class ocpnDC {
61public:
62 ocpnDC(glChartCanvas &canvas);
63 ocpnDC(wxGLCanvas &canvas);
64 ocpnDC(wxDC &pdc);
65 ocpnDC();
66
67 ~ocpnDC();
68
69 void Init();
70
71 void SetGLCanvas(glChartCanvas *canvas);
72 void SetBackground(const wxBrush &brush);
73 void SetPen(const wxPen &pen);
74 void SetBrush(const wxBrush &brush);
75 void SetTextForeground(const wxColour &colour);
76 void SetFont(const wxFont &font);
77 static void SetGLAttrs(bool highQuality);
78 void SetGLStipple() const;
79
80 const wxPen &GetPen() const;
81 const wxBrush &GetBrush() const;
82 const wxFont &GetFont() const;
83
84 void GetSize(wxCoord *width, wxCoord *height) const;
85
102 void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
103 bool b_hiqual = true);
104 void DrawLines(int n, wxPoint points[], wxCoord xoffset = 0,
105 wxCoord yoffset = 0, bool b_hiqual = true);
106 void DrawGLThickLine(float x1, float y1, float x2, float y2, wxPen pen,
107 bool b_hiqual);
108 void DrawGLThickLines(int n, wxPoint points[], wxCoord xoffset,
109 wxCoord yoffset, wxPen pen, bool b_hiqual);
110
111 void StrokeLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
112 void StrokeLine(wxPoint a, wxPoint b) { StrokeLine(a.x, a.y, b.x, b.y); }
113 void StrokeLines(int n, wxPoint *points);
114
115 void Clear();
116 void DrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
117 void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
118 wxCoord rr);
119 void DrawCircle(wxCoord x, wxCoord y, wxCoord radius);
120 void DrawCircle(const wxPoint &pt, wxCoord radius) {
121 DrawCircle(pt.x, pt.y, radius);
122 }
123 void StrokeCircle(wxCoord x, wxCoord y, wxCoord radius);
124
125 void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
126 void DrawPolygon(int n, wxPoint points[], wxCoord xoffset = 0,
127 wxCoord yoffset = 0, float scale = 1.0, float angle = 0.0);
128 void DrawPolygonTessellated(int n, wxPoint points[], wxCoord xoffset = 0,
129 wxCoord yoffset = 0);
130 void StrokePolygon(int n, wxPoint points[], wxCoord xoffset = 0,
131 wxCoord yoffset = 0, float scale = 1.0);
132
133 void DrawBitmap(const wxBitmap &bitmap, wxCoord x, wxCoord y, bool usemask);
134
135 void DrawText(const wxString &text, wxCoord x, wxCoord y, float angle = 0.0);
136 void GetTextExtent(const wxString &string, wxCoord *w, wxCoord *h,
137 wxCoord *descent = NULL, wxCoord *externalLeading = NULL,
138 wxFont *font = NULL);
139
140 void ResetBoundingBox();
141 void CalcBoundingBox(wxCoord x, wxCoord y);
142
143 void DestroyClippingRegion() {}
144
145 wxDC *GetDC() const { return dc; }
146 void SetDPIFactor(double factor) { m_dpi_factor = factor; }
147 void SetVP(ViewPort vp);
148
149#ifdef ocpnUSE_GL
150 GLfloat *s_odc_tess_work_buf;
151#endif
152
153#if defined(USE_ANDROID_GLES2) || defined(ocpnUSE_GLSL)
154 int s_odc_tess_vertex_idx;
155 int s_odc_tess_vertex_idx_this;
156 int s_odc_tess_buf_len;
157 GLenum s_odc_tess_mode;
158 int s_odc_nvertex;
159 vec4 s_odc_tess_color;
160 ViewPort *s_odc_tessVP;
161 GLUtesselator *m_tobj;
162
163#endif
164 int m_canvasIndex;
165#ifdef ocpnUSE_GL
166 TexFont m_texfont;
167#endif
168
169protected:
170 bool ConfigurePen();
171 bool ConfigureBrush();
172
173 void GLDrawBlendData(wxCoord x, wxCoord y, wxCoord w, wxCoord h, int format,
174 const unsigned char *data);
175
176 void drawrrhelperGLES2(wxCoord x0, wxCoord y0, wxCoord r, int quadrant,
177 int steps);
178
179 void BuildShaders();
180
181 glChartCanvas *m_glchartCanvas;
182 wxGLCanvas *m_glcanvas;
183
184 wxDC *dc;
185 wxPen m_pen;
186 wxBrush m_brush;
187 wxColour m_textforegroundcolour;
188 wxFont m_font;
189
190 bool m_buseTex;
191
192#if wxUSE_GRAPHICS_CONTEXT
193 wxGraphicsContext *pgc;
194#endif
195
196 float *workBuf;
197 size_t workBufSize;
198 unsigned int workBufIndex;
199 double m_dpi_factor;
200 ViewPort m_vp;
201#ifdef ocpnUSE_GL
202 GLShaderProgram *m_pcolor_tri_shader_program;
203 GLShaderProgram *m_pAALine_shader_program;
204 GLShaderProgram *m_pcircle_filled_shader_program;
205 GLShaderProgram *m_ptexture_2D_shader_program;
206#endif
207};
208
209#endif
Wrapper class for OpenGL shader programs.
Definition shaders.h:57
ViewPort - Core geographic projection and coordinate transformation engine.
Definition viewport.h:56
OpenGL chart rendering canvas.
Device context class that can use either wxDC or OpenGL for drawing.
Definition ocpndc.h:60
void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, bool b_hiqual=true)
Draw a line between two points using either wxDC or OpenGL.
Definition ocpndc.cpp:474
Platform independent GL includes.
OpenGL shader interface.
Geographic projection and coordinate transformations.