19const char *QSSGRenderTextureFormat::toString()
const
22 case QSSGRenderTextureFormat::R8:
24 case QSSGRenderTextureFormat::R16:
26 case QSSGRenderTextureFormat::R16F:
28 case QSSGRenderTextureFormat::R32I:
30 case QSSGRenderTextureFormat::R32UI:
32 case QSSGRenderTextureFormat::R32F:
34 case QSSGRenderTextureFormat::RG8:
36 case QSSGRenderTextureFormat::RGBA8:
38 case QSSGRenderTextureFormat::RGB8:
40 case QSSGRenderTextureFormat::SRGB8:
42 case QSSGRenderTextureFormat::SRGB8A8:
44 case QSSGRenderTextureFormat::RGB565:
46 case QSSGRenderTextureFormat::RGBA5551:
48 case QSSGRenderTextureFormat::Alpha8:
50 case QSSGRenderTextureFormat::Luminance8:
52 case QSSGRenderTextureFormat::Luminance16:
54 case QSSGRenderTextureFormat::LuminanceAlpha8:
55 return "LuminanceAlpha8";
56 case QSSGRenderTextureFormat::RGBA16F:
58 case QSSGRenderTextureFormat::RG16F:
60 case QSSGRenderTextureFormat::RG32F:
62 case QSSGRenderTextureFormat::RGB32F:
64 case QSSGRenderTextureFormat::RGBA32F:
66 case QSSGRenderTextureFormat::R11G11B10:
68 case QSSGRenderTextureFormat::RGB9E5:
70 case QSSGRenderTextureFormat::RGBE8:
72 case QSSGRenderTextureFormat::RGBA_DXT1:
74 case QSSGRenderTextureFormat::RGB_DXT1:
76 case QSSGRenderTextureFormat::RGBA_DXT3:
78 case QSSGRenderTextureFormat::RGBA_DXT5:
80 case QSSGRenderTextureFormat::R11_EAC_UNorm:
81 return "R11_EAC_UNorm";
82 case QSSGRenderTextureFormat::R11_EAC_SNorm:
83 return "R11_EAC_SNorm";
84 case QSSGRenderTextureFormat::RG11_EAC_UNorm:
85 return "RG11_EAC_UNorm";
86 case QSSGRenderTextureFormat::RG11_EAC_SNorm:
87 return "RG11_EAC_SNorm";
88 case QSSGRenderTextureFormat::RGB8_ETC2:
90 case QSSGRenderTextureFormat::SRGB8_ETC2:
92 case QSSGRenderTextureFormat::RGB8_PunchThrough_Alpha1_ETC2:
93 return "RGB8_PunchThrough_Alpha1_ETC2";
94 case QSSGRenderTextureFormat::SRGB8_PunchThrough_Alpha1_ETC2:
95 return "SRGB8_PunchThrough_Alpha1_ETC2";
96 case QSSGRenderTextureFormat::RGBA8_ETC2_EAC:
97 return "RGBA8_ETC2_EAC";
98 case QSSGRenderTextureFormat::SRGB8_Alpha8_ETC2_EAC:
99 return "SRGB8_Alpha8_ETC2_EAC";
100 case QSSGRenderTextureFormat::RGBA_ASTC_4x4:
101 return "RGBA_ASTC_4x4";
102 case QSSGRenderTextureFormat::RGBA_ASTC_5x4:
103 return "RGBA_ASTC_5x4";
104 case QSSGRenderTextureFormat::RGBA_ASTC_5x5:
105 return "RGBA_ASTC_5x5";
106 case QSSGRenderTextureFormat::RGBA_ASTC_6x5:
107 return "RGBA_ASTC_6x5";
108 case QSSGRenderTextureFormat::RGBA_ASTC_6x6:
109 return "RGBA_ASTC_6x6";
110 case QSSGRenderTextureFormat::RGBA_ASTC_8x5:
111 return "RGBA_ASTC_8x5";
112 case QSSGRenderTextureFormat::RGBA_ASTC_8x6:
113 return "RGBA_ASTC_8x6";
114 case QSSGRenderTextureFormat::RGBA_ASTC_8x8:
115 return "RGBA_ASTC_8x8";
116 case QSSGRenderTextureFormat::RGBA_ASTC_10x5:
117 return "RGBA_ASTC_10x5";
118 case QSSGRenderTextureFormat::RGBA_ASTC_10x6:
119 return "RGBA_ASTC_10x6";
120 case QSSGRenderTextureFormat::RGBA_ASTC_10x8:
121 return "RGBA_ASTC_10x8";
122 case QSSGRenderTextureFormat::RGBA_ASTC_10x10:
123 return "RGBA_ASTC_10x10";
124 case QSSGRenderTextureFormat::RGBA_ASTC_12x10:
125 return "RGBA_ASTC_12x10";
126 case QSSGRenderTextureFormat::RGBA_ASTC_12x12:
127 return "RGBA_ASTC_12x12";
128 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_4x4:
129 return "SRGB8_Alpha8_ASTC_4x4";
130 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_5x4:
131 return "SRGB8_Alpha8_ASTC_5x4";
132 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_5x5:
133 return "SRGB8_Alpha8_ASTC_5x5";
134 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_6x5:
135 return "SRGB8_Alpha8_ASTC_6x5";
136 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_6x6:
137 return "SRGB8_Alpha8_ASTC_6x6";
138 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_8x5:
139 return "SRGB8_Alpha8_ASTC_8x5";
140 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_8x6:
141 return "SRGB8_Alpha8_ASTC_8x6";
142 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_8x8:
143 return "SRGB8_Alpha8_ASTC_8x8";
144 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_10x5:
145 return "SRGB8_Alpha8_ASTC_10x5";
146 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_10x6:
147 return "SRGB8_Alpha8_ASTC_10x6";
148 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_10x8:
149 return "SRGB8_Alpha8_ASTC_10x8";
150 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_10x10:
151 return "SRGB8_Alpha8_ASTC_10x10";
152 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_12x10:
153 return "SRGB8_Alpha8_ASTC_12x10";
154 case QSSGRenderTextureFormat::SRGB8_Alpha8_ASTC_12x12:
155 return "SRGB8_Alpha8_ASTC_12x12";
156 case QSSGRenderTextureFormat::BC1:
158 case QSSGRenderTextureFormat::BC2:
160 case QSSGRenderTextureFormat::BC3:
162 case QSSGRenderTextureFormat::BC4:
164 case QSSGRenderTextureFormat::BC5:
166 case QSSGRenderTextureFormat::BC6H:
168 case QSSGRenderTextureFormat::BC7:
170 case QSSGRenderTextureFormat::Depth16:
172 case QSSGRenderTextureFormat::Depth24:
174 case QSSGRenderTextureFormat::Depth32:
176 case QSSGRenderTextureFormat::Depth24Stencil8:
177 return "Depth24Stencil8";
178 case QSSGRenderTextureFormat::RGB10_A2:
180 case QSSGRenderTextureFormat::RGB16F:
182 case QSSGRenderTextureFormat::RGBA32UI:
184 case QSSGRenderTextureFormat::RGB32UI:
186 case QSSGRenderTextureFormat::RGBA16UI:
188 case QSSGRenderTextureFormat::RGB16UI:
190 case QSSGRenderTextureFormat::RGBA8UI:
192 case QSSGRenderTextureFormat::RGB8UI:
194 case QSSGRenderTextureFormat::RGBA32I:
196 case QSSGRenderTextureFormat::RGB32I:
198 case QSSGRenderTextureFormat::RGBA16I:
200 case QSSGRenderTextureFormat::RGB16I:
202 case QSSGRenderTextureFormat::RGBA8I:
204 case QSSGRenderTextureFormat::RGB8I:
206 case QSSGRenderTextureFormat::Unknown:
210 Q_UNREACHABLE_RETURN(
nullptr);
336void QSSGRenderTextureFormat::decodeToFloat(
void *inPtr, qint32 byteOfs,
float *outPtr)
const
338 Q_ASSERT(byteOfs >= 0);
343 quint8 *src =
reinterpret_cast<quint8 *>(inPtr);
346 outPtr[0] = (
float(src[byteOfs])) / 255.0f;
350 case LuminanceAlpha8:
357 for (qint32 i = 0; i < getSizeofFormat(); ++i) {
358 float val = (
float(src[byteOfs + i])) / 255.0f;
359 outPtr[i] = (i < 3) ? std::pow(val, 0.4545454545f) : val;
364 float pwd = powf(2.0f,
int(src[byteOfs + 3]) - 128);
365 outPtr[0] =
float(src[byteOfs + 0]) * pwd / 255.0;
366 outPtr[1] =
float(src[byteOfs + 1]) * pwd / 255.0;
367 outPtr[2] =
float(src[byteOfs + 2]) * pwd / 255.0;
372 outPtr[0] =
reinterpret_cast<
float *>(src + byteOfs)[0];
375 outPtr[0] =
reinterpret_cast<
float *>(src + byteOfs)[0];
376 outPtr[1] =
reinterpret_cast<
float *>(src + byteOfs)[1];
379 outPtr[0] =
reinterpret_cast<
float *>(src + byteOfs)[0];
380 outPtr[1] =
reinterpret_cast<
float *>(src + byteOfs)[1];
381 outPtr[2] =
reinterpret_cast<
float *>(src + byteOfs)[2];
382 outPtr[3] =
reinterpret_cast<
float *>(src + byteOfs)[3];
385 outPtr[0] =
reinterpret_cast<
float *>(src + byteOfs)[0];
386 outPtr[1] =
reinterpret_cast<
float *>(src + byteOfs)[1];
387 outPtr[2] =
reinterpret_cast<
float *>(src + byteOfs)[2];
393 for (qint32 i = 0; i < (getSizeofFormat() >> 1); ++i) {
397 quint16 h =
reinterpret_cast<quint16 *>(src + byteOfs)[i];
398 quint32 sign = (h & 0x8000u) << 16u;
399 quint32 exponent = (((((h & 0x7c00u) >> 10) - 15) + 127) << 23);
400 quint32 mantissa = ((h & 0x3ffu) << 13);
401 quint32 result = sign | exponent | mantissa;
403 if (h == 0 || h == 0x8000)
405 memcpy(outPtr + i, &result, 4);
422void QSSGRenderTextureFormat::encodeToPixel(
float *inPtr,
void *outPtr, qint32 byteOfs)
const
430 M8E8(
const float val) {
431 float l2 = 1.f + std::floor(log2f(val));
432 float mm = val / powf(2.f, l2);
433 m = quint8(mm * 255.f);
434 e = quint8(l2 + 128);
436 M8E8(
const float val, quint8 exp) {
441 float mm = val / powf(2.f, exp - 128);
442 m = quint8(mm * 255.f);
447 Q_ASSERT(byteOfs >= 0);
448 quint8 *dest =
reinterpret_cast<quint8 *>(outPtr);
450 case QSSGRenderTextureFormat::Alpha8:
451 dest[byteOfs] = quint8(inPtr[0] * 255.0f);
455 case LuminanceAlpha8:
462 for (qint32 i = 0; i < getSizeofFormat(); ++i) {
463 inPtr[i] = (inPtr[i] > 1.0f) ? 1.0f : inPtr[i];
465 dest[byteOfs + i] = quint8(powf(inPtr[i], 2.2f) * 255.0f);
467 dest[byteOfs + i] = quint8(inPtr[i] * 255.0f);
472 float max = qMax(inPtr[0], qMax(inPtr[1], inPtr[2]));
474 M8E8 a(inPtr[0], ex.e);
475 M8E8 b(inPtr[1], ex.e);
476 M8E8 c(inPtr[2], ex.e);
477 quint8 *dst =
reinterpret_cast<quint8 *>(outPtr) + byteOfs;
485 reinterpret_cast<
float *>(dest + byteOfs)[0] = inPtr[0];
488 reinterpret_cast<
float *>(dest + byteOfs)[0] = inPtr[0];
489 reinterpret_cast<
float *>(dest + byteOfs)[1] = inPtr[1];
492 reinterpret_cast<
float *>(dest + byteOfs)[0] = inPtr[0];
493 reinterpret_cast<
float *>(dest + byteOfs)[1] = inPtr[1];
494 reinterpret_cast<
float *>(dest + byteOfs)[2] = inPtr[2];
495 reinterpret_cast<
float *>(dest + byteOfs)[3] = inPtr[3];
498 reinterpret_cast<
float *>(dest + byteOfs)[0] = inPtr[0];
499 reinterpret_cast<
float *>(dest + byteOfs)[1] = inPtr[1];
500 reinterpret_cast<
float *>(dest + byteOfs)[2] = inPtr[2];
506 for (qint32 i = 0; i < (getSizeofFormat() >> 1); ++i) {
510 if (inPtr[i] > 65519.0f)
512 if (std::fabs(inPtr[i]) < 6.10352E-5f)
514 quint32 f =
reinterpret_cast<quint32 *>(inPtr)[i];
515 quint32 sign = (f & 0x80000000) >> 16;
516 qint32 exponent = (f & 0x7f800000) >> 23;
517 quint32 mantissa = (f >> 13) & 0x3ff;
518 exponent = exponent - 112;
523 exponent = exponent << 10;
524 reinterpret_cast<quint16 *>(dest + byteOfs)[i] = quint16(sign | quint32(exponent) | mantissa);
535 dest[byteOfs + 1] = 0;
536 dest[byteOfs + 2] = 0;
537 dest[byteOfs + 3] = 0;