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