12const char *QSSGRenderTextureFormat::toString()
const
15 case QSSGRenderTextureFormat::R8:
17 case QSSGRenderTextureFormat::R16:
19 case QSSGRenderTextureFormat::R16F:
21 case QSSGRenderTextureFormat::R32I:
23 case QSSGRenderTextureFormat::R32UI:
25 case QSSGRenderTextureFormat::R32F:
27 case QSSGRenderTextureFormat::RG8:
29 case QSSGRenderTextureFormat::RGBA8:
31 case QSSGRenderTextureFormat::RGB8:
33 case QSSGRenderTextureFormat::SRGB8:
35 case QSSGRenderTextureFormat::SRGB8A8:
37 case QSSGRenderTextureFormat::RGB565:
39 case QSSGRenderTextureFormat::RGBA5551:
41 case QSSGRenderTextureFormat::Alpha8:
43 case QSSGRenderTextureFormat::Luminance8:
45 case QSSGRenderTextureFormat::Luminance16:
47 case QSSGRenderTextureFormat::LuminanceAlpha8:
48 return "LuminanceAlpha8";
49 case QSSGRenderTextureFormat::RGBA16F:
51 case QSSGRenderTextureFormat::RG16F:
53 case QSSGRenderTextureFormat::RG32F:
55 case QSSGRenderTextureFormat::RGB32F:
57 case QSSGRenderTextureFormat::RGBA32F:
59 case QSSGRenderTextureFormat::R11G11B10:
61 case QSSGRenderTextureFormat::RGB9E5:
63 case QSSGRenderTextureFormat::RGBE8:
65 case QSSGRenderTextureFormat::RGBA_DXT1:
67 case QSSGRenderTextureFormat::RGB_DXT1:
69 case QSSGRenderTextureFormat::RGBA_DXT3:
71 case QSSGRenderTextureFormat::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:
83 case QSSGRenderTextureFormat::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:
151 case QSSGRenderTextureFormat::BC2:
153 case QSSGRenderTextureFormat::BC3:
155 case QSSGRenderTextureFormat::BC4:
157 case QSSGRenderTextureFormat::BC5:
159 case QSSGRenderTextureFormat::BC6H:
161 case QSSGRenderTextureFormat::BC7:
163 case QSSGRenderTextureFormat::Depth16:
165 case QSSGRenderTextureFormat::Depth24:
167 case QSSGRenderTextureFormat::Depth32:
169 case QSSGRenderTextureFormat::Depth24Stencil8:
170 return "Depth24Stencil8";
171 case QSSGRenderTextureFormat::RGB10_A2:
173 case QSSGRenderTextureFormat::RGB16F:
175 case QSSGRenderTextureFormat::RGBA32UI:
177 case QSSGRenderTextureFormat::RGB32UI:
179 case QSSGRenderTextureFormat::RGBA16UI:
181 case QSSGRenderTextureFormat::RGB16UI:
183 case QSSGRenderTextureFormat::RGBA8UI:
185 case QSSGRenderTextureFormat::RGB8UI:
187 case QSSGRenderTextureFormat::RGBA32I:
189 case QSSGRenderTextureFormat::RGB32I:
191 case QSSGRenderTextureFormat::RGBA16I:
193 case QSSGRenderTextureFormat::RGB16I:
195 case QSSGRenderTextureFormat::RGBA8I:
197 case QSSGRenderTextureFormat::RGB8I:
199 case QSSGRenderTextureFormat::Unknown:
203 Q_UNREACHABLE_RETURN(
nullptr);
329void QSSGRenderTextureFormat::decodeToFloat(
void *inPtr, qint32 byteOfs,
float *outPtr)
const
331 Q_ASSERT(byteOfs >= 0);
336 quint8 *src =
reinterpret_cast<quint8 *>(inPtr);
339 outPtr[0] = (
float(src[byteOfs])) / 255.0f;
343 case LuminanceAlpha8:
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;
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;
365 outPtr[0] =
reinterpret_cast<
float *>(src + byteOfs)[0];
368 outPtr[0] =
reinterpret_cast<
float *>(src + byteOfs)[0];
369 outPtr[1] =
reinterpret_cast<
float *>(src + byteOfs)[1];
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];
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];
386 for (qint32 i = 0; i < (getSizeofFormat() >> 1); ++i) {
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;
396 if (h == 0 || h == 0x8000)
398 memcpy(outPtr + i, &result, 4);
415void QSSGRenderTextureFormat::encodeToPixel(
float *inPtr,
void *outPtr, qint32 byteOfs)
const
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);
429 M8E8(
const float val, quint8 exp) {
434 float mm = val / powf(2.f, exp - 128);
435 m = quint8(mm * 255.f);
440 Q_ASSERT(byteOfs >= 0);
441 quint8 *dest =
reinterpret_cast<quint8 *>(outPtr);
443 case QSSGRenderTextureFormat::Alpha8:
444 dest[byteOfs] = quint8(inPtr[0] * 255.0f);
448 case LuminanceAlpha8:
455 for (qint32 i = 0; i < getSizeofFormat(); ++i) {
456 inPtr[i] = (inPtr[i] > 1.0f) ? 1.0f : inPtr[i];
458 dest[byteOfs + i] = quint8(powf(inPtr[i], 2.2f) * 255.0f);
460 dest[byteOfs + i] = quint8(inPtr[i] * 255.0f);
465 float max = qMax(inPtr[0], qMax(inPtr[1], inPtr[2]));
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;
478 reinterpret_cast<
float *>(dest + byteOfs)[0] = inPtr[0];
481 reinterpret_cast<
float *>(dest + byteOfs)[0] = inPtr[0];
482 reinterpret_cast<
float *>(dest + byteOfs)[1] = inPtr[1];
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];
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];
499 for (qint32 i = 0; i < (getSizeofFormat() >> 1); ++i) {
503 if (inPtr[i] > 65519.0f)
505 if (std::fabs(inPtr[i]) < 6.10352E-5f)
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;
516 exponent = exponent << 10;
517 reinterpret_cast<quint16 *>(dest + byteOfs)[i] = quint16(sign | quint32(exponent) | mantissa);
528 dest[byteOfs + 1] = 0;
529 dest[byteOfs + 2] = 0;
530 dest[byteOfs + 3] = 0;