213QSGCompressedTexture::FormatInfo QSGCompressedTexture::formatInfo(quint32 glTextureFormat)
215 switch (glTextureFormat) {
216 case QInternalGLTextureFormat::RGB_DXT1:
217 return { QRhiTexture::BC1,
false };
218 case QInternalGLTextureFormat::SRGB_DXT1:
219 return { QRhiTexture::BC1,
true };
221 case QInternalGLTextureFormat::RGBA_DXT3:
222 return { QRhiTexture::BC2,
false };
223 case QInternalGLTextureFormat::SRGB_Alpha_DXT3:
224 return { QRhiTexture::BC2,
true };
226 case QInternalGLTextureFormat::RGBA_DXT5:
227 return { QRhiTexture::BC3,
false };
228 case QInternalGLTextureFormat::SRGB_Alpha_DXT5:
229 return { QRhiTexture::BC3,
true };
231 case QInternalGLTextureFormat::RGB8_ETC2:
232 return { QRhiTexture::ETC2_RGB8,
false };
233 case QInternalGLTextureFormat::SRGB8_ETC2:
234 return { QRhiTexture::ETC2_RGB8,
true };
236 case QInternalGLTextureFormat::RGB8_PunchThrough_Alpha1_ETC2:
237 return { QRhiTexture::ETC2_RGB8A1,
false };
238 case QInternalGLTextureFormat::SRGB8_PunchThrough_Alpha1_ETC2:
239 return { QRhiTexture::ETC2_RGB8A1,
true };
241 case QInternalGLTextureFormat::RGBA8_ETC2_EAC:
242 return { QRhiTexture::ETC2_RGBA8,
false };
243 case QInternalGLTextureFormat::SRGB8_Alpha8_ETC2_EAC:
244 return { QRhiTexture::ETC2_RGBA8,
true };
246 case QInternalGLTextureFormat::RGBA_ASTC_4x4:
247 return { QRhiTexture::ASTC_4x4,
false };
248 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_4x4:
249 return { QRhiTexture::ASTC_4x4,
true };
251 case QInternalGLTextureFormat::RGBA_ASTC_5x4:
252 return { QRhiTexture::ASTC_5x4,
false };
253 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_5x4:
254 return { QRhiTexture::ASTC_5x4,
true };
256 case QInternalGLTextureFormat::RGBA_ASTC_5x5:
257 return { QRhiTexture::ASTC_5x5,
false };
258 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_5x5:
259 return { QRhiTexture::ASTC_5x5,
true };
261 case QInternalGLTextureFormat::RGBA_ASTC_6x5:
262 return { QRhiTexture::ASTC_6x5,
false };
263 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_6x5:
264 return { QRhiTexture::ASTC_6x5,
true };
266 case QInternalGLTextureFormat::RGBA_ASTC_6x6:
267 return { QRhiTexture::ASTC_6x6,
false };
268 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_6x6:
269 return { QRhiTexture::ASTC_6x6,
true };
271 case QInternalGLTextureFormat::RGBA_ASTC_8x5:
272 return { QRhiTexture::ASTC_8x5,
false };
273 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_8x5:
274 return { QRhiTexture::ASTC_8x5,
true };
276 case QInternalGLTextureFormat::RGBA_ASTC_8x6:
277 return { QRhiTexture::ASTC_8x6,
false };
278 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_8x6:
279 return { QRhiTexture::ASTC_8x6,
true };
281 case QInternalGLTextureFormat::RGBA_ASTC_8x8:
282 return { QRhiTexture::ASTC_8x8,
false };
283 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_8x8:
284 return { QRhiTexture::ASTC_8x8,
true };
286 case QInternalGLTextureFormat::RGBA_ASTC_10x5:
287 return { QRhiTexture::ASTC_10x5,
false };
288 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_10x5:
289 return { QRhiTexture::ASTC_10x5,
true };
291 case QInternalGLTextureFormat::RGBA_ASTC_10x6:
292 return { QRhiTexture::ASTC_10x6,
false };
293 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_10x6:
294 return { QRhiTexture::ASTC_10x6,
true };
296 case QInternalGLTextureFormat::RGBA_ASTC_10x8:
297 return { QRhiTexture::ASTC_10x8,
false };
298 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_10x8:
299 return { QRhiTexture::ASTC_10x8,
true };
301 case QInternalGLTextureFormat::RGBA_ASTC_10x10:
302 return { QRhiTexture::ASTC_10x10,
false };
303 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_10x10:
304 return { QRhiTexture::ASTC_10x10,
true };
306 case QInternalGLTextureFormat::RGBA_ASTC_12x10:
307 return { QRhiTexture::ASTC_12x10,
false };
308 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_12x10:
309 return { QRhiTexture::ASTC_12x10,
true };
311 case QInternalGLTextureFormat::RGBA_ASTC_12x12:
312 return { QRhiTexture::ASTC_12x12,
false };
313 case QInternalGLTextureFormat::SRGB8_Alpha8_ASTC_12x12:
314 return { QRhiTexture::ASTC_12x12,
true };
317 return { QRhiTexture::UnknownFormat,
false };
326void QSGCompressedTexture::commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
333 if (!m_textureData.isValid()) {
334 qCDebug(QSG_LOG_TEXTUREIO,
"Invalid texture data for %s", m_textureData.logName().constData());
338 FormatInfo fmt = formatInfo(m_textureData.glInternalFormat());
339 if (fmt.rhiFormat == QRhiTexture::UnknownFormat) {
340 qWarning(
"Unknown compressed format 0x%x", m_textureData.glInternalFormat());
345 QRhiTexture::Flags texFlags;
347 texFlags |= QRhiTexture::sRGB;
349 if (!rhi->isTextureFormatSupported(fmt.rhiFormat, texFlags)) {
350 qCDebug(QSG_LOG_TEXTUREIO,
"Compressed texture format possibly unsupported: 0x%x",
351 m_textureData.glInternalFormat());
354 if (rhi->backend() == QRhi::Metal) {
355 qWarning(
"Unsupported compressed texture format 0x%x", m_textureData.glInternalFormat());
360 m_texture = rhi->newTexture(fmt.rhiFormat, m_size, 1, texFlags);
361 if (!m_texture->create()) {
362 qWarning(
"Failed to create QRhiTexture for compressed data with format 0x%x",
363 m_textureData.glInternalFormat());
371 resourceUpdates->uploadTexture(
373 QRhiTextureUploadEntry(0, 0,
374 QRhiTextureSubresourceUploadDescription(
375 m_textureData.getDataView().toByteArray())));
377 m_textureData = QTextureFileData();
385bool QSGCompressedTexture::formatIsOpaque(quint32 glTextureFormat)
387 switch (glTextureFormat) {
388 case QInternalGLTextureFormat::RGB_DXT1:
389 case QInternalGLTextureFormat::R_ATI1N_UNorm:
390 case QInternalGLTextureFormat::R_ATI1N_SNorm:
391 case QInternalGLTextureFormat::RG_ATI2N_UNorm:
392 case QInternalGLTextureFormat::RG_ATI2N_SNorm:
393 case QInternalGLTextureFormat::RGB_BP_UNSIGNED_FLOAT:
394 case QInternalGLTextureFormat::RGB_BP_SIGNED_FLOAT:
395 case QInternalGLTextureFormat::R11_EAC_UNorm:
396 case QInternalGLTextureFormat::R11_EAC_SNorm:
397 case QInternalGLTextureFormat::RG11_EAC_UNorm:
398 case QInternalGLTextureFormat::RG11_EAC_SNorm:
399 case QInternalGLTextureFormat::RGB8_ETC2:
400 case QInternalGLTextureFormat::SRGB8_ETC2:
401 case QInternalGLTextureFormat::RGB8_ETC1:
402 case QInternalGLTextureFormat::SRGB_DXT1: