Browse Source

[cocos2dx] Didn't invoke GL program state setup in initialize and setTwoColorTint. See #989

badlogic 8 years ago
parent
commit
cdc335d41b

+ 1 - 1
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

+ 8 - 7
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() {

+ 3 - 2
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;