Add QRhiTexture::RG16 format

Those are needed to handle 16bit YUV formats in Qt Multimedia.

Change-Id: I39c67bf4fcf558487b7819ea38e578f99c12a3ed
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
Lars Knoll 2021-04-04 15:59:54 +02:00
parent 0baa26638d
commit df54a5d087
6 changed files with 29 additions and 0 deletions

View File

@ -2378,6 +2378,8 @@ QRhiResource::Type QRhiRenderBuffer::resourceType() const
\value R16 One component, unsigned normalized 16 bit.
\value RG16 Two component, unsigned normalized 16 bit.
\value RED_OR_ALPHA8 Either same as R8, or is a similar format with the component swizzled to alpha,
depending on \l{QRhi::RedOrAlpha8IsRed}{RedOrAlpha8IsRed}.
@ -4533,6 +4535,9 @@ void QRhiImplementation::textureFormatInfo(QRhiTexture::Format format, const QSi
case QRhiTexture::R16:
bpc = 2;
break;
case QRhiTexture::RG16:
bpc = 4;
break;
case QRhiTexture::RED_OR_ALPHA8:
bpc = 1;
break;

View File

@ -765,6 +765,7 @@ public:
R8,
RG8,
R16,
RG16,
RED_OR_ALPHA8,
RGBA16F,

View File

@ -1214,6 +1214,8 @@ static inline DXGI_FORMAT toD3DTextureFormat(QRhiTexture::Format format, QRhiTex
return DXGI_FORMAT_R8G8_UNORM;
case QRhiTexture::R16:
return DXGI_FORMAT_R16_UNORM;
case QRhiTexture::RG16:
return DXGI_FORMAT_R16G16_UNORM;
case QRhiTexture::RED_OR_ALPHA8:
return DXGI_FORMAT_R8_UNORM;
@ -1300,6 +1302,8 @@ static inline QRhiTexture::Format colorTextureFormatFromDxgiFormat(DXGI_FORMAT f
return QRhiTexture::RG8;
case DXGI_FORMAT_R16_UNORM:
return QRhiTexture::R16;
case DXGI_FORMAT_R16G16_UNORM:
return QRhiTexture::RG16;
default: // this cannot assert, must warn and return unknown
qWarning("DXGI_FORMAT %d is not a recognized uncompressed color format", format);
break;

View File

@ -160,6 +160,10 @@ QT_BEGIN_NAMESPACE
#define GL_R16 0x822A
#endif
#ifndef GL_RG16
#define GL_RG16 0x822C
#endif
#ifndef GL_RED
#define GL_RED 0x1903
#endif
@ -822,6 +826,12 @@ static inline void toGlTextureFormat(QRhiTexture::Format format, const QRhiGles2
*glformat = GL_RED;
*gltype = GL_UNSIGNED_SHORT;
break;
case QRhiTexture::RG16:
*glintformat = GL_RG16;
*glsizedintformat = *glintformat;
*glformat = GL_RG;
*gltype = GL_UNSIGNED_SHORT;
break;
case QRhiTexture::R8:
*glintformat = GL_R8;
*glsizedintformat = *glintformat;
@ -926,6 +936,9 @@ bool QRhiGles2::isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture
case QRhiTexture::R16:
return caps.r16Format;
case QRhiTexture::RG16:
return caps.r16Format;
case QRhiTexture::RGBA16F:
case QRhiTexture::RGBA32F:
return caps.floatFormats;

View File

@ -2348,6 +2348,8 @@ static inline MTLPixelFormat toMetalTextureFormat(QRhiTexture::Format format, QR
#endif
case QRhiTexture::R16:
return MTLPixelFormatR16Unorm;
case QRhiTexture::RG16:
return MTLPixelFormatRG16Unorm;
case QRhiTexture::RED_OR_ALPHA8:
return MTLPixelFormatR8Unorm;

View File

@ -886,6 +886,8 @@ static inline VkFormat toVkTextureFormat(QRhiTexture::Format format, QRhiTexture
return srgb ? VK_FORMAT_R8G8_SRGB : VK_FORMAT_R8G8_UNORM;
case QRhiTexture::R16:
return VK_FORMAT_R16_UNORM;
case QRhiTexture::RG16:
return VK_FORMAT_R16G16_UNORM;
case QRhiTexture::RED_OR_ALPHA8:
return VK_FORMAT_R8_UNORM;
@ -993,6 +995,8 @@ static inline QRhiTexture::Format colorTextureFormatFromVkFormat(VkFormat format
return QRhiTexture::RG8;
case VK_FORMAT_R16_UNORM:
return QRhiTexture::R16;
case VK_FORMAT_R16G16_UNORM:
return QRhiTexture::RG16;
default: // this cannot assert, must warn and return unknown
qWarning("VkFormat %d is not a recognized uncompressed color format", format);
break;