Update METAL backend for SDL_RenderGeometryRaw
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
diff --git a/src/render/metal/SDL_render_metal.m b/src/render/metal/SDL_render_metal.m
index eb3129b..2b90288 100644
--- a/src/render/metal/SDL_render_metal.m
+++ b/src/render/metal/SDL_render_metal.m
@@ -1379,7 +1379,9 @@ METAL_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture *
static int
METAL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
- SDL_Vertex *vertices, int num_vertices, int *indices, int num_indices, float scale_x, float scale_y)
+ const float *xy, int xy_stride, const int *color, int color_stride, const float *uv, int uv_stride,
+ int num_vertices, const void *indices, int num_indices, int size_indice,
+ float scale_x, float scale_y)
{
int count = indices ? num_indices : num_vertices;
int sz = 2 + 4 + (texture ? 2 : 0);
@@ -1392,22 +1394,35 @@ METAL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture
cmd->data.draw.count = count;
for (int i = 0; i < count; i++) {
- SDL_Vertex *v = &vertices[indices ? indices[i] : i];
+ int j;
+ if (size_indice == 4) {
+ j = ((const Uint32 *)indices)[i];
+ } else if (size_indice == 2) {
+ j = ((const Uint16 *)indices)[i];
+ } else if (size_indice == 1) {
+ j = ((const Uint8 *)indices)[i];
+ } else {
+ j = i;
+ }
+
+ float *xy_ = (float *)((char*)xy + j * xy_stride);
+ SDL_Color col_ = *(SDL_Color *)((char*)color + j * color_stride);
- *(verts++) = v->position.x * scale_x;
- *(verts++) = v->position.y * scale_y;
+ *(verts++) = xy_[0] * scale_x;
+ *(verts++) = xy_[1] * scale_y;
- *(verts++) = v->color.r * inv255f;
- *(verts++) = v->color.g * inv255f;
- *(verts++) = v->color.b * inv255f;
- *(verts++) = v->color.a * inv255f;
+ *(verts++) = col_.r * inv255f;
+ *(verts++) = col_.g * inv255f;
+ *(verts++) = col_.b * inv255f;
+ *(verts++) = col_.a * inv255f;
if (texture) {
- *(verts++) = v->tex_coord.x;
- *(verts++) = v->tex_coord.y;
+ float *uv_ = (float *)((char*)uv + j * uv_stride);
+ *(verts++) = uv_[0];
+ *(verts++) = uv_[1];
}
}
-
+
return 0;
}