mirror of https://github.com/axmolengine/axmol.git
PremultipliedAlpha
This commit is contained in:
parent
8b62addcec
commit
22d5008d28
|
@ -1443,10 +1443,6 @@ bool Image::initWithETCData(const unsigned char* data, ssize_t dataLen, bool own
|
|||
return false;
|
||||
}
|
||||
|
||||
// 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.
|
||||
_hasPremultipliedAlpha = true;
|
||||
|
||||
if (Configuration::getInstance()->supportsETC())
|
||||
{
|
||||
//old opengl version has no define for GL_ETC1_RGB8_OES, add macro to make compiler happy.
|
||||
|
|
|
@ -234,7 +234,7 @@ bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, backend::Pi
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Texture2D::updateWithImage(Image* image, backend::PixelFormat format, int index)
|
||||
bool Texture2D::updateWithImage(Image* image, backend::PixelFormat format, int index, bool preMultipliedAlpha)
|
||||
{
|
||||
if (image == nullptr)
|
||||
{
|
||||
|
@ -314,8 +314,6 @@ bool Texture2D::updateWithImage(Image* image, backend::PixelFormat format, int i
|
|||
//pixel format of data is not converted, renderFormat can be different from pixelFormat
|
||||
//it will be done later
|
||||
updateWithMipmaps(image->getMipmaps(), image->getNumberOfMipmaps(), image->getPixelFormat(), renderFormat, imageWidth, imageHeight, image->hasPremultipliedAlpha(), index);
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (image->isCompressed())
|
||||
{
|
||||
|
@ -325,16 +323,17 @@ bool Texture2D::updateWithImage(Image* image, backend::PixelFormat format, int i
|
|||
}
|
||||
|
||||
updateWithData(tempData, tempDataLen, image->getPixelFormat(), image->getPixelFormat(), imageWidth, imageHeight, imageSize, image->hasPremultipliedAlpha(), index);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//after conversion, renderFormat == pixelFormat of data
|
||||
updateWithData(tempData, tempDataLen, imagePixelFormat, renderFormat, imageWidth, imageHeight, imageSize, image->hasPremultipliedAlpha(), index);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (index > 0)
|
||||
this->_hasPremultipliedAlpha = preMultipliedAlpha;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Texture2D::updateWithData(const void* data, ssize_t dataLen, backend::PixelFormat pixelFormat, backend::PixelFormat renderFormat, int pixelsWide, int pixelsHigh, const Size& /*contentSize*/, bool preMultipliedAlpha, int index)
|
||||
|
|
|
@ -178,7 +178,7 @@ public:
|
|||
@param width Specifies the width of the texture subimage.
|
||||
@param height Specifies the height of the texture subimage.
|
||||
*/
|
||||
bool updateWithImage(Image* image, backend::PixelFormat format, int index = 0);
|
||||
bool updateWithImage(Image* image, backend::PixelFormat format, int index = 0, bool preMultipliedAlpha = false);
|
||||
bool updateWithData(const void* data, ssize_t dataLen, backend::PixelFormat pixelFormat, backend::PixelFormat renderFormat, int pixelsWide, int pixelsHigh, const Size& /*contentSize*/, bool preMultipliedAlpha, int index = 0);
|
||||
bool updateWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, backend::PixelFormat pixelFormat, backend::PixelFormat renderFormat, int pixelsWide, int pixelsHigh, bool preMultipliedAlpha = false, int index = 0);
|
||||
|
||||
|
@ -296,7 +296,7 @@ public:
|
|||
|
||||
/** Whether or not the texture has their Alpha premultiplied. */
|
||||
bool hasPremultipliedAlpha() const;
|
||||
|
||||
|
||||
/** Whether or not the texture has mip maps.*/
|
||||
bool hasMipmaps() const;
|
||||
|
||||
|
|
|
@ -348,7 +348,7 @@ void TextureCache::addImageAsyncCallBack(float /*dt*/)
|
|||
texture->autorelease();
|
||||
// ETC1 ALPHA supports.
|
||||
if (asyncStruct->imageAlpha.getFileType() == Image::Format::ETC) {
|
||||
texture->updateWithImage(&asyncStruct->imageAlpha, Texture2D::getDefaultAlphaPixelFormat(), 1);
|
||||
texture->updateWithImage(&asyncStruct->imageAlpha, Texture2D::getDefaultAlphaPixelFormat(), 1, true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -419,8 +419,9 @@ Texture2D * TextureCache::addImage(const std::string &path)
|
|||
{
|
||||
Image imageAlpha;
|
||||
if (imageAlpha.initWithImageFile(alphaFullPath))
|
||||
{
|
||||
texture->updateWithImage(&imageAlpha, Texture2D::getDefaultAlphaPixelFormat(), 1);
|
||||
{ // 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, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue