Fix Metal DXT1 loading

This commit is contained in:
Jack Andersen 2017-12-01 19:49:07 -10:00
parent ce80446e8b
commit 579ddc822c
1 changed files with 7 additions and 1 deletions

View File

@ -289,16 +289,19 @@ class MetalTextureS : public GraphicsDataNode<ITextureS>
MTLPixelFormat pfmt = MTLPixelFormatRGBA8Unorm; MTLPixelFormat pfmt = MTLPixelFormatRGBA8Unorm;
NSUInteger ppitchNum = 4; NSUInteger ppitchNum = 4;
NSUInteger ppitchDenom = 1; NSUInteger ppitchDenom = 1;
NSUInteger bytesPerRow = width * ppitchNum;
switch (fmt) switch (fmt)
{ {
case TextureFormat::I8: case TextureFormat::I8:
pfmt = MTLPixelFormatR8Unorm; pfmt = MTLPixelFormatR8Unorm;
ppitchNum = 1; ppitchNum = 1;
bytesPerRow = width * ppitchNum;
break; break;
case TextureFormat::DXT1: case TextureFormat::DXT1:
pfmt = MTLPixelFormatBC1_RGBA; pfmt = MTLPixelFormatBC1_RGBA;
ppitchNum = 1; ppitchNum = 1;
ppitchDenom = 2; ppitchDenom = 2;
bytesPerRow = width * 8 / 4; // Metal wants this in blocks, not bytes
default: break; default: break;
} }
@ -317,10 +320,13 @@ class MetalTextureS : public GraphicsDataNode<ITextureS>
[m_tex replaceRegion:MTLRegionMake2D(0, 0, width, height) [m_tex replaceRegion:MTLRegionMake2D(0, 0, width, height)
mipmapLevel:i mipmapLevel:i
withBytes:dataIt withBytes:dataIt
bytesPerRow:width * ppitchNum / ppitchDenom]; bytesPerRow:bytesPerRow];
dataIt += width * height * ppitchNum / ppitchDenom; dataIt += width * height * ppitchNum / ppitchDenom;
if (width > 1) if (width > 1)
{
width /= 2; width /= 2;
bytesPerRow /= 2;
}
if (height > 1) if (height > 1)
height /= 2; height /= 2;
} }