RHI: Introduce QRhiTexture::RG8

Change-Id: I58f35b2629bd6464f08cba66e852215472fcbe2a
Fixes: QTBUG-84384
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
VaL Doroshchuk 2020-05-25 11:57:57 +02:00
parent ecca816ea1
commit 0ffef9cb8d
6 changed files with 41 additions and 0 deletions

View File

@ -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;

View File

@ -738,6 +738,7 @@ public:
RGBA8,
BGRA8,
R8,
RG8,
R16,
RED_OR_ALPHA8,

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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