From 8942628ec126e7c01a07e2c1d40c15ec3d401733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 2 Feb 2015 20:30:57 -0800 Subject: [PATCH] Fixed texture size calculation. --- src/bgfx.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/bgfx.cpp b/src/bgfx.cpp index ccc6a86b..2d41903c 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -2311,22 +2311,24 @@ again: void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format) { - _width = bx::uint32_max(1, _width); - _height = bx::uint32_max(1, _height); - _depth = bx::uint32_max(1, _depth); + const ImageBlockInfo& blockInfo = getBlockInfo(_format); + const uint8_t bpp = blockInfo.bitsPerPixel; + const uint32_t blockWidth = blockInfo.blockWidth; + const uint32_t blockHeight = blockInfo.blockHeight; + const uint32_t minBlockX = blockInfo.minBlockX; + const uint32_t minBlockY = blockInfo.minBlockY; + _numMips = bx::uint32_max(1, _numMips); - uint32_t width = _width; - uint32_t height = _height; - uint32_t depth = _depth; - - uint32_t bpp = getBitsPerPixel(_format); + uint32_t width = bx::uint32_max(1, _width); + uint32_t height = bx::uint32_max(1, _height); + uint32_t depth = bx::uint32_max(1, _depth); uint32_t size = 0; for (uint32_t lod = 0; lod < _numMips; ++lod) { - width = bx::uint32_max(1, width); - height = bx::uint32_max(1, height); + 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); size += width*height*depth*bpp/8;