Commit eff840bb9b66ff9da0a0170938bb9061aac2f054

Sylvain 2021-04-01T23:30:59

Add OpenGLES implementation

diff --git a/src/render/opengles/SDL_glesfuncs.h b/src/render/opengles/SDL_glesfuncs.h
index 9ee75fb..4b74958 100644
--- a/src/render/opengles/SDL_glesfuncs.h
+++ b/src/render/opengles/SDL_glesfuncs.h
@@ -27,6 +27,7 @@ SDL_PROC_OES(void, glBlendFuncSeparateOES, (GLenum, GLenum, GLenum, GLenum))
 SDL_PROC(void, glClear, (GLbitfield))
 SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf))
 SDL_PROC(void, glColor4f, (GLfloat, GLfloat, GLfloat, GLfloat))
+SDL_PROC(void, glColorPointer, (GLint, GLenum, GLsizei, const GLvoid *))
 SDL_PROC(void, glDeleteTextures, (GLsizei, const GLuint *))
 SDL_PROC(void, glDisable, (GLenum))
 SDL_PROC(void, glDisableClientState, (GLenum array))
diff --git a/src/render/opengles/SDL_render_gles.c b/src/render/opengles/SDL_render_gles.c
index 49878c8..d594447 100644
--- a/src/render/opengles/SDL_render_gles.c
+++ b/src/render/opengles/SDL_render_gles.c
@@ -755,6 +755,63 @@ GLES_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * 
     return 0;
 }
 
+static int
+GLES_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
+        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)
+{
+    GLES_TextureData *texturedata = NULL;
+    int i;
+    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;
+    }
+
+    if (texture) {
+        texturedata = (GLES_TextureData *) texture->driverdata;
+    }
+
+    cmd->data.draw.count = count;
+
+    for (i = 0; i < count; i++) {
+        int j;
+        float *xy_;
+        SDL_Color col_;
+        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;
+        }
+
+        xy_ = (float *)((char*)xy + j * xy_stride);
+        col_ = *(SDL_Color *)((char*)color + j * color_stride);
+
+        *(verts++) = xy_[0] * scale_x;
+        *(verts++) = xy_[1] * scale_y;
+
+        *(verts++) = col_.r * inv255f;
+        *(verts++) = col_.g * inv255f;
+        *(verts++) = col_.b * inv255f;
+        *(verts++) = col_.a * inv255f;
+
+        if (texture) {
+            float *uv_ = (float *)((char*)uv + j * uv_stride);
+            *(verts++) = uv_[0] * texturedata->texw;
+            *(verts++) = uv_[1] * texturedata->texh;
+        }
+    }
+    return 0;
+}
+
 static void
 SetDrawState(GLES_RenderData *data, const SDL_RenderCommand *cmd)
 {
@@ -988,6 +1045,33 @@ GLES_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vert
                 break;
             }
 
+            case SDL_RENDERCMD_GEOMETRY: {
+                const GLfloat *verts = (GLfloat *) (((Uint8 *) vertices) + cmd->data.draw.first);
+                SDL_Texture *texture = cmd->data.draw.texture;
+                const size_t count = cmd->data.draw.count;
+                int stride = (2 + 4 + (texture ? 2 : 0)) * sizeof (float);
+
+                if (texture) {
+                    SetCopyState(data, cmd);
+                } else {
+                    SetDrawState(data, cmd);
+                }
+
+                data->glEnableClientState(GL_COLOR_ARRAY);
+
+                data->glVertexPointer(2, GL_FLOAT, stride, verts);
+                data->glColorPointer(4, GL_FLOAT, stride, verts + 2);
+                if (texture) {
+                    data->glTexCoordPointer(2, GL_FLOAT, stride, verts + 2 + 4);
+                }
+
+                data->glDrawArrays(GL_TRIANGLES, 0, (GLsizei) count);
+
+                data->glDisableClientState(GL_COLOR_ARRAY);
+
+                break;
+            }
+
             case SDL_RENDERCMD_NO_OP:
                 break;
         }
@@ -1198,6 +1282,7 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
     renderer->QueueFillRects = GLES_QueueFillRects;
     renderer->QueueCopy = GLES_QueueCopy;
     renderer->QueueCopyEx = GLES_QueueCopyEx;
+    renderer->QueueGeometry = GLES_QueueGeometry;
     renderer->RunCommandQueue = GLES_RunCommandQueue;
     renderer->RenderReadPixels = GLES_RenderReadPixels;
     renderer->RenderPresent = GLES_RenderPresent;