Merge pull request #186 from halx99/fix-185

Fix ASTC bytesPerRow calculation
This commit is contained in:
HALX99 2020-08-29 10:27:04 -07:00 committed by GitHub
commit 066b74d1d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 6 deletions

View File

@ -132,7 +132,7 @@ namespace
break; break;
default: default:
CCASSERT(false, "Not supported ETC format!"); CCASSERT(false, "Not supported ETC format!");
break; return 0;
} }
auto blocksPerRow = (width + (blockWidth - 1)) / blockWidth; auto blocksPerRow = (width + (blockWidth - 1)) / blockWidth;
bytesPerRow = blocksPerRow * bytesPerBlock; bytesPerRow = blocksPerRow * bytesPerBlock;
@ -144,22 +144,25 @@ namespace
{ {
std::size_t bytesPerRow = 0; std::size_t bytesPerRow = 0;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
uint32_t bytesPerBlock = 0; // @ASTC: bytesPerBlock always 16
uint32_t bytesPerBlock = 16, blockWidth = 0;
switch (pixleFormat) { switch (pixleFormat) {
case MTLPixelFormatASTC_4x4_sRGB: case MTLPixelFormatASTC_4x4_sRGB:
case MTLPixelFormatASTC_4x4_LDR: case MTLPixelFormatASTC_4x4_LDR:
case MTLPixelFormatASTC_4x4_HDR: case MTLPixelFormatASTC_4x4_HDR:
bytesPerBlock = 4; blockWidth = 4;
break; break;
case MTLPixelFormatASTC_8x8_sRGB: case MTLPixelFormatASTC_8x8_sRGB:
case MTLPixelFormatASTC_8x8_LDR: case MTLPixelFormatASTC_8x8_LDR:
case MTLPixelFormatASTC_8x8_HDR: case MTLPixelFormatASTC_8x8_HDR:
bytesPerBlock = 8; blockWidth = 8;
break; break;
default: default:
CCASSERT(false, "Not supported ASTC format!"); CCASSERT(false, "Not supported ASTC format!");
return 0;
} }
bytesPerRow = width * bytesPerBlock; auto blocksPerRow = (width + (blockWidth - 1)) / blockWidth;
bytesPerRow = blocksPerRow * bytesPerBlock;
#endif #endif
return bytesPerRow; return bytesPerRow;
} }
@ -178,7 +181,7 @@ namespace
bytesPerBlock = 16; bytesPerBlock = 16;
break; break;
default: default:
break; return 0;
} }
auto blocksPerRow = (width + (blockWidth - 1)) / blockWidth; auto blocksPerRow = (width + (blockWidth - 1)) / blockWidth;
bytesPerRow = blocksPerRow * bytesPerBlock; bytesPerRow = blocksPerRow * bytesPerBlock;