From c2e100d65d156cabfcae5af686f503412eec7760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sun, 1 Feb 2015 21:38:47 -0800 Subject: [PATCH] Added minimum number of blocks for PTC textures. Issue #250. --- src/image.cpp | 102 +++++++++++++++++++++++++------------------------- src/image.h | 2 + 2 files changed, 54 insertions(+), 50 deletions(-) diff --git a/src/image.cpp b/src/image.cpp index eea632fe..85e599bf 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -12,54 +12,54 @@ namespace bgfx { static const ImageBlockInfo s_imageBlockInfo[] = { - { 4, 4, 4, 8 }, // BC1 - { 8, 4, 4, 16 }, // BC2 - { 8, 4, 4, 16 }, // BC3 - { 4, 4, 4, 8 }, // BC4 - { 8, 4, 4, 16 }, // BC5 - { 8, 4, 4, 16 }, // BC6H - { 8, 4, 4, 16 }, // BC7 - { 4, 4, 4, 8 }, // ETC1 - { 4, 4, 4, 8 }, // ETC2 - { 8, 4, 4, 16 }, // ETC2A - { 4, 4, 4, 8 }, // ETC2A1 - { 2, 8, 4, 8 }, // PTC12 - { 4, 4, 4, 8 }, // PTC14 - { 2, 8, 4, 8 }, // PTC12A - { 4, 4, 4, 8 }, // PTC14A - { 2, 8, 4, 8 }, // PTC22 - { 4, 4, 4, 8 }, // PTC24 - { 0, 0, 0, 0 }, // Unknown - { 1, 8, 1, 1 }, // R1 - { 8, 1, 1, 1 }, // R8 - { 16, 1, 1, 2 }, // R16 - { 16, 1, 1, 2 }, // R16F - { 32, 1, 1, 4 }, // R32 - { 32, 1, 1, 4 }, // R32F - { 16, 1, 1, 2 }, // RG8 - { 32, 1, 1, 4 }, // RG16 - { 32, 1, 1, 4 }, // RG16F - { 64, 1, 1, 8 }, // RG32 - { 64, 1, 1, 8 }, // RG32F - { 32, 1, 1, 4 }, // BGRA8 - { 64, 1, 1, 8 }, // RGBA16 - { 64, 1, 1, 8 }, // RGBA16F - { 128, 1, 1, 16 }, // RGBA32 - { 128, 1, 1, 16 }, // RGBA32F - { 16, 1, 1, 2 }, // R5G6B5 - { 16, 1, 1, 2 }, // RGBA4 - { 16, 1, 1, 2 }, // RGB5A1 - { 32, 1, 1, 4 }, // RGB10A2 - { 32, 1, 1, 4 }, // R11G11B10F - { 0, 0, 0, 0 }, // UnknownDepth - { 16, 1, 1, 2 }, // D16 - { 24, 1, 1, 3 }, // D24 - { 32, 1, 1, 4 }, // D24S8 - { 32, 1, 1, 4 }, // D32 - { 16, 1, 1, 2 }, // D16F - { 24, 1, 1, 3 }, // D24F - { 32, 1, 1, 4 }, // D32F - { 8, 1, 1, 1 }, // D0S8 + { 4, 4, 4, 8, 1, 1 }, // BC1 + { 8, 4, 4, 16, 1, 1 }, // BC2 + { 8, 4, 4, 16, 1, 1 }, // BC3 + { 4, 4, 4, 8, 1, 1 }, // BC4 + { 8, 4, 4, 16, 1, 1 }, // BC5 + { 8, 4, 4, 16, 1, 1 }, // BC6H + { 8, 4, 4, 16, 1, 1 }, // BC7 + { 4, 4, 4, 8, 1, 1 }, // ETC1 + { 4, 4, 4, 8, 1, 1 }, // ETC2 + { 8, 4, 4, 16, 1, 1 }, // ETC2A + { 4, 4, 4, 8, 1, 1 }, // ETC2A1 + { 2, 8, 4, 8, 2, 2 }, // PTC12 + { 4, 4, 4, 8, 2, 2 }, // PTC14 + { 2, 8, 4, 8, 2, 2 }, // PTC12A + { 4, 4, 4, 8, 2, 2 }, // PTC14A + { 2, 8, 4, 8, 2, 2 }, // PTC22 + { 4, 4, 4, 8, 2, 2 }, // PTC24 + { 0, 0, 0, 0, 1, 1 }, // Unknown + { 1, 8, 1, 1, 1, 1 }, // R1 + { 8, 1, 1, 1, 1, 1 }, // R8 + { 16, 1, 1, 2, 1, 1 }, // R16 + { 16, 1, 1, 2, 1, 1 }, // R16F + { 32, 1, 1, 4, 1, 1 }, // R32 + { 32, 1, 1, 4, 1, 1 }, // R32F + { 16, 1, 1, 2, 1, 1 }, // RG8 + { 32, 1, 1, 4, 1, 1 }, // RG16 + { 32, 1, 1, 4, 1, 1 }, // RG16F + { 64, 1, 1, 8, 1, 1 }, // RG32 + { 64, 1, 1, 8, 1, 1 }, // RG32F + { 32, 1, 1, 4, 1, 1 }, // BGRA8 + { 64, 1, 1, 8, 1, 1 }, // RGBA16 + { 64, 1, 1, 8, 1, 1 }, // RGBA16F + { 128, 1, 1, 16, 1, 1 }, // RGBA32 + { 128, 1, 1, 16, 1, 1 }, // RGBA32F + { 16, 1, 1, 2, 1, 1 }, // R5G6B5 + { 16, 1, 1, 2, 1, 1 }, // RGBA4 + { 16, 1, 1, 2, 1, 1 }, // RGB5A1 + { 32, 1, 1, 4, 1, 1 }, // RGB10A2 + { 32, 1, 1, 4, 1, 1 }, // R11G11B10F + { 0, 0, 0, 0, 1, 1 }, // UnknownDepth + { 16, 1, 1, 2, 1, 1 }, // D16 + { 24, 1, 1, 3, 1, 1 }, // D24 + { 32, 1, 1, 4, 1, 1 }, // D24S8 + { 32, 1, 1, 4, 1, 1 }, // D32 + { 16, 1, 1, 2, 1, 1 }, // D16F + { 24, 1, 1, 3, 1, 1 }, // D24F + { 32, 1, 1, 4, 1, 1 }, // D32F + { 8, 1, 1, 1, 1, 1 }, // D0S8 }; BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_imageBlockInfo) ); @@ -2103,6 +2103,8 @@ namespace bgfx const uint32_t blockSize = blockInfo.blockSize; const uint32_t blockWidth = blockInfo.blockWidth; const uint32_t blockHeight = blockInfo.blockHeight; + const uint32_t minBlockX = blockInfo.minBlockX; + const uint32_t minBlockY = blockInfo.minBlockY; if (UINT32_MAX == _imageContainer.m_offset) { @@ -2127,8 +2129,8 @@ namespace bgfx // skip imageSize in KTX format. offset += _imageContainer.m_ktx ? sizeof(uint32_t) : 0; - width = bx::uint32_max(blockWidth, ( (width +blockWidth -1)/blockWidth )*blockWidth); - height = bx::uint32_max(blockHeight, ( (height+blockHeight-1)/blockHeight)*blockHeight); + width = bx::uint32_max(blockWidth * minBlockX, ( (width + blockWidth - 1) / blockWidth )*blockWidth); + height = bx::uint32_max(blockHeight * minBlockY, ( (height + blockHeight - 1) / blockHeight)*blockHeight); depth = bx::uint32_max(1, depth); uint32_t size = width*height*depth*bpp/8; diff --git a/src/image.h b/src/image.h index 23fa05e2..3ddb1086 100644 --- a/src/image.h +++ b/src/image.h @@ -43,6 +43,8 @@ namespace bgfx uint8_t blockWidth; uint8_t blockHeight; uint8_t blockSize; + uint8_t minBlockX; + uint8_t minBlockY; }; ///