GLES2: batch non joined lines (see #4964)
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
diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index 6602c62..7a39c72 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -1136,7 +1136,31 @@ GLES2_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
case SDL_RENDERCMD_DRAW_LINES: {
if (SetDrawState(data, cmd, GLES2_IMAGESOURCE_SOLID) == 0) {
- data->glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) cmd->data.draw.count);
+ size_t count = cmd->data.draw.count;
+ if (count > 2) {
+ /* joined lines cannot be grouped */
+ data->glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)count);
+ } else {
+ /* let's group non joined lines */
+ SDL_RenderCommand *finalcmd = cmd;
+ SDL_RenderCommand *nextcmd = cmd->next;
+
+ while (nextcmd != NULL) {
+ const SDL_RenderCommandType nextcmdtype = nextcmd->command;
+ if (nextcmdtype != SDL_RENDERCMD_DRAW_LINES) {
+ break; /* can't go any further on this draw call, different render command up next. */
+ } else if (nextcmd->data.draw.count != 2) {
+ break; /* can't go any further on this draw call, those are joined lines */
+ } else {
+ finalcmd = nextcmd; /* we can combine copy operations here. Mark this one as the furthest okay command. */
+ count += cmd->data.draw.count;
+ }
+ nextcmd = nextcmd->next;
+ }
+
+ data->glDrawArrays(GL_LINES, 0, (GLsizei)count);
+ cmd = finalcmd; /* skip any copy commands we just combined in here. */
+ }
}
break;
}