-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed an issue where the shader would come off when run setTexture. #20603
base: v4
Are you sure you want to change the base?
Fixed an issue where the shader would come off when run setTexture. #20603
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, check does custom shader is better
Does a custom shader solve this problem? |
Please refer to this commit: axmolengine/axmol@27bdca3 |
Thank you very much. I pushed a fix commit. |
The added condition
because
This would probably work better, and what @halx99 may have meant:
It would then correctly set the ETC1 or POSITION_TEXTURE_COLOR shader depending on the passed in texture, and it won't affect sprites with custom shaders. Otherwise, you can explicitly check for the ETC1 and POSITION_TEXTURE_COLOR shaders, in case a non-custom shader is being used on the sprite that isn't one of them:
|
Yes, @rh101 's code is better |
cocos/2d/CCSprite.cpp
Outdated
if (_programState == nullptr || _programState->getProgram()->getProgramType() == backend::ProgramType::POSITION_TEXTURE_COLOR) { | ||
const auto isETC1 = texture && texture->getAlphaTextureName(); | ||
setProgramState((isETC1) ? backend::ProgramType::ETC1 : backend::ProgramType::POSITION_TEXTURE_COLOR); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your advice.
Is it okay with such a fix?
if (_programState == nullptr || _programState->getProgram()->getProgramType() == backend::ProgramType::POSITION_TEXTURE_COLOR) { | |
const auto isETC1 = texture && texture->getAlphaTextureName(); | |
setProgramState((isETC1) ? backend::ProgramType::ETC1 : backend::ProgramType::POSITION_TEXTURE_COLOR); | |
} | |
if (_programState == nullptr || _programState->getProgram()->getProgramType() == backend::ProgramType::POSITION_TEXTURE_COLOR || | |
_programState->getProgram()->getProgramType() == backend::ProgramType::ETC1) { | |
const auto isETC1 = texture && texture->getAlphaTextureName(); | |
setProgramState((isETC1) ? backend::ProgramType::ETC1 : backend::ProgramType::POSITION_TEXTURE_COLOR); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that would work fine, since it covers all cases.
…overed in all cases.
Summary
Fix issue #20600 , When I set a shader in
Sprite
and executesetTexture
, the shader comes off.Event
setProgramState
as below ...sprite->setProgramState(programState);
setTexture
.sprite->setTexture(filePath);
Then the shader will not run.
Why I submitted a Pull Request.
Currently, it can be dealt with by calling
setProgramState
immediately after callingsetTexture
as shown below.But developers need to explicitly keep
ProgramState
, and I think it's a redundant implementation.So I submitted a Pull Request.