From 579ddc822c769998bdefa527476e13f834beee91 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 1 Dec 2017 19:49:07 -1000 Subject: [PATCH] Fix Metal DXT1 loading --- lib/graphicsdev/Metal.mm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/graphicsdev/Metal.mm b/lib/graphicsdev/Metal.mm index b6500f4..5dbca8d 100644 --- a/lib/graphicsdev/Metal.mm +++ b/lib/graphicsdev/Metal.mm @@ -289,16 +289,19 @@ class MetalTextureS : public GraphicsDataNode MTLPixelFormat pfmt = MTLPixelFormatRGBA8Unorm; NSUInteger ppitchNum = 4; NSUInteger ppitchDenom = 1; + NSUInteger bytesPerRow = width * ppitchNum; switch (fmt) { case TextureFormat::I8: pfmt = MTLPixelFormatR8Unorm; ppitchNum = 1; + bytesPerRow = width * ppitchNum; break; case TextureFormat::DXT1: pfmt = MTLPixelFormatBC1_RGBA; ppitchNum = 1; ppitchDenom = 2; + bytesPerRow = width * 8 / 4; // Metal wants this in blocks, not bytes default: break; } @@ -317,10 +320,13 @@ class MetalTextureS : public GraphicsDataNode [m_tex replaceRegion:MTLRegionMake2D(0, 0, width, height) mipmapLevel:i withBytes:dataIt - bytesPerRow:width * ppitchNum / ppitchDenom]; + bytesPerRow:bytesPerRow]; dataIt += width * height * ppitchNum / ppitchDenom; if (width > 1) + { width /= 2; + bytesPerRow /= 2; + } if (height > 1) height /= 2; }