Make astc works on ios platform.

This commit is contained in:
halx99 2020-02-14 19:10:01 +08:00
parent 363dab75c9
commit a460438c3b
3 changed files with 37 additions and 3 deletions

View File

@ -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");

View File

@ -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)
{

View File

@ -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;