mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-18 04:53:06 +01:00
texture format info: Invert R and B in RGB5A1 (#2876)
d3d9: Revert76db2ed38dto force software conversion and use the format that does exist d3d11: Force software conversion because the format doesn't exist gl: Revertb36aa71403to swizzle R and B mtl: Swizzle R and B
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#if BGFX_CONFIG_RENDERER_DIRECT3D11
|
||||
# include "renderer_d3d11.h"
|
||||
# include <bx/pixelformat.h>
|
||||
|
||||
namespace bgfx { namespace d3d11
|
||||
{
|
||||
@@ -4468,6 +4469,7 @@ namespace bgfx { namespace d3d11
|
||||
, swizzle ? " (swizzle BGRA8 -> RGBA8)" : ""
|
||||
);
|
||||
|
||||
uint8_t* temp = NULL;
|
||||
for (uint16_t side = 0; side < numSides; ++side)
|
||||
{
|
||||
for (uint8_t lod = 0, num = ti.numMips; lod < num; ++lod)
|
||||
@@ -4480,7 +4482,7 @@ namespace bgfx { namespace d3d11
|
||||
if (convert)
|
||||
{
|
||||
uint32_t srcpitch = mip.m_width*bpp/8;
|
||||
uint8_t* temp = (uint8_t*)BX_ALLOC(g_allocator, srcpitch*mip.m_height);
|
||||
temp = (uint8_t*)BX_ALLOC(g_allocator, srcpitch*mip.m_height);
|
||||
bimg::imageDecodeToBgra8(g_allocator, temp, mip.m_data, mip.m_width, mip.m_height, srcpitch, mip.m_format);
|
||||
|
||||
srd[kk].pSysMem = temp;
|
||||
@@ -4494,6 +4496,15 @@ namespace bgfx { namespace d3d11
|
||||
else
|
||||
{
|
||||
srd[kk].SysMemPitch = mip.m_width*mip.m_bpp/8;
|
||||
|
||||
switch (m_textureFormat)
|
||||
{
|
||||
case TextureFormat::RGB5A1:
|
||||
temp = (uint8_t*)BX_ALLOC(g_allocator, srd[kk].SysMemPitch*mip.m_height);
|
||||
bimg::imageConvert(temp, 16, bx::packBgr5a1, mip.m_data, bx::unpackRgb5a1, srd[kk].SysMemPitch*mip.m_height);
|
||||
srd[kk].pSysMem = temp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
srd[kk].SysMemSlicePitch = mip.m_height*srd[kk].SysMemPitch;
|
||||
@@ -4718,8 +4729,7 @@ namespace bgfx { namespace d3d11
|
||||
DX_CHECK(s_renderD3D11->m_device->CreateUnorderedAccessView(m_ptr, NULL, &m_uav) );
|
||||
}
|
||||
|
||||
if (convert
|
||||
&& 0 != kk)
|
||||
if (temp != NULL)
|
||||
{
|
||||
kk = 0;
|
||||
for (uint16_t side = 0; side < numSides; ++side)
|
||||
@@ -4794,9 +4804,11 @@ namespace bgfx { namespace d3d11
|
||||
box.back = 1;
|
||||
}
|
||||
|
||||
const bimg::ImageBlockInfo & blockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(m_textureFormat) );
|
||||
const uint16_t blockHeight = blockInfo.blockHeight;
|
||||
const uint16_t bpp = blockInfo.bitsPerPixel;
|
||||
const uint32_t subres = _mip + ( (layer + _side) * m_numMips);
|
||||
const bool depth = bimg::isDepth(bimg::TextureFormat::Enum(m_textureFormat) );
|
||||
const uint32_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_textureFormat) );
|
||||
uint32_t rectpitch = _rect.m_width*bpp/8;
|
||||
if (bimg::isCompressed(bimg::TextureFormat::Enum(m_textureFormat)))
|
||||
{
|
||||
@@ -4822,6 +4834,22 @@ namespace bgfx { namespace d3d11
|
||||
box.bottom = bx::max(1u, m_height >> _mip);
|
||||
}
|
||||
|
||||
{
|
||||
uint8_t* src = data;
|
||||
for (uint32_t yy = 0, height = _rect.m_height; yy < height; yy += blockHeight)
|
||||
{
|
||||
switch (m_textureFormat)
|
||||
{
|
||||
case TextureFormat::RGB5A1:
|
||||
temp = (uint8_t*)BX_ALLOC(g_allocator, rectpitch);
|
||||
bimg::imageConvert(temp, 16, bx::packBgr5a1, src, bx::unpackRgb5a1, rectpitch);
|
||||
data = temp;
|
||||
break;
|
||||
}
|
||||
src += srcpitch;
|
||||
}
|
||||
}
|
||||
|
||||
deviceCtx->UpdateSubresource(
|
||||
m_ptr
|
||||
, subres
|
||||
|
||||
@@ -3037,6 +3037,10 @@ namespace bgfx { namespace d3d9
|
||||
uint32_t size = useMipSize ? mip.m_size : mipSize;
|
||||
switch (m_textureFormat)
|
||||
{
|
||||
case TextureFormat::RGB5A1:
|
||||
bimg::imageConvert(bits, 16, bx::packBgr5a1, mip.m_data, bx::unpackRgb5a1, size);
|
||||
break;
|
||||
|
||||
case TextureFormat::RGBA4:
|
||||
bimg::imageConvert(bits, 16, bx::packBgra4, mip.m_data, bx::unpackRgba4, size);
|
||||
break;
|
||||
@@ -3098,6 +3102,10 @@ namespace bgfx { namespace d3d9
|
||||
{
|
||||
switch (m_textureFormat)
|
||||
{
|
||||
case TextureFormat::RGB5A1:
|
||||
bimg::imageConvert(dst, 16, bx::packBgr5a1, src, bx::unpackRgb5a1, rectpitch);
|
||||
break;
|
||||
|
||||
case TextureFormat::RGBA4:
|
||||
bimg::imageConvert(dst, 16, bx::packBgra4, src, bx::unpackRgba4, rectpitch);
|
||||
break;
|
||||
|
||||
@@ -289,7 +289,7 @@ namespace bgfx { namespace gl
|
||||
{ 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_RGB5_A1, GL_ZERO, GL_BGRA, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, false, { $_, $_, $_, $_ } }, // RGB5A1
|
||||
{ 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
|
||||
{ GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false, { $_, $_, $_, $_ } }, // UnknownDepth
|
||||
|
||||
@@ -306,7 +306,7 @@ namespace bgfx { namespace mtl
|
||||
{ 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
|
||||
{ MTLPixelFormat(41/*A1BGR5Unorm*/), MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // RGB5A1
|
||||
{ MTLPixelFormatA1BGR5Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $B, $G, $R, $A }, 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
|
||||
|
||||
Reference in New Issue
Block a user