8const char *QSSGRenderTextureFormat::toString()
const
11 case QSSGRenderTextureFormat::R8:
13 case QSSGRenderTextureFormat::R16:
15 case QSSGRenderTextureFormat::R16F:
17 case QSSGRenderTextureFormat::R32I:
19 case QSSGRenderTextureFormat::R32UI:
21 case QSSGRenderTextureFormat::R32F:
23 case QSSGRenderTextureFormat::RG8:
25 case QSSGRenderTextureFormat::RGBA8:
27 case QSSGRenderTextureFormat::RGB8:
29 case QSSGRenderTextureFormat::SRGB8:
31 case QSSGRenderTextureFormat::SRGB8A8:
33 case QSSGRenderTextureFormat::RGB565:
35 case QSSGRenderTextureFormat::RGBA5551:
37 case QSSGRenderTextureFormat::Alpha8:
39 case QSSGRenderTextureFormat::Luminance8:
41 case QSSGRenderTextureFormat::Luminance16:
43 case QSSGRenderTextureFormat::LuminanceAlpha8:
44 return "LuminanceAlpha8";
45 case QSSGRenderTextureFormat::RGBA16F:
47 case QSSGRenderTextureFormat::RG16F:
49 case QSSGRenderTextureFormat::RG32F:
51 case QSSGRenderTextureFormat::RGB32F:
53 case QSSGRenderTextureFormat::RGBA32F:
55 case QSSGRenderTextureFormat::R11G11B10:
57 case QSSGRenderTextureFormat::RGB9E5:
59 case QSSGRenderTextureFormat::RGBE8:
61 case QSSGRenderTextureFormat::RGBA_DXT1:
63 case QSSGRenderTextureFormat::RGB_DXT1:
65 case QSSGRenderTextureFormat::RGBA_DXT3:
67 case QSSGRenderTextureFormat::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:
79 case QSSGRenderTextureFormat::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:
147 case QSSGRenderTextureFormat::BC2:
149 case QSSGRenderTextureFormat::BC3:
151 case QSSGRenderTextureFormat::BC4:
153 case QSSGRenderTextureFormat::BC5:
155 case QSSGRenderTextureFormat::BC6H:
157 case QSSGRenderTextureFormat::BC7:
159 case QSSGRenderTextureFormat::Depth16:
161 case QSSGRenderTextureFormat::Depth24:
163 case QSSGRenderTextureFormat::Depth32:
165 case QSSGRenderTextureFormat::Depth24Stencil8:
166 return "Depth24Stencil8";
167 case QSSGRenderTextureFormat::RGB10_A2:
169 case QSSGRenderTextureFormat::RGB16F:
171 case QSSGRenderTextureFormat::RGBA32UI:
173 case QSSGRenderTextureFormat::RGB32UI:
175 case QSSGRenderTextureFormat::RGBA16UI:
177 case QSSGRenderTextureFormat::RGB16UI:
179 case QSSGRenderTextureFormat::RGBA8UI:
181 case QSSGRenderTextureFormat::RGB8UI:
183 case QSSGRenderTextureFormat::RGBA32I:
185 case QSSGRenderTextureFormat::RGB32I:
187 case QSSGRenderTextureFormat::RGBA16I:
189 case QSSGRenderTextureFormat::RGB16I:
191 case QSSGRenderTextureFormat::RGBA8I:
193 case QSSGRenderTextureFormat::RGB8I:
195 case QSSGRenderTextureFormat::Unknown:
199 Q_UNREACHABLE_RETURN(
nullptr);
325void QSSGRenderTextureFormat::decodeToFloat(
void *inPtr, qint32 byteOfs,
float *outPtr)
const
327 Q_ASSERT(byteOfs >= 0);
332 quint8 *src =
reinterpret_cast<quint8 *>(inPtr);
335 outPtr[0] = (
float(src[byteOfs])) / 255.0f;
339 case LuminanceAlpha8:
346 for (qint32 i = 0; i < getSizeofFormat(); ++i) {
347 float val = (
float(src[byteOfs + i])) / 255.0f;
348 outPtr[i] = (i < 3) ? std::pow(val, 0.4545454545f) : val;
353 float pwd = powf(2.0f,
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;
361 outPtr[0] =
reinterpret_cast<
float *>(src + byteOfs)[0];
364 outPtr[0] =
reinterpret_cast<
float *>(src + byteOfs)[0];
365 outPtr[1] =
reinterpret_cast<
float *>(src + byteOfs)[1];
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];
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];
382 for (qint32 i = 0; i < (getSizeofFormat() >> 1); ++i) {
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;
392 if (h == 0 || h == 0x8000)
394 memcpy(outPtr + i, &result, 4);
411void QSSGRenderTextureFormat::encodeToPixel(
float *inPtr,
void *outPtr, qint32 byteOfs)
const
419 M8E8(
const float val) {
420 float l2 = 1.f + std::floor(log2f(val));
421 float mm = val / powf(2.f, l2);
422 m = quint8(mm * 255.f);
423 e = quint8(l2 + 128);
425 M8E8(
const float val, quint8 exp) {
430 float mm = val / powf(2.f, exp - 128);
431 m = quint8(mm * 255.f);
436 Q_ASSERT(byteOfs >= 0);
437 quint8 *dest =
reinterpret_cast<quint8 *>(outPtr);
439 case QSSGRenderTextureFormat::Alpha8:
440 dest[byteOfs] = quint8(inPtr[0] * 255.0f);
444 case LuminanceAlpha8:
451 for (qint32 i = 0; i < getSizeofFormat(); ++i) {
452 inPtr[i] = (inPtr[i] > 1.0f) ? 1.0f : inPtr[i];
454 dest[byteOfs + i] = quint8(powf(inPtr[i], 2.2f) * 255.0f);
456 dest[byteOfs + i] = quint8(inPtr[i] * 255.0f);
461 float max = qMax(inPtr[0], qMax(inPtr[1], inPtr[2]));
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;
474 reinterpret_cast<
float *>(dest + byteOfs)[0] = inPtr[0];
477 reinterpret_cast<
float *>(dest + byteOfs)[0] = inPtr[0];
478 reinterpret_cast<
float *>(dest + byteOfs)[1] = inPtr[1];
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];
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];
495 for (qint32 i = 0; i < (getSizeofFormat() >> 1); ++i) {
499 if (inPtr[i] > 65519.0f)
501 if (std::fabs(inPtr[i]) < 6.10352E-5f)
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;
512 exponent = exponent << 10;
513 reinterpret_cast<quint16 *>(dest + byteOfs)[i] = quint16(sign | quint32(exponent) | mantissa);
524 dest[byteOfs + 1] = 0;
525 dest[byteOfs + 2] = 0;
526 dest[byteOfs + 3] = 0;