浏览代码

Feature/new skeleton culling (#1196)

* Fix culling of skeleton and clean up code

* Optionally draw the bounding rectangle of skeletons

* Add Visual Studio compiler support

* Fix indentation

* Fix indentation

* Fix indentation

* Revert some indentation changes
sp-stefano-lanza 7 年之前
父节点
当前提交
7183e3b0bd

+ 1 - 1
spine-cocos2dx/example/Classes/AppDelegate.cpp

@@ -65,7 +65,7 @@ bool AppDelegate::applicationDidFinishLaunching () {
 	glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
 	glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
 #endif
 #endif
 
 
-	Size frameSize = glview->getFrameSize();
+	cocos2d::Size frameSize = glview->getFrameSize();
 	
 	
 	vector<string> searchPath;
 	vector<string> searchPath;
 
 

+ 2 - 2
spine-cocos2dx/example/Classes/BatchingExample.cpp

@@ -67,14 +67,14 @@ bool BatchingExample::init () {
 
 
 	int xMin = _contentSize.width * 0.10f, xMax = _contentSize.width * 0.90f;
 	int xMin = _contentSize.width * 0.10f, xMax = _contentSize.width * 0.90f;
 	int yMin = 0, yMax = _contentSize.height * 0.7f;
 	int yMin = 0, yMax = _contentSize.height * 0.7f;
-	for (int i = 0, j = 0; i < NUM_SKELETONS; i++) {
+	for (int i = 0; i < NUM_SKELETONS; i++) {
 		// Each skeleton node shares the same atlas, skeleton data, and mix times.
 		// Each skeleton node shares the same atlas, skeleton data, and mix times.
 		SkeletonAnimation* skeletonNode = SkeletonAnimation::createWithData(_skeletonData, false);
 		SkeletonAnimation* skeletonNode = SkeletonAnimation::createWithData(_skeletonData, false);
 		skeletonNode->setAnimationStateData(_stateData);
 		skeletonNode->setAnimationStateData(_stateData);
 
 
 		skeletonNode->setAnimation(0, "walk", true);
 		skeletonNode->setAnimation(0, "walk", true);
 		skeletonNode->addAnimation(0, "jump", true, RandomHelper::random_int(0, 300) / 100.0f);
 		skeletonNode->addAnimation(0, "jump", true, RandomHelper::random_int(0, 300) / 100.0f);
-		skeletonNode->addAnimation(0, "run", true);
+		skeletonNode->addAnimation(0, "run", true);
 		
 		
 		// alternative setting two color tint for groups of 10 skeletons
 		// alternative setting two color tint for groups of 10 skeletons
 		// should end up with #skeletons / 10 batches
 		// should end up with #skeletons / 10 batches

+ 4 - 2
spine-cocos2dx/example/Classes/CoinExample.cpp

@@ -53,8 +53,10 @@ bool CoinExample::init () {
 	
 	
 	EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
 	EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
 	listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool {
 	listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool {
-		if (!skeletonNode->getDebugBonesEnabled())
-			skeletonNode->setDebugBonesEnabled(true);
+		if (!skeletonNode->getDebugBonesEnabled()) {
+			skeletonNode->setDebugBonesEnabled(true);
+			skeletonNode->setDebugBoundingRectEnabled(true);
+		}
 		else if (skeletonNode->getTimeScale() == 1)
 		else if (skeletonNode->getTimeScale() == 1)
 			skeletonNode->setTimeScale(0.3f);
 			skeletonNode->setTimeScale(0.3f);
 		else
 		else

+ 4 - 2
spine-cocos2dx/example/Classes/GoblinsExample.cpp

@@ -54,8 +54,10 @@ bool GoblinsExample::init () {
 	
 	
 	EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
 	EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
 	listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool {
 	listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool {
-		if (!skeletonNode->getDebugBonesEnabled())
-			skeletonNode->setDebugBonesEnabled(true);
+		if (!skeletonNode->getDebugBonesEnabled()) {
+			skeletonNode->setDebugBonesEnabled(true);
+			skeletonNode->setDebugBoundingRectEnabled(true);
+		}
 		else if (skeletonNode->getTimeScale() == 1)
 		else if (skeletonNode->getTimeScale() == 1)
 			skeletonNode->setTimeScale(0.3f);
 			skeletonNode->setTimeScale(0.3f);
 		else
 		else

+ 2 - 1
spine-cocos2dx/example/Classes/RaptorExample.cpp

@@ -66,7 +66,8 @@ bool RaptorExample::init () {
 	listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool {
 	listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool {
 		if (!skeletonNode->getDebugBonesEnabled()) {
 		if (!skeletonNode->getDebugBonesEnabled()) {
 			skeletonNode->setDebugBonesEnabled(true);
 			skeletonNode->setDebugBonesEnabled(true);
-			skeletonNode->setDebugMeshesEnabled(true);
+			skeletonNode->setDebugMeshesEnabled(true);
+			skeletonNode->setDebugBoundingRectEnabled(true);
 		} else if (skeletonNode->getTimeScale() == 1)
 		} else if (skeletonNode->getTimeScale() == 1)
 			skeletonNode->setTimeScale(0.3f);
 			skeletonNode->setTimeScale(0.3f);
 		else
 		else

+ 9 - 2
spine-cocos2dx/example/Classes/SkeletonRendererSeparatorExample.cpp

@@ -77,8 +77,15 @@ bool SkeletonRendererSeparatorExample::init () {
 	
 	
 	EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
 	EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
 	listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool {
 	listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool {
-		if (!backNode->getDebugBonesEnabled())
-			backNode->setDebugBonesEnabled(true);
+		if (!backNode->getDebugBonesEnabled())
+		{
+			backNode->setDebugBonesEnabled(true);
+			backNode->setDebugSlotsEnabled(true);
+			backNode->setDebugBoundingRectEnabled(true);
+			frontNode->setDebugBonesEnabled(true);
+			frontNode->setDebugSlotsEnabled(true);
+			frontNode->setDebugBoundingRectEnabled(true);
+		}
 		else if (backNode->getTimeScale() == 1)
 		else if (backNode->getTimeScale() == 1)
 			backNode->setTimeScale(0.3f);
 			backNode->setTimeScale(0.3f);
 		else
 		else

+ 4 - 2
spine-cocos2dx/example/Classes/SpineboyExample.cpp

@@ -84,8 +84,10 @@ bool SpineboyExample::init () {
 	
 	
 	EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
 	EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
 	listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool {
 	listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool {
-		if (!skeletonNode->getDebugBonesEnabled())
-			skeletonNode->setDebugBonesEnabled(true);
+		if (!skeletonNode->getDebugBonesEnabled()) {
+			skeletonNode->setDebugBonesEnabled(true);
+			skeletonNode->setDebugBoundingRectEnabled(true);
+		}
 		else if (skeletonNode->getTimeScale() == 1)
 		else if (skeletonNode->getTimeScale() == 1)
 			skeletonNode->setTimeScale(0.3f);
 			skeletonNode->setTimeScale(0.3f);
 		else
 		else

+ 5 - 2
spine-cocos2dx/example/Classes/TankExample.cpp

@@ -53,8 +53,11 @@ bool TankExample::init () {
 	
 	
 	EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
 	EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
 	listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool {
 	listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool {
-		if (!skeletonNode->getDebugBonesEnabled())
-			skeletonNode->setDebugBonesEnabled(true);
+		if (!skeletonNode->getDebugBonesEnabled()) {
+			skeletonNode->setDebugBonesEnabled(true);
+			skeletonNode->setDebugSlotsEnabled(true);
+			skeletonNode->setDebugBoundingRectEnabled(true);
+		}
 		else if (skeletonNode->getTimeScale() == 1)
 		else if (skeletonNode->getTimeScale() == 1)
 			skeletonNode->setTimeScale(0.3f);
 			skeletonNode->setTimeScale(0.3f);
 		else
 		else

+ 464 - 291
spine-cocos2dx/src/spine/SkeletonRenderer.cpp

@@ -36,34 +36,32 @@
 #include <spine/Cocos2dAttachmentLoader.h>
 #include <spine/Cocos2dAttachmentLoader.h>
 #include <algorithm>
 #include <algorithm>
 
 
-#define INITIAL_WORLD_VERTICES_LENGTH 1000
-// Used for transforming attachments for bounding boxes & debug rendering
-static float* worldVertices = nullptr;
-static size_t worldVerticesLength = 0;
-
-void ensureWorldVerticesCapacity(size_t capacity) {
-	if (worldVerticesLength < capacity) {
-		float* newWorldVertices = new float[capacity];
-		memcpy(newWorldVertices, worldVertices, capacity * sizeof(float));
-		delete[] worldVertices;
-		worldVertices = newWorldVertices;
-		worldVerticesLength = capacity;
-	}
-}
-
 USING_NS_CC;
 USING_NS_CC;
-using std::min;
-using std::max;
+
 
 
 namespace spine {
 namespace spine {
 
 
-void SkeletonRenderer::destroyScratchBuffers() {
-	if (worldVertices) {
-		delete[] worldVertices;
-		worldVertices = nullptr;
-		worldVerticesLength = 0;
-	}
-}
+
+int computeTotalCoordCount(const spSkeleton& skeleton, int startSlotIndex, int endSlotIndex);
+cocos2d::Rect computeBoundingRect(const float* coords, int vertexCount);
+void interleaveCoordinates(float* dst, const float* src, int vertexCount, int dstStride);
+BlendFunc makeBlendFunc(int blendMode, bool premultipliedAlpha);
+void transformWorldVertices(float* dstCoord, int coordCount, const spSkeleton& skeleton, int startSlotIndex, int endSlotIndex);
+bool cullRectangle(const Mat4 &transform, const cocos2d::Rect& rect, const Camera& camera);
+Color4B spColorToColor4B(const spColor& color);
+bool slotIsOutRange(const spSlot& slot, int startSlotIndex, int endSlotIndex);
+
+
+// C Variable length array
+#ifdef _MSC_VER
+    // VLA not supported, use _alloca
+    #define VLA(type, arr, count) \
+        type* arr = static_cast<type*>( _alloca(sizeof(type) * count) )
+#else
+    #define VLA(type, arr, count) \
+        type arr[count]
+#endif
+
 
 
 SkeletonRenderer* SkeletonRenderer::createWithSkeleton(spSkeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData) {
 SkeletonRenderer* SkeletonRenderer::createWithSkeleton(spSkeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData) {
 	SkeletonRenderer* node = new SkeletonRenderer(skeleton, ownsSkeleton, ownsSkeletonData);
 	SkeletonRenderer* node = new SkeletonRenderer(skeleton, ownsSkeleton, ownsSkeletonData);
@@ -90,11 +88,6 @@ SkeletonRenderer* SkeletonRenderer::createWithFile (const std::string& skeletonD
 }
 }
 
 
 void SkeletonRenderer::initialize () {
 void SkeletonRenderer::initialize () {
-	if (!worldVertices) {
-		worldVertices = new float[INITIAL_WORLD_VERTICES_LENGTH];
-		worldVerticesLength = INITIAL_WORLD_VERTICES_LENGTH;
-	}
-
 	_clipper = spSkeletonClipping_create();
 	_clipper = spSkeletonClipping_create();
 
 
 	_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
 	_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
@@ -144,26 +137,26 @@ void SkeletonRenderer::setSkeletonData (spSkeletonData *skeletonData, bool ownsS
 }
 }
 
 
 SkeletonRenderer::SkeletonRenderer ()
 SkeletonRenderer::SkeletonRenderer ()
-	: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr), _startSlotIndex(-1), _endSlotIndex(-1) {
+	: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _timeScale(1), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
 }
 }
 
 
 SkeletonRenderer::SkeletonRenderer(spSkeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData)
 SkeletonRenderer::SkeletonRenderer(spSkeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData)
-	: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr), _startSlotIndex(-1), _endSlotIndex(-1) {
+	: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _timeScale(1), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
 	initWithSkeleton(skeleton, ownsSkeleton, ownsSkeletonData);
 	initWithSkeleton(skeleton, ownsSkeleton, ownsSkeletonData);
 }
 }
 
 
 SkeletonRenderer::SkeletonRenderer (spSkeletonData *skeletonData, bool ownsSkeletonData)
 SkeletonRenderer::SkeletonRenderer (spSkeletonData *skeletonData, bool ownsSkeletonData)
-	: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr), _startSlotIndex(-1), _endSlotIndex(-1) {
+	: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _timeScale(1), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
 	initWithData(skeletonData, ownsSkeletonData);
 	initWithData(skeletonData, ownsSkeletonData);
 }
 }
 
 
 SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, spAtlas* atlas, float scale)
 SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, spAtlas* atlas, float scale)
-	: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr), _startSlotIndex(-1), _endSlotIndex(-1) {
+	: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _timeScale(1), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
 	initWithJsonFile(skeletonDataFile, atlas, scale);
 	initWithJsonFile(skeletonDataFile, atlas, scale);
 }
 }
 
 
 SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, const std::string& atlasFile, float scale)
 SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, const std::string& atlasFile, float scale)
-	: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr), _startSlotIndex(-1), _endSlotIndex(-1) {
+	: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _timeScale(1), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
 	initWithJsonFile(skeletonDataFile, atlasFile, scale);
 	initWithJsonFile(skeletonDataFile, atlasFile, scale);
 }
 }
 
 
@@ -262,53 +255,68 @@ void SkeletonRenderer::update (float deltaTime) {
 }
 }
 
 
 void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t transformFlags) {
 void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t transformFlags) {
-	SkeletonBatch* batch = SkeletonBatch::getInstance();
-	SkeletonTwoColorBatch* twoColorBatch = SkeletonTwoColorBatch::getInstance();
-	bool isTwoColorTint = this->isTwoColorTint();
+	assert(_skeleton);
 
 
 	// Early exit if the skeleton is invisible
 	// Early exit if the skeleton is invisible
 	if (getDisplayedOpacity() == 0 || _skeleton->color.a == 0){
 	if (getDisplayedOpacity() == 0 || _skeleton->color.a == 0){
 		return;
 		return;
 	}
 	}
 
 
-	if (_effect) _effect->begin(_effect, _skeleton);
+	const int coordCount = computeTotalCoordCount(*_skeleton, _startSlotIndex, _endSlotIndex);
+	if (coordCount == 0)
+	{
+		return;
+	}
+	assert(coordCount % 2 == 0);
 
 
-	Color4F nodeColor;
-	nodeColor.r = getDisplayedColor().r / (float)255;
-	nodeColor.g = getDisplayedColor().g / (float)255;
-	nodeColor.b = getDisplayedColor().b / (float)255;
-	nodeColor.a = getDisplayedOpacity() / (float)255;
+	VLA(float, worldCoords, coordCount);
+	transformWorldVertices(worldCoords, coordCount, *_skeleton, _startSlotIndex, _endSlotIndex);
 
 
-    Color4F color;
-	Color4F darkColor;
-	float darkPremultipliedAlpha = _premultipliedAlpha ? 255 : 0;
+	#if CC_USE_CULLING
+	const Camera* camera = Camera::getVisitingCamera();
+	const cocos2d::Rect brect = computeBoundingRect(worldCoords, coordCount / 2);
+	_boundingRect = brect;
+	if (camera && cullRectangle(transform, brect, *camera))
+	{
+		return;
+	}
+	#endif
+
+	const float* worldCoordPtr = worldCoords;
+	SkeletonBatch* batch = SkeletonBatch::getInstance();
+	SkeletonTwoColorBatch* twoColorBatch = SkeletonTwoColorBatch::getInstance();
+	const bool hasSingleTint = (isTwoColorTint() == false);
+
+	if (_effect) {
+		_effect->begin(_effect, _skeleton);
+	}
+
+	const Color3B displayedColor = getDisplayedColor();
+	spColor nodeColor;
+	nodeColor.r = displayedColor.r / 255.f;
+	nodeColor.g = displayedColor.g / 255.f;
+	nodeColor.b = displayedColor.b / 255.f;
+	nodeColor.a = getDisplayedOpacity() / 255.f;
+
+	spColor color;
+	spColor darkColor;
+	const float darkPremultipliedAlpha = _premultipliedAlpha ? 1.f : 0;
 	AttachmentVertices* attachmentVertices = nullptr;
 	AttachmentVertices* attachmentVertices = nullptr;
 	TwoColorTrianglesCommand* lastTwoColorTrianglesCommand = nullptr;
 	TwoColorTrianglesCommand* lastTwoColorTrianglesCommand = nullptr;
-	bool inRange = _startSlotIndex != -1 || _endSlotIndex != -1 ? false : true;
 	for (int i = 0, n = _skeleton->slotsCount; i < n; ++i) {
 	for (int i = 0, n = _skeleton->slotsCount; i < n; ++i) {
 		spSlot* slot = _skeleton->drawOrder[i];
 		spSlot* slot = _skeleton->drawOrder[i];
 
 
-		if (_startSlotIndex >= 0 && _startSlotIndex == slot->data->index) {
-			inRange = true;
-		}
-
-		if (!inRange) {
+		if (!slot->attachment) {
 			spSkeletonClipping_clipEnd(_clipper, slot);
 			spSkeletonClipping_clipEnd(_clipper, slot);
 			continue;
 			continue;
 		}
 		}
 
 
-		if (_endSlotIndex >= 0 && _endSlotIndex == slot->data->index) {
-			inRange = false;
-		}
-
-		if (!slot->attachment) {
+		if (slotIsOutRange(*slot, _startSlotIndex, _endSlotIndex)) {
 			spSkeletonClipping_clipEnd(_clipper, slot);
 			spSkeletonClipping_clipEnd(_clipper, slot);
 			continue;
 			continue;
 		}
 		}
-
 		// Early exit if slot is invisible
 		// Early exit if slot is invisible
 		if (slot->color.a == 0) {
 		if (slot->color.a == 0) {
-			spSkeletonClipping_clipEnd(_clipper, slot);
 			continue;
 			continue;
 		}
 		}
 
 
@@ -317,58 +325,66 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
 
 
 		switch (slot->attachment->type) {
 		switch (slot->attachment->type) {
 		case SP_ATTACHMENT_REGION: {
 		case SP_ATTACHMENT_REGION: {
-			spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
-			attachmentVertices = getAttachmentVertices(attachment);
-
+			spRegionAttachment* attachment = reinterpret_cast<spRegionAttachment*>(slot->attachment);
 			// Early exit if attachment is invisible
 			// Early exit if attachment is invisible
 			if (attachment->color.a == 0) {
 			if (attachment->color.a == 0) {
 				spSkeletonClipping_clipEnd(_clipper, slot);
 				spSkeletonClipping_clipEnd(_clipper, slot);
 				continue;
 				continue;
 			}
 			}
+			attachmentVertices = getAttachmentVertices(attachment);
 
 
-			if (!isTwoColorTint) {
+			float* dstTriangleVertices = nullptr;
+			int dstStride = 0; // in floats
+			if (hasSingleTint) {
 				triangles.indices = attachmentVertices->_triangles->indices;
 				triangles.indices = attachmentVertices->_triangles->indices;
 				triangles.indexCount = attachmentVertices->_triangles->indexCount;
 				triangles.indexCount = attachmentVertices->_triangles->indexCount;
 				triangles.verts = batch->allocateVertices(attachmentVertices->_triangles->vertCount);
 				triangles.verts = batch->allocateVertices(attachmentVertices->_triangles->vertCount);
 				triangles.vertCount = attachmentVertices->_triangles->vertCount;
 				triangles.vertCount = attachmentVertices->_triangles->vertCount;
-				memcpy(triangles.verts, attachmentVertices->_triangles->verts, sizeof(cocos2d::V3F_C4B_T2F) * attachmentVertices->_triangles->vertCount);
-				spRegionAttachment_computeWorldVertices(attachment, slot->bone, (float*)triangles.verts, 0, 6);
+				assert(triangles.vertCount == 4);
+				std::memcpy(triangles.verts, attachmentVertices->_triangles->verts, sizeof(cocos2d::V3F_C4B_T2F) * attachmentVertices->_triangles->vertCount);
+				dstStride = sizeof(V3F_C4B_T2F) / sizeof(float);
+				dstTriangleVertices = reinterpret_cast<float*>(triangles.verts);
 			} else {
 			} else {
 				trianglesTwoColor.indices = attachmentVertices->_triangles->indices;
 				trianglesTwoColor.indices = attachmentVertices->_triangles->indices;
 				trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount;
 				trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount;
 				trianglesTwoColor.verts = twoColorBatch->allocateVertices(attachmentVertices->_triangles->vertCount);
 				trianglesTwoColor.verts = twoColorBatch->allocateVertices(attachmentVertices->_triangles->vertCount);
 				trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount;
 				trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount;
+				assert(trianglesTwoColor.vertCount == 4);
 				for (int i = 0; i < trianglesTwoColor.vertCount; i++) {
 				for (int i = 0; i < trianglesTwoColor.vertCount; i++) {
 					trianglesTwoColor.verts[i].texCoords = attachmentVertices->_triangles->verts[i].texCoords;
 					trianglesTwoColor.verts[i].texCoords = attachmentVertices->_triangles->verts[i].texCoords;
 				}
 				}
-				spRegionAttachment_computeWorldVertices(attachment, slot->bone, (float*)trianglesTwoColor.verts, 0, 7);
+				dstTriangleVertices = reinterpret_cast<float*>(trianglesTwoColor.verts);
+				dstStride = sizeof(V3F_C4B_C4B_T2F) / sizeof(float);
 			}
 			}
+			// Copy world vertices to triangle vertices
+			interleaveCoordinates(dstTriangleVertices, worldCoordPtr, 4, dstStride);
+			worldCoordPtr += 8;
 
 
-            color.r = attachment->color.r;
-			color.g = attachment->color.g;
-			color.b = attachment->color.b;
-			color.a = attachment->color.a;
+			color = attachment->color;
 
 
 			break;
 			break;
 		}
 		}
 		case SP_ATTACHMENT_MESH: {
 		case SP_ATTACHMENT_MESH: {
-			spMeshAttachment* attachment = (spMeshAttachment*)slot->attachment;
-			attachmentVertices = getAttachmentVertices(attachment);
-
+			spMeshAttachment* attachment = reinterpret_cast<spMeshAttachment*>(slot->attachment);
 			// Early exit if attachment is invisible
 			// Early exit if attachment is invisible
 			if (attachment->color.a == 0) {
 			if (attachment->color.a == 0) {
 				spSkeletonClipping_clipEnd(_clipper, slot);
 				spSkeletonClipping_clipEnd(_clipper, slot);
 				continue;
 				continue;
 			}
 			}
+			attachmentVertices = getAttachmentVertices(attachment);
 
 
-			if (!isTwoColorTint) {
+			float* dstTriangleVertices = nullptr;
+			int dstStride = 0; // in floats
+			int dstVertexCount = 0;
+			if (hasSingleTint) {
 				triangles.indices = attachmentVertices->_triangles->indices;
 				triangles.indices = attachmentVertices->_triangles->indices;
 				triangles.indexCount = attachmentVertices->_triangles->indexCount;
 				triangles.indexCount = attachmentVertices->_triangles->indexCount;
 				triangles.verts = batch->allocateVertices(attachmentVertices->_triangles->vertCount);
 				triangles.verts = batch->allocateVertices(attachmentVertices->_triangles->vertCount);
 				triangles.vertCount = attachmentVertices->_triangles->vertCount;
 				triangles.vertCount = attachmentVertices->_triangles->vertCount;
-				memcpy(triangles.verts, attachmentVertices->_triangles->verts, sizeof(cocos2d::V3F_C4B_T2F) * attachmentVertices->_triangles->vertCount);
-				int vertexSizeInFloats = sizeof(cocos2d::V3F_C4B_T2F) / sizeof(float);
-				spVertexAttachment_computeWorldVertices(SUPER(attachment), slot, 0, attachment->super.worldVerticesLength, (float*)triangles.verts, 0, vertexSizeInFloats);
+				std::memcpy(triangles.verts, attachmentVertices->_triangles->verts, sizeof(cocos2d::V3F_C4B_T2F) * attachmentVertices->_triangles->vertCount);
+				dstTriangleVertices = (float*)triangles.verts;
+				dstStride = sizeof(V3F_C4B_T2F) / sizeof(float);
+				dstVertexCount = triangles.vertCount;
 			} else {
 			} else {
 				trianglesTwoColor.indices = attachmentVertices->_triangles->indices;
 				trianglesTwoColor.indices = attachmentVertices->_triangles->indices;
 				trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount;
 				trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount;
@@ -377,19 +393,21 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
 				for (int i = 0; i < trianglesTwoColor.vertCount; i++) {
 				for (int i = 0; i < trianglesTwoColor.vertCount; i++) {
 					trianglesTwoColor.verts[i].texCoords = attachmentVertices->_triangles->verts[i].texCoords;
 					trianglesTwoColor.verts[i].texCoords = attachmentVertices->_triangles->verts[i].texCoords;
 				}
 				}
-				int vertexSizeInFloats = sizeof(V3F_C4B_C4B_T2F) / sizeof(float);
-				spVertexAttachment_computeWorldVertices(SUPER(attachment), slot, 0, attachment->super.worldVerticesLength, (float*)trianglesTwoColor.verts, 0, vertexSizeInFloats);
+				dstTriangleVertices = (float*)trianglesTwoColor.verts;
+				dstStride = sizeof(V3F_C4B_C4B_T2F) / sizeof(float);
+				dstVertexCount = trianglesTwoColor.vertCount;
 			}
 			}
 
 
-			color.r = attachment->color.r;
-			color.g = attachment->color.g;
-			color.b = attachment->color.b;
-			color.a = attachment->color.a;
+			// Copy world vertices to triangle vertices
+			assert(dstVertexCount * 2 == attachment->super.worldVerticesLength);
+			interleaveCoordinates(dstTriangleVertices, worldCoordPtr, dstVertexCount, dstStride);
+			worldCoordPtr += dstVertexCount * 2;
 
 
+			color = attachment->color;
 			break;
 			break;
 		}
 		}
 		case SP_ATTACHMENT_CLIPPING: {
 		case SP_ATTACHMENT_CLIPPING: {
-			spClippingAttachment* clip = (spClippingAttachment*)slot->attachment;
+			spClippingAttachment* clip = reinterpret_cast<spClippingAttachment*>(slot->attachment);
 			spSkeletonClipping_clipStart(_clipper, slot, clip);
 			spSkeletonClipping_clipStart(_clipper, slot, clip);
 			continue;
 			continue;
 		}
 		}
@@ -398,54 +416,35 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
 			continue;
 			continue;
 		}
 		}
 
 
-		float alpha = nodeColor.a * _skeleton->color.a * slot->color.a * color.a * 255;
-		// skip rendering if the color of this attachment is 0
-		if (alpha == 0){
-			spSkeletonClipping_clipEnd(_clipper, slot);
-			continue;
-		}
-		float multiplier = _premultipliedAlpha ? alpha : 255;
-		
-		float red = nodeColor.r * _skeleton->color.r * slot->color.r * multiplier;
-		float green = nodeColor.g * _skeleton->color.g * slot->color.g * multiplier;
-		float blue = nodeColor.b * _skeleton->color.b * slot->color.b * multiplier;
-		
-		color.r = red * color.r;
-		color.g = green * color.g;
-		color.b = blue * color.b;
-		color.a = alpha;
-		
 		if (slot->darkColor) {
 		if (slot->darkColor) {
-			darkColor.r = red * slot->darkColor->r;
-			darkColor.g = green * slot->darkColor->g;
-			darkColor.b = blue * slot->darkColor->b;
+			darkColor = *slot->darkColor;
 		} else {
 		} else {
 			darkColor.r = 0;
 			darkColor.r = 0;
 			darkColor.g = 0;
 			darkColor.g = 0;
 			darkColor.b = 0;
 			darkColor.b = 0;
 		}
 		}
 		darkColor.a = darkPremultipliedAlpha;
 		darkColor.a = darkPremultipliedAlpha;
-
-		BlendFunc blendFunc;
-		switch (slot->data->blendMode) {
-			case SP_BLEND_MODE_ADDITIVE:
-				blendFunc.src = _premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
-				blendFunc.dst = GL_ONE;
-				break;
-			case SP_BLEND_MODE_MULTIPLY:
-				blendFunc.src = GL_DST_COLOR;
-				blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
-				break;
-			case SP_BLEND_MODE_SCREEN:
-				blendFunc.src = GL_ONE;
-				blendFunc.dst = GL_ONE_MINUS_SRC_COLOR;
-				break;
-			default:
-				blendFunc.src = _premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
-				blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
+		color.a *= nodeColor.a * _skeleton->color.a * slot->color.a;
+		// skip rendering if the color of this attachment is 0
+		if (color.a == 0){
+			spSkeletonClipping_clipEnd(_clipper, slot);
+			continue;
+		}
+		color.r *= nodeColor.r * _skeleton->color.r * slot->color.r;
+		color.g *= nodeColor.g * _skeleton->color.g * slot->color.g;
+		color.b *= nodeColor.b * _skeleton->color.b * slot->color.b;
+		if (_premultipliedAlpha)
+		{
+			color.r *= color.a;
+			color.g *= color.a;
+			color.b *= color.a;
 		}
 		}
 
 
-		if (!isTwoColorTint) {
+		const cocos2d::Color4B color4B = spColorToColor4B(color);
+		const cocos2d::Color4B darkColor4B = spColorToColor4B(darkColor);
+		const BlendFunc blendFunc = makeBlendFunc(slot->data->blendMode, _premultipliedAlpha);
+
+		if (hasSingleTint) {
 			if (spSkeletonClipping_isClipping(_clipper)) {
 			if (spSkeletonClipping_isClipping(_clipper)) {
 				spSkeletonClipping_clipTriangles(_clipper, (float*)&triangles.verts[0].vertices, triangles.vertCount * sizeof(cocos2d::V3F_C4B_T2F) / 4, triangles.indices, triangles.indexCount, (float*)&triangles.verts[0].texCoords, 6);
 				spSkeletonClipping_clipTriangles(_clipper, (float*)&triangles.verts[0].vertices, triangles.vertCount * sizeof(cocos2d::V3F_C4B_T2F) / 4, triangles.indices, triangles.indexCount, (float*)&triangles.verts[0].texCoords, 6);
 				batch->deallocateVertices(triangles.vertCount);
 				batch->deallocateVertices(triangles.vertCount);
@@ -458,80 +457,60 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
 				triangles.vertCount = _clipper->clippedVertices->size >> 1;
 				triangles.vertCount = _clipper->clippedVertices->size >> 1;
 				triangles.verts = batch->allocateVertices(triangles.vertCount);
 				triangles.verts = batch->allocateVertices(triangles.vertCount);
 				triangles.indexCount = _clipper->clippedTriangles->size;
 				triangles.indexCount = _clipper->clippedTriangles->size;
-				triangles.indices = batch->allocateIndices(triangles.indexCount);
-				memcpy(triangles.indices, _clipper->clippedTriangles->items, sizeof(unsigned short) * _clipper->clippedTriangles->size);
+				triangles.indices =
+				batch->allocateIndices(triangles.indexCount);
+				std::memcpy(triangles.indices, _clipper->clippedTriangles->items, sizeof(unsigned short) * _clipper->clippedTriangles->size);
 
 
 				cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _glProgramState, blendFunc, triangles, transform, transformFlags);
 				cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _glProgramState, blendFunc, triangles, transform, transformFlags);
 
 
-				float* verts = _clipper->clippedVertices->items;
-				float* uvs = _clipper->clippedUVs->items;
+				const float* verts = _clipper->clippedVertices->items;
+				const float* uvs = _clipper->clippedUVs->items;
 				if (_effect) {
 				if (_effect) {
-					spColor light;
-					spColor dark;
-					light.r = color.r / 255.0f;
-					light.g = color.g / 255.0f;
-					light.b = color.b / 255.0f;
-					light.a = color.a / 255.0f;
-					dark.r = dark.g = dark.b = dark.a = 0;
-					for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv+=2) {
-						V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;
-						spColor lightCopy = light;
-						spColor darkCopy = dark;
+					V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts;
+					spColor darkTmp;
+					for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv+=2, ++vertex) {
+						spColor lightCopy = color;
 						vertex->vertices.x = verts[vv];
 						vertex->vertices.x = verts[vv];
 						vertex->vertices.y = verts[vv + 1];
 						vertex->vertices.y = verts[vv + 1];
 						vertex->texCoords.u = uvs[vv];
 						vertex->texCoords.u = uvs[vv];
 						vertex->texCoords.v = uvs[vv + 1];
 						vertex->texCoords.v = uvs[vv + 1];
-						_effect->transform(_effect, &vertex->vertices.x, &vertex->vertices.y, &vertex->texCoords.u, &vertex->texCoords.v, &lightCopy, &darkCopy);
-						vertex->colors.r = (GLubyte)(lightCopy.r * 255);
-						vertex->colors.g = (GLubyte)(lightCopy.g * 255);
-						vertex->colors.b = (GLubyte)(lightCopy.b * 255);
-						vertex->colors.a = (GLubyte)(lightCopy.a * 255);
+						_effect->transform(_effect, &vertex->vertices.x, &vertex->vertices.y, &vertex->texCoords.u, &vertex->texCoords.v, &lightCopy, &darkTmp);
+						vertex->colors = spColorToColor4B(lightCopy);
 					}
 					}
 				} else {
 				} else {
-					for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv+=2) {
-						V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;
+					const cocos2d::Color4B color4B = spColorToColor4B(color);
+					V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts;
+					for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv+=2, ++vertex) {
 						vertex->vertices.x = verts[vv];
 						vertex->vertices.x = verts[vv];
 						vertex->vertices.y = verts[vv + 1];
 						vertex->vertices.y = verts[vv + 1];
 						vertex->texCoords.u = uvs[vv];
 						vertex->texCoords.u = uvs[vv];
 						vertex->texCoords.v = uvs[vv + 1];
 						vertex->texCoords.v = uvs[vv + 1];
-						vertex->colors.r = (GLubyte)color.r;
-						vertex->colors.g = (GLubyte)color.g;
-						vertex->colors.b = (GLubyte)color.b;
-						vertex->colors.a = (GLubyte)color.a;
+						vertex->colors = color4B;
 					}
 					}
 				}
 				}
 			} else {
 			} else {
+				// Not clipping
+
 				cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _glProgramState, blendFunc, triangles, transform, transformFlags);
 				cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _glProgramState, blendFunc, triangles, transform, transformFlags);
 
 
 				if (_effect) {
 				if (_effect) {
-					spColor light;
-					spColor dark;
-					light.r = color.r / 255.0f;
-					light.g = color.g / 255.0f;
-					light.b = color.b / 255.0f;
-					light.a = color.a / 255.0f;
-					dark.r = dark.g = dark.b = dark.a = 0;
-					for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v) {
-						V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;
-						spColor lightCopy = light;
-						spColor darkCopy = dark;
-						_effect->transform(_effect, &vertex->vertices.x, &vertex->vertices.y, &vertex->texCoords.u, &vertex->texCoords.v, &lightCopy, &darkCopy);
-						vertex->colors.r = (GLubyte)(lightCopy.r * 255);
-						vertex->colors.g = (GLubyte)(lightCopy.g * 255);
-						vertex->colors.b = (GLubyte)(lightCopy.b * 255);
-						vertex->colors.a = (GLubyte)(lightCopy.a * 255);
+					V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts;
+					spColor darkTmp;
+					for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v, ++vertex) {
+						spColor lightCopy = color;
+						_effect->transform(_effect, &vertex->vertices.x, &vertex->vertices.y, &vertex->texCoords.u, &vertex->texCoords.v, &lightCopy, &darkTmp);
+						vertex->colors = spColorToColor4B(lightCopy);
 					}
 					}
 				} else {
 				} else {
-					for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v) {
-						V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;
-						vertex->colors.r = (GLubyte)color.r;
-						vertex->colors.g = (GLubyte)color.g;
-						vertex->colors.b = (GLubyte)color.b;
-						vertex->colors.a = (GLubyte)color.a;
+					V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts;
+					for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v, ++vertex) {
+						vertex->colors = color4B;
 					}
 					}
 				}
 				}
 			}
 			}
 		} else {
 		} else {
+			// Two tints
+
 			if (spSkeletonClipping_isClipping(_clipper)) {
 			if (spSkeletonClipping_isClipping(_clipper)) {
 				spSkeletonClipping_clipTriangles(_clipper, (float*)&trianglesTwoColor.verts[0].position, trianglesTwoColor.vertCount * sizeof(V3F_C4B_C4B_T2F) / 4, trianglesTwoColor.indices, trianglesTwoColor.indexCount, (float*)&trianglesTwoColor.verts[0].texCoords, 7);
 				spSkeletonClipping_clipTriangles(_clipper, (float*)&trianglesTwoColor.verts[0].position, trianglesTwoColor.vertCount * sizeof(V3F_C4B_C4B_T2F) / 4, trianglesTwoColor.indices, trianglesTwoColor.indexCount, (float*)&trianglesTwoColor.verts[0].texCoords, 7);
 				twoColorBatch->deallocateVertices(trianglesTwoColor.vertCount);
 				twoColorBatch->deallocateVertices(trianglesTwoColor.vertCount);
@@ -545,99 +524,54 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
 				trianglesTwoColor.verts = twoColorBatch->allocateVertices(trianglesTwoColor.vertCount);
 				trianglesTwoColor.verts = twoColorBatch->allocateVertices(trianglesTwoColor.vertCount);
 				trianglesTwoColor.indexCount = _clipper->clippedTriangles->size;
 				trianglesTwoColor.indexCount = _clipper->clippedTriangles->size;
 				trianglesTwoColor.indices = twoColorBatch->allocateIndices(trianglesTwoColor.indexCount);
 				trianglesTwoColor.indices = twoColorBatch->allocateIndices(trianglesTwoColor.indexCount);
-				memcpy(trianglesTwoColor.indices, _clipper->clippedTriangles->items, sizeof(unsigned short) * _clipper->clippedTriangles->size);
+				std::memcpy(trianglesTwoColor.indices, _clipper->clippedTriangles->items, sizeof(unsigned short) * _clipper->clippedTriangles->size);
 
 
 				TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags);
 				TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags);
 
 
-				float* verts = _clipper->clippedVertices->items;
-				float* uvs = _clipper->clippedUVs->items;
+				const float* verts = _clipper->clippedVertices->items;
+				const float* uvs = _clipper->clippedUVs->items;
 
 
 				if (_effect) {
 				if (_effect) {
-					spColor light;
-					spColor dark;
-					light.r = color.r / 255.0f;
-					light.g = color.g / 255.0f;
-					light.b = color.b / 255.0f;
-					light.a = color.a / 255.0f;
-					dark.r = darkColor.r / 255.0f;
-					dark.g = darkColor.g / 255.0f;
-					dark.b = darkColor.b / 255.0f;
-					dark.a = darkColor.a / 255.0f;
-					for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv += 2) {
-						V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;
-						spColor lightCopy = light;
-						spColor darkCopy = dark;
+					V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts;
+					for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv += 2, ++vertex) {
+						spColor lightCopy = color;
+						spColor darkCopy = darkColor;
 						vertex->position.x = verts[vv];
 						vertex->position.x = verts[vv];
 						vertex->position.y = verts[vv + 1];
 						vertex->position.y = verts[vv + 1];
 						vertex->texCoords.u = uvs[vv];
 						vertex->texCoords.u = uvs[vv];
 						vertex->texCoords.v = uvs[vv + 1];
 						vertex->texCoords.v = uvs[vv + 1];
 						_effect->transform(_effect, &vertex->position.x, &vertex->position.y, &vertex->texCoords.u, &vertex->texCoords.v, &lightCopy, &darkCopy);
 						_effect->transform(_effect, &vertex->position.x, &vertex->position.y, &vertex->texCoords.u, &vertex->texCoords.v, &lightCopy, &darkCopy);
-						vertex->color.r = (GLubyte)(lightCopy.r * 255);
-						vertex->color.g = (GLubyte)(lightCopy.g * 255);
-						vertex->color.b = (GLubyte)(lightCopy.b * 255);
-						vertex->color.a = (GLubyte)(lightCopy.a * 255);
-						vertex->color2.r = (GLubyte)(darkCopy.r * 255);
-						vertex->color2.g = (GLubyte)(darkCopy.g * 255);
-						vertex->color2.b = (GLubyte)(darkCopy.b * 255);
-						vertex->color2.a = (GLubyte)darkColor.a;
+						vertex->color = spColorToColor4B(lightCopy);
+						vertex->color2 = spColorToColor4B(darkCopy);
 					}
 					}
 				} else {
 				} else {
-					for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv += 2) {
-						V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;
+					V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts;
+					for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv += 2, ++vertex) {
 						vertex->position.x = verts[vv];
 						vertex->position.x = verts[vv];
 						vertex->position.y = verts[vv + 1];
 						vertex->position.y = verts[vv + 1];
 						vertex->texCoords.u = uvs[vv];
 						vertex->texCoords.u = uvs[vv];
 						vertex->texCoords.v = uvs[vv + 1];
 						vertex->texCoords.v = uvs[vv + 1];
-						vertex->color.r = (GLubyte)color.r;
-						vertex->color.g = (GLubyte)color.g;
-						vertex->color.b = (GLubyte)color.b;
-						vertex->color.a = (GLubyte)color.a;
-						vertex->color2.r = (GLubyte)darkColor.r;
-						vertex->color2.g = (GLubyte)darkColor.g;
-						vertex->color2.b = (GLubyte)darkColor.b;
-						vertex->color2.a = (GLubyte)darkColor.a;
+						vertex->color = color4B;
+						vertex->color2 = darkColor4B;
 					}
 					}
 				}
 				}
 			} else {
 			} else {
 				TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags);
 				TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags);
 
 
 				if (_effect) {
 				if (_effect) {
-					spColor light;
-					spColor dark;
-					light.r = color.r / 255.0f;
-					light.g = color.g / 255.0f;
-					light.b = color.b / 255.0f;
-					light.a = color.a / 255.0f;
-					dark.r = darkColor.r / 255.0f;
-					dark.g = darkColor.g / 255.0f;
-					dark.b = darkColor.b / 255.0f;
-					dark.a = darkColor.a / 255.0f;
-
-					for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v) {
-						V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;
-						spColor lightCopy = light;
-						spColor darkCopy = dark;
+					V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts;
+					for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v, ++vertex) {
+						spColor lightCopy = color;
+						spColor darkCopy = darkColor;
 						_effect->transform(_effect, &vertex->position.x, &vertex->position.y, &vertex->texCoords.u, &vertex->texCoords.v, &lightCopy, &darkCopy);
 						_effect->transform(_effect, &vertex->position.x, &vertex->position.y, &vertex->texCoords.u, &vertex->texCoords.v, &lightCopy, &darkCopy);
-						vertex->color.r = (GLubyte)(lightCopy.r * 255);
-						vertex->color.g = (GLubyte)(lightCopy.g * 255);
-						vertex->color.b = (GLubyte)(lightCopy.b * 255);
-						vertex->color.a = (GLubyte)(lightCopy.a * 255);
-						vertex->color2.r = (GLubyte)(darkCopy.r * 255);
-						vertex->color2.g = (GLubyte)(darkCopy.g * 255);
-						vertex->color2.b = (GLubyte)(darkCopy.b * 255);
-						vertex->color2.a = (GLubyte)darkColor.a;
+						vertex->color = spColorToColor4B(lightCopy);
+						vertex->color2 = spColorToColor4B(darkCopy);
 					}
 					}
 				} else {
 				} else {
-					for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v) {
-						V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;
-						vertex->color.r = (GLubyte)color.r;
-						vertex->color.g = (GLubyte)color.g;
-						vertex->color.b = (GLubyte)color.b;
-						vertex->color.a = (GLubyte)color.a;
-						vertex->color2.r = (GLubyte)darkColor.r;
-						vertex->color2.g = (GLubyte)darkColor.g;
-						vertex->color2.b = (GLubyte)darkColor.b;
-						vertex->color2.a = (GLubyte)darkColor.a;
+					V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts;
+					for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v, ++vertex) {
+						vertex->color = color4B;
+						vertex->color2 = darkColor4B;
 					}
 					}
 				}
 				}
 			}
 			}
