Add OpenGLES 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 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
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;