OpenCPN Partial API docs
Loading...
Searching...
No Matches
ocpndc.h
1/******************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: Layer to use wxDC or opengl
5 * Author: Sean D'Epagnier
6 *
7 ***************************************************************************
8 * Copyright (C) 2011 by Sean D'Epagnier *
9 * sean at depagnier dot com *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
20 * *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program; if not, write to the *
23 * Free Software Foundation, Inc., *
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
25 ***************************************************************************
26 *
27 *f
28 */
29
30#ifndef __OCPNDC_H__
31#define __OCPNDC_H__
32
33#include "linmath.h"
34
35#include "TexFont.h"
36#include "viewport.h"
37#ifdef ocpnUSE_GL
38#include "shaders.h"
39#endif
40
41class ViewPort;
42class GLUtesselator;
43
44void DrawGLThickLine(float x1, float y1, float x2, float y2, wxPen pen,
45 bool b_hiqual);
46
47//----------------------------------------------------------------------------
48// ocpnDC
49//----------------------------------------------------------------------------
50
51class wxGLCanvas;
52class glChartCanvas;
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:84
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:476