@@ -683,10 +617,12 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
 		}
 		}
 	}
 	}
 
 
-	if (_effect) _effect->end(_effect);
+	if (_effect) {
+		_effect->end(_effect);
+	}
 
 
-	if (_debugSlots || _debugBones || _debugMeshes) {
-        drawDebug(renderer, transform, transformFlags);
+	if (_debugBoundingRect || _debugSlots || _debugBones || _debugMeshes) {
+		drawDebug(renderer, transform, transformFlags);
 	}
 	}
 }
 }
 
 
@@ -698,29 +634,52 @@ void SkeletonRenderer::drawDebug (Renderer* renderer, const Mat4 &transform, uin
 
 
     DrawNode* drawNode = DrawNode::create();
     DrawNode* drawNode = DrawNode::create();
 
 
+    // Draw bounding rectangle
+    if (_debugBoundingRect) {
+        glLineWidth(2);
+        const cocos2d::Rect brect = getBoundingBox();
+        const Vec2 points[4] =
+        {
+            brect.origin,
+            { brect.origin.x + brect.size.width, brect.origin.y },
+            { brect.origin.x + brect.size.width, brect.origin.y + brect.size.height },
+            { brect.origin.x, brect.origin.y + brect.size.height }
+        };
+        drawNode->drawPoly(points, 4, true, Color4F::GREEN);
+    }
+
     if (_debugSlots) {
     if (_debugSlots) {
         // Slots.
         // Slots.
         // DrawPrimitives::setDrawColor4B(0, 0, 255, 255);
         // DrawPrimitives::setDrawColor4B(0, 0, 255, 255);
         glLineWidth(1);
         glLineWidth(1);
-        Vec2 points[4];
         V3F_C4B_T2F_Quad quad;
         V3F_C4B_T2F_Quad quad;
         for (int i = 0, n = _skeleton->slotsCount; i < n; i++) {
         for (int i = 0, n = _skeleton->slotsCount; i < n; i++) {
             spSlot* slot = _skeleton->drawOrder[i];
             spSlot* slot = _skeleton->drawOrder[i];
-            if (!slot->attachment || slot->attachment->type != SP_ATTACHMENT_REGION) continue;
+            if (!slot->attachment || slot->attachment->type != SP_ATTACHMENT_REGION) {
+                continue;
+            }
+            if (slotIsOutRange(*slot, _startSlotIndex, _endSlotIndex)) {
+                continue;
+            }
             spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
             spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
+            float worldVertices[8];
             spRegionAttachment_computeWorldVertices(attachment, slot->bone, worldVertices, 0, 2);
             spRegionAttachment_computeWorldVertices(attachment, slot->bone, worldVertices, 0, 2);
-            points[0] = Vec2(worldVertices[0], worldVertices[1]);
-            points[1] = Vec2(worldVertices[2], worldVertices[3]);
-            points[2] = Vec2(worldVertices[4], worldVertices[5]);
-            points[3] = Vec2(worldVertices[6], worldVertices[7]);
+            const Vec2 points[4] =
+            {
+                { worldVertices[0], worldVertices[1] },
+                { worldVertices[2], worldVertices[3] },
+                { worldVertices[4], worldVertices[5] },
+                { worldVertices[6], worldVertices[7] }
+            };
             drawNode->drawPoly(points, 4, true, Color4F::BLUE);
             drawNode->drawPoly(points, 4, true, Color4F::BLUE);
         }
         }
     }
     }
+
     if (_debugBones) {
     if (_debugBones) {
         // Bone lengths.
         // Bone lengths.
         glLineWidth(2);
         glLineWidth(2);
         for (int i = 0, n = _skeleton->bonesCount; i < n; i++) {
         for (int i = 0, n = _skeleton->bonesCount; i < n; i++) {
-            spBone *bone = _skeleton->bones[i];
+            const spBone *bone = _skeleton->bones[i];
             float x = bone->data->length * bone->a + bone->worldX;
             float x = bone->data->length * bone->a + bone->worldX;
             float y = bone->data->length * bone->c + bone->worldY;
             float y = bone->data->length * bone->c + bone->worldY;
             drawNode->drawLine(Vec2(bone->worldX, bone->worldY), Vec2(x, y), Color4F::RED);
             drawNode->drawLine(Vec2(bone->worldX, bone->worldY), Vec2(x, y), Color4F::RED);
@@ -728,7 +687,7 @@ void SkeletonRenderer::drawDebug (Renderer* renderer, const Mat4 &transform, uin
         // Bone origins.
         // Bone origins.
         auto color = Color4F::BLUE; // Root bone is blue.
         auto color = Color4F::BLUE; // Root bone is blue.
         for (int i = 0, n = _skeleton->bonesCount; i < n; i++) {
         for (int i = 0, n = _skeleton->bonesCount; i < n; i++) {
-            spBone *bone = _skeleton->bones[i];
+            const spBone *bone = _skeleton->bones[i];
             drawNode->drawPoint(Vec2(bone->worldX, bone->worldY), 4, color);
             drawNode->drawPoint(Vec2(bone->worldX, bone->worldY), 4, color);
             if (i == 0) color = Color4F::GREEN;
             if (i == 0) color = Color4F::GREEN;
         }
         }
@@ -741,15 +700,20 @@ void SkeletonRenderer::drawDebug (Renderer* renderer, const Mat4 &transform, uin
 			spSlot* slot = _skeleton->drawOrder[i];
 			spSlot* slot = _skeleton->drawOrder[i];
 			if (!slot->attachment || slot->attachment->type != SP_ATTACHMENT_MESH) continue;
 			if (!slot->attachment || slot->attachment->type != SP_ATTACHMENT_MESH) continue;
 			spMeshAttachment* attachment = (spMeshAttachment*)slot->attachment;
 			spMeshAttachment* attachment = (spMeshAttachment*)slot->attachment;
-			ensureWorldVerticesCapacity(attachment->super.worldVerticesLength);
-			spVertexAttachment_computeWorldVertices(SUPER(attachment), slot, 0, attachment->super.worldVerticesLength, worldVertices, 0, 2);
-			for (int ii = 0; ii < attachment->trianglesCount;) {
-				Vec2 v1(worldVertices + (attachment->triangles[ii++] * 2));
-				Vec2 v2(worldVertices + (attachment->triangles[ii++] * 2));
-				Vec2 v3(worldVertices + (attachment->triangles[ii++] * 2));
-				drawNode->drawLine(v1, v2, Color4F::YELLOW);
-				drawNode->drawLine(v2, v3, Color4F::YELLOW);
-				drawNode->drawLine(v3, v1, Color4F::YELLOW);
+			VLA(float, worldCoord, attachment->super.worldVerticesLength);
+			spVertexAttachment_computeWorldVertices(SUPER(attachment), slot, 0, attachment->super.worldVerticesLength, worldCoord, 0, 2);
+			for (int t = 0; t < attachment->trianglesCount; t += 3) {
+				// Fetch triangle indices
+				const int idx0 = attachment->triangles[t + 0];
+				const int idx1 = attachment->triangles[t + 1];
+				const int idx2 = attachment->triangles[t + 2];
+				const Vec2 v[3] =
+				{
+					worldCoord + (idx0 * 2),
+					worldCoord + (idx1 * 2),
+					worldCoord + (idx2 * 2)
+				};
+				drawNode->drawPoly(v, 3, true, Color4F::YELLOW);
 			}
 			}
 		}
 		}
 
 
@@ -767,35 +731,8 @@ AttachmentVertices* SkeletonRenderer::getAttachmentVertices (spMeshAttachment* a
 	return (AttachmentVertices*)attachment->rendererObject;
 	return (AttachmentVertices*)attachment->rendererObject;
 }
 }
 
 
-Rect SkeletonRenderer::getBoundingBox () const {
-	float minX = FLT_MAX, minY = FLT_MAX, maxX = -FLT_MAX, maxY = -FLT_MAX;
-	float scaleX = getScaleX(), scaleY = getScaleY();
-	for (int i = 0; i < _skeleton->slotsCount; ++i) {
-		spSlot* slot = _skeleton->slots[i];
-		if (!slot->attachment) continue;
-		int verticesCount;
-		if (slot->attachment->type == SP_ATTACHMENT_REGION) {
-			spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
-			spRegionAttachment_computeWorldVertices(attachment, slot->bone, worldVertices, 0, 2);
-			verticesCount = 8;
-		} else if (slot->attachment->type == SP_ATTACHMENT_MESH) {
-			spMeshAttachment* mesh = (spMeshAttachment*)slot->attachment;
-			ensureWorldVerticesCapacity(mesh->super.worldVerticesLength);
-			spVertexAttachment_computeWorldVertices(SUPER(mesh), slot, 0, mesh->super.worldVerticesLength, worldVertices, 0, 2);
-			verticesCount = mesh->super.worldVerticesLength;
-		} else
-			continue;
-		for (int ii = 0; ii < verticesCount; ii += 2) {
-			float x = worldVertices[ii] * scaleX, y = worldVertices[ii + 1] * scaleY;
-			minX = min(minX, x);
-			minY = min(minY, y);
-			maxX = max(maxX, x);
-			maxY = max(maxY, y);
-		}
-	}
-	Vec2 position = getPosition();
-    if (minX == FLT_MAX) minX = minY = maxX = maxY = 0;
-	return Rect(position.x + minX, position.y + minY, maxX - minX, maxY - minY);
+cocos2d::Rect SkeletonRenderer::getBoundingBox () const {
+	return _boundingRect;
 }
 }
 
 
 // --- Convenience methods for Skeleton_* functions.
 // --- Convenience methods for Skeleton_* functions.
@@ -852,11 +789,11 @@ void SkeletonRenderer::setVertexEffect(spVertexEffect *effect) {
 }
 }
 
 
 void SkeletonRenderer::setSlotsRange(int startSlotIndex, int endSlotIndex) {
 void SkeletonRenderer::setSlotsRange(int startSlotIndex, int endSlotIndex) {
-	this->_startSlotIndex = startSlotIndex;
-	this->_endSlotIndex = endSlotIndex;
+	_startSlotIndex = startSlotIndex == -1 ? 0 : startSlotIndex;
+	_endSlotIndex = endSlotIndex == -1 ? std::numeric_limits<int>::max() : endSlotIndex;
 }
 }
 
 
-spSkeleton* SkeletonRenderer::getSkeleton () {
+spSkeleton* SkeletonRenderer::getSkeleton () const {
 	return _skeleton;
 	return _skeleton;
 }
 }
 
 
@@ -888,6 +825,14 @@ bool SkeletonRenderer::getDebugMeshesEnabled () const {
 	return _debugMeshes;
 	return _debugMeshes;
 }
 }
 
 
+void SkeletonRenderer::setDebugBoundingRectEnabled(bool enabled) {
+    _debugBoundingRect = enabled;
+}
+
+bool SkeletonRenderer::getDebugBoundingRectEnabled() const {
+    return _debugBoundingRect;
+}
+
 void SkeletonRenderer::onEnter () {
 void SkeletonRenderer::onEnter () {
 #if CC_ENABLE_SCRIPT_BINDING
 #if CC_ENABLE_SCRIPT_BINDING
 	if (_scriptType == kScriptTypeJavascript && ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter)) return;
 	if (_scriptType == kScriptTypeJavascript && ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter)) return;
@@ -922,4 +867,232 @@ bool SkeletonRenderer::isOpacityModifyRGB () const {
 	return _premultipliedAlpha;
 	return _premultipliedAlpha;
 }
 }
 
 
+
+    cocos2d::Rect computeBoundingRect(const float* coords, int vertexCount)
+    {
+        assert(coords);
+        assert(vertexCount > 0);
+
+        const float* v = coords;
+        float minX = v[0];
+        float minY = v[1];
+        float maxX = minX;
+        float maxY = minY;
+        for (int i = 1; i < vertexCount; ++i)
+        {
+            v += 2;
+            float x = v[0];
+            float y = v[1];
+            minX = std::min(minX, x);
+            minY = std::min(minY, y);
+            maxX = std::max(maxX, x);
+            maxY = std::max(maxY, y);
+        }
+        return { minX, minY, maxX - minX, maxY - minY };
+    }
+
+    bool slotIsOutRange(const spSlot& slot, int startSlotIndex, int endSlotIndex)
+    {
+        return startSlotIndex > slot.data->index || endSlotIndex < slot.data->index;
+    }
+
+    int computeTotalCoordCount(const spSkeleton& skeleton, int startSlotIndex, int endSlotIndex)
+    {
+        int coordCount = 0;
+        for (int i = 0; i < skeleton.slotsCount; ++i)
+        {
+            const spSlot& slot = *skeleton.slots[i];
+            if (!slot.attachment)
+            {
+                continue;
+            }
+            if (slotIsOutRange(slot, startSlotIndex, endSlotIndex))
+            {
+                continue;
+            }
+            // Early exit if slot is invisible
+            if (slot.color.a == 0) {
+                continue;
+            }
+            if (slot.attachment->type == SP_ATTACHMENT_REGION)
+            {
+                // Early exit if attachment is invisible
+                spRegionAttachment* attachment = reinterpret_cast<spRegionAttachment*>(slot.attachment);
+                if (attachment->color.a == 0) {
+                    continue;
+                }
+                coordCount += 8;
+            }
+            else if (slot.attachment->type == SP_ATTACHMENT_MESH)
+            {
+                const spMeshAttachment* mesh = reinterpret_cast<const spMeshAttachment*>(slot.attachment);
+                // Early exit if attachment is invisible
+                if (mesh->color.a == 0) {
+                    continue;
+                }
+                coordCount += mesh->super.worldVerticesLength;
+            }
+        }
+        return coordCount;
+    }
+
+
+    void transformWorldVertices(float* dstCoord, int coordCount, const spSkeleton& skeleton, int startSlotIndex, int endSlotIndex)
+    {
+        float* dstPtr = dstCoord;
+#ifndef NDEBUG
+        float* const dstEnd = dstCoord + coordCount;
+#endif
+        for (int i = 0; i < skeleton.slotsCount; ++i)
+        {
+            /*const*/ spSlot& slot = *skeleton.drawOrder[i]; // match the draw order of SkeletonRenderer::Draw
+            if (!slot.attachment)
+            {
+                continue;
+            }
+            if (slotIsOutRange(slot, startSlotIndex, endSlotIndex))
+            {
+                continue;
+            }
+            // Early exit if slot is invisible
+            if (slot.color.a == 0) {
+                continue;
+            }
+            if (slot.attachment->type == SP_ATTACHMENT_REGION)
+            {
+                spRegionAttachment* attachment = reinterpret_cast<spRegionAttachment*>(slot.attachment);
+                // Early exit if attachment is invisible
+                if (attachment->color.a == 0) {
+                    continue;
+                }
+                assert(dstPtr + 8 <= dstEnd);
+                spRegionAttachment_computeWorldVertices(attachment, slot.bone, dstPtr, 0, 2);
+                dstPtr += 8;
+            }
+            else if (slot.attachment->type == SP_ATTACHMENT_MESH)
+            {
+                spMeshAttachment* mesh = reinterpret_cast<spMeshAttachment*>(slot.attachment);
+                // Early exit if attachment is invisible
+                if (mesh->color.a == 0) {
+                    continue;
+                }
+                assert(dstPtr + mesh->super.worldVerticesLength <= dstEnd);
+                spVertexAttachment_computeWorldVertices(SUPER(mesh), &slot, 0, mesh->super.worldVerticesLength, dstPtr, 0, 2);
+                dstPtr += mesh->super.worldVerticesLength;
+            }
+        }
+        assert(dstPtr == dstEnd);
+    }
+
+    void interleaveCoordinates(float* __restrict dst, const float* __restrict src, int count, int dstStride)
+    {
+        if (dstStride == 2)
+        {
+            std::memcpy(dst, src, sizeof(float) * count * 2);
+        }
+        else
+        {
+            for (int i = 0; i < count; ++i)
+            {
+                dst[0] = src[0];
+                dst[1] = src[1];
+                dst += dstStride;
+                src += 2;
+            }
+        }
+
+    }
+
+    BlendFunc makeBlendFunc(int blendMode, bool premultipliedAlpha)
+    {
+        BlendFunc blendFunc;
+        switch (blendMode) {
+            case SP_BLEND_MODE_ADDITIVE:
+                blendFunc.src = premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
+                blendFunc.dst = GL_ONE;
+                break;
+            case SP_BLEND_MODE_MULTIPLY:
+                blendFunc.src = GL_DST_COLOR;
+                blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
+                break;
+            case SP_BLEND_MODE_SCREEN:
+                blendFunc.src = GL_ONE;
+                blendFunc.dst = GL_ONE_MINUS_SRC_COLOR;
+                break;
+            default:
+                blendFunc.src = premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
+                blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
+                break;
+        }
+        return blendFunc;
+    }
+
+
+    bool cullRectangle(const Mat4 &transform, const cocos2d::Rect& rect, const Camera& camera)
+    {
+        // Compute rectangle center and half extents in local space
+        // TODO: Pass the bounding rectangle with this representation directly
+        const float halfRectWidth = rect.size.width * 0.5f;
+        const float halfRectHeight = rect.size.height * 0.5f;
+        const float l_cx = rect.origin.x + halfRectWidth;
+        const float l_cy = rect.origin.y + halfRectHeight;
+
+        // Transform rectangle center to world space
+        const float w_cx = (l_cx * transform.m[0] + l_cy * transform.m[4]) + transform.m[12];
+        const float w_cy = (l_cx * transform.m[1] + l_cy * transform.m[5]) + transform.m[13];
+
+        // Compute rectangle half extents in world space
+        const float w_ex = std::abs(halfRectWidth * transform.m[0]) + std::abs(halfRectHeight * transform.m[4]);
+        const float w_ey = std::abs(halfRectWidth * transform.m[1]) + std::abs(halfRectHeight * transform.m[5]);
+
+        // Transform rectangle to clip space
+        const Mat4& viewMatrix = camera.getViewMatrix();
+        const Mat4& projectionMatrix = camera.getProjectionMatrix();
+        const float c_cx = (w_cx + viewMatrix.m[12]) * projectionMatrix.m[0];
+        const float c_cy = (w_cy + viewMatrix.m[13]) * projectionMatrix.m[5];
+        const float c_ex = w_ex * projectionMatrix.m[0];
+        const float c_ey = w_ey * projectionMatrix.m[5];
+        // The rectangle has z == 0 in world space
+        // cw = projectionMatrix[11] * vz = -vz = wz -viewMatrix.m[14] = -viewMatrix.m[14]
+        const float c_w = -viewMatrix.m[14]; // w in clip space
+
+        // For each edge, test the rectangle corner closest to it
+        // If its distance to the edge is negative, the whole rectangle is outside the screen
+        // Note: the test is conservative and can return false positives in some cases
+        // The test is done in clip space [-1, +1]
+        // e.g. left culling <==> (c_cx + c_ex) / cw < -1 <==> (c_cx + c_ex) < -cw
+
+        // Left
+        if (c_cx + c_ex < -c_w)
+        {
+            return true;
+        }
+
+        // Right
+        if (c_cx - c_ex > c_w)
+        {
+            return true;
+        }
+
+        // Bottom
+        if (c_cy + c_ey < -c_w)
+        {
+            return true;
+        }
+
+        // Top
+        if (c_cy - c_ey > c_w)
+        {
+            return true;
+        }
+
+        return false;
+    }
+
+
+    Color4B spColorToColor4B(const spColor& color)
+    {
+        return { (GLubyte)(color.r * 255.f), (GLubyte)(color.g * 255.f), (GLubyte)(color.b * 255.f), (GLubyte)(color.a * 255.f) };
+    }
+
 }
 }

