mirror of https://github.com/axmolengine/axmol.git
Make astc works on ios platform.
This commit is contained in:
parent
363dab75c9
commit
a460438c3b
|
@ -281,8 +281,8 @@ bool Texture2D::updateWithImage(Image* image, backend::PixelFormat format, int i
|
||||||
case PixelFormat::ASTC4:
|
case PixelFormat::ASTC4:
|
||||||
case PixelFormat::ASTC8:
|
case PixelFormat::ASTC8:
|
||||||
renderFormat = imagePixelFormat;
|
renderFormat = imagePixelFormat;
|
||||||
default:
|
|
||||||
break;
|
break;
|
||||||
|
default:;
|
||||||
}
|
}
|
||||||
//override renderFormat, since some render format is not supported by metal
|
//override renderFormat, since some render format is not supported by metal
|
||||||
switch (renderFormat)
|
switch (renderFormat)
|
||||||
|
@ -326,14 +326,16 @@ bool Texture2D::updateWithImage(Image* image, backend::PixelFormat format, int i
|
||||||
}
|
}
|
||||||
else if (image->isCompressed())
|
else if (image->isCompressed())
|
||||||
{
|
{
|
||||||
|
#ifndef CC_USE_METAL
|
||||||
switch (imagePixelFormat) {
|
switch (imagePixelFormat) {
|
||||||
|
case PixelFormat::ETC:
|
||||||
case PixelFormat::ASTC4:
|
case PixelFormat::ASTC4:
|
||||||
case PixelFormat::ASTC8:
|
case PixelFormat::ASTC8:
|
||||||
case PixelFormat::ETC:
|
|
||||||
renderFormat = imagePixelFormat;
|
renderFormat = imagePixelFormat;
|
||||||
|
break;
|
||||||
default:;
|
default:;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (renderFormat != image->getPixelFormat())
|
if (renderFormat != image->getPixelFormat())
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: WARNING: This image is compressed and we can't convert it for now");
|
CCLOG("cocos2d: WARNING: This image is compressed and we can't convert it for now");
|
||||||
|
|
|
@ -140,6 +140,30 @@ namespace
|
||||||
return bytesPerRow;
|
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 getBytesPerRowS3TC(MTLPixelFormat pixleFormat, std::size_t width)
|
||||||
{
|
{
|
||||||
std::size_t bytesPerRow = 0;
|
std::size_t bytesPerRow = 0;
|
||||||
|
@ -176,6 +200,10 @@ namespace
|
||||||
{
|
{
|
||||||
bytesPerRow = getBytesPerRowETC(pixelFormat, width);
|
bytesPerRow = getBytesPerRowETC(pixelFormat, width);
|
||||||
}
|
}
|
||||||
|
else if (textureFormat == PixelFormat::ASTC4 || textureFormat == PixelFormat::ASTC8)
|
||||||
|
{
|
||||||
|
bytesPerRow = getBytesPerRowASTC(pixelFormat, width);
|
||||||
|
}
|
||||||
else if(textureFormat >= PixelFormat::S3TC_DXT1 &&
|
else if(textureFormat >= PixelFormat::S3TC_DXT1 &&
|
||||||
textureFormat <= PixelFormat::S3TC_DXT5)
|
textureFormat <= PixelFormat::S3TC_DXT5)
|
||||||
{
|
{
|
||||||
|
|
|
@ -123,6 +123,10 @@ MTLPixelFormat Utils::toMTLPixelFormat(PixelFormat textureFormat)
|
||||||
return MTLPixelFormatPVRTC_RGB_2BPP;
|
return MTLPixelFormatPVRTC_RGB_2BPP;
|
||||||
case PixelFormat::ETC:
|
case PixelFormat::ETC:
|
||||||
return MTLPixelFormatETC2_RGB8;
|
return MTLPixelFormatETC2_RGB8;
|
||||||
|
case PixelFormat::ASTC4:
|
||||||
|
return MTLPixelFormatASTC_4x4_LDR;
|
||||||
|
case PixelFormat::ASTC8:
|
||||||
|
return MTLPixelFormatASTC_8x8_LDR;
|
||||||
#else
|
#else
|
||||||
case PixelFormat::S3TC_DXT1:
|
case PixelFormat::S3TC_DXT1:
|
||||||
return MTLPixelFormatBC1_RGBA;
|
return MTLPixelFormatBC1_RGBA;
|
||||||
|
|
Loading…
Reference in New Issue