Add sysrender interface
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 99050cc..e7aa73f 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -562,6 +562,25 @@ QueueCmdCopyEx(SDL_Renderer *renderer, SDL_Texture * texture,
return retval;
}
+static int
+QueueCmdGeometry(SDL_Renderer *renderer, SDL_Texture *texture,
+ SDL_Vertex *vertices, int num_vertices, int *indices, int num_indices, float scale_x, float scale_y)
+{
+ SDL_RenderCommand *cmd;
+ int retval = -1;
+ if (texture) {
+ cmd = PrepQueueCmdDrawTexture(renderer, texture, SDL_RENDERCMD_GEOMETRY);
+ } else {
+ cmd = PrepQueueCmdDrawSolid(renderer, SDL_RENDERCMD_GEOMETRY);
+ }
+ if (cmd != NULL) {
+ retval = renderer->QueueGeometry(renderer, cmd, texture, vertices, num_vertices, indices, num_indices, scale_x, scale_y);
+ if (retval < 0) {
+ cmd->command = SDL_RENDERCMD_NO_OP;
+ }
+ }
+ return retval;
+}
static int UpdateLogicalSize(SDL_Renderer *renderer);
@@ -3304,6 +3323,77 @@ SDL_RenderCopyExF(SDL_Renderer * renderer, SDL_Texture * texture,
}
int
+SDL_RenderGeometry(SDL_Renderer *renderer,
+ SDL_Texture *texture,
+ SDL_Vertex *vertices, int num_vertices,
+ int *indices, int num_indices)
+{
+ int i;
+ int retval;
+ int count = indices ? num_indices : num_vertices;
+
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ if (!renderer->QueueGeometry) {
+ return SDL_Unsupported();
+ }
+
+ if (texture) {
+ CHECK_TEXTURE_MAGIC(texture, -1);
+
+ if (renderer != texture->renderer) {
+ return SDL_SetError("Texture was not created with this renderer");
+ }
+ }
+
+ if (!vertices) {
+ return SDL_InvalidParamError("points");
+ }
+
+ if (count % 3 != 0) {
+ return SDL_InvalidParamError(indices ? "num_indices" : "num_vertices");
+ }
+
+ /* Don't draw while we're hidden */
+ if (renderer->hidden) {
+ return 0;
+ }
+
+ if (num_vertices < 3) {
+ return 0;
+ }
+
+ if (texture && texture->native) {
+ texture = texture->native;
+ }
+
+ if (texture) {
+ for (i = 0; i < num_vertices; ++i) {
+ if (vertices[i].tex_coord.x < 0 || vertices[i].tex_coord.y < 0 || vertices[i].tex_coord.x >= texture->w || vertices[i].tex_coord.y >= texture->h) {
+ return SDL_SetError("Values of 'vertices' out of bounds");
+ }
+ }
+ }
+
+ if (indices) {
+ for (i = 0; i < num_indices; ++i) {
+ if (indices[i] < 0 || indices[i] >= num_vertices) {
+ return SDL_SetError("Values of 'indices' out of bounds");
+ }
+ }
+ }
+
+
+ if (texture) {
+ texture->last_command_generation = renderer->render_command_generation;
+ }
+
+ retval = QueueCmdGeometry(renderer, texture, vertices, num_vertices, indices, num_indices, renderer->scale.x, renderer->scale.y);
+
+ return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
+}
+
+int
SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, void * pixels, int pitch)
{
diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h
index 87d14c2..1beb4b2 100644
--- a/src/render/SDL_sysrender.h
+++ b/src/render/SDL_sysrender.h
@@ -75,7 +75,8 @@ typedef enum
SDL_RENDERCMD_DRAW_LINES,
SDL_RENDERCMD_FILL_RECTS,
SDL_RENDERCMD_COPY,
- SDL_RENDERCMD_COPY_EX
+ SDL_RENDERCMD_COPY_EX,
+ SDL_RENDERCMD_GEOMETRY
} SDL_RenderCommandType;
typedef struct SDL_RenderCommand
@@ -128,6 +129,10 @@ struct SDL_Renderer
int (*QueueCopyEx) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
const SDL_Rect * srcquad, const SDL_FRect * dstrect,
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip);
+
+ int (*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);
+
int (*RunCommandQueue) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize);
int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels,