214QSGCompressedTexture::FormatInfo QSGCompressedTexture::formatInfo(quint32 glTextureFormat)
216 switch (glTextureFormat) {
217 case QInternalGLTextureFormat::RGB_DXT1:
218 return { QRhiTexture::BC1,
false };
219 case QInternalGLTextureFormat::SRGB_DXT1:
220 return { QRhiTexture::BC1,
true };
222 case QInternalGLTextureFormat::RGBA_DXT3:
223 return { QRhiTexture::BC2,
false };
224 case QInternalGLTextureFormat::SRGB_Alpha_DXT3:
225 return { QRhiTexture::BC2,
true };
227 case QInternalGLTextureFormat::RGBA_DXT5:
228 return { QRhiTexture::BC3,
false };
229 case QInternalGLTextureFormat::SRGB_Alpha_DXT5:
230 return { QRhiTexture::BC3,
true };
232 case QInternalGLTextureFormat::RGB8_ETC2:
233 return { QRhiTexture::ETC2_RGB8,
false };
234 case QInternalGLTextureFormat::SRGB8_ETC2:
235 return { QRhiTexture::ETC2_RGB8,
true };
237 case QInternalGLTextureFormat::RGB8_PunchThrough_Alpha1_ETC2:
238 return { QRhiTexture::ETC2_RGB8A1,
false };
239 case QInternalGLTextureFormat::SRGB8_PunchThrough_Alpha1_ETC2:
240 return { QRhiTexture::ETC2_RGB8A1,
true };
242 case QInternalGLTextureFormat::RGBA8_ETC2_EAC:
243 return { QRhiTexture::ETC2_RGBA8,
false };
244 case QInternalGLTextureFormat::SRGB8_Alpha8_ETC2_EAC:
245 return { QRhiTexture::ETC2_RGBA8,
true };
247 case QInternalGLTextureFormat::RGBA_ASTC_4x4:
248 return { QRhiTexture::ASTC_4x4,
false };
249 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_4x4:
250 return { QRhiTexture::ASTC_4x4,
true };
252 case QInternalGLTextureFormat::RGBA_ASTC_5x4:
253 return { QRhiTexture::ASTC_5x4,
false };
254 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_5x4:
255 return { QRhiTexture::ASTC_5x4,
true };
257 case QInternalGLTextureFormat::RGBA_ASTC_5x5:
258 return { QRhiTexture::ASTC_5x5,
false };
259 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_5x5:
260 return { QRhiTexture::ASTC_5x5,
true };
262 case QInternalGLTextureFormat::RGBA_ASTC_6x5:
263 return { QRhiTexture::ASTC_6x5,
false };
264 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_6x5:
265 return { QRhiTexture::ASTC_6x5,
true };
267 case QInternalGLTextureFormat::RGBA_ASTC_6x6:
268 return { QRhiTexture::ASTC_6x6,
false };
269 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_6x6:
270 return { QRhiTexture::ASTC_6x6,
true };
272 case QInternalGLTextureFormat::RGBA_ASTC_8x5:
273 return { QRhiTexture::ASTC_8x5,
false };
274 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_8x5:
275 return { QRhiTexture::ASTC_8x5,
true };
277 case QInternalGLTextureFormat::RGBA_ASTC_8x6:
278 return { QRhiTexture::ASTC_8x6,
false };
279 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_8x6:
280 return { QRhiTexture::ASTC_8x6,
true };
282 case QInternalGLTextureFormat::RGBA_ASTC_8x8:
283 return { QRhiTexture::ASTC_8x8,
false };
284 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_8x8:
285 return { QRhiTexture::ASTC_8x8,
true };
287 case QInternalGLTextureFormat::RGBA_ASTC_10x5:
288 return { QRhiTexture::ASTC_10x5,
false };
289 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_10x5:
290 return { QRhiTexture::ASTC_10x5,
true };
292 case QInternalGLTextureFormat::RGBA_ASTC_10x6:
293 return { QRhiTexture::ASTC_10x6,
false };
294 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_10x6:
295 return { QRhiTexture::ASTC_10x6,
true };
297 case QInternalGLTextureFormat::RGBA_ASTC_10x8:
298 return { QRhiTexture::ASTC_10x8,
false };
299 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_10x8:
300 return { QRhiTexture::ASTC_10x8,
true };
302 case QInternalGLTextureFormat::RGBA_ASTC_10x10:
303 return { QRhiTexture::ASTC_10x10,
false };
304 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_10x10:
305 return { QRhiTexture::ASTC_10x10,
true };
307 case QInternalGLTextureFormat::RGBA_ASTC_12x10:
308 return { QRhiTexture::ASTC_12x10,
false };
309 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_12x10:
310 return { QRhiTexture::ASTC_12x10,
true };
312 case QInternalGLTextureFormat::RGBA_ASTC_12x12:
313 return { QRhiTexture::ASTC_12x12,
false };
314 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_12x12:
315 return { QRhiTexture::ASTC_12x12,
true };
318 return { QRhiTexture::UnknownFormat,
false };
327void QSGCompressedTexture::commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
334 if (!m_textureData.isValid()) {
335 qCDebug(QSG_LOG_TEXTUREIO,
"Invalid texture data for %s", m_textureData.logName().constData());
339 FormatInfo fmt = formatInfo(m_textureData.glInternalFormat());
340 if (fmt.rhiFormat == QRhiTexture::UnknownFormat) {
341 qWarning(
"Unknown compressed format 0x%x", m_textureData.glInternalFormat());
346 QRhiTexture::Flags texFlags;
348 texFlags |= QRhiTexture::sRGB;
350 if (!rhi->isTextureFormatSupported(fmt.rhiFormat, texFlags)) {
351 qCDebug(QSG_LOG_TEXTUREIO,
"Compressed texture format possibly unsupported: 0x%x",
352 m_textureData.glInternalFormat());
355 if (rhi->backend() == QRhi::Metal) {
356 qWarning(
"Unsupported compressed texture format 0x%x", m_textureData.glInternalFormat());
361 m_texture = rhi->newTexture(fmt.rhiFormat, m_size, 1, texFlags);
362 if (!m_texture->create()) {
363 qWarning(
"Failed to create QRhiTexture for compressed data with format 0x%x",
364 m_textureData.glInternalFormat());
372 resourceUpdates->uploadTexture(
374 QRhiTextureUploadEntry(0, 0,
375 QRhiTextureSubresourceUploadDescription(
376 m_textureData.getDataView().toByteArray())));
378 m_textureData = QTextureFileData();
386bool QSGCompressedTexture::formatIsOpaque(quint32 glTextureFormat)
388 switch (glTextureFormat) {
389 case QInternalGLTextureFormat::RGB_DXT1:
390 case QInternalGLTextureFormat::R_ATI1N_UNorm:
391 case QInternalGLTextureFormat::R_ATI1N_SNorm:
392 case QInternalGLTextureFormat::RG_ATI2N_UNorm:
393 case QInternalGLTextureFormat::RG_ATI2N_SNorm:
394 case QInternalGLTextureFormat::RGB_BP_UNSIGNED_FLOAT:
395 case QInternalGLTextureFormat::RGB_BP_SIGNED_FLOAT:
396 case QInternalGLTextureFormat::R11_EAC_UNorm:
397 case QInternalGLTextureFormat::R11_EAC_SNorm:
398 case QInternalGLTextureFormat::RG11_EAC_UNorm:
399 case QInternalGLTextureFormat::RG11_EAC_SNorm:
400 case QInternalGLTextureFormat::RGB8_ETC2:
401 case QInternalGLTextureFormat::SRGB8_ETC2:
402 case QInternalGLTextureFormat::RGB8_ETC1:
403 case QInternalGLTextureFormat::SRGB_DXT1: