| TGX 1.1.2 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// generic check for FPU support
46#if defined(__ARM_FP) && ((__ARM_FP & 0x4) != 0)
47 #define TGX_COMPILER_HAS_FPU 1
48#elif defined(__XTENSA__) && !defined(__XTENSA_SOFT_FLOAT__)
49 #define TGX_COMPILER_HAS_FPU 1
50#elif defined(__riscv_flen) && (__riscv_flen >= 32)
51 #define TGX_COMPILER_HAS_FPU 1
52#else
53 #define TGX_COMPILER_HAS_FPU 0
54#endif
55
56
57//
58// Board specific optimizations.
59//
60// - TGX_PROGMEM_DEFAULT_CACHE_SIZE : size of the cache when reading from PROGMEM. Use to optimize cache read when accessing image in flash.
61//
62// - TGX_USE_FAST_INV_SQRT_TRICK : fast inverse 'quake like' square root trick to speed up computations.
63// - TGX_USE_FAST_SQRT_TRICK : fast 'quake like' square root trick to speed up computations.
64// - TGX_USE_FAST_INV_TRICK : fast inverse 'quake like' trick to speed up computations.
65// - TGX_USE_FMA_MATH : use explicit fused multiply-add in small floating-point vector/matrix operations.
66//
67// - TGX_INLINE/TGX_NOINLINE : inlining strategy for time critical/non-critical functions.
68//
83#if defined(_WIN32) || defined(_WIN64) || defined(__linux__) || defined(__APPLE__) || defined(__MACH__) || defined(__ANDROID__) || defined(__unix__)
84 // TGX is running on a computer.
85 #define TGX_RUN_ON_CPU
86 #define TGX_HAS_FPU 1
87 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 262144
88 #define TGX_USE_FAST_INV_SQRT_TRICK 0
89 #define TGX_USE_FAST_SQRT_TRICK 0
90 #define TGX_USE_FAST_INV_TRICK 0
91 #define TGX_USE_FMA_MATH 0
92 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 0
93 #define TGX_INLINE
94 #define TGX_INLINE_ZDIVIDE
95 #define TGX_NOINLINE
96
97#elif defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41)
98 // teensy 4.0 and 4.1
99 #define TGX_RUN_ON_TEENSY4
100 #define TGX_HAS_FPU TGX_COMPILER_HAS_FPU
101 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 8192
102 #define TGX_USE_FAST_INV_SQRT_TRICK 1
103 #define TGX_USE_FAST_SQRT_TRICK 1
104 #define TGX_USE_FAST_INV_TRICK 1
105 #define TGX_USE_FMA_MATH 1
106 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 0
107 #define TGX_INLINE __attribute__((always_inline))
108 #define TGX_INLINE_ZDIVIDE __attribute__((always_inline))
109 #define TGX_NOINLINE
110
111#elif defined(ARDUINO_TEENSY36)
112 // teensy 3.6
113 #define TGX_RUN_ON_TEENSY3
114 #define TGX_HAS_FPU TGX_COMPILER_HAS_FPU
115 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 2048
116 #define TGX_USE_FAST_INV_SQRT_TRICK 1
117 #define TGX_USE_FAST_SQRT_TRICK 0
118 #define TGX_USE_FAST_INV_TRICK 1
119 #define TGX_USE_FMA_MATH 0
120 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 0
121 #define TGX_INLINE __attribute__((always_inline))
122 #define TGX_INLINE_ZDIVIDE
123 #define TGX_NOINLINE
124
125#elif defined(ARDUINO_TEENSY35)
126 // teensy 3.5
127 #define TGX_RUN_ON_TEENSY3
128 #define TGX_HAS_FPU TGX_COMPILER_HAS_FPU
129 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 2048
130 #define TGX_USE_FAST_INV_SQRT_TRICK 1
131 #define TGX_USE_FAST_SQRT_TRICK 0
132 #define TGX_USE_FAST_INV_TRICK 1
133 #define TGX_USE_FMA_MATH 0
134 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 0
135 #define TGX_INLINE __attribute__((always_inline))
136 #define TGX_INLINE_ZDIVIDE
137 #define TGX_NOINLINE
138
139#elif defined(ARDUINO_TEENSY32) || defined(ARDUINO_TEENSY31)
140 // teensy 3.1 and 3.2
141 #define TGX_RUN_ON_TEENSY3
142 #define TGX_HAS_FPU 0
143 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 1024
144 #define TGX_USE_FAST_INV_SQRT_TRICK 1
145 #define TGX_USE_FAST_SQRT_TRICK 0
146 #define TGX_USE_FAST_INV_TRICK 1
147 #define TGX_USE_FMA_MATH 0
148 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 0
149 #define TGX_INLINE __attribute__((always_inline))
150 #define TGX_INLINE_ZDIVIDE
151 #define TGX_NOINLINE
152
153#elif defined(ARDUINO_TEENSYLC)
154 // teensy LC
155 #define TGX_RUN_ON_TEENSYLC
156 #define TGX_HAS_FPU 0
157 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 256
158 #define TGX_USE_FAST_INV_SQRT_TRICK 0
159 #define TGX_USE_FAST_SQRT_TRICK 0
160 #define TGX_USE_FAST_INV_TRICK 0
161 #define TGX_USE_FMA_MATH 0
162 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 0
163 #define TGX_INLINE
164 #define TGX_INLINE_ZDIVIDE
165 #define TGX_NOINLINE
166
167#elif defined(ARDUINO_ARCH_RP2350) || defined(PICO_RP2350) || defined(TARGET_RP2350)
168 // Raspberry Pico 2350
169 #define TGX_RUN_ON_RP2350
170 #define TGX_HAS_FPU TGX_COMPILER_HAS_FPU
171 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
172 #define TGX_USE_FAST_INV_SQRT_TRICK 1
173 #define TGX_USE_FAST_SQRT_TRICK 1
174 #define TGX_USE_FAST_INV_TRICK 1
175 #define TGX_USE_FMA_MATH 0
176 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 1
177 #define TGX_INLINE __attribute__((always_inline))
178 #define TGX_INLINE_ZDIVIDE __attribute__((always_inline))
179 #define TGX_NOINLINE
180
181#elif defined(ARDUINO_ARCH_RP2040) || defined(PICO_RP2040) || defined(TARGET_RP2040)
182 // Raspberry Pico 2040
183 #define TGX_RUN_ON_RP2040
184 #define TGX_HAS_FPU 0
185 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 2048
186 #define TGX_USE_FAST_INV_SQRT_TRICK 0
187 #define TGX_USE_FAST_SQRT_TRICK 0
188 #define TGX_USE_FAST_INV_TRICK 0
189 #define TGX_USE_FMA_MATH 0
190 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 0
191 #define TGX_INLINE
192 #define TGX_INLINE_ZDIVIDE
193 #define TGX_NOINLINE
194
195#elif defined(CONFIG_IDF_TARGET_ESP32S2) || defined(ESP32S2)
196 // ESP32 S2
197 #define TGX_RUN_ON_ESP32S2
198 #define TGX_HAS_FPU 0
199 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 2048
200 #define TGX_USE_FAST_INV_SQRT_TRICK 0
201 #define TGX_USE_FAST_SQRT_TRICK 0
202 #define TGX_USE_FAST_INV_TRICK 0
203 #define TGX_USE_FMA_MATH 0
204 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 0
205 #define TGX_INLINE
206 #define TGX_INLINE_ZDIVIDE
207 #define TGX_NOINLINE
208
209#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ESP32S3)
210 // ESP32 S3
211 #define TGX_RUN_ON_ESP32S3
212 #define TGX_HAS_FPU TGX_COMPILER_HAS_FPU
213 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
214 #define TGX_USE_FAST_INV_SQRT_TRICK 0 // unused: specific assembly code used instead.
215 #define TGX_USE_FAST_SQRT_TRICK 0 //
216 #define TGX_USE_FAST_INV_TRICK 0 // unused: specific assembly code used instead.
217 #define TGX_USE_FMA_MATH 0
218 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 0
219 #define TGX_INLINE __attribute__((always_inline))
220 #define TGX_INLINE_ZDIVIDE __attribute__((always_inline))
221 #define TGX_NOINLINE
222
223#elif defined(CONFIG_IDF_TARGET_ESP32P4) || defined(ESP32P4)
224 // ESP32 P4
225 #define TGX_RUN_ON_ESP32P4
226 #define TGX_HAS_FPU TGX_COMPILER_HAS_FPU
227 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
228 #define TGX_USE_FAST_INV_SQRT_TRICK 1
229 #define TGX_USE_FAST_SQRT_TRICK 1
230 #define TGX_USE_FAST_INV_TRICK 1
231 #define TGX_USE_FMA_MATH 0
232 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 0
233 #define TGX_INLINE __attribute__((always_inline))
234 #define TGX_INLINE_ZDIVIDE
235 #define TGX_NOINLINE
236
237#elif defined(CONFIG_IDF_TARGET_ESP32) || defined(ESP32)
238 // fallback to original
239 // nb: `ESP32` is defined for all ESP32 variants so this case should be the last
240 #define TGX_RUN_ON_ESP32
241 #define TGX_HAS_FPU TGX_COMPILER_HAS_FPU
242 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
243 #define TGX_USE_FAST_INV_SQRT_TRICK 0 // unused: specific assembly code used instead.
244 #define TGX_USE_FAST_SQRT_TRICK 0 //
245 #define TGX_USE_FAST_INV_TRICK 0 //
246 #define TGX_USE_FMA_MATH 0
247 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 0
248 #define TGX_INLINE __attribute__((always_inline))
249 #define TGX_INLINE_ZDIVIDE
250 #define TGX_NOINLINE __attribute__((noinline, noclone))
251
252#elif defined(__ARM_ARCH_6M__)
253 // generic Cortex-M0 (use same setting as Teensy LC)
254 #define TGX_RUN_ON_TEENSYLC
255 #define TGX_HAS_FPU 0
256 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 256
257 #define TGX_USE_FAST_INV_SQRT_TRICK 0
258 #define TGX_USE_FAST_SQRT_TRICK 0
259 #define TGX_USE_FAST_INV_TRICK 0
260 #define TGX_USE_FMA_MATH 0
261 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 0
262 #define TGX_INLINE
263 #define TGX_INLINE_ZDIVIDE
264 #define TGX_NOINLINE
265
266#elif defined(__ARM_ARCH_7M__)
267 // generic Cortex-M3 (use same setting as Teensy3.2)
268 #define TGX_RUN_ON_TEENSY3
269 #define TGX_HAS_FPU 0
270 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 1024
271 #define TGX_USE_FAST_INV_SQRT_TRICK 1
272 #define TGX_USE_FAST_SQRT_TRICK 0
273 #define TGX_USE_FAST_INV_TRICK 1
274 #define TGX_USE_FMA_MATH 0
275 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 0
276 #define TGX_INLINE __attribute__((always_inline))
277 #define TGX_INLINE_ZDIVIDE
278 #define TGX_NOINLINE
279
280#elif (defined(__ARM_ARCH_7EM__) && defined(__ARM_FP) && ((__ARM_FP & 0x8) != 0)) || defined(STM32H7xx)
281 // generic Cortex-M7 (use same setting as Teensy 4.0/4.1)
282 #define TGX_RUN_ON_TEENSY4
283 #define TGX_HAS_FPU TGX_COMPILER_HAS_FPU
284 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
285 #define TGX_USE_FAST_INV_SQRT_TRICK 1
286 #define TGX_USE_FAST_SQRT_TRICK 1
287 #define TGX_USE_FAST_INV_TRICK 1
288 #define TGX_USE_FMA_MATH 1
289 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 0
290 #define TGX_INLINE __attribute__((always_inline))
291 #define TGX_INLINE_ZDIVIDE
292 #define TGX_NOINLINE
293
294#elif defined(__ARM_ARCH_7EM__)
295 // generic Cortex-M4 (use same setting as Teensy 3.6/3.5)
296 #define TGX_RUN_ON_TEENSY3
297 #define TGX_HAS_FPU TGX_COMPILER_HAS_FPU
298 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 2048
299 #define TGX_USE_FAST_INV_SQRT_TRICK 1
300 #define TGX_USE_FAST_SQRT_TRICK 0
301 #define TGX_USE_FAST_INV_TRICK 1
302 #define TGX_USE_FMA_MATH 0
303 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 0
304 #define TGX_INLINE __attribute__((always_inline))
305 #define TGX_INLINE_ZDIVIDE
306 #define TGX_NOINLINE
307
308#elif defined(__ARM_ARCH_8M_MAIN__)
309 // generic Cortex-M33 (use same setting as RP2350)
310 #define TGX_RUN_ON_RP2350
311 #define TGX_HAS_FPU TGX_COMPILER_HAS_FPU
312 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 4096
313 #define TGX_USE_FAST_INV_SQRT_TRICK 1
314 #define TGX_USE_FAST_SQRT_TRICK 1
315 #define TGX_USE_FAST_INV_TRICK 1
316 #define TGX_USE_FMA_MATH 0
317 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 1
318 #define TGX_INLINE __attribute__((always_inline))
319 #define TGX_INLINE_ZDIVIDE __attribute__((always_inline))
320 #define TGX_NOINLINE
321
322#else
323 // unknown board/architecture
324 #define TGX_RUN_ON_CPU
325 #define TGX_HAS_FPU 1
326 #define TGX_PROGMEM_DEFAULT_CACHE_SIZE 1024
327 #define TGX_USE_FAST_INV_SQRT_TRICK 0
328 #define TGX_USE_FAST_SQRT_TRICK 0
329 #define TGX_USE_FAST_INV_TRICK 0
330 #define TGX_USE_FMA_MATH 0
331 #define TGX_SHADER_USE_INCREMENTAL_PIXEL_POINTERS 0
332 #define TGX_INLINE
333 #define TGX_INLINE_ZDIVIDE
334 #define TGX_NOINLINE
335#endif
336
337
338
339#if defined(ESP32) || defined(ESP_PLATFORM)
340 #include "esp_attr.h"
341 #define TGX_HOT_IRAM IRAM_ATTR
342#else
343 #define TGX_HOT_IRAM
344#endif
345
346
347
348
349
354#ifndef TGX_SHADER_GOURAUD_TEXTURE_FLOAT_INCREMENTAL
355#if TGX_HAS_FPU
356#define TGX_SHADER_GOURAUD_TEXTURE_FLOAT_INCREMENTAL 1
357#else // disable incremental float computation for Gouraud shading on architectures without FPU
358#define TGX_SHADER_GOURAUD_TEXTURE_FLOAT_INCREMENTAL 0
359#endif
360#endif
361
362#ifndef TGX_SHADER_GOURAUD_RGB565_FLOAT_INCREMENTAL
363#if TGX_HAS_FPU
364#define TGX_SHADER_GOURAUD_RGB565_FLOAT_INCREMENTAL 1
365#else // disable incremental float computation for Gouraud shading on architectures without FPU
366#define TGX_SHADER_GOURAUD_RGB565_FLOAT_INCREMENTAL 0
367#endif
368#endif
369
370#ifndef TGX_SHADER_RGB565_FAST_TEXTURE_MODULATE
371#define TGX_SHADER_RGB565_FAST_TEXTURE_MODULATE 1
372#endif
373
374#ifndef TGX_SHADER_RGB565_FAST_BILINEAR
375#define TGX_SHADER_RGB565_FAST_BILINEAR 1
376#endif
377
378#ifndef TGX_SHADER_RGB565_FAST_CLAMP
379#define TGX_SHADER_RGB565_FAST_CLAMP 0
380#endif
381
382
383
384
385
386
387
392#ifndef TGX_SINGLE_PRECISION_COMPUTATIONS
393 #define TGX_SINGLE_PRECISION_COMPUTATIONS 1
394#endif
395
396
401#define TGX_DEFAULT_NO_BLENDING -1.0f
402
403
408#ifndef TGX_MESHLET_SPHERE_CLIP
409 #define TGX_MESHLET_SPHERE_CLIP 1
410#endif
411
416#ifndef TGX_MESHLET_WIREFRAME_CULL
417 #define TGX_MESHLET_WIREFRAME_CULL 1
418#endif
419
420