Skip to content

Commit

Permalink
[android] Fix Canvas.drawVertices() for Android <= 9. Closes #2638
Browse files Browse the repository at this point in the history
  • Loading branch information
badlogic committed Oct 1, 2024
1 parent fb1cd5e commit 7994973
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Build;

/** Is responsible to transform the {@link Skeleton} with its current pose to {@link SkeletonRenderer.RenderCommand} commands and
* render them to a {@link Canvas}. */
Expand Down Expand Up @@ -246,8 +247,18 @@ public void renderToCanvas (Canvas canvas, Array<RenderCommand> commands) {
for (int i = 0; i < commands.size; i++) {
RenderCommand command = commands.get(i);

canvas.drawVertices(Canvas.VertexMode.TRIANGLES, command.vertices.size, command.vertices.items, 0, command.uvs.items, 0,
command.colors.items, 0, command.indices.items, 0, command.indices.size, command.texture.getPaint(command.blendMode));
if (Build.VERSION.SDK_INT >= 29) {
canvas.drawVertices(Canvas.VertexMode.TRIANGLES, command.vertices.size, command.vertices.items, 0, command.uvs.items, 0,
command.colors.items, 0, command.indices.items, 0, command.indices.size, command.texture.getPaint(command.blendMode));
} else {
// See https://github.com/EsotericSoftware/spine-runtimes/issues/2638
int[] colors = command.colors.items;
int[] colorsCopy = new int[command.vertices.size];
System.arraycopy(colors, 0, colorsCopy, 0, command.colors.size);

canvas.drawVertices(Canvas.VertexMode.TRIANGLES, command.vertices.size, command.vertices.items, 0, command.uvs.items, 0,
colorsCopy, 0, command.indices.items, 0, command.indices.size, command.texture.getPaint(command.blendMode));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import android.content.Context;
import android.graphics.Canvas;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
Expand Down Expand Up @@ -187,6 +188,10 @@ public SpineView build () {
public SpineView (Context context, SpineController controller) {
super(context);
this.controller = controller;
// See https://github.com/EsotericSoftware/spine-runtimes/issues/2638
if (Build.VERSION.SDK_INT < 29) {
this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
}

/** Constructs a new {@link SpineView} without providing a {@link SpineController}, which you need to provide using
Expand Down

0 comments on commit 7994973

Please sign in to comment.