From 054a9ecd8370f4e92ea381c748ecb58284e9b845 Mon Sep 17 00:00:00 2001 From: Sandy Date: Mon, 22 Aug 2022 22:03:22 -0400 Subject: [PATCH] Texture format info: Invert R and B in RGBA4 (#2878) * texture format info: Invert R and B in RGBA4 d3d9: Revert 06c08adc9ea586b5e1b51fd98fe403dacfef83cd to force software conversion because the format doesn't exist d3d11: Force software conversion because the format doesn't exist gl: Revert 3e3e655262c3ed39ae0115fa5509c7785c4c67eb to swizzle R and B mtl: Swizzle channels * metal: Remove explicit conversion of RGBA4 and RGB5A1 in osx * metal: Set alpha bit to correct end of short --- src/renderer_d3d11.cpp | 10 ++++++++++ src/renderer_gl.cpp | 2 +- src/renderer_mtl.mm | 8 +++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 7a5fd0e27..055a38b61 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -4504,6 +4504,11 @@ namespace bgfx { namespace d3d11 bimg::imageConvert(temp, 16, bx::packBgr5a1, mip.m_data, bx::unpackRgb5a1, srd[kk].SysMemPitch*mip.m_height); srd[kk].pSysMem = temp; break; + case TextureFormat::RGBA4: + temp = (uint8_t*)BX_ALLOC(g_allocator, srd[kk].SysMemPitch*mip.m_height); + bimg::imageConvert(temp, 16, bx::packBgra4, mip.m_data, bx::unpackRgba4, srd[kk].SysMemPitch*mip.m_height); + srd[kk].pSysMem = temp; + break; } } @@ -4845,6 +4850,11 @@ namespace bgfx { namespace d3d11 bimg::imageConvert(temp, 16, bx::packBgr5a1, src, bx::unpackRgb5a1, rectpitch); data = temp; break; + case TextureFormat::RGBA4: + temp = (uint8_t*)BX_ALLOC(g_allocator, rectpitch); + bimg::imageConvert(temp, 16, bx::packBgra4, src, bx::unpackRgba4, rectpitch); + data = temp; + break; } src += srcpitch; } diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 15b91d00b..b999ef0e4 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -288,7 +288,7 @@ namespace bgfx { namespace gl { GL_RGBA32UI, GL_ZERO, RGBA_INTEGER, GL_RGBA_INTEGER, GL_UNSIGNED_INT, false, { $_, $_, $_, $_ } }, // RGBA32U { GL_RGBA32F, GL_ZERO, GL_RGBA, GL_RGBA, GL_FLOAT, false, { $_, $_, $_, $_ } }, // RGBA32F { GL_RGB565, GL_ZERO, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, false, { $_, $_, $_, $_ } }, // R5G6B5 - { GL_RGBA4, GL_ZERO, GL_BGRA, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV, false, { $_, $_, $_, $_ } }, // RGBA4 + { GL_RGBA4, GL_ZERO, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4_REV, false, { $_, $_, $_, $_ } }, // RGBA4 { GL_RGB5_A1, GL_ZERO, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, false, { $_, $_, $_, $_ } }, // RGB5A1 { GL_RGB10_A2, GL_ZERO, GL_RGBA, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, false, { $_, $_, $_, $_ } }, // RGB10A2 { GL_R11F_G11F_B10F, GL_ZERO, GL_RGB, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, false, { $_, $_, $_, $_ } }, // RG11B10F diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index cb402b517..8d4b71b6f 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -305,8 +305,8 @@ namespace bgfx { namespace mtl { MTLPixelFormatRGBA32Uint, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, true }, // RGBA32U { MTLPixelFormatRGBA32Float, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, true }, // RGBA32F { MTLPixelFormat(40/*B5G6R5Unorm*/), MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // R5G6B5 - { MTLPixelFormat(42/*ABGR4Unorm*/), MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // RGBA4 - { MTLPixelFormatA1BGR5Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $B, $G, $R, $A }, true }, // RGB5A1 + { MTLPixelFormatABGR4Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $A, $B, $G, $R }, true }, // RGBA4 + { MTLPixelFormatBGR5A1Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $A, $R, $G, $B }, true }, // RGB5A1 { MTLPixelFormatRGB10A2Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // RGB10A2 { MTLPixelFormatRG11B10Float, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // RG11B10F { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // UnknownDepth @@ -764,9 +764,7 @@ BX_STATIC_ASSERT(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNa g_caps.formats[TextureFormat::PTC14 ] = g_caps.formats[TextureFormat::PTC12A] = g_caps.formats[TextureFormat::PTC14A] = - g_caps.formats[TextureFormat::R5G6B5] = - g_caps.formats[TextureFormat::RGBA4 ] = - g_caps.formats[TextureFormat::RGB5A1] = BGFX_CAPS_FORMAT_TEXTURE_NONE; + g_caps.formats[TextureFormat::R5G6B5] = BGFX_CAPS_FORMAT_TEXTURE_NONE; g_caps.formats[TextureFormat::RGB9E5F] &= ~(BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA); }