From cdc335d41b05caa159836d74907f51c4be4db252 Mon Sep 17 00:00:00 2001 From: badlogic Date: Thu, 28 Sep 2017 17:00:05 +0200 Subject: [PATCH] [cocos2dx] Didn't invoke GL program state setup in initialize and setTwoColorTint. See #989 --- CHANGELOG.md | 2 +- spine-cocos2dx/src/spine/SkeletonRenderer.cpp | 15 ++++++++------- spine-cocos2dx/src/spine/SkeletonRenderer.h | 5 +++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fa74cae7..e1b4f35c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,7 +62,7 @@ * Added support for clipping. * SkeletonRenderer now combines the displayed color of the Node (cascaded from all parents) with the skeleton color for tinting. * Added support for vertex effects. See `RaptorExample.cpp`. - * Added ETC1 support, thanks @halx99! + * Added ETC1 alpha support, thanks @halx99! Does not work when two color tint is enabled. ### Cocos2d-Objc * Fixed renderer to work with 3.6 changes diff --git a/spine-cocos2dx/src/spine/SkeletonRenderer.cpp b/spine-cocos2dx/src/spine/SkeletonRenderer.cpp index 44a391b08..bb55557d4 100644 --- a/spine-cocos2dx/src/spine/SkeletonRenderer.cpp +++ b/spine-cocos2dx/src/spine/SkeletonRenderer.cpp @@ -68,10 +68,15 @@ void SkeletonRenderer::initialize () { _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; setOpacityModifyRGB(true); - setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP)); + setupGLProgramState(false); } -void SkeletonRenderer::setupGLProgramState () { +void SkeletonRenderer::setupGLProgramState (bool twoColorTintEnabled) { + if (twoColorTintEnabled) { + setGLProgramState(SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState()); + return; + } + Texture2D *texture = nullptr; for (int i = 0, n = _skeleton->slotsCount; i < n; i++) { spSlot* slot = _skeleton->drawOrder[i]; @@ -95,7 +100,6 @@ void SkeletonRenderer::setupGLProgramState () { break; } } - setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP, texture)); } @@ -737,10 +741,7 @@ bool SkeletonRenderer::setAttachment (const std::string& slotName, const char* a } void SkeletonRenderer::setTwoColorTint(bool enabled) { - if (enabled) - setGLProgramState(SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState()); - else - setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP)); + setupGLProgramState(enabled); } bool SkeletonRenderer::isTwoColorTint() { diff --git a/spine-cocos2dx/src/spine/SkeletonRenderer.h b/spine-cocos2dx/src/spine/SkeletonRenderer.h index 072f84de1..8ac8f9a62 100644 --- a/spine-cocos2dx/src/spine/SkeletonRenderer.h +++ b/spine-cocos2dx/src/spine/SkeletonRenderer.h @@ -124,11 +124,12 @@ CC_CONSTRUCTOR_ACCESS: void initWithBinaryFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1); virtual void initialize (); - void setupGLProgramState(); + protected: void setSkeletonData (spSkeletonData* skeletonData, bool ownsSkeletonData); virtual AttachmentVertices* getAttachmentVertices (spRegionAttachment* attachment) const; - virtual AttachmentVertices* getAttachmentVertices (spMeshAttachment* attachment) const; + virtual AttachmentVertices* getAttachmentVertices (spMeshAttachment* attachment) const; + void setupGLProgramState(bool twoColorTintEnabled); bool _ownsSkeletonData; spAtlas* _atlas;