diff --git a/cocos/renderer/CCTexture2D.cpp b/cocos/renderer/CCTexture2D.cpp index 3a6b8cecb2..3afda7ba49 100644 --- a/cocos/renderer/CCTexture2D.cpp +++ b/cocos/renderer/CCTexture2D.cpp @@ -281,8 +281,8 @@ bool Texture2D::updateWithImage(Image* image, backend::PixelFormat format, int i case PixelFormat::ASTC4: case PixelFormat::ASTC8: renderFormat = imagePixelFormat; - default: break; + default:; } //override renderFormat, since some render format is not supported by metal switch (renderFormat) @@ -326,14 +326,16 @@ bool Texture2D::updateWithImage(Image* image, backend::PixelFormat format, int i } else if (image->isCompressed()) { +#ifndef CC_USE_METAL switch (imagePixelFormat) { + case PixelFormat::ETC: case PixelFormat::ASTC4: case PixelFormat::ASTC8: - case PixelFormat::ETC: renderFormat = imagePixelFormat; + break; default:; } - +#endif if (renderFormat != image->getPixelFormat()) { CCLOG("cocos2d: WARNING: This image is compressed and we can't convert it for now"); diff --git a/cocos/renderer/backend/metal/TextureMTL.mm b/cocos/renderer/backend/metal/TextureMTL.mm index 4a0c5bbb5f..5512f9d0af 100644 --- a/cocos/renderer/backend/metal/TextureMTL.mm +++ b/cocos/renderer/backend/metal/TextureMTL.mm @@ -140,6 +140,30 @@ namespace return bytesPerRow; } + std::size_t getBytesPerRowASTC(MTLPixelFormat pixleFormat, std::size_t width) + { + std::size_t bytesPerRow = 0; +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + uint32_t bytesPerBlock = 0; + switch (pixleFormat) { + case MTLPixelFormatASTC_4x4_sRGB: + case MTLPixelFormatASTC_4x4_LDR: + case MTLPixelFormatASTC_4x4_HDR: + bytesPerBlock = 4; + break; + case MTLPixelFormatASTC_8x8_sRGB: + case MTLPixelFormatASTC_8x8_LDR: + case MTLPixelFormatASTC_8x8_HDR: + bytesPerBlock = 8; + break; + default: + CCASSERT(false, "Not supported ASTC format!"); + } + bytesPerRow = width * bytesPerBlock; +#endif + return bytesPerRow; + } + std::size_t getBytesPerRowS3TC(MTLPixelFormat pixleFormat, std::size_t width) { std::size_t bytesPerRow = 0; @@ -176,6 +200,10 @@ namespace { bytesPerRow = getBytesPerRowETC(pixelFormat, width); } + else if (textureFormat == PixelFormat::ASTC4 || textureFormat == PixelFormat::ASTC8) + { + bytesPerRow = getBytesPerRowASTC(pixelFormat, width); + } else if(textureFormat >= PixelFormat::S3TC_DXT1 && textureFormat <= PixelFormat::S3TC_DXT5) { diff --git a/cocos/renderer/backend/metal/Utils.mm b/cocos/renderer/backend/metal/Utils.mm index 0974d4f330..eb49aa25da 100644 --- a/cocos/renderer/backend/metal/Utils.mm +++ b/cocos/renderer/backend/metal/Utils.mm @@ -123,6 +123,10 @@ MTLPixelFormat Utils::toMTLPixelFormat(PixelFormat textureFormat) return MTLPixelFormatPVRTC_RGB_2BPP; case PixelFormat::ETC: return MTLPixelFormatETC2_RGB8; + case PixelFormat::ASTC4: + return MTLPixelFormatASTC_4x4_LDR; + case PixelFormat::ASTC8: + return MTLPixelFormatASTC_8x8_LDR; #else case PixelFormat::S3TC_DXT1: return MTLPixelFormatBC1_RGBA;