Skip to content

Commit 068c0f0

Browse files
rh101minggo
authored andcommitted
Sprite and RenderTexture blending mode set based off texture premultiplied alpha setting (#20154)
* Added RenderTexture::saveToFileAsNonPMA() to save images without PMA. Set the PMA parameter to true when calling initWithRawData() inside RenderTexture::newImage(), since textures are PMA. Renamed Image::premultipliedAlpha() to Image::premultiplyAlpha() to better reflect it's action, and made it public. Added Image::reversePremultipliedAlpha() to allow the reversing of the PMA. Updated CCImage-ios.mm to set the correct bitmapInfo for PMA and non-PMA images before saving a file. Updated RenderTextureTest::RenderTextureSave() to cater for non-PMA file saving. * [CCImage-ios.mm] Fixed indentation. * [CCSprite.cpp] Sprite:initWithTexture() should set the blend mode depending on the texture premultiplied alpha setting. [CCRenderTexture.cpp] Sprite::setOpacityModifyRGB() is set based on the premultiplied alpha setting. * Fix for incorrect _opacityModifyRGB on non-PMA. * [CCSprite.cpp] Removed redundant code related to blending mode and opacityModifyRGB when creating a sprite with a texture.
1 parent 8f454b4 commit 068c0f0

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

cocos/2d/CCRenderTexture.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,11 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat
305305

306306
#if CC_ENABLE_PREMULTIPLIED_ALPHA != 0
307307
_sprite->setBlendFunc(BlendFunc::ALPHA_PREMULTIPLIED);
308+
_sprite->setOpacityModifyRGB(true);
308309
#else
309310
_sprite->setBlendFunc(BlendFunc::ALPHA_NON_PREMULTIPLIED);
311+
_sprite->setOpacityModifyRGB(false);
310312
#endif
311-
_sprite->setOpacityModifyRGB(true);
312313

313314
glBindRenderbuffer(GL_RENDERBUFFER, oldRBO);
314315
glBindFramebuffer(GL_FRAMEBUFFER, _oldFBO);

cocos/2d/CCSprite.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,6 @@ bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated)
269269
_recursiveDirty = false;
270270
setDirty(false);
271271

272-
_opacityModifyRGB = true;
273-
274-
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
275-
276272
_flippedX = _flippedY = false;
277273

278274
// default transform anchor: center

0 commit comments

Comments
 (0)