Эх сурвалжийг харах

[bugfix] spine-cocos2dx renderer issues (#1577)

* fix some bugs

* auto release program
Arnold 5 жил өмнө
parent
commit
8c8b08f80b

+ 1 - 1
spine-cocos2dx/src/spine/SkeletonRenderer.cpp

@@ -810,7 +810,7 @@ namespace spine {
 	}
 	}
 
 
 	void SkeletonRenderer::setTwoColorTint(bool enabled) {
 	void SkeletonRenderer::setTwoColorTint(bool enabled) {
-#if COCOS2D_VERSION > 0x00040000
+#if COCOS2D_VERSION >= 0x00040000
 		_twoColorTint = enabled;
 		_twoColorTint = enabled;
 #endif
 #endif
 		setupGLProgramState(enabled);
 		setupGLProgramState(enabled);

+ 8 - 6
spine-cocos2dx/src/spine/v4/SkeletonBatch.cpp

@@ -59,15 +59,17 @@ void SkeletonBatch::destroyInstance () {
 
 
 SkeletonBatch::SkeletonBatch () {
 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<backend::ProgramState>(program);
     _programState = std::make_shared<backend::ProgramState>(program);
-    program->autorelease();
-
+    
     auto vertexLayout = _programState->getVertexLayout();
     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]));
     vertexLayout->setLayout(sizeof(_vertices[0]));
 
 
 
 

+ 9 - 4
spine-cocos2dx/src/spine/v4/SkeletonTwoColorBatch.cpp

@@ -114,10 +114,15 @@ namespace {
 
 
         auto layout = programState->getVertexLayout();
         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));
         layout->setLayout(sizeof(spine::V3F_C4B_C4B_T2F));
 
 
         __twoColorProgramState = std::shared_ptr<backend::ProgramState>(programState);
         __twoColorProgramState = std::shared_ptr<backend::ProgramState>(programState);