1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "qssgrenderbasetypes_p.h"
5
6QT_BEGIN_NAMESPACE
7
8const char *QSSGRenderTextureFormat::toString() const
9{
10 switch (format) {
11 case QSSGRenderTextureFormat::R8:
12 return "R8";
13 case QSSGRenderTextureFormat::R16:
14 return "R16";
15 case QSSGRenderTextureFormat::R16F:
16 return "R16F";
17 case QSSGRenderTextureFormat::R32I:
18 return "R32I";
19 case QSSGRenderTextureFormat::R32UI:
20 return "R32UI";
21 case QSSGRenderTextureFormat::R32F:
22 return "R32F";
23 case QSSGRenderTextureFormat::RG8:
24 return "RG8";
25 case QSSGRenderTextureFormat::RGBA8:
26 return "RGBA8";
27 case QSSGRenderTextureFormat::RGB8:
28 return "RGB8";
29 case QSSGRenderTextureFormat::SRGB8:
30 return "SRGB8";
31 case QSSGRenderTextureFormat::SRGB8A8:
32 return "SRGB8A8";
33 case QSSGRenderTextureFormat::RGB565:
34 return "RGB565";
35 case QSSGRenderTextureFormat::RGBA5551:
36 return "RGBA5551";
37 case QSSGRenderTextureFormat::Alpha8:
38 return "Alpha8";
39 case QSSGRenderTextureFormat::Luminance8:
40 return "Luminance8";
41 case QSSGRenderTextureFormat::Luminance16:
42 return "Luminance16";
43 case QSSGRenderTextureFormat::LuminanceAlpha8:
44 return "LuminanceAlpha8";
45 case QSSGRenderTextureFormat::RGBA16F:
46 return "RGBA16F";
47 case QSSGRenderTextureFormat::RG16F:
48 return "RG16F";
49 case QSSGRenderTextureFormat::RG32F:
50 return "RG32F";
51 case QSSGRenderTextureFormat::RGB32F:
52 return "RGB32F";
53 case QSSGRenderTextureFormat::RGBA32F:
54 return "RGBA32F";
55 case QSSGRenderTextureFormat::R11G11B10:
56 return "R11G11B10";
57 case QSSGRenderTextureFormat::RGB9E5:
58 return "RGB9E5";
59 case QSSGRenderTextureFormat::RGBE8:
60 return "RGBE8";
61 case QSSGRenderTextureFormat::RGBA_DXT1:
62 return "RGBA_DXT1";
63 case QSSGRenderTextureFormat::RGB_DXT1:
64 return "RGB_DXT1";
65 case QSSGRenderTextureFormat::RGBA_DXT3:
66 return "RGBA_DXT3";
67 case QSSGRenderTextureFormat::RGBA_DXT5:
68 return "RGBA_DXT5";
69 case QSSGRenderTextureFormat::R11_EAC_UNorm:
70 return "R11_EAC_UNorm";
71 case QSSGRenderTextureFormat::R11_EAC_SNorm:
72 return "R11_EAC_SNorm";
73 case QSSGRenderTextureFormat::RG11_EAC_UNorm:
74 return "RG11_EAC_UNorm";
75 case QSSGRenderTextureFormat::RG11_EAC_SNorm:
76 return "RG11_EAC_SNorm";
77 case QSSGRenderTextureFormat::RGB8_ETC2:
78 return "RGB8_ETC2";
79 case QSSGRenderTextureFormat::SRGB8_ETC2:
80 return "SRGB8_ETC2";
81 case QSSGRenderTextureFormat::RGB8_PunchThrough_Alpha1_ETC2:
82 return "RGB8_PunchThrough_Alpha1_ETC2";
83 case QSSGRenderTextureFormat::SRGB8_PunchThrough_Alpha1_ETC2:
84 return "SRGB8_PunchThrough_Alpha1_ETC2";
85 case QSSGRenderTextureFormat::RGBA8_ETC2_EAC:
86 return "RGBA8_ETC2_EAC";
87 case QSSGRenderTextureFormat::SRGB8_Alpha8_ETC2_EAC:
88 return "SRGB8_Alpha8_ETC2_EAC";
89 case QSSGRenderTextureFormat::RGBA_ASTC_4x4:
90 return "RGBA_ASTC_4x4";
91 case QSSGRenderTextureFormat::RGBA_ASTC_5x4:
92 return "RGBA_ASTC_5x4";
93 case QSSGRenderTextureFormat::RGBA_ASTC_5x5:
94 return "RGBA_ASTC_5x5";
95 case QSSGRenderTextureFormat::RGBA_ASTC_6x5:
96 return "RGBA_ASTC_6x5";
97 case QSSGRenderTextureFormat::RGBA_ASTC_6x6:
98 return "RGBA_ASTC_6x6";
99 case QSSGRenderTextureFormat::RGBA_ASTC_8x5:
100 return "RGBA_ASTC_8x5";
101 case QSSGRenderTextureFormat::RGBA_ASTC_8x6:
102 return "RGBA_ASTC_8x6";
103 case QSSGRenderTextureFormat::RGBA_ASTC_8x8:
104 return "RGBA_ASTC_8x8";
105 case QSSGRenderTextureFormat::RGBA_ASTC_10x5:
106 return "RGBA_ASTC_10x5";
107 case QSSGRenderTextureFormat::RGBA_ASTC_10x6:
108 return "RGBA_ASTC_10x6";
109 case QSSGRenderTextureFormat::RGBA_ASTC_10x8:
110 return "RGBA_ASTC_10x8";
111 case QSSGRenderTextureFormat::RGBA_ASTC_10x10:
112 return "RGBA_ASTC_10x10";
113 case QSSGRenderTextureFormat::RGBA_ASTC_12x10:
114 return "RGBA_ASTC_12x10";
115 case QSSGRenderTextureFormat::RGBA_ASTC_12x12:
116 return "RGBA_ASTC_12x12";
117 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_4x4:
118 return "SRGB8_Alpha8_ASTC_4x4";
119 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_5x4:
120 return "SRGB8_Alpha8_ASTC_5x4";
121 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_5x5:
122 return "SRGB8_Alpha8_ASTC_5x5";
123 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_6x5:
124 return "SRGB8_Alpha8_ASTC_6x5";
125 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_6x6:
126 return "SRGB8_Alpha8_ASTC_6x6";
127 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_8x5:
128 return "SRGB8_Alpha8_ASTC_8x5";
129 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_8x6:
130 return "SRGB8_Alpha8_ASTC_8x6";
131 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_8x8:
132 return "SRGB8_Alpha8_ASTC_8x8";
133 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_10x5:
134 return "SRGB8_Alpha8_ASTC_10x5";
135 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_10x6:
136 return "SRGB8_Alpha8_ASTC_10x6";
137 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_10x8:
138 return "SRGB8_Alpha8_ASTC_10x8";
139 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_10x10:
140 return "SRGB8_Alpha8_ASTC_10x10";
141 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_12x10:
142 return "SRGB8_Alpha8_ASTC_12x10";
143 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_12x12:
144 return "SRGB8_Alpha8_ASTC_12x12";
145 case QSSGRenderTextureFormat::BC1:
146 return "BC1";
147 case QSSGRenderTextureFormat::BC2:
148 return "BC2";
149 case QSSGRenderTextureFormat::BC3:
150 return "BC3";
151 case QSSGRenderTextureFormat::BC4:
152 return "BC4";
153 case QSSGRenderTextureFormat::BC5:
154 return "BC5";
155 case QSSGRenderTextureFormat::BC6H:
156 return "BC6H";
157 case QSSGRenderTextureFormat::BC7:
158 return "BC7";
159 case QSSGRenderTextureFormat::Depth16:
160 return "Depth16";
161 case QSSGRenderTextureFormat::Depth24:
162 return "Depth24";
163 case QSSGRenderTextureFormat::Depth32:
164 return "Depth32";
165 case QSSGRenderTextureFormat::Depth24Stencil8:
166 return "Depth24Stencil8";
167 case QSSGRenderTextureFormat::RGB10_A2:
168 return "RGB10_A2";
169 case QSSGRenderTextureFormat::RGB16F:
170 return "RGB16F";
171 case QSSGRenderTextureFormat::RGBA32UI:
172 return "RGBA32UI";
173 case QSSGRenderTextureFormat::RGB32UI:
174 return "RGB32UI";
175 case QSSGRenderTextureFormat::RGBA16UI:
176 return "RGBA16UI";
177 case QSSGRenderTextureFormat::RGB16UI:
178 return "RGB16UI";
179 case QSSGRenderTextureFormat::RGBA8UI:
180 return "RGBA8UI";
181 case QSSGRenderTextureFormat::RGB8UI:
182 return "RGB8UI";
183 case QSSGRenderTextureFormat::RGBA32I:
184 return "RGBA32I";
185 case QSSGRenderTextureFormat::RGB32I:
186 return "RGB32I";
187 case QSSGRenderTextureFormat::RGBA16I:
188 return "RGBA16I";
189 case QSSGRenderTextureFormat::RGB16I:
190 return "RGB16I";
191 case QSSGRenderTextureFormat::RGBA8I:
192 return "RGBA8I";
193 case QSSGRenderTextureFormat::RGB8I:
194 return "RGB8I";
195 case QSSGRenderTextureFormat::Unknown:
196 return "Unknown";
197 }
198
199 Q_UNREACHABLE_RETURN(nullptr);
200}
201
202qint32 QSSGRenderTextureFormat::getSizeofFormat() const noexcept
203{
204 switch (format) {
205 case R8:
206 return 1;
207 case R16F:
208 return 2;
209 case R16:
210 return 2;
211 case R32I:
212 return 4;
213 case R32F:
214 return 4;
215 case RGBE8:
216 case RGBA8:
217 return 4;
218 case RGB8:
219 return 3;
220 case RGB565:
221 return 2;
222 case RGBA5551:
223 return 2;
224 case Alpha8:
225 return 1;
226 case Luminance8:
227 return 1;
228 case LuminanceAlpha8:
229 return 1;
230 case Depth16:
231 return 2;
232 case Depth24:
233 return 3;
234 case Depth32:
235 return 4;
236 case Depth24Stencil8:
237 return 4;
238 case RGB9E5:
239 return 4;
240 case SRGB8:
241 return 3;
242 case SRGB8A8:
243 return 4;
244 case RGBA16F:
245 return 8;
246 case RG16F:
247 return 4;
248 case RG32F:
249 return 8;
250 case RGBA32F:
251 return 16;
252 case RGB32F:
253 return 12;
254 case R11G11B10:
255 return 4;
256 default:
257 break;
258 }
259 Q_ASSERT(false);
260 return 0;
261}
262
263qint32 QSSGRenderTextureFormat::getNumberOfComponent() const noexcept
264{
265 switch (format) {
266 case R8:
267 return 1;
268 case R16F:
269 return 1;
270 case R16:
271 return 1;
272 case R32I:
273 return 1;
274 case R32F:
275 return 1;
276 case RGBA8:
277 return 4;
278 case RGB8:
279 return 3;
280 case RGB565:
281 return 3;
282 case RGBA5551:
283 return 4;
284 case Alpha8:
285 return 1;
286 case Luminance8:
287 return 1;
288 case LuminanceAlpha8:
289 return 2;
290 case Depth16:
291 return 1;
292 case Depth24:
293 return 1;
294 case Depth32:
295 return 1;
296 case Depth24Stencil8:
297 return 2;
298 case RGB9E5:
299 return 3;
300 case SRGB8:
301 return 3;
302 case SRGB8A8:
303 return 4;
304 case RGBA16F:
305 return 4;
306 case RG16F:
307 return 2;
308 case RG32F:
309 return 2;
310 case RGBA32F:
311 return 4;
312 case RGB32F:
313 return 3;
314 case R11G11B10:
315 return 3;
316 case RGBE8:
317 return 4;
318 default:
319 break;
320 }
321 Q_ASSERT(false);
322 return 0;
323}
324
325void QSSGRenderTextureFormat::decodeToFloat(void *inPtr, qint32 byteOfs, float *outPtr) const
326{
327 Q_ASSERT(byteOfs >= 0);
328 outPtr[0] = 0.0f;
329 outPtr[1] = 0.0f;
330 outPtr[2] = 0.0f;
331 outPtr[3] = 0.0f;
332 quint8 *src = reinterpret_cast<quint8 *>(inPtr);
333 switch (format) {
334 case Alpha8:
335 outPtr[0] = (float(src[byteOfs])) / 255.0f;
336 break;
337
338 case Luminance8:
339 case LuminanceAlpha8:
340 case R8:
341 case RG8:
342 case RGB8:
343 case RGBA8:
344 case SRGB8:
345 case SRGB8A8:
346 for (qint32 i = 0; i < getSizeofFormat(); ++i) {
347 float val = (float(src[byteOfs + i])) / 255.0f;
348 outPtr[i] = (i < 3) ? std::pow(x: val, y: 0.4545454545f) : val;
349 }
350 break;
351 case RGBE8:
352 {
353 float pwd = powf(x: 2.0f, y: int(src[byteOfs + 3]) - 128);
354 outPtr[0] = float(src[byteOfs + 0]) * pwd / 255.0;
355 outPtr[1] = float(src[byteOfs + 1]) * pwd / 255.0;
356 outPtr[2] = float(src[byteOfs + 2]) * pwd / 255.0;
357 outPtr[3] = 1.0f;
358 } break;
359
360 case R32F:
361 outPtr[0] = reinterpret_cast<float *>(src + byteOfs)[0];
362 break;
363 case RG32F:
364 outPtr[0] = reinterpret_cast<float *>(src + byteOfs)[0];
365 outPtr[1] = reinterpret_cast<float *>(src + byteOfs)[1];
366 break;
367 case RGBA32F:
368 outPtr[0] = reinterpret_cast<float *>(src + byteOfs)[0];
369 outPtr[1] = reinterpret_cast<float *>(src + byteOfs)[1];
370 outPtr[2] = reinterpret_cast<float *>(src + byteOfs)[2];
371 outPtr[3] = reinterpret_cast<float *>(src + byteOfs)[3];
372 break;
373 case RGB32F:
374 outPtr[0] = reinterpret_cast<float *>(src + byteOfs)[0];
375 outPtr[1] = reinterpret_cast<float *>(src + byteOfs)[1];
376 outPtr[2] = reinterpret_cast<float *>(src + byteOfs)[2];
377 break;
378
379 case R16F:
380 case RG16F:
381 case RGBA16F:
382 for (qint32 i = 0; i < (getSizeofFormat() >> 1); ++i) {
383 // NOTE : This only works on the assumption that we don't have any denormals,
384 // Infs or NaNs.
385 // Every pixel in our source image should be "regular"
386 quint16 h = reinterpret_cast<quint16 *>(src + byteOfs)[i];
387 quint32 sign = (h & 0x8000u) << 16u;
388 quint32 exponent = (((((h & 0x7c00u) >> 10) - 15) + 127) << 23);
389 quint32 mantissa = ((h & 0x3ffu) << 13);
390 quint32 result = sign | exponent | mantissa;
391
392 if (h == 0 || h == 0x8000)
393 result = 0;
394 memcpy(dest: outPtr + i, src: &result, n: 4);
395 }
396 break;
397
398 case R11G11B10:
399 // place holder
400 Q_ASSERT(false);
401 break;
402
403 default:
404 outPtr[0] = 0.0f;
405 outPtr[1] = 0.0f;
406 outPtr[2] = 0.0f;
407 outPtr[3] = 0.0f;
408 break;
409 }
410}
411void QSSGRenderTextureFormat::encodeToPixel(float *inPtr, void *outPtr, qint32 byteOfs) const
412{
413 struct M8E8
414 {
415 quint8 m;
416 quint8 e;
417 M8E8() : m(0), e(0){
418 }
419 M8E8(const float val) {
420 float l2 = 1.f + std::floor(x: log2f(x: val));
421 float mm = val / powf(x: 2.f, y: l2);
422 m = quint8(mm * 255.f);
423 e = quint8(l2 + 128);
424 }
425 M8E8(const float val, quint8 exp) {
426 if (val <= 0) {
427 m = e = 0;
428 return;
429 }
430 float mm = val / powf(x: 2.f, y: exp - 128);
431 m = quint8(mm * 255.f);
432 e = exp;
433 }
434 };
435
436 Q_ASSERT(byteOfs >= 0);
437 quint8 *dest = reinterpret_cast<quint8 *>(outPtr);
438 switch (format) {
439 case QSSGRenderTextureFormat::Alpha8:
440 dest[byteOfs] = quint8(inPtr[0] * 255.0f);
441 break;
442
443 case Luminance8:
444 case LuminanceAlpha8:
445 case R8:
446 case RG8:
447 case RGB8:
448 case RGBA8:
449 case SRGB8:
450 case SRGB8A8:
451 for (qint32 i = 0; i < getSizeofFormat(); ++i) {
452 inPtr[i] = (inPtr[i] > 1.0f) ? 1.0f : inPtr[i];
453 if (i < 3)
454 dest[byteOfs + i] = quint8(powf(x: inPtr[i], y: 2.2f) * 255.0f);
455 else
456 dest[byteOfs + i] = quint8(inPtr[i] * 255.0f);
457 }
458 break;
459 case RGBE8:
460 {
461 float max = qMax(a: inPtr[0], b: qMax(a: inPtr[1], b: inPtr[2]));
462 M8E8 ex(max);
463 M8E8 a(inPtr[0], ex.e);
464 M8E8 b(inPtr[1], ex.e);
465 M8E8 c(inPtr[2], ex.e);
466 quint8 *dst = reinterpret_cast<quint8 *>(outPtr) + byteOfs;
467 dst[0] = a.m;
468 dst[1] = b.m;
469 dst[2] = c.m;
470 dst[3] = ex.e;
471 } break;
472
473 case R32F:
474 reinterpret_cast<float *>(dest + byteOfs)[0] = inPtr[0];
475 break;
476 case RG32F:
477 reinterpret_cast<float *>(dest + byteOfs)[0] = inPtr[0];
478 reinterpret_cast<float *>(dest + byteOfs)[1] = inPtr[1];
479 break;
480 case RGBA32F:
481 reinterpret_cast<float *>(dest + byteOfs)[0] = inPtr[0];
482 reinterpret_cast<float *>(dest + byteOfs)[1] = inPtr[1];
483 reinterpret_cast<float *>(dest + byteOfs)[2] = inPtr[2];
484 reinterpret_cast<float *>(dest + byteOfs)[3] = inPtr[3];
485 break;
486 case RGB32F:
487 reinterpret_cast<float *>(dest + byteOfs)[0] = inPtr[0];
488 reinterpret_cast<float *>(dest + byteOfs)[1] = inPtr[1];
489 reinterpret_cast<float *>(dest + byteOfs)[2] = inPtr[2];
490 break;
491
492 case R16F:
493 case RG16F:
494 case RGBA16F:
495 for (qint32 i = 0; i < (getSizeofFormat() >> 1); ++i) {
496 // NOTE : This also has the limitation of not handling infs, NaNs and
497 // denormals, but it should be
498 // sufficient for our purposes.
499 if (inPtr[i] > 65519.0f)
500 inPtr[i] = 65519.0f;
501 if (std::fabs(x: inPtr[i]) < 6.10352E-5f)
502 inPtr[i] = 0.0f;
503 quint32 f = reinterpret_cast<quint32 *>(inPtr)[i];
504 quint32 sign = (f & 0x80000000) >> 16;
505 qint32 exponent = (f & 0x7f800000) >> 23;
506 quint32 mantissa = (f >> 13) & 0x3ff;
507 exponent = exponent - 112;
508 if (exponent > 31)
509 exponent = 31;
510 if (exponent < 0)
511 exponent = 0;
512 exponent = exponent << 10;
513 reinterpret_cast<quint16 *>(dest + byteOfs)[i] = quint16(sign | quint32(exponent) | mantissa);
514 }
515 break;
516
517 case R11G11B10:
518 // place holder
519 Q_ASSERT(false);
520 break;
521
522 default:
523 dest[byteOfs] = 0;
524 dest[byteOfs + 1] = 0;
525 dest[byteOfs + 2] = 0;
526 dest[byteOfs + 3] = 0;
527 break;
528 }
529}
530
531const char *QSSGBaseTypeHelpers::toString(QSSGRenderWinding value)
532{
533 switch (value) {
534 case QSSGRenderWinding::Clockwise:
535 return "Clockwise";
536 case QSSGRenderWinding::CounterClockwise:
537 return "CounterClockwise";
538 }
539
540 Q_UNREACHABLE_RETURN(nullptr);
541}
542
543const char *QSSGBaseTypeHelpers::toString(QSSGCullFaceMode value)
544{
545 switch (value) {
546 case QSSGCullFaceMode::Front:
547 return "Front";
548 case QSSGCullFaceMode::Back:
549 return "Back";
550 case QSSGCullFaceMode::FrontAndBack:
551 return "FrontAndBack";
552 case QSSGCullFaceMode::Unknown:
553 return "Unknown";
554 case QSSGCullFaceMode::Disabled:
555 return "Disabled";
556 }
557
558 Q_UNREACHABLE_RETURN(nullptr);
559}
560
561const char *QSSGBaseTypeHelpers::toString(QSSGRenderTextureCubeFace value)
562{
563 switch (value) {
564 case QSSGRenderTextureCubeFace::NegX:
565 return "NegX";
566 case QSSGRenderTextureCubeFace::NegZ:
567 return "NegZ";
568 case QSSGRenderTextureCubeFace::NegY:
569 return "NegY";
570 case QSSGRenderTextureCubeFace::PosY:
571 return "PosY";
572 case QSSGRenderTextureCubeFace::PosX:
573 return "PosX";
574 case QSSGRenderTextureCubeFace::PosZ:
575 return "PosZ";
576 }
577
578 Q_UNREACHABLE_RETURN(nullptr);
579}
580
581const char *QSSGBaseTypeHelpers::toString(QSSGRenderTextureTypeValue value)
582{
583 switch (value) {
584 case QSSGRenderTextureTypeValue::Unknown:
585 return "Unknown";
586 case QSSGRenderTextureTypeValue::Diffuse:
587 return "Diffuse";
588 case QSSGRenderTextureTypeValue::Specular:
589 return "Specular";
590 case QSSGRenderTextureTypeValue::Environment:
591 return "Environment";
592 case QSSGRenderTextureTypeValue::Bump:
593 return "Bump";
594 case QSSGRenderTextureTypeValue::Normal:
595 return "Normal";
596 case QSSGRenderTextureTypeValue::Emissive:
597 return "Emissive";
598 case QSSGRenderTextureTypeValue::Anisotropy:
599 return "Anisotropy";
600 case QSSGRenderTextureTypeValue::Translucent:
601 return "Translucent";
602 }
603
604 Q_UNREACHABLE_RETURN(nullptr);
605}
606
607const char *QSSGBaseTypeHelpers::toString(QSSGDepthDrawMode value)
608{
609 switch (value) {
610 case QSSGDepthDrawMode::OpaqueOnly:
611 return "OpaqueOnly";
612 case QSSGDepthDrawMode::Always:
613 return "Always";
614 case QSSGDepthDrawMode::Never:
615 return "Never";
616 case QSSGDepthDrawMode::OpaquePrePass:
617 return "OpaquePrePass";
618 }
619
620 Q_UNREACHABLE_RETURN(nullptr);
621}
622
623const char *QSSGBaseTypeHelpers::toString(QSSGRenderComponentType value)
624{
625 switch (value) {
626 case QSSGRenderComponentType::UnsignedInt8:
627 return "UnsignedInt8";
628 case QSSGRenderComponentType::Int8:
629 return "Int8";
630 case QSSGRenderComponentType::UnsignedInt16:
631 return "UnsignedInt16";
632 case QSSGRenderComponentType::Int16:
633 return "Int16";
634 case QSSGRenderComponentType::UnsignedInt32:
635 return "UnsignedInt32";
636 case QSSGRenderComponentType::Int32:
637 return "Int32";
638 case QSSGRenderComponentType::UnsignedInt64:
639 return "UnsignedInt64";
640 case QSSGRenderComponentType::Int64:
641 return "Int64";
642 case QSSGRenderComponentType::Float16:
643 return "Float16";
644 case QSSGRenderComponentType::Float32:
645 return "Float32";
646 case QSSGRenderComponentType::Float64:
647 return "Float64";
648 }
649
650 Q_UNREACHABLE_RETURN("Unknown");
651}
652
653const char *QSSGBaseTypeHelpers::toString(QSSGRenderTextureFormat::Format value)
654{
655 return QSSGRenderTextureFormat(value).toString();
656}
657
658const char *QSSGBaseTypeHelpers::toString(QSSGRenderTextureCoordOp value)
659{
660 switch (value) {
661 case QSSGRenderTextureCoordOp::ClampToEdge:
662 return "ClampToEdge";
663 case QSSGRenderTextureCoordOp::MirroredRepeat:
664 return "MirroredRepeat";
665 case QSSGRenderTextureCoordOp::Repeat:
666 return "Repeat";
667 case QSSGRenderTextureCoordOp::Unknown:
668 return "Unknown";
669 }
670
671 Q_UNREACHABLE_RETURN(nullptr);
672}
673
674const char *QSSGBaseTypeHelpers::toString(QSSGRenderTextureFilterOp value)
675{
676 switch (value) {
677 case QSSGRenderTextureFilterOp::Nearest:
678 return "Nearest";
679 case QSSGRenderTextureFilterOp::Linear:
680 return "Linear";
681 case QSSGRenderTextureFilterOp::None:
682 return "None";
683 }
684
685 Q_UNREACHABLE_RETURN(nullptr);
686}
687
688const char *QSSGBaseTypeHelpers::displayName(QSSGRenderTextureCubeFace face)
689{
690 switch (face) {
691 case QSSGRenderTextureCubeFace::NegX:
692 return "-X";
693 case QSSGRenderTextureCubeFace::NegZ:
694 return "-Z";
695 case QSSGRenderTextureCubeFace::NegY:
696 return "-Y";
697 case QSSGRenderTextureCubeFace::PosY:
698 return "+Y";
699 case QSSGRenderTextureCubeFace::PosX:
700 return "+X";
701 case QSSGRenderTextureCubeFace::PosZ:
702 return "+Z";
703 }
704
705 Q_UNREACHABLE_RETURN(nullptr);
706}
707
708size_t QSSGBaseTypeHelpers::getSizeOfType(QSSGRenderComponentType type)
709{
710 switch (type) {
711 case QSSGRenderComponentType::UnsignedInt8:
712 return sizeof(quint8);
713 case QSSGRenderComponentType::Int8:
714 return sizeof(qint8);
715 case QSSGRenderComponentType::UnsignedInt16:
716 return sizeof(quint16);
717 case QSSGRenderComponentType::Int16:
718 return sizeof(qint16);
719 case QSSGRenderComponentType::UnsignedInt32:
720 return sizeof(quint32);
721 case QSSGRenderComponentType::Int32:
722 return sizeof(qint32);
723 case QSSGRenderComponentType::UnsignedInt64:
724 return sizeof(quint64);
725 case QSSGRenderComponentType::Int64:
726 return sizeof(qint64);
727 case QSSGRenderComponentType::Float16:
728 return sizeof(qfloat16);
729 case QSSGRenderComponentType::Float32:
730 return sizeof(float);
731 case QSSGRenderComponentType::Float64:
732 return sizeof(double);
733 }
734 Q_UNREACHABLE_RETURN(0);
735}
736
737QT_END_NAMESPACE
738

source code of qtquick3d/src/utils/qssgrenderbasetypes.cpp