|
@@ -28,7 +28,6 @@
|
|
|
*****************************************************************************/
|
|
|
|
|
|
#include <algorithm>
|
|
|
-#include <spine/AttachmentVertices.h>
|
|
|
#include <spine/Extension.h>
|
|
|
#include <spine/spine-cocos2dx.h>
|
|
|
|
|
@@ -100,34 +99,13 @@ namespace spine {
|
|
|
}
|
|
|
|
|
|
void SkeletonRenderer::setupGLProgramState(bool twoColorTintEnabled) {
|
|
|
- if (twoColorTintEnabled) {
|
|
|
#if COCOS2D_VERSION < 0x00040000
|
|
|
+ if (twoColorTintEnabled) {
|
|
|
setGLProgramState(SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState());
|
|
|
-#endif
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- Texture2D *texture = nullptr;
|
|
|
- for (int i = 0, n = _skeleton->getSlots().size(); i < n; i++) {
|
|
|
- Slot *slot = _skeleton->getDrawOrder()[i];
|
|
|
- Attachment *const attachment = slot->getAttachment();
|
|
|
- if (!attachment) continue;
|
|
|
- if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
|
|
|
- RegionAttachment *regionAttachment = static_cast<RegionAttachment *>(attachment);
|
|
|
- texture = static_cast<AttachmentVertices *>(regionAttachment->getRendererObject())->_texture;
|
|
|
- } else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
|
|
|
- MeshAttachment *meshAttachment = static_cast<MeshAttachment *>(attachment);
|
|
|
- texture = static_cast<AttachmentVertices *>(meshAttachment->getRendererObject())->_texture;
|
|
|
- } else {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- if (texture != nullptr) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-#if COCOS2D_VERSION < 0x00040000
|
|
|
- setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP, texture));
|
|
|
+ setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP, nullptr));
|
|
|
#endif
|
|
|
}
|
|
|
|
|
@@ -290,11 +268,9 @@ namespace spine {
|
|
|
Color color;
|
|
|
Color darkColor;
|
|
|
const float darkPremultipliedAlpha = _premultipliedAlpha ? 1.f : 0;
|
|
|
- AttachmentVertices *attachmentVertices = nullptr;
|
|
|
TwoColorTrianglesCommand *lastTwoColorTrianglesCommand = nullptr;
|
|
|
for (int i = 0, n = _skeleton->getSlots().size(); i < n; ++i) {
|
|
|
Slot *slot = _skeleton->getDrawOrder()[i];
|
|
|
- ;
|
|
|
|
|
|
if (nothingToDraw(*slot, _startSlotIndex, _endSlotIndex)) {
|
|
|
_clipper->clipEnd(*slot);
|
|
@@ -303,31 +279,39 @@ namespace spine {
|
|
|
|
|
|
cocos2d::TrianglesCommand::Triangles triangles;
|
|
|
TwoColorTriangles trianglesTwoColor;
|
|
|
+ static unsigned short quadIndices[6] = {0, 1, 2, 2, 3, 0};
|
|
|
+ Texture2D *texture = nullptr;
|
|
|
|
|
|
if (slot->getAttachment()->getRTTI().isExactly(RegionAttachment::rtti)) {
|
|
|
RegionAttachment *attachment = static_cast<RegionAttachment *>(slot->getAttachment());
|
|
|
- attachmentVertices = static_cast<AttachmentVertices *>(attachment->getRendererObject());
|
|
|
+ texture = (Texture2D*)((AtlasRegion*)attachment->getRegion())->page->getRendererObject();
|
|
|
|
|
|
float *dstTriangleVertices = nullptr;
|
|
|
int dstStride = 0;// in floats
|
|
|
if (hasSingleTint) {
|
|
|
- triangles.indices = attachmentVertices->_triangles->indices;
|
|
|
- triangles.indexCount = attachmentVertices->_triangles->indexCount;
|
|
|
- triangles.verts = batch->allocateVertices(attachmentVertices->_triangles->vertCount);
|
|
|
- triangles.vertCount = attachmentVertices->_triangles->vertCount;
|
|
|
+ triangles.indices = quadIndices;
|
|
|
+ triangles.indexCount = 6;
|
|
|
+ triangles.verts = batch->allocateVertices(4);
|
|
|
+ triangles.vertCount = 4;
|
|
|
assert(triangles.vertCount == 4);
|
|
|
- memcpy(triangles.verts, attachmentVertices->_triangles->verts, sizeof(cocos2d::V3F_C4B_T2F) * attachmentVertices->_triangles->vertCount);
|
|
|
+ for (int v = 0, i = 0; v < triangles.vertCount; v++, i += 2) {
|
|
|
+ auto &texCoords = triangles.verts[v].texCoords;
|
|
|
+ texCoords.u = attachment->getUVs()[i];
|
|
|
+ texCoords.v = attachment->getUVs()[i + 1];
|
|
|
+ }
|
|
|
dstStride = sizeof(V3F_C4B_T2F) / sizeof(float);
|
|
|
dstTriangleVertices = reinterpret_cast<float *>(triangles.verts);
|
|
|
} else {
|
|
|
- trianglesTwoColor.indices = attachmentVertices->_triangles->indices;
|
|
|
- trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount;
|
|
|
- trianglesTwoColor.verts = twoColorBatch->allocateVertices(attachmentVertices->_triangles->vertCount);
|
|
|
- trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount;
|
|
|
+ trianglesTwoColor.indices = quadIndices;
|
|
|
+ trianglesTwoColor.indexCount = 6;
|
|
|
+ trianglesTwoColor.verts = twoColorBatch->allocateVertices(4);
|
|
|
+ trianglesTwoColor.vertCount = 4;
|
|
|
assert(trianglesTwoColor.vertCount == 4);
|
|
|
- for (int v = 0; v < trianglesTwoColor.vertCount; v++) {
|
|
|
- trianglesTwoColor.verts[v].texCoords = attachmentVertices->_triangles->verts[v].texCoords;
|
|
|
- }
|
|
|
+ for (int v = 0, i = 0; v < trianglesTwoColor.vertCount; v++, i += 2) {
|
|
|
+ auto &texCoords = trianglesTwoColor.verts[v].texCoords;
|
|
|
+ texCoords.u = attachment->getUVs()[i];
|
|
|
+ texCoords.v = attachment->getUVs()[i + 1];
|
|
|
+ }
|
|
|
dstTriangleVertices = reinterpret_cast<float *>(trianglesTwoColor.verts);
|
|
|
dstStride = sizeof(V3F_C4B_C4B_T2F) / sizeof(float);
|
|
|
}
|
|
@@ -338,28 +322,34 @@ namespace spine {
|
|
|
color = attachment->getColor();
|
|
|
} else if (slot->getAttachment()->getRTTI().isExactly(MeshAttachment::rtti)) {
|
|
|
MeshAttachment *attachment = (MeshAttachment *) slot->getAttachment();
|
|
|
- attachmentVertices = (AttachmentVertices *) attachment->getRendererObject();
|
|
|
+ texture = (Texture2D*)((AtlasRegion*)attachment->getRegion())->page->getRendererObject();
|
|
|
|
|
|
float *dstTriangleVertices = nullptr;
|
|
|
int dstStride = 0;// in floats
|
|
|
int dstVertexCount = 0;
|
|
|
if (hasSingleTint) {
|
|
|
- triangles.indices = attachmentVertices->_triangles->indices;
|
|
|
- triangles.indexCount = attachmentVertices->_triangles->indexCount;
|
|
|
- triangles.verts = batch->allocateVertices(attachmentVertices->_triangles->vertCount);
|
|
|
- triangles.vertCount = attachmentVertices->_triangles->vertCount;
|
|
|
- memcpy(triangles.verts, attachmentVertices->_triangles->verts, sizeof(cocos2d::V3F_C4B_T2F) * attachmentVertices->_triangles->vertCount);
|
|
|
+ triangles.indices = attachment->getTriangles().buffer();
|
|
|
+ triangles.indexCount = (unsigned short)attachment->getTriangles().size();
|
|
|
+ triangles.verts = batch->allocateVertices(attachment->getWorldVerticesLength() / 2);
|
|
|
+ triangles.vertCount = attachment->getWorldVerticesLength() / 2;
|
|
|
+ for (int v = 0, i = 0; v < triangles.vertCount; v++, i += 2) {
|
|
|
+ auto &texCoords = triangles.verts[v].texCoords;
|
|
|
+ texCoords.u = attachment->getUVs()[i];
|
|
|
+ texCoords.v = attachment->getUVs()[i + 1];
|
|
|
+ }
|
|
|
dstTriangleVertices = (float *) triangles.verts;
|
|
|
dstStride = sizeof(V3F_C4B_T2F) / sizeof(float);
|
|
|
dstVertexCount = triangles.vertCount;
|
|
|
} else {
|
|
|
- trianglesTwoColor.indices = attachmentVertices->_triangles->indices;
|
|
|
- trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount;
|
|
|
- trianglesTwoColor.verts = twoColorBatch->allocateVertices(attachmentVertices->_triangles->vertCount);
|
|
|
- trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount;
|
|
|
- for (int v = 0; v < trianglesTwoColor.vertCount; v++) {
|
|
|
- trianglesTwoColor.verts[v].texCoords = attachmentVertices->_triangles->verts[v].texCoords;
|
|
|
- }
|
|
|
+ trianglesTwoColor.indices = attachment->getTriangles().buffer();
|
|
|
+ trianglesTwoColor.indexCount = (unsigned short)attachment->getTriangles().size();
|
|
|
+ trianglesTwoColor.verts = twoColorBatch->allocateVertices(attachment->getWorldVerticesLength() / 2);
|
|
|
+ trianglesTwoColor.vertCount = attachment->getWorldVerticesLength() / 2;
|
|
|
+ for (int v = 0, i = 0; v < trianglesTwoColor.vertCount; v++, i += 2) {
|
|
|
+ auto &texCoords = trianglesTwoColor.verts[v].texCoords;
|
|
|
+ texCoords.u = attachment->getUVs()[i];
|
|
|
+ texCoords.v = attachment->getUVs()[i + 1];
|
|
|
+ }
|
|
|
dstTriangleVertices = (float *) trianglesTwoColor.verts;
|
|
|
dstStride = sizeof(V3F_C4B_C4B_T2F) / sizeof(float);
|
|
|
dstVertexCount = trianglesTwoColor.vertCount;
|
|
@@ -405,7 +395,7 @@ namespace spine {
|
|
|
|
|
|
const cocos2d::Color4B color4B = ColorToColor4B(color);
|
|
|
const cocos2d::Color4B darkColor4B = ColorToColor4B(darkColor);
|
|
|
- const BlendFunc blendFunc = makeBlendFunc(slot->getData().getBlendMode(), attachmentVertices->_texture->hasPremultipliedAlpha());
|
|
|
+ const BlendFunc blendFunc = makeBlendFunc(slot->getData().getBlendMode(), texture->hasPremultipliedAlpha());
|
|
|
_blendFunc = blendFunc;
|
|
|
|
|
|
if (hasSingleTint) {
|
|
@@ -421,14 +411,13 @@ namespace spine {
|
|
|
triangles.vertCount = _clipper->getClippedVertices().size() / 2;
|
|
|
triangles.verts = batch->allocateVertices(triangles.vertCount);
|
|
|
triangles.indexCount = _clipper->getClippedTriangles().size();
|
|
|
- triangles.indices =
|
|
|
- batch->allocateIndices(triangles.indexCount);
|
|
|
+ triangles.indices = batch->allocateIndices(triangles.indexCount);
|
|
|
memcpy(triangles.indices, _clipper->getClippedTriangles().buffer(), sizeof(unsigned short) * _clipper->getClippedTriangles().size());
|
|
|
|
|
|
#if COCOS2D_VERSION < 0x00040000
|
|
|
- cocos2d::TrianglesCommand *batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _glProgramState, blendFunc, triangles, transform, transformFlags);
|
|
|
+ cocos2d::TrianglesCommand *batchedTriangles = batch->addCommand(renderer, _globalZOrder, texture, _glProgramState, blendFunc, triangles, transform, transformFlags);
|
|
|
#else
|
|
|
- cocos2d::TrianglesCommand *batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _programState, blendFunc, triangles, transform, transformFlags);
|
|
|
+ cocos2d::TrianglesCommand *batchedTriangles = batch->addCommand(renderer, _globalZOrder, texture, _programState, blendFunc, triangles, transform, transformFlags);
|
|
|
#endif
|
|
|
|
|
|
const float *verts = _clipper->getClippedVertices().buffer();
|
|
@@ -444,9 +433,9 @@ namespace spine {
|
|
|
} else {
|
|
|
// Not clipping.
|
|
|
#if COCOS2D_VERSION < 0x00040000
|
|
|
- cocos2d::TrianglesCommand *batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _glProgramState, blendFunc, triangles, transform, transformFlags);
|
|
|
+ cocos2d::TrianglesCommand *batchedTriangles = batch->addCommand(renderer, _globalZOrder, texture, _glProgramState, blendFunc, triangles, transform, transformFlags);
|
|
|
#else
|
|
|
- cocos2d::TrianglesCommand *batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _programState, blendFunc, triangles, transform, transformFlags);
|
|
|
+ cocos2d::TrianglesCommand *batchedTriangles = batch->addCommand(renderer, _globalZOrder, texture, _programState, blendFunc, triangles, transform, transformFlags);
|
|
|
#endif
|
|
|
V3F_C4B_T2F *vertex = batchedTriangles->getTriangles().verts;
|
|
|
for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v, ++vertex) {
|
|
@@ -472,9 +461,9 @@ namespace spine {
|
|
|
memcpy(trianglesTwoColor.indices, _clipper->getClippedTriangles().buffer(), sizeof(unsigned short) * _clipper->getClippedTriangles().size());
|
|
|
|
|
|
#if COCOS2D_VERSION < 0x00040000
|
|
|
- TwoColorTrianglesCommand *batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags);
|
|
|
+ TwoColorTrianglesCommand *batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags);
|
|
|
#else
|
|
|
- TwoColorTrianglesCommand *batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _programState, blendFunc, trianglesTwoColor, transform, transformFlags);
|
|
|
+ TwoColorTrianglesCommand *batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, texture, _programState, blendFunc, trianglesTwoColor, transform, transformFlags);
|
|
|
#endif
|
|
|
|
|
|
const float *verts = _clipper->getClippedVertices().buffer();
|
|
@@ -492,9 +481,9 @@ namespace spine {
|
|
|
} else {
|
|
|
|
|
|
#if COCOS2D_VERSION < 0x00040000
|
|
|
- TwoColorTrianglesCommand *batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags);
|
|
|
+ TwoColorTrianglesCommand *batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags);
|
|
|
#else
|
|
|
- TwoColorTrianglesCommand *batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _programState, blendFunc, trianglesTwoColor, transform, transformFlags);
|
|
|
+ TwoColorTrianglesCommand *batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, texture, _programState, blendFunc, trianglesTwoColor, transform, transformFlags);
|
|
|
#endif
|
|
|
|
|
|
V3F_C4B_C4B_T2F *vertex = batchedTriangles->getTriangles().verts;
|