Explorar o código

Fixed .ktx parsing.

Branimir Karadžić %!s(int64=8) %!d(string=hai) anos
pai
achega
55d2962d4a
Modificáronse 2 ficheiros con 10 adicións e 7 borrados
  1. 9 6
      src/image.cpp
  2. 1 1
      tools/texturec/texturec.cpp

+ 9 - 6
src/image.cpp

@@ -3136,15 +3136,18 @@ namespace bimg
 
 			for (uint8_t lod = 0, num = _imageContainer.m_numMips; lod < num; ++lod)
 			{
-				uint32_t imageSize = bx::toHostEndian(*(const uint32_t*)&data[offset], _imageContainer.m_ktxLE) / _imageContainer.m_numLayers;
-				offset += sizeof(uint32_t);
-
 				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;
+				const uint32_t mipSize = width*height*depth*bpp/8;
+
+				const uint32_t size = mipSize*numSides;
+				uint32_t imageSize = bx::toHostEndian(*(const uint32_t*)&data[offset], _imageContainer.m_ktxLE);
 				BX_CHECK(size == imageSize, "KTX: Image size mismatch %d (expected %d).", size, imageSize);
+				BX_UNUSED(size, imageSize);
+
+				offset += sizeof(uint32_t);
 
 				for (uint16_t side = 0; side < numSides; ++side)
 				{
@@ -3154,7 +3157,7 @@ namespace bimg
 						_mip.m_width     = width;
 						_mip.m_height    = height;
 						_mip.m_blockSize = blockSize;
-						_mip.m_size      = size;
+						_mip.m_size      = mipSize;
 						_mip.m_data      = &data[offset];
 						_mip.m_bpp       = bpp;
 						_mip.m_format    = format;
@@ -3162,7 +3165,7 @@ namespace bimg
 						return true;
 					}
 
-					offset += imageSize;
+					offset += mipSize;
 
 					BX_CHECK(offset <= _size, "Reading past size of data buffer! (offset %d, size %d)", offset, _size);
 					BX_UNUSED(_size);

+ 1 - 1
tools/texturec/texturec.cpp

@@ -26,7 +26,7 @@
 #include <string>
 
 #define BIMG_TEXTUREC_VERSION_MAJOR 1
-#define BIMG_TEXTUREC_VERSION_MINOR 5
+#define BIMG_TEXTUREC_VERSION_MINOR 6
 
 struct Options
 {