OpenCPN Partial API docs
Loading...
Searching...
No Matches
glTextureDescriptor.cpp
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#include "glTextureDescriptor.h"
26#include <wx/thread.h>
27
28#if defined(__OCPN__ANDROID__)
29#include <GLES2/gl2.h>
30#elif defined(__WXQT__) || defined(__WXGTK__)
31#include <GL/glew.h>
32#endif
33
34wxCriticalSection gs_critSect;
35
36glTextureDescriptor::glTextureDescriptor() {
37 for (int i = 0; i < 10; i++) {
38 map_array[i] = NULL;
39 comp_array[i] = NULL;
40 compcomp_array[i] = NULL;
41 compcomp_size[i] = 0;
42 }
43
44 tex_name = 0;
45 nGPU_compressed = GPU_TEXTURE_UNKNOWN;
46 tex_mem_used = 0;
47 compdata_ticks = 0;
48}
49
50glTextureDescriptor::~glTextureDescriptor() { FreeAll(); }
51
52void glTextureDescriptor::FreeAll() {
53 FreeMap();
54 FreeComp();
55 FreeCompComp();
56}
57
58void glTextureDescriptor::FreeMap() {
59 for (int i = 0; i < 10; i++) {
60 free(map_array[i]);
61 map_array[i] = 0;
62 }
63}
64
65void glTextureDescriptor::FreeComp() {
66 for (int i = 0; i < 10; i++) {
67 free(comp_array[i]);
68 comp_array[i] = NULL;
69 }
70}
71
72void glTextureDescriptor::FreeCompComp() {
73 for (int i = 0; i < 10; i++) {
74 free(compcomp_array[i]);
75 compcomp_array[i] = NULL;
76 compcomp_size[i] = 0;
77 }
78}
79
80size_t glTextureDescriptor::GetMapArrayAlloc(void) {
81 size_t size = 512 * 512 * 3;
82 size_t ret = 0;
83 for (int i = 0; i < 10; i++) {
84 if (map_array[i]) {
85 ret += size;
86 }
87 size /= 4;
88 }
89
90 return ret;
91}
92
93size_t glTextureDescriptor::GetCompArrayAlloc(void) {
94 size_t size = (512 * 512 * 3) / 6;
95 size_t ret = 0;
96 for (int i = 0; i < 10; i++) {
97 if (comp_array[i]) {
98 ret += size;
99 }
100 size /= 4;
101 }
102
103 return ret;
104}
105
106size_t glTextureDescriptor::GetCompCompArrayAlloc(void) {
107 size_t ret = 0;
108 for (int i = 0; i < 10; i++) {
109 if (compcomp_size[i]) ret += compcomp_size[i];
110 }
111
112 return ret;
113}
114
115bool glTextureDescriptor::IsCompCompArrayComplete(int base_level) {
116 extern int g_mipmap_max_level;
117 for (int level = base_level; level < g_mipmap_max_level + 1; level++)
118 if (!compcomp_array[level]) return false;
119
120 return true;
121}