+ 7 - 5
spine-cocos2dx/src/spine/SkeletonRenderer.h

@@ -49,12 +49,11 @@ public:
 
 
 	virtual void update (float deltaTime) override;
 	virtual void update (float deltaTime) override;
 	virtual void draw (cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t transformFlags) override;
 	virtual void draw (cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t transformFlags) override;
-	virtual void drawDebug (cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t transformFlags);
 	virtual cocos2d::Rect getBoundingBox () const override;
 	virtual cocos2d::Rect getBoundingBox () const override;
 	virtual void onEnter () override;
 	virtual void onEnter () override;
 	virtual void onExit () override;
 	virtual void onExit () override;
 
 
-	spSkeleton* getSkeleton();
+	spSkeleton* getSkeleton() const;
 
 
 	void setTimeScale(float scale);
 	void setTimeScale(float scale);
 	float getTimeScale() const;
 	float getTimeScale() const;
@@ -68,6 +67,9 @@ public:
 	
 	
 	void setDebugMeshesEnabled(bool enabled);
 	void setDebugMeshesEnabled(bool enabled);
 	bool getDebugMeshesEnabled() const;
 	bool getDebugMeshesEnabled() const;
+ 
+	void setDebugBoundingRectEnabled(bool enabled);
+	bool getDebugBoundingRectEnabled() const;
 
 
 	// --- Convenience methods for common Skeleton_* functions.
 	// --- Convenience methods for common Skeleton_* functions.
 	void updateWorldTransform ();
 	void updateWorldTransform ();
