diff --git a/cocos/2d/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp index ba0d32d3e6..56bfb910bc 100644 --- a/cocos/2d/CCDrawNode.cpp +++ b/cocos/2d/CCDrawNode.cpp @@ -150,7 +150,7 @@ bool DrawNode::init() void DrawNode::updateShader() { auto* program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_COLOR_LENGTH_TEXTURE); - setProgramState(new (std::nothrow) backend::ProgramState(program)); + attachProgramState(new (std::nothrow) backend::ProgramState(program)); _customCommand.getPipelineDescriptor().programState = _programState; setVertexLayout(_customCommand); _customCommand.setDrawType(CustomCommand::DrawType::ARRAY); diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index 89c9295afd..6f2612c19b 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -2131,7 +2131,9 @@ int Node::getAttachedNodeCount() void Node::setProgramStateWithRegistry(backend::ProgramType programType, Texture2D* texture) { auto formatEXT = texture ? texture->getTextureFormatEXT() : 0; - setProgramState(backend::ProgramStateRegistry::getInstance()->getProgramState(programType, formatEXT)); + auto programState = backend::ProgramStateRegistry::getInstance()->newProgramState(programType, formatEXT); + setProgramState(programState); + programState->release(); } void Node::updateProgramStateTexture(Texture2D* texture) diff --git a/cocos/renderer/backend/ProgramStateRegistry.cpp b/cocos/renderer/backend/ProgramStateRegistry.cpp index 347d3451c6..eea75b0cb5 100644 --- a/cocos/renderer/backend/ProgramStateRegistry.cpp +++ b/cocos/renderer/backend/ProgramStateRegistry.cpp @@ -43,7 +43,7 @@ void ProgramStateRegistry::clearPrograms() { this->_registry.clear(); } -ProgramState* ProgramStateRegistry::getProgramState(ProgramType programType, int textureFormatEXT) +ProgramState* ProgramStateRegistry::newProgramState(ProgramType programType, int textureFormatEXT) { uint32_t key = (static_cast(programType) << 16) | textureFormatEXT; auto it = this->_registry.find(key); diff --git a/cocos/renderer/backend/ProgramStateRegistry.h b/cocos/renderer/backend/ProgramStateRegistry.h index 8dc5d7ba34..1ddbbe888d 100644 --- a/cocos/renderer/backend/ProgramStateRegistry.h +++ b/cocos/renderer/backend/ProgramStateRegistry.h @@ -41,7 +41,7 @@ public: void registerProgram(ProgramType programType, int textureFormatEXT, Program*); - ProgramState* getProgramState(ProgramType programType, int textureFormatEXT); + ProgramState* newProgramState(ProgramType programType, int textureFormatEXT); ProgramType getProgramType(ProgramType programType, int textureFormatEXT); protected: