diff --git a/cocos/renderer/CCTexture2D.cpp b/cocos/renderer/CCTexture2D.cpp index 499b2d5f83..3c7ff09591 100644 --- a/cocos/renderer/CCTexture2D.cpp +++ b/cocos/renderer/CCTexture2D.cpp @@ -335,6 +335,8 @@ bool Texture2D::updateWithImage(Image* image, backend::PixelFormat format, int i } _flagsAndFormatEXT |= formatEXT; + + // pitfall: because we do merge etc1 alpha at shader, so must mark as _hasPremultipliedAlpha = true to makesure alpha blend works well. if (formatEXT == TextureFormatEXT::ETC1_ALPHA) setPremultipliedAlpha(true); diff --git a/cocos/renderer/CCTextureCache.cpp b/cocos/renderer/CCTextureCache.cpp index e7f69da981..910f3e2371 100644 --- a/cocos/renderer/CCTextureCache.cpp +++ b/cocos/renderer/CCTextureCache.cpp @@ -419,8 +419,7 @@ Texture2D * TextureCache::addImage(const std::string &path) { Image imageAlpha; if (imageAlpha.initWithImageFile(alphaFullPath)) - { // pitfall: because we do merge etc1 alpha at shader, so must mark as _hasPremultipliedAlpha=true to makesure alpha blend works well. - // the Premultiply operation can only do at shader. + { texture->updateWithImage(&imageAlpha, Texture2D::getDefaultAlphaPixelFormat(), 1, TextureFormatEXT::ETC1_ALPHA); } } @@ -830,8 +829,11 @@ void VolatileTextureMgr::reloadAllTextures() reloadTexture(vt->_texture, vt->_fileName, vt->_pixelFormat); // etc1 support check whether alpha texture exists & load it - auto alphaFile = vt->_fileName + TextureCache::getETC1AlphaFileSuffix(); - reloadTexture(vt->_texture->getAlphaTexture(), alphaFile, vt->_pixelFormat); + Image image; + if (image.initWithImageFile(vt->_fileName + TextureCache::getETC1AlphaFileSuffix())) + { + vt->_texture->updateWithImage(&image, vt->_pixelFormat, 1, TextureFormatEXT::ETC1_ALPHA); + } } break; case VolatileTexture::kImageData: diff --git a/cocos/renderer/backend/opengl/TextureGL.h b/cocos/renderer/backend/opengl/TextureGL.h index 6372502042..6a6608e2c7 100644 --- a/cocos/renderer/backend/opengl/TextureGL.h +++ b/cocos/renderer/backend/opengl/TextureGL.h @@ -226,7 +226,7 @@ public: */ void apply(int index) const; - int getCount() const { return 1; } + int getCount() const override { return 1; } private: void setTexParameters();