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 <vector>
34
35#include "dychart.h"
36
37#include "linmath.h"
38
39#include "TexFont.h"
40#include "viewport.h"
41#ifdef ocpnUSE_GL
42#include "shaders.h"
43#endif
44
45class ViewPort;
46class GLUtesselator;
47
48void DrawGLThickLine(float x1, float y1, float x2, float y2, wxPen pen,
49 bool b_hiqual);
50
51//----------------------------------------------------------------------------
52// ocpnDC
53//----------------------------------------------------------------------------
54
55class wxGLCanvas;
56class glChartCanvas;
57
64class ocpnDC {
65public:
66 ocpnDC(glChartCanvas &canvas);
67 ocpnDC(wxGLCanvas &canvas);
68 ocpnDC(wxDC &pdc);
69 ocpnDC();
70
71 ~ocpnDC();
72
73 void Init();
74
75 void SetGLCanvas(glChartCanvas *canvas);
76 void SetBackground(const wxBrush &brush);
77 void SetPen(const wxPen &pen);
78 void SetBrush(const wxBrush &brush);
79 void SetTextForeground(const wxColour &colour);
80 void SetFont(const wxFont &font);
81 static void SetGLAttrs(bool highQuality);
82 void SetGLStipple() const;
83
84 const wxPen &GetPen() const;
85 const wxBrush &GetBrush() const;
86 const wxFont &GetFont() const;
87
88 void GetSize(wxCoord *width, wxCoord *height) const;
89
106 void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
107 bool b_hiqual = true);
108 void DrawLines(int n, wxPoint points[], wxCoord xoffset = 0,
109 wxCoord yoffset = 0, bool b_hiqual = true);
110 void DrawGLThickLine(float x1, float y1, float x2, float y2, wxPen pen,
111 bool b_hiqual);
112 void DrawGLThickLines(int n, wxPoint points[], wxCoord xoffset,
113 wxCoord yoffset, wxPen pen, bool b_hiqual);
114
115 void StrokeLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
116 void StrokeLine(wxPoint a, wxPoint b) { StrokeLine(a.x, a.y, b.x, b.y); }
117 void StrokeLines(int n, wxPoint *points);
118
119 void Clear();
120 void DrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
121 void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
122 wxCoord rr);
123 void DrawCircle(wxCoord x, wxCoord y, wxCoord radius);
124 void DrawCircle(const wxPoint &pt, wxCoord radius) {
125 DrawCircle(pt.x, pt.y, radius);
126 }
127 void StrokeCircle(wxCoord x, wxCoord y, wxCoord radius);
128
129 void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
130 void DrawPolygon(int n, wxPoint points[], wxCoord xoffset = 0,
131 wxCoord yoffset = 0, float scale = 1.0, float angle = 0.0);
132 void DrawPolygonTessellated(int n, wxPoint points[], wxCoord xoffset = 0,
133 wxCoord yoffset = 0);
134 void StrokePolygon(int n, wxPoint points[], wxCoord xoffset = 0,
135 wxCoord yoffset = 0, float scale = 1.0);
136
137 void DrawBitmap(const wxBitmap &bitmap, wxCoord x, wxCoord y, bool usemask);
138
139 void DrawText(const wxString &text, wxCoord x, wxCoord y, float angle = 0.0);
140 void GetTextExtent(const wxString &string, wxCoord *w, wxCoord *h,
141 wxCoord *descent = NULL, wxCoord *externalLeading = NULL,
142 wxFont *font = NULL);
143
144 void ResetBoundingBox();
145 void CalcBoundingBox(wxCoord x, wxCoord y);
146
147 void DestroyClippingRegion() {}
148
149 wxDC *GetDC() const { return dc; }
150 void SetDPIFactor(double factor) { m_dpi_factor = factor; }
151 void SetVP(ViewPort vp);
152
153#ifdef ocpnUSE_GL
154 GLfloat *s_odc_tess_work_buf;
155#endif
156
157#if defined(USE_ANDROID_GLES2) || defined(ocpnUSE_GLSL)
158 int s_odc_tess_vertex_idx;
159 int s_odc_tess_vertex_idx_this;
160 int s_odc_tess_buf_len;
161 GLenum s_odc_tess_mode;
162 int s_odc_nvertex;
163 vec4 s_odc_tess_color;
164 ViewPort *s_odc_tessVP;
165 GLUtesselator *m_tobj;
166
167#endif
168 int m_canvasIndex;
169#ifdef ocpnUSE_GL
170 TexFont m_texfont;
171#endif
172
173protected:
174 bool ConfigurePen();
175 bool ConfigureBrush();
176
177 void GLDrawBlendData(wxCoord x, wxCoord y, wxCoord w, wxCoord h, int format,
178 const unsigned char *data);
179
180 void drawrrhelperGLES2(wxCoord x0, wxCoord y0, wxCoord r, int quadrant,
181 int steps);
182
183 void BuildShaders();
184
185 glChartCanvas *m_glchartCanvas;
186 wxGLCanvas *m_glcanvas;
187
188 wxDC *dc;
189 wxPen m_pen;
190 wxBrush m_brush;
191 wxColour m_textforegroundcolour;
192 wxFont m_font;
193
194 bool m_buseTex;
195
196#if wxUSE_GRAPHICS_CONTEXT
197 wxGraphicsContext *pgc;
198#endif
199
200 float *workBuf;
201 size_t workBufSize;
202 unsigned int workBufIndex;
203 double m_dpi_factor;
204 ViewPort m_vp;
205#ifdef ocpnUSE_GL
206 GLShaderProgram *m_pcolor_tri_shader_program;
207 GLShaderProgram *m_pAALine_shader_program;
208 GLShaderProgram *m_pcircle_filled_shader_program;
209 GLShaderProgram *m_ptexture_2D_shader_program;
210#endif
211};
212
213#endif
Wrapper class for OpenGL shader programs.
Definition shaders.h:57
Represents the view port for chart display in OpenCPN.
Definition viewport.h:84
OpenGL chart rendering canvas.
Device context class that can use either wxDC or OpenGL for drawing.
Definition ocpndc.h:64
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