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 cdd8e86d6..9efb1affa 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java @@ -30,9 +30,7 @@ package com.esotericsoftware.spine; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch; @@ -273,8 +271,7 @@ public class SkeletonRenderer { BlendMode slotBlendMode = slot.data.getBlendMode(); if (slotBlendMode != blendMode) { blendMode = slotBlendMode; - Gdx.gl.glEnable(GL20.GL_BLEND); - Gdx.gl.glBlendFunc(blendMode.getSource(premultipliedAlpha), blendMode.getDest()); + batch.setBlendFunction(blendMode.getSource(premultipliedAlpha), blendMode.getDest()); } batch.draw(texture, vertices, 0, verticesLength, triangles, 0, triangles.length); } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/TwoColorPolygonBatch.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/TwoColorPolygonBatch.java index dcf322f93..95da0cde9 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/TwoColorPolygonBatch.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/TwoColorPolygonBatch.java @@ -52,6 +52,8 @@ public class TwoColorPolygonBatch { private int vertexIndex, triangleIndex; private Texture lastTexture; private boolean drawing; + private int blendSrcFunc = GL20.GL_SRC_ALPHA; + private int blendDstFunc = GL20.GL_ONE_MINUS_SRC_ALPHA; public TwoColorPolygonBatch (int size) { this(size, size * 2); @@ -128,7 +130,7 @@ public class TwoColorPolygonBatch { mesh.setVertices(vertices, 0, vertexIndex); mesh.setIndices(triangles, 0, triangleIndex); Gdx.gl.glEnable(GL20.GL_BLEND); - + Gdx.gl.glBlendFunc(blendSrcFunc, blendDstFunc); mesh.render(shader, GL20.GL_TRIANGLES, 0, triangleIndex); vertexIndex = 0; @@ -178,6 +180,13 @@ public class TwoColorPolygonBatch { } } + public void setBlendFunction (int srcFunc, int dstFunc) { + if (blendSrcFunc == srcFunc && blendDstFunc == dstFunc) return; + flush(); + blendSrcFunc = srcFunc; + blendDstFunc = dstFunc; + } + private ShaderProgram createDefaultShader () { String vertexShader = "attribute vec4 a_position;\n" // + "attribute vec4 a_light;\n" //