Add OpenGLES2 implementation
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
diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index 0d55d19..7cf67b9 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -959,6 +959,41 @@ GLES2_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture *
}
static int
+GLES2_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 i;
+ const SDL_bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 || renderer->target->format == SDL_PIXELFORMAT_RGB888));
+ int count = indices ? num_indices : num_vertices;
+ GLfloat *verts;
+ int sz = 2 + 4 + (texture ? 2 : 0);
+
+ verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * sz * sizeof (GLfloat), 0, &cmd->data.draw.first);
+ if (!verts) {
+ return -1;
+ }
+
+ cmd->data.draw.count = count;
+
+ for (i = 0; i < count; i++) {
+ SDL_Vertex *v = &vertices[indices ? indices[i] : i];
+
+ *(verts++) = v->position.x * scale_x;
+ *(verts++) = v->position.y * scale_y;
+ *(verts++) = (colorswap ? v->color.b : v->color.r) * inv255f;
+ *(verts++) = v->color.g * inv255f;
+ *(verts++) = (colorswap ? v->color.r : v->color.b) * inv255f;
+ *(verts++) = v->color.a * inv255f;
+
+ if (texture) {
+ *(verts++) = v->tex_coord.x / texture->w;
+ *(verts++) = v->tex_coord.y / texture->h;
+ }
+ }
+ return 0;
+}
+
+static int
SetDrawState(GLES2_RenderData *data, const SDL_RenderCommand *cmd, const GLES2_ImageSource imgsrc)
{
const SDL_bool was_copy_ex = data->drawstate.is_copy_ex;
@@ -1333,6 +1368,23 @@ GLES2_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
break;
}
+ case SDL_RENDERCMD_GEOMETRY: {
+ SDL_Texture *texture = cmd->data.draw.texture;
+ const size_t count = cmd->data.draw.count;
+ int ret;
+
+ if (texture) {
+ ret = SetCopyState(renderer, cmd);
+ } else {
+ ret = SetDrawState(data, cmd, GLES2_IMAGESOURCE_SOLID);
+ }
+
+ if (ret == 0) {
+ data->glDrawArrays(GL_TRIANGLES, 0, count);
+ }
+ break;
+ }
+
case SDL_RENDERCMD_NO_OP:
break;
}
@@ -2127,6 +2179,7 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
renderer->QueueFillRects = GLES2_QueueFillRects;
renderer->QueueCopy = GLES2_QueueCopy;
renderer->QueueCopyEx = GLES2_QueueCopyEx;
+ renderer->QueueGeometry = GLES2_QueueGeometry;
renderer->RunCommandQueue = GLES2_RunCommandQueue;
renderer->RenderReadPixels = GLES2_RenderReadPixels;
renderer->RenderPresent = GLES2_RenderPresent;