@@ -113,9 +115,6 @@ public:
 	virtual void setOpacityModifyRGB (bool value) override;
 	virtual void setOpacityModifyRGB (bool value) override;
 	virtual bool isOpacityModifyRGB () const override;
 	virtual bool isOpacityModifyRGB () const override;
 	
 	
-	// Frees global memory used for temporay vertex transformations.
-	static void destroyScratchBuffers();
-
 CC_CONSTRUCTOR_ACCESS:
 CC_CONSTRUCTOR_ACCESS:
 	SkeletonRenderer ();
 	SkeletonRenderer ();
 	SkeletonRenderer(spSkeleton* skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false);
 	SkeletonRenderer(spSkeleton* skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false);
@@ -139,6 +138,7 @@ protected:
 	virtual AttachmentVertices* getAttachmentVertices (spRegionAttachment* attachment) const;
 	virtual AttachmentVertices* getAttachmentVertices (spRegionAttachment* attachment) const;
 	virtual AttachmentVertices* getAttachmentVertices (spMeshAttachment* attachment) const;
 	virtual AttachmentVertices* getAttachmentVertices (spMeshAttachment* attachment) const;
 	void setupGLProgramState(bool twoColorTintEnabled);
 	void setupGLProgramState(bool twoColorTintEnabled);
