diff --git a/cocos/renderer/CCTexture2D.cpp b/cocos/renderer/CCTexture2D.cpp index 571edffa06..e41a610dd5 100644 --- a/cocos/renderer/CCTexture2D.cpp +++ b/cocos/renderer/CCTexture2D.cpp @@ -711,7 +711,7 @@ std::string Texture2D::getDescription() const // implementation Texture2D (Image) bool Texture2D::initWithImage(Image *image) { - return initWithImage(image, PixelFormat::NONE); + return initWithImage(image, g_defaultAlphaPixelFormat); } bool Texture2D::initWithImage(Image *image, PixelFormat format) @@ -736,14 +736,14 @@ bool Texture2D::initWithImage(Image *image, PixelFormat format) unsigned char* tempData = image->getData(); Size imageSize = Size((float)imageWidth, (float)imageHeight); - PixelFormat pixelFormat = PixelFormat::NONE; + PixelFormat pixelFormat = ((PixelFormat::NONE == format) || (PixelFormat::AUTO == format)) ? image->getRenderFormat() : format; PixelFormat renderFormat = image->getRenderFormat(); size_t tempDataLen = image->getDataLen(); if (image->getNumberOfMipmaps() > 1) { - if (format != PixelFormat::NONE) + if (pixelFormat != image->getRenderFormat()) { CCLOG("cocos2d: WARNING: This image has more than 1 mipmaps and we will not convert the data format"); } @@ -754,7 +754,7 @@ bool Texture2D::initWithImage(Image *image, PixelFormat format) } else if (image->isCompressed()) { - if (format != PixelFormat::NONE) + if (pixelFormat != image->getRenderFormat()) { CCLOG("cocos2d: WARNING: This image is compressed and we cann't convert it for now"); } @@ -764,15 +764,6 @@ bool Texture2D::initWithImage(Image *image, PixelFormat format) } else { - // compute pixel format - if (format != PixelFormat::NONE) - { - pixelFormat = format; - }else - { - pixelFormat = g_defaultAlphaPixelFormat; - } - unsigned char* outTempData = nullptr; ssize_t outTempDataLen = 0;