mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-10 04:36:57 +08:00
[gdx] Update TwoColorPolygonBatch to match latest libgdx changes.
This commit is contained in:
parent
b8ed13f219
commit
12338fa262
@ -67,9 +67,13 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
private int blendDstFuncAlpha = GL20.GL_ONE_MINUS_SRC_ALPHA;
|
private int blendDstFuncAlpha = GL20.GL_ONE_MINUS_SRC_ALPHA;
|
||||||
private boolean premultipliedAlpha;
|
private boolean premultipliedAlpha;
|
||||||
|
|
||||||
private float light = Color.WHITE.toFloatBits();
|
private final Color light = new Color(1, 1, 1, 1);
|
||||||
private float dark = Color.BLACK.toFloatBits();
|
private final Color dark = new Color(0, 0, 0, 1);
|
||||||
private Color tempColor = new Color(1, 1, 1, 1);
|
private float lightPacked = Color.WHITE.toFloatBits();
|
||||||
|
private float darkPacked = Color.BLACK.toFloatBits();
|
||||||
|
|
||||||
|
/** Number of rendering calls, ever. Will not be reset unless set manually. **/
|
||||||
|
public int totalRenderCalls = 0;
|
||||||
|
|
||||||
public TwoColorPolygonBatch () {
|
public TwoColorPolygonBatch () {
|
||||||
this(2000);
|
this(2000);
|
||||||
@ -122,61 +126,53 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setColor (Color tint) {
|
public void setColor (Color tint) {
|
||||||
light = tint.toFloatBits();
|
light.set(tint);
|
||||||
|
lightPacked = tint.toFloatBits();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setColor (float r, float g, float b, float a) {
|
public void setColor (float r, float g, float b, float a) {
|
||||||
int intBits = (int)(255 * a) << 24 | (int)(255 * b) << 16 | (int)(255 * g) << 8 | (int)(255 * r);
|
light.set(r, g, b, a);
|
||||||
light = NumberUtils.intToFloatColor(intBits);
|
lightPacked = light.toFloatBits();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setColor (float color) {
|
public void setPackedColor (float packedColor) {
|
||||||
this.light = color;
|
Color.rgba8888ToColor(light, NumberUtils.floatToIntColor(packedColor));
|
||||||
|
lightPacked = packedColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Color getColor () {
|
public Color getColor () {
|
||||||
int intBits = NumberUtils.floatToIntColor(light);
|
return light;
|
||||||
Color color = this.tempColor;
|
|
||||||
color.r = (intBits & 0xff) / 255f;
|
|
||||||
color.g = ((intBits >>> 8) & 0xff) / 255f;
|
|
||||||
color.b = ((intBits >>> 16) & 0xff) / 255f;
|
|
||||||
color.a = ((intBits >>> 24) & 0xff) / 255f;
|
|
||||||
return color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getPackedColor () {
|
public float getPackedColor () {
|
||||||
return light;
|
return lightPacked;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDarkColor (Color tint) {
|
public void setDarkColor (Color tint) {
|
||||||
dark = tint.toFloatBits();
|
dark.set(tint);
|
||||||
|
darkPacked = tint.toFloatBits();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDarkColor (float r, float g, float b, float a) {
|
public void setDarkColor (float r, float g, float b, float a) {
|
||||||
int intBits = (int)(255 * a) << 24 | (int)(255 * b) << 16 | (int)(255 * g) << 8 | (int)(255 * r);
|
dark.set(r, g, b, a);
|
||||||
dark = NumberUtils.intToFloatColor(intBits);
|
darkPacked = dark.toFloatBits();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDarkColor (float color) {
|
public void setPackedDarkColor (float packedColor) {
|
||||||
this.dark = color;
|
Color.rgba8888ToColor(dark, NumberUtils.floatToIntColor(packedColor));
|
||||||
|
this.darkPacked = packedColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color getDarkColor () {
|
public Color getDarkColor () {
|
||||||
int intBits = NumberUtils.floatToIntColor(dark);
|
return dark;
|
||||||
Color color = this.tempColor;
|
|
||||||
color.r = (intBits & 0xff) / 255f;
|
|
||||||
color.g = ((intBits >>> 8) & 0xff) / 255f;
|
|
||||||
color.b = ((intBits >>> 16) & 0xff) / 255f;
|
|
||||||
color.a = ((intBits >>> 24) & 0xff) / 255f;
|
|
||||||
return color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getPackedDarkColor () {
|
public float getPackedDarkColor () {
|
||||||
return dark;
|
return darkPacked;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Draws a polygon region with the bottom left corner at x,y having the width and height of the region. */
|
/** Draws a polygon region with the bottom left corner at x,y having the width and height of the region. */
|
||||||
@ -193,7 +189,7 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
if (texture != lastTexture)
|
if (texture != lastTexture)
|
||||||
switchTexture(texture);
|
switchTexture(texture);
|
||||||
else if (triangleIndex + regionTrianglesLength > triangles.length
|
else if (triangleIndex + regionTrianglesLength > triangles.length
|
||||||
|| vertexIndex + regionVerticesLength * VERTEX_SIZE / 2 > vertices.length) flush();
|
|| vertexIndex + regionVerticesLength * VERTEX_SIZE / 2 > vertices.length) flush();
|
||||||
|
|
||||||
int triangleIndex = this.triangleIndex;
|
int triangleIndex = this.triangleIndex;
|
||||||
int vertexIndex = this.vertexIndex;
|
int vertexIndex = this.vertexIndex;
|
||||||
@ -204,8 +200,8 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
this.triangleIndex = triangleIndex;
|
this.triangleIndex = triangleIndex;
|
||||||
|
|
||||||
final float[] vertices = this.vertices;
|
final float[] vertices = this.vertices;
|
||||||
final float light = this.light;
|
final float light = this.lightPacked;
|
||||||
final float dark = this.dark;
|
final float dark = this.darkPacked;
|
||||||
final float[] textureCoords = region.getTextureCoords();
|
final float[] textureCoords = region.getTextureCoords();
|
||||||
|
|
||||||
for (int i = 0; i < regionVerticesLength; i += 2) {
|
for (int i = 0; i < regionVerticesLength; i += 2) {
|
||||||
@ -234,7 +230,7 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
if (texture != lastTexture)
|
if (texture != lastTexture)
|
||||||
switchTexture(texture);
|
switchTexture(texture);
|
||||||
else if (triangleIndex + regionTrianglesLength > triangles.length
|
else if (triangleIndex + regionTrianglesLength > triangles.length
|
||||||
|| vertexIndex + regionVerticesLength * VERTEX_SIZE / 2 > vertices.length) flush();
|
|| vertexIndex + regionVerticesLength * VERTEX_SIZE / 2 > vertices.length) flush();
|
||||||
|
|
||||||
int triangleIndex = this.triangleIndex;
|
int triangleIndex = this.triangleIndex;
|
||||||
int vertexIndex = this.vertexIndex;
|
int vertexIndex = this.vertexIndex;
|
||||||
@ -245,8 +241,8 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
this.triangleIndex = triangleIndex;
|
this.triangleIndex = triangleIndex;
|
||||||
|
|
||||||
final float[] vertices = this.vertices;
|
final float[] vertices = this.vertices;
|
||||||
final float light = this.light;
|
final float light = this.lightPacked;
|
||||||
final float dark = this.dark;
|
final float dark = this.darkPacked;
|
||||||
final float[] textureCoords = region.getTextureCoords();
|
final float[] textureCoords = region.getTextureCoords();
|
||||||
final float sX = width / textureRegion.getRegionWidth();
|
final float sX = width / textureRegion.getRegionWidth();
|
||||||
final float sY = height / textureRegion.getRegionHeight();
|
final float sY = height / textureRegion.getRegionHeight();
|
||||||
@ -267,7 +263,7 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
* polygon region should be scaled around originX, originY. Rotation specifies the angle of counter clockwise rotation of the
|
* polygon region should be scaled around originX, originY. Rotation specifies the angle of counter clockwise rotation of the
|
||||||
* rectangle around originX, originY. */
|
* rectangle around originX, originY. */
|
||||||
public void draw (PolygonRegion region, float x, float y, float originX, float originY, float width, float height,
|
public void draw (PolygonRegion region, float x, float y, float originX, float originY, float width, float height,
|
||||||
float scaleX, float scaleY, float rotation) {
|
float scaleX, float scaleY, float rotation) {
|
||||||
if (!drawing) throw new IllegalStateException("begin must be called before draw.");
|
if (!drawing) throw new IllegalStateException("begin must be called before draw.");
|
||||||
|
|
||||||
final short[] triangles = this.triangles;
|
final short[] triangles = this.triangles;
|
||||||
@ -281,7 +277,7 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
if (texture != lastTexture)
|
if (texture != lastTexture)
|
||||||
switchTexture(texture);
|
switchTexture(texture);
|
||||||
else if (triangleIndex + regionTrianglesLength > triangles.length
|
else if (triangleIndex + regionTrianglesLength > triangles.length
|
||||||
|| vertexIndex + regionVerticesLength * VERTEX_SIZE / 2 > vertices.length) flush();
|
|| vertexIndex + regionVerticesLength * VERTEX_SIZE / 2 > vertices.length) flush();
|
||||||
|
|
||||||
int triangleIndex = this.triangleIndex;
|
int triangleIndex = this.triangleIndex;
|
||||||
int vertexIndex = this.vertexIndex;
|
int vertexIndex = this.vertexIndex;
|
||||||
@ -292,8 +288,8 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
this.triangleIndex = triangleIndex;
|
this.triangleIndex = triangleIndex;
|
||||||
|
|
||||||
final float[] vertices = this.vertices;
|
final float[] vertices = this.vertices;
|
||||||
final float light = this.light;
|
final float light = this.lightPacked;
|
||||||
final float dark = this.dark;
|
final float dark = this.darkPacked;
|
||||||
final float[] textureCoords = region.getTextureCoords();
|
final float[] textureCoords = region.getTextureCoords();
|
||||||
|
|
||||||
final float worldOriginX = x + originX;
|
final float worldOriginX = x + originX;
|
||||||
@ -343,7 +339,7 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw (Texture texture, float x, float y, float originX, float originY, float width, float height, float scaleX,
|
public void draw (Texture texture, float x, float y, float originX, float originY, float width, float height, float scaleX,
|
||||||
float scaleY, float rotation, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY) {
|
float scaleY, float rotation, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY) {
|
||||||
if (!drawing) throw new IllegalStateException("begin must be called before draw.");
|
if (!drawing) throw new IllegalStateException("begin must be called before draw.");
|
||||||
|
|
||||||
final short[] triangles = this.triangles;
|
final short[] triangles = this.triangles;
|
||||||
@ -455,8 +451,8 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
v2 = tmp;
|
v2 = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
float light = this.light;
|
float light = this.lightPacked;
|
||||||
float dark = this.dark;
|
float dark = this.darkPacked;
|
||||||
int idx = this.vertexIndex;
|
int idx = this.vertexIndex;
|
||||||
vertices[idx++] = x1;
|
vertices[idx++] = x1;
|
||||||
vertices[idx++] = y1;
|
vertices[idx++] = y1;
|
||||||
@ -490,7 +486,7 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw (Texture texture, float x, float y, float width, float height, int srcX, int srcY, int srcWidth,
|
public void draw (Texture texture, float x, float y, float width, float height, int srcX, int srcY, int srcWidth,
|
||||||
int srcHeight, boolean flipX, boolean flipY) {
|
int srcHeight, boolean flipX, boolean flipY) {
|
||||||
if (!drawing) throw new IllegalStateException("begin must be called before draw.");
|
if (!drawing) throw new IllegalStateException("begin must be called before draw.");
|
||||||
|
|
||||||
final short[] triangles = this.triangles;
|
final short[] triangles = this.triangles;
|
||||||
@ -530,8 +526,8 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
v2 = tmp;
|
v2 = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
float light = this.light;
|
float light = this.lightPacked;
|
||||||
float dark = this.dark;
|
float dark = this.darkPacked;
|
||||||
int idx = this.vertexIndex;
|
int idx = this.vertexIndex;
|
||||||
vertices[idx++] = x;
|
vertices[idx++] = x;
|
||||||
vertices[idx++] = y;
|
vertices[idx++] = y;
|
||||||
@ -592,8 +588,8 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
final float fx2 = x + srcWidth;
|
final float fx2 = x + srcWidth;
|
||||||
final float fy2 = y + srcHeight;
|
final float fy2 = y + srcHeight;
|
||||||
|
|
||||||
float light = this.light;
|
float light = this.lightPacked;
|
||||||
float dark = this.dark;
|
float dark = this.darkPacked;
|
||||||
int idx = this.vertexIndex;
|
int idx = this.vertexIndex;
|
||||||
vertices[idx++] = x;
|
vertices[idx++] = x;
|
||||||
vertices[idx++] = y;
|
vertices[idx++] = y;
|
||||||
@ -650,8 +646,8 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
final float fx2 = x + width;
|
final float fx2 = x + width;
|
||||||
final float fy2 = y + height;
|
final float fy2 = y + height;
|
||||||
|
|
||||||
float light = this.light;
|
float light = this.lightPacked;
|
||||||
float dark = this.dark;
|
float dark = this.darkPacked;
|
||||||
int idx = this.vertexIndex;
|
int idx = this.vertexIndex;
|
||||||
vertices[idx++] = x;
|
vertices[idx++] = x;
|
||||||
vertices[idx++] = y;
|
vertices[idx++] = y;
|
||||||
@ -717,8 +713,8 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
final float u2 = 1;
|
final float u2 = 1;
|
||||||
final float v2 = 0;
|
final float v2 = 0;
|
||||||
|
|
||||||
float light = this.light;
|
float light = this.lightPacked;
|
||||||
float dark = this.dark;
|
float dark = this.darkPacked;
|
||||||
int idx = this.vertexIndex;
|
int idx = this.vertexIndex;
|
||||||
vertices[idx++] = x;
|
vertices[idx++] = x;
|
||||||
vertices[idx++] = y;
|
vertices[idx++] = y;
|
||||||
@ -750,8 +746,9 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
this.vertexIndex = idx;
|
this.vertexIndex = idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Draws a rectangle using the given vertices. There must be 4 vertices, each made up of 6 elements in this order: x, y, lightColor, darkColor,
|
/** Draws a rectangle using the given vertices. There must be 4 vertices, each made up of 6 elements in this order: x, y,
|
||||||
* u, v. The {@link #getColor()} and {@link #getDarkColor()} from the TwoColorPolygonBatch is not applied. */
|
* lightColor, darkColor, u, v. The {@link #getColor()} and {@link #getDarkColor()} from the TwoColorPolygonBatch is not
|
||||||
|
* applied. */
|
||||||
@Override
|
@Override
|
||||||
public void draw (Texture texture, float[] spriteVertices, int offset, int count) {
|
public void draw (Texture texture, float[] spriteVertices, int offset, int count) {
|
||||||
if (!drawing) throw new IllegalStateException("begin must be called before draw.");
|
if (!drawing) throw new IllegalStateException("begin must be called before draw.");
|
||||||
@ -832,8 +829,8 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
final float u2 = region.getU2();
|
final float u2 = region.getU2();
|
||||||
final float v2 = region.getV();
|
final float v2 = region.getV();
|
||||||
|
|
||||||
float light = this.light;
|
float light = this.lightPacked;
|
||||||
float dark = this.dark;
|
float dark = this.darkPacked;
|
||||||
int idx = this.vertexIndex;
|
int idx = this.vertexIndex;
|
||||||
vertices[idx++] = x;
|
vertices[idx++] = x;
|
||||||
vertices[idx++] = y;
|
vertices[idx++] = y;
|
||||||
@ -867,7 +864,7 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw (TextureRegion region, float x, float y, float originX, float originY, float width, float height,
|
public void draw (TextureRegion region, float x, float y, float originX, float originY, float width, float height,
|
||||||
float scaleX, float scaleY, float rotation) {
|
float scaleX, float scaleY, float rotation) {
|
||||||
if (!drawing) throw new IllegalStateException("begin must be called before draw.");
|
if (!drawing) throw new IllegalStateException("begin must be called before draw.");
|
||||||
|
|
||||||
final short[] triangles = this.triangles;
|
final short[] triangles = this.triangles;
|
||||||
@ -968,8 +965,8 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
final float u2 = region.getU2();
|
final float u2 = region.getU2();
|
||||||
final float v2 = region.getV();
|
final float v2 = region.getV();
|
||||||
|
|
||||||
float light = this.light;
|
float light = this.lightPacked;
|
||||||
float dark = this.dark;
|
float dark = this.darkPacked;
|
||||||
int idx = this.vertexIndex;
|
int idx = this.vertexIndex;
|
||||||
vertices[idx++] = x1;
|
vertices[idx++] = x1;
|
||||||
vertices[idx++] = y1;
|
vertices[idx++] = y1;
|
||||||
@ -1003,7 +1000,7 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw (TextureRegion region, float x, float y, float originX, float originY, float width, float height,
|
public void draw (TextureRegion region, float x, float y, float originX, float originY, float width, float height,
|
||||||
float scaleX, float scaleY, float rotation, boolean clockwise) {
|
float scaleX, float scaleY, float rotation, boolean clockwise) {
|
||||||
if (!drawing) throw new IllegalStateException("begin must be called before draw.");
|
if (!drawing) throw new IllegalStateException("begin must be called before draw.");
|
||||||
|
|
||||||
final short[] triangles = this.triangles;
|
final short[] triangles = this.triangles;
|
||||||
@ -1120,8 +1117,8 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
v4 = region.getV2();
|
v4 = region.getV2();
|
||||||
}
|
}
|
||||||
|
|
||||||
float light = this.light;
|
float light = this.lightPacked;
|
||||||
float dark = this.dark;
|
float dark = this.darkPacked;
|
||||||
int idx = this.vertexIndex;
|
int idx = this.vertexIndex;
|
||||||
vertices[idx++] = x1;
|
vertices[idx++] = x1;
|
||||||
vertices[idx++] = y1;
|
vertices[idx++] = y1;
|
||||||
@ -1191,8 +1188,8 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
final float u2 = region.getU2();
|
final float u2 = region.getU2();
|
||||||
final float v2 = region.getV();
|
final float v2 = region.getV();
|
||||||
|
|
||||||
float light = this.light;
|
float light = this.lightPacked;
|
||||||
float dark = this.dark;
|
float dark = this.darkPacked;
|
||||||
int idx = vertexIndex;
|
int idx = vertexIndex;
|
||||||
vertices[idx++] = x1;
|
vertices[idx++] = x1;
|
||||||
vertices[idx++] = y1;
|
vertices[idx++] = y1;
|
||||||
@ -1228,6 +1225,8 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
public void flush () {
|
public void flush () {
|
||||||
if (vertexIndex == 0) return;
|
if (vertexIndex == 0) return;
|
||||||
|
|
||||||
|
totalRenderCalls++;
|
||||||
|
|
||||||
lastTexture.bind();
|
lastTexture.bind();
|
||||||
Mesh mesh = this.mesh;
|
Mesh mesh = this.mesh;
|
||||||
mesh.setVertices(vertices, 0, vertexIndex);
|
mesh.setVertices(vertices, 0, vertexIndex);
|
||||||
@ -1241,13 +1240,13 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disableBlending() {
|
public void disableBlending () {
|
||||||
flush();
|
flush();
|
||||||
blendingDisabled = true;
|
blendingDisabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enableBlending() {
|
public void enableBlending () {
|
||||||
flush();
|
flush();
|
||||||
blendingDisabled = false;
|
blendingDisabled = false;
|
||||||
}
|
}
|
||||||
@ -1323,7 +1322,7 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ShaderProgram getShader() {
|
public ShaderProgram getShader () {
|
||||||
return shader;
|
return shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1366,12 +1365,12 @@ public class TwoColorPolygonBatch implements Batch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBlendSrcFuncAlpha() {
|
public int getBlendSrcFuncAlpha () {
|
||||||
return blendSrcFuncAlpha;
|
return blendSrcFuncAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBlendDstFuncAlpha() {
|
public int getBlendDstFuncAlpha () {
|
||||||
return blendDstFuncAlpha;
|
return blendDstFuncAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user