mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 09:46:02 +08:00
[cocos2dx] Tint black did not work, didn't multiple dark color with skeleton/attachment color. Closes #1158.
This commit is contained in:
parent
a578be88e0
commit
ce536558e5
@ -266,6 +266,11 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
|||||||
SkeletonTwoColorBatch* twoColorBatch = SkeletonTwoColorBatch::getInstance();
|
SkeletonTwoColorBatch* twoColorBatch = SkeletonTwoColorBatch::getInstance();
|
||||||
bool isTwoColorTint = this->isTwoColorTint();
|
bool isTwoColorTint = this->isTwoColorTint();
|
||||||
|
|
||||||
|
// Early exit if the skeleton is invisible
|
||||||
|
if (getDisplayedOpacity() == 0 || _skeleton->color.a == 0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_effect) _effect->begin(_effect, _skeleton);
|
if (_effect) _effect->begin(_effect, _skeleton);
|
||||||
|
|
||||||
Color4F nodeColor;
|
Color4F nodeColor;
|
||||||
@ -276,7 +281,6 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
|||||||
|
|
||||||
Color4F color;
|
Color4F color;
|
||||||
Color4F darkColor;
|
Color4F darkColor;
|
||||||
float darkPremultipliedAlpha = _premultipliedAlpha ? 255 : 0;
|
|
||||||
AttachmentVertices* attachmentVertices = nullptr;
|
AttachmentVertices* attachmentVertices = nullptr;
|
||||||
TwoColorTrianglesCommand* lastTwoColorTrianglesCommand = nullptr;
|
TwoColorTrianglesCommand* lastTwoColorTrianglesCommand = nullptr;
|
||||||
bool inRange = _startSlotIndex != -1 || _endSlotIndex != -1 ? false : true;
|
bool inRange = _startSlotIndex != -1 || _endSlotIndex != -1 ? false : true;
|
||||||
@ -301,6 +305,12 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Early exit if slot is invisible
|
||||||
|
if (slot->color.a == 0) {
|
||||||
|
spSkeletonClipping_clipEnd(_clipper, slot);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
cocos2d::TrianglesCommand::Triangles triangles;
|
cocos2d::TrianglesCommand::Triangles triangles;
|
||||||
TwoColorTriangles trianglesTwoColor;
|
TwoColorTriangles trianglesTwoColor;
|
||||||
|
|
||||||
@ -309,6 +319,12 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
|||||||
spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
|
spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
|
||||||
attachmentVertices = getAttachmentVertices(attachment);
|
attachmentVertices = getAttachmentVertices(attachment);
|
||||||
|
|
||||||
|
// Early exit if attachment is invisible
|
||||||
|
if (attachment->color.a == 0) {
|
||||||
|
spSkeletonClipping_clipEnd(_clipper, slot);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isTwoColorTint) {
|
if (!isTwoColorTint) {
|
||||||
triangles.indices = attachmentVertices->_triangles->indices;
|
triangles.indices = attachmentVertices->_triangles->indices;
|
||||||
triangles.indexCount = attachmentVertices->_triangles->indexCount;
|
triangles.indexCount = attachmentVertices->_triangles->indexCount;
|
||||||
@ -338,6 +354,12 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
|||||||
spMeshAttachment* attachment = (spMeshAttachment*)slot->attachment;
|
spMeshAttachment* attachment = (spMeshAttachment*)slot->attachment;
|
||||||
attachmentVertices = getAttachmentVertices(attachment);
|
attachmentVertices = getAttachmentVertices(attachment);
|
||||||
|
|
||||||
|
// Early exit if attachment is invisible
|
||||||
|
if (attachment->color.a == 0) {
|
||||||
|
spSkeletonClipping_clipEnd(_clipper, slot);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isTwoColorTint) {
|
if (!isTwoColorTint) {
|
||||||
triangles.indices = attachmentVertices->_triangles->indices;
|
triangles.indices = attachmentVertices->_triangles->indices;
|
||||||
triangles.indexCount = attachmentVertices->_triangles->indexCount;
|
triangles.indexCount = attachmentVertices->_triangles->indexCount;
|
||||||
@ -375,27 +397,33 @@ 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 = slot->darkColor->r * 255;
|
darkColor.r = red * slot->darkColor->r;
|
||||||
darkColor.g = slot->darkColor->g * 255;
|
darkColor.g = green * slot->darkColor->g;
|
||||||
darkColor.b = slot->darkColor->b * 255;
|
darkColor.b = blue * slot->darkColor->b;
|
||||||
} 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 = _premultipliedAlpha ? 255 : 0;
|
||||||
|
|
||||||
color.a *= nodeColor.a * _skeleton->color.a * slot->color.a * 255;
|
|
||||||
// skip rendering if the color of this attachment is 0
|
|
||||||
if (color.a == 0){
|
|
||||||
spSkeletonClipping_clipEnd(_clipper, slot);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
float multiplier = _premultipliedAlpha ? color.a : 255;
|
|
||||||
color.r *= nodeColor.r * _skeleton->color.r * slot->color.r * multiplier;
|
|
||||||
color.g *= nodeColor.g * _skeleton->color.g * slot->color.g * multiplier;
|
|
||||||
color.b *= nodeColor.b * _skeleton->color.b * slot->color.b * multiplier;
|
|
||||||
|
|
||||||
BlendFunc blendFunc;
|
BlendFunc blendFunc;
|
||||||
switch (slot->data->blendMode) {
|
switch (slot->data->blendMode) {
|
||||||
@ -533,7 +561,7 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
|||||||
dark.r = darkColor.r / 255.0f;
|
dark.r = darkColor.r / 255.0f;
|
||||||
dark.g = darkColor.g / 255.0f;
|
dark.g = darkColor.g / 255.0f;
|
||||||
dark.b = darkColor.b / 255.0f;
|
dark.b = darkColor.b / 255.0f;
|
||||||
dark.a = darkColor.a / 255.0f;
|
// dark.a = darkColor.a / 255.0f;
|
||||||
for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv += 2) {
|
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 + v;
|
||||||
spColor lightCopy = light;
|
spColor lightCopy = light;
|
||||||
@ -596,7 +624,7 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
|||||||
vertex->color2.r = (GLubyte)(darkCopy.r * 255);
|
vertex->color2.r = (GLubyte)(darkCopy.r * 255);
|
||||||
vertex->color2.g = (GLubyte)(darkCopy.g * 255);
|
vertex->color2.g = (GLubyte)(darkCopy.g * 255);
|
||||||
vertex->color2.b = (GLubyte)(darkCopy.b * 255);
|
vertex->color2.b = (GLubyte)(darkCopy.b * 255);
|
||||||
vertex->color2.a = (GLubyte)darkColor.a;
|
// vertex->color2.a = (GLubyte)darkColor.a;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v) {
|
for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v) {
|
||||||
@ -894,3 +922,4 @@ bool SkeletonRenderer::isOpacityModifyRGB () const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user