Fix ParticleBatchNode texture not bind [ci build]

This commit is contained in:
halx99 2021-01-19 23:53:22 +08:00
parent 610ec87b15
commit ab8cde3e95
2 changed files with 18 additions and 10 deletions

View File

@ -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

View File

@ -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;