TGX 1.1.1
A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.
Loading...
Searching...
No Matches
tgx_config.h
Go to the documentation of this file.
1
5//
6// Copyright 2020 Arvind Singh
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Lesser General Public
10// License as published by the Free Software Foundation; either
11//version 2.1 of the License, or (at your option) any later version.
12//
13// This library 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 GNU
16// Lesser General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public
19// License along with this library; If not, see <http://www.gnu.org/licenses/>.
20
21
22
23// disable mtools extensions by default
24#ifndef MTOOLS_TGX_EXTENSIONS
25#define MTOOLS_TGX_EXTENSIONS 0
26#endif
27
28#ifdef ARDUINO
29 #include <Arduino.h>
30 #define TGX_ON_ARDUINO
31#elif defined(ESP_PLATFORM)
32 #include "sdkconfig.h"
33#endif
34
35#ifndef PROGMEM
36 #define PROGMEM
37#endif
38
39#ifndef FLASHMEM
40 #define FLASHMEM
41#endif
42
43
44
45//
46// Board specific optimizations.
47//
48// - TGX_PROGMEM_DEFAULT_CACHE_SIZE : size of the cache when reading from PROGMEM. Use to optimize cache read when accessing image in flash.
49//
50// - TGX_USE_FAST_INV_SQRT_TRICK : fast inverse 'quake like' square root trick to speed up computations.
51// - TGX_USE_FAST_SQRT_TRICK : fast 'quake like' square root trick to speed up computations.
52// - TGX_USE_FAST_INV_TRICK : fast inverse 'quake like' trick to speed up computations.
53// - TGX_USE_FMA_MATH : use explicit fused multiply-add in small floating-point vector/matrix operations.
54//
55// - TGX_INLINE/TGX_NOINLINE : inlining strategy for time critical/non-critical functions.
56//
70#if defined(_WIN32) || defined(_WIN64) || defined(__linux__) || defined(__APPLE__) || defined(__MACH__) || defined(__ANDROID__) || defined(__unix__)
71 // TGX is running on a computer.
72 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 262144
73 #define TGX_USE_FAST_INV_SQRT_TRICK 0
74 #define TGX_USE_FAST_SQRT_TRICK 0
75 #define TGX_USE_FAST_INV_TRICK 0
76 #define TGX_USE_FMA_MATH 0
77 #define TGX_INLINE
78 #define TGX_NOINLINE
79
80#elif defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41)
81 // teensy 4.0 and 4.1
82 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 8192
83 #define TGX_USE_FAST_INV_SQRT_TRICK 1
84 #define TGX_USE_FAST_SQRT_TRICK 1
85 #define TGX_USE_FAST_INV_TRICK 1
86 #define TGX_USE_FMA_MATH 1
87 #define TGX_INLINE __attribute__((always_inline))
88 #define TGX_NOINLINE
89
90#elif defined(ARDUINO_TEENSY36)
91 // teensy 3.6
92 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 2048
93 #define TGX_USE_FAST_INV_SQRT_TRICK 1
94 #define TGX_USE_FAST_SQRT_TRICK 0
95 #define TGX_USE_FAST_INV_TRICK 1
96 #define TGX_USE_FMA_MATH 0
97 #define TGX_INLINE __attribute__((always_inline))
98 #define TGX_NOINLINE
99
100#elif defined(ARDUINO_TEENSY35)
101 // teensy 3.5
102 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 2048
103 #define TGX_USE_FAST_INV_SQRT_TRICK 1
104 #define TGX_USE_FAST_SQRT_TRICK 0
105 #define TGX_USE_FAST_INV_TRICK 1
106 #define TGX_USE_FMA_MATH 0
107 #define TGX_INLINE __attribute__((always_inline))
108 #define TGX_NOINLINE
109
110#elif defined(ARDUINO_TEENSY32) || defined(ARDUINO_TEENSY31)
111 // teensy 3.1 and 3.2
112 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 1024
113 #define TGX_USE_FAST_INV_SQRT_TRICK 1
114 #define TGX_USE_FAST_SQRT_TRICK 0
115 #define TGX_USE_FAST_INV_TRICK 1
116 #define TGX_USE_FMA_MATH 0
117 #define TGX_INLINE __attribute__((always_inline))
118 #define TGX_NOINLINE
119
120#elif defined(ARDUINO_TEENSYLC)
121 // teensy LC
122 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 256
123 #define TGX_USE_FAST_INV_SQRT_TRICK 0
124 #define TGX_USE_FAST_SQRT_TRICK 0
125 #define TGX_USE_FAST_INV_TRICK 0
126 #define TGX_USE_FMA_MATH 0
127 #define TGX_INLINE
128 #define TGX_NOINLINE
129
130#elif defined(ARDUINO_ARCH_RP2350) || defined(PICO_RP2350)
131 // Raspberry Pico 2350
132 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
133 #define TGX_USE_FAST_INV_SQRT_TRICK 1
134 #define TGX_USE_FAST_SQRT_TRICK 1
135 #define TGX_USE_FAST_INV_TRICK 1
136 #define TGX_USE_FMA_MATH 0
137 #define TGX_INLINE __attribute__((always_inline))
138 #define TGX_NOINLINE
139
140#elif defined(ARDUINO_ARCH_RP2040) || defined(PICO_RP2040)
141 // Raspberry Pico 2040
142 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 2048
143 #define TGX_USE_FAST_INV_SQRT_TRICK 0
144 #define TGX_USE_FAST_SQRT_TRICK 0
145 #define TGX_USE_FAST_INV_TRICK 0
146 #define TGX_USE_FMA_MATH 0
147 #define TGX_INLINE
148 #define TGX_NOINLINE
149
150#elif defined(CONFIG_IDF_TARGET_ESP32S2) || defined(ESP32S2)
151 // ESP32 S2
152 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 2048
153 #define TGX_USE_FAST_INV_SQRT_TRICK 0
154 #define TGX_USE_FAST_SQRT_TRICK 0
155 #define TGX_USE_FAST_INV_TRICK 0
156 #define TGX_USE_FMA_MATH 0
157 #define TGX_INLINE
158 #define TGX_NOINLINE
159
160#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ESP32S3)
161 // ESP32 S3
162 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
163 #define TGX_USE_FAST_INV_SQRT_TRICK 0 // unused: specific assembly code used instead.
164 #define TGX_USE_FAST_SQRT_TRICK 0 //
165 #define TGX_USE_FAST_INV_TRICK 0 // unused: specific assembly code used instead.
166 #define TGX_USE_FMA_MATH 0
167 #define TGX_INLINE __attribute__((always_inline))
168 #define TGX_NOINLINE
169
170#elif defined(CONFIG_IDF_TARGET_ESP32P4) || defined(ESP32P4)
171 // ESP32 P4
172 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
173 #define TGX_USE_FAST_INV_SQRT_TRICK 1
174 #define TGX_USE_FAST_SQRT_TRICK 1
175 #define TGX_USE_FAST_INV_TRICK 1
176 #define TGX_USE_FMA_MATH 0
177 #define TGX_INLINE __attribute__((always_inline))
178 #define TGX_NOINLINE
179
180#elif defined(CONFIG_IDF_TARGET_ESP32) || defined(ESP32)
181 // fallback to original
182 // nb: `ESP32` is defined for all ESP32 variants so this case should be the last
183 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
184 #define TGX_USE_FAST_INV_SQRT_TRICK 0 // unused: specific assembly code used instead.
185 #define TGX_USE_FAST_SQRT_TRICK 0 //
186 #define TGX_USE_FAST_INV_TRICK 0 //
187 #define TGX_USE_FMA_MATH 0
188 #define TGX_INLINE __attribute__((always_inline))
189 #define TGX_NOINLINE __attribute__((noinline, noclone))
190
191#elif defined(__ARM_ARCH_6M__)
192 // generic Cortex-M0 (use same setting as Teensy LC)
193 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 256
194 #define TGX_USE_FAST_INV_SQRT_TRICK 0
195 #define TGX_USE_FAST_SQRT_TRICK 0
196 #define TGX_USE_FAST_INV_TRICK 0
197 #define TGX_USE_FMA_MATH 0
198 #define TGX_INLINE
199 #define TGX_NOINLINE
200
201#elif defined(__ARM_ARCH_7M__)
202 // generic Cortex-M3 (use same setting as Teensy3.2)
203 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 1024
204 #define TGX_USE_FAST_INV_SQRT_TRICK 1
205 #define TGX_USE_FAST_SQRT_TRICK 0
206 #define TGX_USE_FAST_INV_TRICK 1
207 #define TGX_USE_FMA_MATH 0
208 #define TGX_INLINE __attribute__((always_inline))
209 #define TGX_NOINLINE
210
211#elif (defined(__ARM_ARCH_7EM__) && defined(__ARM_FP) && (__ARM_FP == 0xC)) || defined(STM32H7xx)
212 // generic Cortex-M7 (use same setting as Teensy 4.0/4.1)
213 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
214 #define TGX_USE_FAST_INV_SQRT_TRICK 1
215 #define TGX_USE_FAST_SQRT_TRICK 1
216 #define TGX_USE_FAST_INV_TRICK 1
217 #define TGX_USE_FMA_MATH 1
218 #define TGX_INLINE __attribute__((always_inline))
219 #define TGX_NOINLINE
220
221#elif defined(__ARM_ARCH_7EM__)
222 // generic Cortex-M4 (use same setting as Teensy 3.6/3.5)
223 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 2048
224 #define TGX_USE_FAST_INV_SQRT_TRICK 1
225 #define TGX_USE_FAST_SQRT_TRICK 0
226 #define TGX_USE_FAST_INV_TRICK 1
227 #define TGX_USE_FMA_MATH 0
228 #define TGX_INLINE __attribute__((always_inline))
229 #define TGX_NOINLINE
230
231#elif defined(__ARM_ARCH_8M_MAIN__)
232 // generic Cortex-M33 (use same setting as RP2350)
233 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
234 #define TGX_USE_FAST_INV_SQRT_TRICK 1
235 #define TGX_USE_FAST_SQRT_TRICK 1
236 #define TGX_USE_FAST_INV_TRICK 1
237 #define TGX_USE_FMA_MATH 0
238 #define TGX_INLINE __attribute__((always_inline))
239 #define TGX_NOINLINE
240
241#else
242 // unknown board/architecture
243 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 1024
244 #define TGX_USE_FAST_INV_SQRT_TRICK 0
245 #define TGX_USE_FAST_SQRT_TRICK 0
246 #define TGX_USE_FAST_INV_TRICK 0
247 #define TGX_USE_FMA_MATH 0
248 #define TGX_INLINE
249 #define TGX_NOINLINE
250#endif
251
252
253
254
259#ifndef TGX_SINGLE_PRECISION_COMPUTATIONS
260 #define TGX_SINGLE_PRECISION_COMPUTATIONS 1
261#endif
262
263
268#define TGX_DEFAULT_NO_BLENDING -1.0f
269
270
275#ifndef TGX_MESHLET_SPHERE_CLIP
276 #define TGX_MESHLET_SPHERE_CLIP 1
277#endif
278
283#ifndef TGX_MESHLET_WIREFRAME_CULL
284 #define TGX_MESHLET_WIREFRAME_CULL 1
285#endif
286
287