From 8c8b08f80b8e4b6913625e6aee5f7502831b5ace Mon Sep 17 00:00:00 2001 From: Arnold <40414978+PatriceJiang@users.noreply.github.com> Date: Wed, 18 Dec 2019 16:19:58 +0800 Subject: [PATCH] [bugfix] spine-cocos2dx renderer issues (#1577) * fix some bugs * auto release program --- spine-cocos2dx/src/spine/SkeletonRenderer.cpp | 2 +- spine-cocos2dx/src/spine/v4/SkeletonBatch.cpp | 14 ++++++++------ .../src/spine/v4/SkeletonTwoColorBatch.cpp | 13 +++++++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/spine-cocos2dx/src/spine/SkeletonRenderer.cpp b/spine-cocos2dx/src/spine/SkeletonRenderer.cpp index 409877d81..2542c6ece 100644 --- a/spine-cocos2dx/src/spine/SkeletonRenderer.cpp +++ b/spine-cocos2dx/src/spine/SkeletonRenderer.cpp @@ -810,7 +810,7 @@ namespace spine { } void SkeletonRenderer::setTwoColorTint(bool enabled) { -#if COCOS2D_VERSION > 0x00040000 +#if COCOS2D_VERSION >= 0x00040000 _twoColorTint = enabled; #endif setupGLProgramState(enabled); diff --git a/spine-cocos2dx/src/spine/v4/SkeletonBatch.cpp b/spine-cocos2dx/src/spine/v4/SkeletonBatch.cpp index 33997d347..36e338c4b 100644 --- a/spine-cocos2dx/src/spine/v4/SkeletonBatch.cpp +++ b/spine-cocos2dx/src/spine/v4/SkeletonBatch.cpp @@ -59,15 +59,17 @@ void SkeletonBatch::destroyInstance () { SkeletonBatch::SkeletonBatch () { - auto program = backend::Device::getInstance()->newProgram(positionTextureColor_vert, positionTextureColor_frag); + auto program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_TEXTURE_COLOR); _programState = std::make_shared(program); - program->autorelease(); - + auto vertexLayout = _programState->getVertexLayout(); - vertexLayout->setAttribute("a_position", 0, backend::VertexFormat::FLOAT3, offsetof(V3F_C4B_T2F, vertices), false); - vertexLayout->setAttribute("a_color", 2, backend::VertexFormat::UBYTE4, offsetof(V3F_C4B_T2F, colors), true); - vertexLayout->setAttribute("a_texCoord", 1, backend::VertexFormat::FLOAT2, offsetof(V3F_C4B_T2F, texCoords), false); + auto locPosition = _programState->getAttributeLocation("a_position"); + auto locTexcoord = _programState->getAttributeLocation("a_texCoord"); + auto locColor = _programState->getAttributeLocation("a_color"); + vertexLayout->setAttribute("a_position", locPosition, backend::VertexFormat::FLOAT3, offsetof(V3F_C4B_T2F, vertices), false); + vertexLayout->setAttribute("a_color", locColor, backend::VertexFormat::UBYTE4, offsetof(V3F_C4B_T2F, colors), true); + vertexLayout->setAttribute("a_texCoord", locTexcoord, backend::VertexFormat::FLOAT2, offsetof(V3F_C4B_T2F, texCoords), false); vertexLayout->setLayout(sizeof(_vertices[0])); diff --git a/spine-cocos2dx/src/spine/v4/SkeletonTwoColorBatch.cpp b/spine-cocos2dx/src/spine/v4/SkeletonTwoColorBatch.cpp index 3e21bcc17..3330edc9e 100644 --- a/spine-cocos2dx/src/spine/v4/SkeletonTwoColorBatch.cpp +++ b/spine-cocos2dx/src/spine/v4/SkeletonTwoColorBatch.cpp @@ -114,10 +114,15 @@ namespace { auto layout = programState->getVertexLayout(); - layout->setAttribute("a_position", 0, backend::VertexFormat::FLOAT3, offsetof(spine::V3F_C4B_C4B_T2F, position), false); - layout->setAttribute("a_color", 1, backend::VertexFormat::UBYTE4, offsetof(spine::V3F_C4B_C4B_T2F, color), true); - layout->setAttribute("a_color2", 2, backend::VertexFormat::UBYTE4, offsetof(spine::V3F_C4B_C4B_T2F, color2), true); - layout->setAttribute("a_texCoords", 3, backend::VertexFormat::FLOAT2, offsetof(spine::V3F_C4B_C4B_T2F, texCoords), false); + auto locPosition = programState->getAttributeLocation("a_position"); + auto locTexcoord = programState->getAttributeLocation("a_texCoords"); + auto locColor = programState->getAttributeLocation("a_color"); + auto locColor2 = programState->getAttributeLocation("a_color2"); + + layout->setAttribute("a_position", locPosition, backend::VertexFormat::FLOAT3, offsetof(spine::V3F_C4B_C4B_T2F, position), false); + layout->setAttribute("a_color", locColor, backend::VertexFormat::UBYTE4, offsetof(spine::V3F_C4B_C4B_T2F, color), true); + layout->setAttribute("a_color2", locColor2, backend::VertexFormat::UBYTE4, offsetof(spine::V3F_C4B_C4B_T2F, color2), true); + layout->setAttribute("a_texCoords", locTexcoord, backend::VertexFormat::FLOAT2, offsetof(spine::V3F_C4B_C4B_T2F, texCoords), false); layout->setLayout(sizeof(spine::V3F_C4B_C4B_T2F)); __twoColorProgramState = std::shared_ptr(programState);