From ab8cde3e95a4fb946b2d20b1883669367f20f761 Mon Sep 17 00:00:00 2001 From: halx99 Date: Tue, 19 Jan 2021 23:53:22 +0800 Subject: [PATCH] Fix ParticleBatchNode texture not bind [ci build] --- cocos/2d/CCParticleBatchNode.cpp | 25 +++++++++++++++---------- cocos/2d/CCParticleBatchNode.h | 3 +++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/cocos/2d/CCParticleBatchNode.cpp b/cocos/2d/CCParticleBatchNode.cpp index 51d161f94e..0a6cf7e289 100644 --- a/cocos/2d/CCParticleBatchNode.cpp +++ b/cocos/2d/CCParticleBatchNode.cpp @@ -6,6 +6,7 @@ * Copyright (c) 2011 Marco Tillemans * Copyright (c) 2013-2016 Chukong Technologies Inc. * Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + * Copyright (c) 2020-2021 C4games.com. * * http://www.cocos2d-x.org * @@ -123,6 +124,8 @@ bool ParticleBatchNode::initWithTexture(Texture2D *tex, int capacity) { _textureAtlas = new (std::nothrow) TextureAtlas(); _textureAtlas->initWithTexture(tex, capacity); + + updateProgramStateTexture(); _children.reserve(capacity); @@ -443,7 +446,6 @@ void ParticleBatchNode::draw(Renderer* renderer, const Mat4 & transform, uint32_ Mat4 finalMat = projectionMat * transform; auto programState = _customCommand.getPipelineDescriptor().programState; programState->setUniform(_mvpMatrixLocaiton, finalMat.m, sizeof(finalMat.m)); - if (_textureAtlas->isDirty()) { const auto& quads = _textureAtlas->getQuads(); @@ -532,15 +534,18 @@ void ParticleBatchNode::updateBlendFunc() void ParticleBatchNode::setTexture(Texture2D* texture) { _textureAtlas->setTexture(texture); - if (texture) { - auto programState = _customCommand.getPipelineDescriptor().programState; - programState->setTexture(_textureAtlas->getTexture()->getBackendTexture()); - // If the new texture has No premultiplied alpha, AND the blendFunc hasn't been changed, then update it - if (!texture->hasPremultipliedAlpha() && (_blendFunc.src == CC_BLEND_SRC && _blendFunc.dst == CC_BLEND_DST)) - { - _blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED; - } - } + updateProgramStateTexture(); +} + +void ParticleBatchNode::updateProgramStateTexture() +{ + auto texture = _textureAtlas->getTexture(); + assert(texture != nullptr); + auto programState = _customCommand.getPipelineDescriptor().programState; + programState->setTexture(texture->getBackendTexture()); + // If the new texture has No premultiplied alpha, AND the blendFunc hasn't been changed, then update it + if (!texture->hasPremultipliedAlpha() && (_blendFunc.src == CC_BLEND_SRC && _blendFunc.dst == CC_BLEND_DST)) + _blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED; } Texture2D* ParticleBatchNode::getTexture() const diff --git a/cocos/2d/CCParticleBatchNode.h b/cocos/2d/CCParticleBatchNode.h index 9a24fffc11..11cd0dd512 100644 --- a/cocos/2d/CCParticleBatchNode.h +++ b/cocos/2d/CCParticleBatchNode.h @@ -170,6 +170,9 @@ private: int addChildHelper(ParticleSystem* child, int z, int aTag, const std::string &name, bool setTag); void addChildByTagOrName(ParticleSystem* child, int z, int tag, const std::string &name, bool setTag); void updateBlendFunc(); + + void updateProgramStateTexture(); + /** the texture atlas used for drawing the quads */ TextureAtlas* _textureAtlas = nullptr;