|
@@ -77,21 +77,21 @@ void SkeletonRenderer::setSkeletonData (spSkeletonData *skeletonData, bool ownsS
|
|
}
|
|
}
|
|
|
|
|
|
SkeletonRenderer::SkeletonRenderer ()
|
|
SkeletonRenderer::SkeletonRenderer ()
|
|
- : _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1) {
|
|
|
|
|
|
+ : _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr) {
|
|
}
|
|
}
|
|
|
|
|
|
SkeletonRenderer::SkeletonRenderer (spSkeletonData *skeletonData, bool ownsSkeletonData)
|
|
SkeletonRenderer::SkeletonRenderer (spSkeletonData *skeletonData, bool ownsSkeletonData)
|
|
- : _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1) {
|
|
|
|
|
|
+ : _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr) {
|
|
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) {
|
|
|
|
|
|
+ : _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr) {
|
|
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) {
|
|
|
|
|
|
+ : _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr) {
|
|
initWithJsonFile(skeletonDataFile, atlasFile, scale);
|
|
initWithJsonFile(skeletonDataFile, atlasFile, scale);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -183,6 +183,8 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
|
SkeletonBatch* batch = SkeletonBatch::getInstance();
|
|
SkeletonBatch* batch = SkeletonBatch::getInstance();
|
|
SkeletonTwoColorBatch* twoColorBatch = SkeletonTwoColorBatch::getInstance();
|
|
SkeletonTwoColorBatch* twoColorBatch = SkeletonTwoColorBatch::getInstance();
|
|
bool isTwoColorTint = this->isTwoColorTint();
|
|
bool isTwoColorTint = this->isTwoColorTint();
|
|
|
|
+
|
|
|
|
+ if (_effect) _effect->begin(_effect, _skeleton);
|
|
|
|
|
|
Color4F nodeColor;
|
|
Color4F nodeColor;
|
|
nodeColor.r = getDisplayedColor().r / (float)255;
|
|
nodeColor.r = getDisplayedColor().r / (float)255;
|
|
@@ -321,26 +323,70 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
|
|
|
|
|
float* verts = _clipper->clippedVertices->items;
|
|
float* verts = _clipper->clippedVertices->items;
|
|
float* uvs = _clipper->clippedUVs->items;
|
|
float* uvs = _clipper->clippedUVs->items;
|
|
- for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv+=2) {
|
|
|
|
- V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;
|
|
|
|
- vertex->vertices.x = verts[vv];
|
|
|
|
- vertex->vertices.y = verts[vv + 1];
|
|
|
|
- vertex->texCoords.u = uvs[vv];
|
|
|
|
- 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;
|
|
|
|
|
|
+ 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;
|
|
|
|
+ vertex->vertices.x = verts[vv];
|
|
|
|
+ vertex->vertices.y = verts[vv + 1];
|
|
|
|
+ vertex->texCoords.u = uvs[vv];
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv+=2) {
|
|
|
|
+ V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;
|
|
|
|
+ vertex->vertices.x = verts[vv];
|
|
|
|
+ vertex->vertices.y = verts[vv + 1];
|
|
|
|
+ vertex->texCoords.u = uvs[vv];
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
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);
|
|
|
|
|
|
- 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;
|
|
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ } 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;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
@@ -361,34 +407,94 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
|
|
|
|
|
float* verts = _clipper->clippedVertices->items;
|
|
float* verts = _clipper->clippedVertices->items;
|
|
float* uvs = _clipper->clippedUVs->items;
|
|
float* uvs = _clipper->clippedUVs->items;
|
|
- for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv += 2) {
|
|
|
|
- V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;
|
|
|
|
- vertex->position.x = verts[vv];
|
|
|
|
- vertex->position.y = verts[vv + 1];
|
|
|
|
- vertex->texCoords.u = uvs[vv];
|
|
|
|
- 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 = 1;
|
|
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+ vertex->position.x = verts[vv];
|
|
|
|
+ vertex->position.y = verts[vv + 1];
|
|
|
|
+ vertex->texCoords.u = uvs[vv];
|
|
|
|
+ vertex->texCoords.v = uvs[vv + 1];
|
|
|
|
+ _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 = 1;
|
|
|
|
+ }
|
|
|
|
+ } 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;
|
|
|
|
+ vertex->position.x = verts[vv];
|
|
|
|
+ vertex->position.y = verts[vv + 1];
|
|
|
|
+ vertex->texCoords.u = uvs[vv];
|
|
|
|
+ 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 = 1;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} 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);
|
|
|
|
|
|
- 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 = 1;
|
|
|
|
|
|
+ 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;
|
|
|
|
+ _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 = 1;
|
|
|
|
+ }
|
|
|
|
+ } 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 = 1;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -432,6 +538,8 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (_effect) _effect->end(_effect);
|
|
|
|
|
|
if (_debugSlots || _debugBones || _debugMeshes) {
|
|
if (_debugSlots || _debugBones || _debugMeshes) {
|
|
drawDebug(renderer, transform, transformFlags);
|
|
drawDebug(renderer, transform, transformFlags);
|
|
@@ -595,6 +703,10 @@ void SkeletonRenderer::setTwoColorTint(bool enabled) {
|
|
bool SkeletonRenderer::isTwoColorTint() {
|
|
bool SkeletonRenderer::isTwoColorTint() {
|
|
return getGLProgramState() == SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState();
|
|
return getGLProgramState() == SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+void SkeletonRenderer::setVertexEffect(spVertexEffect *effect) {
|
|
|
|
+ this->_effect = effect;
|
|
|
|
+}
|
|
|
|
|
|
spSkeleton* SkeletonRenderer::getSkeleton () {
|
|
spSkeleton* SkeletonRenderer::getSkeleton () {
|
|
return _skeleton;
|
|
return _skeleton;
|