Created
June 5, 2018 20:56
-
-
Save piotr-j/669d77fc9b385d12a9a40c7258bc8b58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean convertSpriteVertices = true; | |
/** 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, | |
* u, v. The {@link #getColor()} and {@link #getDarkColor()} from the TwoColorPolygonBatch is not applied. */ | |
@Override | |
public void draw (Texture texture, float[] spriteVertices, int offset, int count) { | |
if (!drawing) throw new IllegalStateException("begin must be called before draw."); | |
final short[] triangles = this.triangles; | |
final float[] vertices = this.vertices; | |
int oldCount = count; | |
if (convertSpriteVertices) { | |
count = SPRITE_SIZE * (count / 20); | |
} | |
final int triangleCount = count / SPRITE_SIZE * 6; | |
if (texture != lastTexture) | |
switchTexture(texture); | |
else if (triangleIndex + triangleCount > triangles.length || vertexIndex + count > vertices.length) // | |
flush(); | |
final int vertexIndex = this.vertexIndex; | |
int triangleIndex = this.triangleIndex; | |
short vertex = (short)(vertexIndex / VERTEX_SIZE); | |
for (int n = triangleIndex + triangleCount; triangleIndex < n; triangleIndex += 6, vertex += 4) { | |
triangles[triangleIndex] = vertex; | |
triangles[triangleIndex + 1] = (short)(vertex + 1); | |
triangles[triangleIndex + 2] = (short)(vertex + 2); | |
triangles[triangleIndex + 3] = (short)(vertex + 2); | |
triangles[triangleIndex + 4] = (short)(vertex + 3); | |
triangles[triangleIndex + 5] = vertex; | |
} | |
this.triangleIndex = triangleIndex; | |
if (convertSpriteVertices) { | |
int idx = vertexIndex; | |
for (int i = 0; i < oldCount; i += 5) { | |
vertices[idx++] = spriteVertices[i]; | |
vertices[idx++] = spriteVertices[i + 1]; | |
vertices[idx++] = spriteVertices[i + 2]; | |
vertices[idx++] = 0; // dark | |
vertices[idx++] = spriteVertices[i + 3]; | |
vertices[idx++] = spriteVertices[i + 4]; | |
} | |
} else { | |
System.arraycopy(spriteVertices, offset, vertices, vertexIndex, count); | |
} | |
this.vertexIndex += count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment