From f06bfd9f1683dd931b79c1c66ac2402502f9f9df Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Mon, 9 Oct 2017 11:44:00 +0200 Subject: [PATCH 1/3] [libgdx] Better exception message for Batch that can't render meshes. --- .../src/com/esotericsoftware/spine/SkeletonRenderer.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java index a60dc87f4..c40e79202 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java @@ -101,9 +101,8 @@ public class SkeletonRenderer { continue; } else if (attachment instanceof MeshAttachment) { - throw new RuntimeException( - "SkeletonRenderer#draw(PolygonSpriteBatch, Skeleton) or #draw(TwoColorPolygonBatch, Skeleton) must be used to " - + "render meshes."); + throw new RuntimeException(batch.getClass().getSimpleName() + + " cannot render meshes, PolygonSpriteBatch or TwoColorPolygonBatch is required."); } else if (attachment instanceof SkeletonAttachment) { Skeleton attachmentSkeleton = ((SkeletonAttachment)attachment).getSkeleton(); From 76f0b208d98bdb24695f0ca1ffe9221dde9d7e5b Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Mon, 9 Oct 2017 11:52:01 +0200 Subject: [PATCH 2/3] Changed SV bg color to match editor default bg color (when gradient is off and square alpha is 0). --- .../src/com/esotericsoftware/spine/SkeletonViewer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/SkeletonViewer.java b/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/SkeletonViewer.java index bcb2bc168..302d269a7 100644 --- a/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/SkeletonViewer.java +++ b/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/SkeletonViewer.java @@ -253,7 +253,7 @@ public class SkeletonViewer extends ApplicationAdapter { } public void render () { - Gdx.gl.glClearColor(0.3f, 0.3f, 0.3f, 1); + Gdx.gl.glClearColor(112 / 255f, 111 / 255f, 118 / 255f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); float delta = Gdx.graphics.getDeltaTime(); From 812510e948cc2c81adcb14b1b307aa60d8a07862 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Mon, 9 Oct 2017 11:52:29 +0200 Subject: [PATCH 3/3] [libgdx] Avoid batch flush when switching between normal and additive rendering with PMA. --- .../spine/SkeletonRenderer.java | 48 +++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java index c40e79202..34642d98a 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java @@ -66,6 +66,7 @@ public class SkeletonRenderer { if (vertexEffect != null) vertexEffect.begin(skeleton); boolean premultipliedAlpha = this.premultipliedAlpha; + BlendMode blendMode = null; float[] vertices = this.vertices.items; Color skeletonColor = skeleton.color; float r = skeletonColor.r, g = skeletonColor.g, b = skeletonColor.b, a = skeletonColor.a; @@ -79,6 +80,17 @@ public class SkeletonRenderer { Color color = region.getColor(), slotColor = slot.getColor(); float alpha = a * slotColor.a * color.a * 255; float multiplier = premultipliedAlpha ? alpha : 255; + + BlendMode slotBlendMode = slot.data.getBlendMode(); + if (slotBlendMode != blendMode) { + if (slotBlendMode == BlendMode.additive && premultipliedAlpha) { + slotBlendMode = BlendMode.normal; + alpha = 0; + } + blendMode = slotBlendMode; + batch.setBlendFunction(blendMode.getSource(premultipliedAlpha), blendMode.getDest()); + } + float c = NumberUtils.intToFloatColor(((int)alpha << 24) // | ((int)(b * slotColor.b * color.b * multiplier) << 16) // | ((int)(g * slotColor.g * color.g * multiplier) << 8) // @@ -92,8 +104,6 @@ public class SkeletonRenderer { if (vertexEffect != null) applyVertexEffect(vertices, 20, 5, c, 0); - BlendMode blendMode = slot.data.getBlendMode(); - batch.setBlendFunction(blendMode.getSource(premultipliedAlpha), blendMode.getDest()); batch.draw(region.getRegion().getTexture(), vertices, 0, 20); } else if (attachment instanceof ClippingAttachment) { @@ -174,17 +184,22 @@ public class SkeletonRenderer { Color slotColor = slot.getColor(); float alpha = a * slotColor.a * color.a * 255; float multiplier = premultipliedAlpha ? alpha : 255; + + BlendMode slotBlendMode = slot.data.getBlendMode(); + if (slotBlendMode != blendMode) { + if (slotBlendMode == BlendMode.additive && premultipliedAlpha) { + slotBlendMode = BlendMode.normal; + alpha = 0; + } + blendMode = slotBlendMode; + batch.setBlendFunction(blendMode.getSource(premultipliedAlpha), blendMode.getDest()); + } + float c = NumberUtils.intToFloatColor(((int)alpha << 24) // | ((int)(b * slotColor.b * color.b * multiplier) << 16) // | ((int)(g * slotColor.g * color.g * multiplier) << 8) // | (int)(r * slotColor.r * color.r * multiplier)); - BlendMode slotBlendMode = slot.data.getBlendMode(); - if (slotBlendMode != blendMode) { - blendMode = slotBlendMode; - batch.setBlendFunction(blendMode.getSource(premultipliedAlpha), blendMode.getDest()); - } - if (clipper.isClipping()) { clipper.clipTriangles(vertices, verticesLength, triangles, triangles.length, uvs, c, 0, false); FloatArray clippedVertices = clipper.getClippedVertices(); @@ -287,6 +302,17 @@ public class SkeletonRenderer { Color lightColor = slot.getColor(); float alpha = a * lightColor.a * color.a * 255; float multiplier = premultipliedAlpha ? alpha : 255; + + BlendMode slotBlendMode = slot.data.getBlendMode(); + if (slotBlendMode != blendMode) { + if (slotBlendMode == BlendMode.additive && premultipliedAlpha) { + slotBlendMode = BlendMode.normal; + alpha = 0; + } + blendMode = slotBlendMode; + batch.setBlendFunction(blendMode.getSource(premultipliedAlpha), blendMode.getDest()); + } + float red = r * color.r * multiplier; float green = g * color.g * multiplier; float blue = b * color.b * multiplier; @@ -300,12 +326,6 @@ public class SkeletonRenderer { | (int)(green * darkColor.g) << 8 // | (int)(red * darkColor.r)); - BlendMode slotBlendMode = slot.data.getBlendMode(); - if (slotBlendMode != blendMode) { - blendMode = slotBlendMode; - batch.setBlendFunction(blendMode.getSource(premultipliedAlpha), blendMode.getDest()); - } - if (clipper.isClipping()) { clipper.clipTriangles(vertices, verticesLength, triangles, triangles.length, uvs, light, dark, true); FloatArray clippedVertices = clipper.getClippedVertices();