OpenCPN Partial API docs
Loading...
Searching...
No Matches
gl_tex_cache.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 __GLTEXTCACHE_H__
25#define __GLTEXTCACHE_H__
26
27#include <wx/glcanvas.h>
28#include <wx/ffile.h>
29#include <wx/timer.h>
30#include <stdint.h>
31
32#include "model/ocpn_types.h"
33#include "color_types.h"
34#include "bbox.h"
35#include "viewport.h"
36
38
39#define COMPRESSED_CACHE_MAGIC 0xf013 // change this when the format changes
40
41#define FACTORY_TIMER 10000
42
43void HalfScaleChartBits(int width, int height, unsigned char *source,
44 unsigned char *target);
45
46class ChartBaseBSB;
48
50 uint32_t magic;
51 uint32_t format;
52 uint32_t chartdate;
53 uint32_t m_nentries;
54 uint32_t catalog_offset;
55 uint32_t chartfile_date;
56 uint32_t chartfile_size;
57};
58
60 int mip_level;
61 ColorScheme tcolorscheme;
62 int x;
63 int y;
64};
65
67 int texture_offset;
68 uint32_t compressed_size;
69};
70
71#define CATALOG_ENTRY_SERIAL_SIZE 6 * sizeof(uint32_t)
72
74public:
77 CatalogEntry(int level, int x0, int y0, ColorScheme colorscheme);
78 int GetSerialSize();
79 void Serialize(unsigned char *);
80 void DeSerialize(unsigned char *);
83};
84
85WX_DEFINE_ARRAY(CatalogEntry *, ArrayOfCatalogEntries);
86
87class glTexTile {
88public:
89 glTexTile() {
90 m_coords = m_texcoords = NULL;
91 m_ncoords = 0;
92 }
93 virtual ~glTexTile() {
94 delete[] m_coords;
95 delete[] m_texcoords;
96 }
97
98 wxRect rect;
99 LLBBox box;
100 // LLRegion region;
101
102 int m_ncoords;
103 float *m_coords, *m_texcoords;
104};
105
106#define MAX_TEX_LEVEL 10
107
109public:
110 glTexFactory(ChartBase *chart, int raster_format);
112
113 glTextureDescriptor *GetOrCreateTD(const wxRect &rect);
114 bool BuildTexture(glTextureDescriptor *ptd, int base_level,
115 const wxRect &rect);
116 bool PrepareTexture(int base_level, const wxRect &rect,
117 ColorScheme color_scheme, int mem_used);
118 int GetTextureLevel(glTextureDescriptor *ptd, const wxRect &rect, int level,
119 ColorScheme color_scheme);
120 bool UpdateCacheAllLevels(const wxRect &rect, ColorScheme color_scheme,
121 unsigned char **compcomp_array, int *compcomp_size);
122 bool IsLevelInCache(int level, const wxRect &rect, ColorScheme color_scheme);
123 wxString GetChartPath() { return m_ChartPath; }
124 wxString GetHashKey() { return m_HashKey; }
125 void SetHashKey(wxString key) { m_HashKey = key; }
126 bool OnTimer();
127 void AccumulateMemStatistics(int &map_size, int &comp_size,
128 int &compcomp_size);
129 void DeleteTexture(const wxRect &rect);
130 void DeleteAllTextures(void);
131 void DeleteSomeTextures(long target);
132 void DeleteAllDescriptors(void);
133 bool BackgroundCompressionAsJob() const;
134 void PurgeBackgroundCompressionPool();
135 void SetLRUTime(int lru) { m_LRUtime = lru; }
136 int GetLRUTime() { return m_LRUtime; }
137 void FreeSome(long target);
138 void FreeIfCached();
139
140 glTextureDescriptor *GetpTD(wxRect &rect);
141
142 void PrepareTiles(const ViewPort &vp, bool use_norm_vp, ChartBase *pChart);
143 glTexTile **GetTiles(int &num) {
144 num = m_ntex;
145 return m_tiles;
146 }
147 void GetCenter(double &lat, double &lon) { lat = m_clat, lon = m_clon; }
148
149private:
150 bool LoadCatalog(void);
151 bool LoadHeader(void);
152 bool WriteCatalogAndHeader();
153
154 bool UpdateCachePrecomp(unsigned char *data, int data_size,
155 const wxRect &rect, int level,
156 ColorScheme color_scheme, bool write_catalog = true);
157 bool UpdateCacheLevel(const wxRect &rect, int level, ColorScheme color_scheme,
158 unsigned char *data, int size);
159
160 void DeleteSingleTexture(glTextureDescriptor *ptd);
161
162 CatalogEntryValue *GetCacheEntryValue(int level, int x, int y,
163 ColorScheme color_scheme);
164 bool AddCacheEntryValue(const CatalogEntry &p);
165 int ArrayIndex(int x, int y) const {
166 return ((y / m_tex_dim) * m_stride) + (x / m_tex_dim);
167 }
168 void ArrayXY(wxRect *r, int index) const;
169
170 int n_catalog_entries;
171
172 CatalogEntryValue *m_cache[N_COLOR_SCHEMES][MAX_TEX_LEVEL];
173
174 wxString m_ChartPath;
175 wxString m_HashKey;
176 wxString m_CompressedCacheFilePath;
177
178 int m_catalog_offset;
179 bool m_hdrOK;
180 bool m_catalogOK;
181 bool m_newCatalog;
182
183 bool m_catalogCorrupted;
184
185 wxFFile *m_fs;
186 uint32_t m_chart_date_binary;
187 uint32_t m_chartfile_date_binary;
188 uint32_t m_chartfile_size;
189
190 int m_stride;
191 int m_ntex;
192 int m_tex_dim;
193 int m_size_X;
194 int m_size_Y;
195 int m_nx_tex;
196 int m_ny_tex;
197
198 int m_LRUtime;
199
200 glTextureDescriptor **m_td_array;
201
202 double m_clat, m_clon;
203 glTexTile **m_tiles;
204 int m_prepared_projection_type;
205 bool m_north; // used for polar projection
206};
207
208#endif
Base class for BSB (Maptech/NOS) format nautical charts.
Definition chartimg.h:127
Base class for all chart types.
Definition chartbase.h:125
Wrapper class for plugin-based charts.
Definition chartimg.h:388
ViewPort - Core geographic projection and coordinate transformation engine.
Definition viewport.h:84