[c][cpp][sfml][cocos2d-x] Skip rendering of skeleton/slot/attachment early if alpha is 0. See #1145

This commit is contained in:
badlogic 2018-07-18 12:04:11 +02:00
parent 046c9b871a
commit 6e83e6aed1
3 changed files with 74 additions and 4 deletions

View File

@ -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;
@ -301,6 +306,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 +320,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 +355,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;

View File

@ -116,6 +116,9 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
states.texture = 0; states.texture = 0;
unsigned short quadIndices[6] = { 0, 1, 2, 2, 3, 0 }; unsigned short quadIndices[6] = { 0, 1, 2, 2, 3, 0 };
// Early out if skeleton is invisible
if (skeleton->color.a == 0) return;
if (vertexEffect != 0) vertexEffect->begin(vertexEffect, skeleton); if (vertexEffect != 0) vertexEffect->begin(vertexEffect, skeleton);
sf::Vertex vertex; sf::Vertex vertex;
@ -125,6 +128,12 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
Attachment* attachment = slot->attachment; Attachment* attachment = slot->attachment;
if (!attachment) continue; if (!attachment) continue;
// Early out if slot is invisible
if (slot->color.a == 0) {
spSkeletonClipping_clipEnd(clipper, slot);
continue;
}
float* vertices = worldVertices; float* vertices = worldVertices;
int verticesCount = 0; int verticesCount = 0;
float* uvs = 0; float* uvs = 0;
@ -134,16 +143,31 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
if (attachment->type == ATTACHMENT_REGION) { if (attachment->type == ATTACHMENT_REGION) {
RegionAttachment* regionAttachment = (RegionAttachment*)attachment; RegionAttachment* regionAttachment = (RegionAttachment*)attachment;
attachmentColor = &regionAttachment->color;
// Early out if slot is invisible
if (attachmentColor->a == 0) {
spSkeletonClipping_clipEnd(clipper, slot);
continue;
}
spRegionAttachment_computeWorldVertices(regionAttachment, slot->bone, vertices, 0, 2); spRegionAttachment_computeWorldVertices(regionAttachment, slot->bone, vertices, 0, 2);
verticesCount = 4; verticesCount = 4;
uvs = regionAttachment->uvs; uvs = regionAttachment->uvs;
indices = quadIndices; indices = quadIndices;
indicesCount = 6; indicesCount = 6;
texture = (Texture*)((AtlasRegion*)regionAttachment->rendererObject)->page->rendererObject; texture = (Texture*)((AtlasRegion*)regionAttachment->rendererObject)->page->rendererObject;
attachmentColor = &regionAttachment->color;
} else if (attachment->type == ATTACHMENT_MESH) { } else if (attachment->type == ATTACHMENT_MESH) {
MeshAttachment* mesh = (MeshAttachment*)attachment; MeshAttachment* mesh = (MeshAttachment*)attachment;
attachmentColor = &mesh->color;
// Early out if slot is invisible
if (attachmentColor->a == 0) {
spSkeletonClipping_clipEnd(clipper, slot);
continue;
}
if (mesh->super.worldVerticesLength > SPINE_MESH_VERTEX_COUNT_MAX) continue; if (mesh->super.worldVerticesLength > SPINE_MESH_VERTEX_COUNT_MAX) continue;
texture = (Texture*)((AtlasRegion*)mesh->rendererObject)->page->rendererObject; texture = (Texture*)((AtlasRegion*)mesh->rendererObject)->page->rendererObject;
spVertexAttachment_computeWorldVertices(SUPER(mesh), slot, 0, mesh->super.worldVerticesLength, worldVertices, 0, 2); spVertexAttachment_computeWorldVertices(SUPER(mesh), slot, 0, mesh->super.worldVerticesLength, worldVertices, 0, 2);
@ -151,7 +175,7 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
uvs = mesh->uvs; uvs = mesh->uvs;
indices = mesh->triangles; indices = mesh->triangles;
indicesCount = mesh->trianglesCount; indicesCount = mesh->trianglesCount;
attachmentColor = &mesh->color;
} else if (attachment->type == SP_ATTACHMENT_CLIPPING) { } else if (attachment->type == SP_ATTACHMENT_CLIPPING) {
spClippingAttachment* clip = (spClippingAttachment*)slot->attachment; spClippingAttachment* clip = (spClippingAttachment*)slot->attachment;
spSkeletonClipping_clipStart(clipper, slot, clip); spSkeletonClipping_clipStart(clipper, slot, clip);

View File

@ -91,6 +91,9 @@ void SkeletonDrawable::draw(RenderTarget &target, RenderStates states) const {
vertexArray->clear(); vertexArray->clear();
states.texture = NULL; states.texture = NULL;
// Early out if the skeleton alpha is 0
if (skeleton->getColor().a == 0) return;
if (vertexEffect != NULL) vertexEffect->begin(*skeleton); if (vertexEffect != NULL) vertexEffect->begin(*skeleton);
sf::Vertex vertex; sf::Vertex vertex;
@ -100,6 +103,12 @@ void SkeletonDrawable::draw(RenderTarget &target, RenderStates states) const {
Attachment *attachment = slot.getAttachment(); Attachment *attachment = slot.getAttachment();
if (!attachment) continue; if (!attachment) continue;
// Early out if the slot color is 0
if (slot.getColor().a == 0) {
clipper.clipEnd(slot);
continue;
}
Vector<float> *vertices = &worldVertices; Vector<float> *vertices = &worldVertices;
int verticesCount = 0; int verticesCount = 0;
Vector<float> *uvs = NULL; Vector<float> *uvs = NULL;
@ -109,6 +118,14 @@ void SkeletonDrawable::draw(RenderTarget &target, RenderStates states) const {
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
RegionAttachment *regionAttachment = (RegionAttachment *) attachment; RegionAttachment *regionAttachment = (RegionAttachment *) attachment;
attachmentColor = &regionAttachment->getColor();
// Early out if the attachment color is 0
if (attachmentColor->a == 0) {
clipper.clipEnd(slot);
continue;
}
worldVertices.setSize(8, 0); worldVertices.setSize(8, 0);
regionAttachment->computeWorldVertices(slot.getBone(), worldVertices, 0, 2); regionAttachment->computeWorldVertices(slot.getBone(), worldVertices, 0, 2);
verticesCount = 4; verticesCount = 4;
@ -116,10 +133,17 @@ void SkeletonDrawable::draw(RenderTarget &target, RenderStates states) const {
indices = &quadIndices; indices = &quadIndices;
indicesCount = 6; indicesCount = 6;
texture = (Texture *) ((AtlasRegion *) regionAttachment->getRendererObject())->page->rendererObject; texture = (Texture *) ((AtlasRegion *) regionAttachment->getRendererObject())->page->rendererObject;
attachmentColor = &regionAttachment->getColor();
} else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { } else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
MeshAttachment *mesh = (MeshAttachment *) attachment; MeshAttachment *mesh = (MeshAttachment *) attachment;
attachmentColor = &mesh->getColor();
// Early out if the attachment color is 0
if (attachmentColor->a == 0) {
clipper.clipEnd(slot);
continue;
}
worldVertices.setSize(mesh->getWorldVerticesLength(), 0); worldVertices.setSize(mesh->getWorldVerticesLength(), 0);
texture = (Texture *) ((AtlasRegion *) mesh->getRendererObject())->page->rendererObject; texture = (Texture *) ((AtlasRegion *) mesh->getRendererObject())->page->rendererObject;
mesh->computeWorldVertices(slot, 0, mesh->getWorldVerticesLength(), worldVertices, 0, 2); mesh->computeWorldVertices(slot, 0, mesh->getWorldVerticesLength(), worldVertices, 0, 2);
@ -127,7 +151,6 @@ void SkeletonDrawable::draw(RenderTarget &target, RenderStates states) const {
uvs = &mesh->getUVs(); uvs = &mesh->getUVs();
indices = &mesh->getTriangles(); indices = &mesh->getTriangles();
indicesCount = mesh->getTriangles().size(); indicesCount = mesh->getTriangles().size();
attachmentColor = &mesh->getColor();
} else if (attachment->getRTTI().isExactly(ClippingAttachment::rtti)) { } else if (attachment->getRTTI().isExactly(ClippingAttachment::rtti)) {
ClippingAttachment *clip = (ClippingAttachment *) slot.getAttachment(); ClippingAttachment *clip = (ClippingAttachment *) slot.getAttachment();
clipper.clipStart(slot, clip); clipper.clipStart(slot, clip);