+	virtual void drawDebug (cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t transformFlags);
 
 
 	bool _ownsSkeletonData;
 	bool _ownsSkeletonData;
 	bool _ownsSkeleton;
 	bool _ownsSkeleton;
@@ -152,8 +152,10 @@ protected:
 	bool _debugSlots;
 	bool _debugSlots;
 	bool _debugBones;
 	bool _debugBones;
 	bool _debugMeshes;
 	bool _debugMeshes;
+	bool _debugBoundingRect;
 	spSkeletonClipping* _clipper;
 	spSkeletonClipping* _clipper;
 	spVertexEffect* _effect;
 	spVertexEffect* _effect;
+	cocos2d::Rect _boundingRect;
 	
 	
 	int _startSlotIndex;
 	int _startSlotIndex;
 	int _endSlotIndex;
 	int _endSlotIndex;

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

@@ -57,7 +57,7 @@ void TwoColorTrianglesCommand::init(float globalOrder, GLuint textureID, GLProgr
 	if(_triangles.indexCount % 3 != 0) {
 	if(_triangles.indexCount % 3 != 0) {
 	int count = _triangles.indexCount;
 	int count = _triangles.indexCount;
 		_triangles.indexCount = count / 3 * 3;
 		_triangles.indexCount = count / 3 * 3;
-		CCLOGERROR("Resize indexCount from %zd to %zd, size must be multiple times of 3", count, _triangles.indexCount);
+		CCLOGERROR("Resize indexCount from %d to %d, size must be multiple times of 3", count, _triangles.indexCount);
 	}
 	}
 	_mv = mv;
 	_mv = mv;