From 0ffef9cb8da7682b42f595c683d7ef9cb22dabd7 Mon Sep 17 00:00:00 2001 From: VaL Doroshchuk Date: Mon, 25 May 2020 11:57:57 +0200 Subject: RHI: Introduce QRhiTexture::RG8 Change-Id: I58f35b2629bd6464f08cba66e852215472fcbe2a Fixes: QTBUG-84384 Reviewed-by: Laszlo Agocs --- src/gui/rhi/qrhi.cpp | 5 +++++ src/gui/rhi/qrhi_p.h | 1 + src/gui/rhi/qrhid3d11.cpp | 4 ++++ src/gui/rhi/qrhigles2.cpp | 17 +++++++++++++++++ src/gui/rhi/qrhimetal.mm | 6 ++++++ src/gui/rhi/qrhivulkan.cpp | 8 ++++++++ 6 files changed, 41 insertions(+) (limited to 'src') diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 64d1d5a017..798c5e1a8a 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -2213,6 +2213,8 @@ QRhiResource::Type QRhiRenderBuffer::resourceType() const \value R8 One component, unsigned normalized 8 bit. + \value RG8 Two components, unsigned normalized 8 bit. + \value R16 One component, unsigned normalized 16 bit. \value RED_OR_ALPHA8 Either same as R8, or is a similar format with the component swizzled to alpha, @@ -4089,6 +4091,9 @@ void QRhiImplementation::textureFormatInfo(QRhiTexture::Format format, const QSi case QRhiTexture::R8: bpc = 1; break; + case QRhiTexture::RG8: + bpc = 2; + break; case QRhiTexture::R16: bpc = 2; break; diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h index 12a294e8c2..928d708624 100644 --- a/src/gui/rhi/qrhi_p.h +++ b/src/gui/rhi/qrhi_p.h @@ -738,6 +738,7 @@ public: RGBA8, BGRA8, R8, + RG8, R16, RED_OR_ALPHA8, diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index 97294669f7..d1d4745bc8 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -1138,6 +1138,8 @@ static inline DXGI_FORMAT toD3DTextureFormat(QRhiTexture::Format format, QRhiTex return srgb ? DXGI_FORMAT_B8G8R8A8_UNORM_SRGB : DXGI_FORMAT_B8G8R8A8_UNORM; case QRhiTexture::R8: return DXGI_FORMAT_R8_UNORM; + case QRhiTexture::RG8: + return DXGI_FORMAT_R8G8_UNORM; case QRhiTexture::R16: return DXGI_FORMAT_R16_UNORM; case QRhiTexture::RED_OR_ALPHA8: @@ -1218,6 +1220,8 @@ static inline QRhiTexture::Format colorTextureFormatFromDxgiFormat(DXGI_FORMAT f return QRhiTexture::BGRA8; case DXGI_FORMAT_R8_UNORM: return QRhiTexture::R8; + case DXGI_FORMAT_R8G8_UNORM: + return QRhiTexture::RG8; case DXGI_FORMAT_R16_UNORM: return QRhiTexture::R16; default: // this cannot assert, must warn and return unknown diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 2e57ed1b80..25931bfb80 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -145,6 +145,14 @@ QT_BEGIN_NAMESPACE #define GL_R8 0x8229 #endif +#ifndef GL_RG8 +#define GL_RG8 0x822B +#endif + +#ifndef GL_RG +#define GL_RG 0x8227 +#endif + #ifndef GL_R16 #define GL_R16 0x822A #endif @@ -719,6 +727,12 @@ static inline void toGlTextureFormat(QRhiTexture::Format format, const QRhiGles2 *glformat = GL_RED; *gltype = GL_UNSIGNED_BYTE; break; + case QRhiTexture::RG8: + *glintformat = GL_RG8; + *glsizedintformat = *glintformat; + *glformat = GL_RG; + *gltype = GL_UNSIGNED_BYTE; + break; case QRhiTexture::RED_OR_ALPHA8: *glintformat = caps.coreProfile ? GL_R8 : GL_ALPHA; *glsizedintformat = *glintformat; @@ -787,6 +801,9 @@ bool QRhiGles2::isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture case QRhiTexture::R8: return caps.r8Format; + case QRhiTexture::RG8: + return caps.r8Format; + case QRhiTexture::R16: return caps.r16Format; diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index 5d94b481a6..33fe389892 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -2246,6 +2246,12 @@ static inline MTLPixelFormat toMetalTextureFormat(QRhiTexture::Format format, QR return MTLPixelFormatR8Unorm; #else return srgb ? MTLPixelFormatR8Unorm_sRGB : MTLPixelFormatR8Unorm; +#endif + case QRhiTexture::RG8: +#ifdef Q_OS_MACOS + return MTLPixelFormatRG8Unorm; +#else + return srgb ? MTLPixelFormatRG8Unorm_sRGB : MTLPixelFormatRG8Unorm; #endif case QRhiTexture::R16: return MTLPixelFormatR16Unorm; diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 1591829cac..164d596d74 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -791,6 +791,8 @@ static inline VkFormat toVkTextureFormat(QRhiTexture::Format format, QRhiTexture return srgb ? VK_FORMAT_B8G8R8A8_SRGB : VK_FORMAT_B8G8R8A8_UNORM; case QRhiTexture::R8: return srgb ? VK_FORMAT_R8_SRGB : VK_FORMAT_R8_UNORM; + case QRhiTexture::RG8: + return srgb ? VK_FORMAT_R8G8_SRGB : VK_FORMAT_R8G8_UNORM; case QRhiTexture::R16: return VK_FORMAT_R16_UNORM; case QRhiTexture::RED_OR_ALPHA8: @@ -884,10 +886,16 @@ static inline QRhiTexture::Format colorTextureFormatFromVkFormat(VkFormat format return QRhiTexture::BGRA8; case VK_FORMAT_R8_UNORM: return QRhiTexture::R8; + case VK_FORMAT_R8G8_UNORM: + return QRhiTexture::RG8; case VK_FORMAT_R8_SRGB: if (flags) (*flags) |= QRhiTexture::sRGB; return QRhiTexture::R8; + case VK_FORMAT_R8G8_SRGB: + if (flags) + (*flags) |= QRhiTexture::sRGB; + return QRhiTexture::RG8; case VK_FORMAT_R16_UNORM: return QRhiTexture::R16; default: // this cannot assert, must warn and return unknown -- cgit v1.2.3