Commit 3d99d31026bb69e208ac82c30c67e62ca1333141

Sylvain 2022-10-18T10:34:56

Fixed bug #6401 - back-end can choose the order the triangles when rendering rects, attempt to fix small glitch rendering.

diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index aaf2e85..7dd1985 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -552,6 +552,7 @@ QueueCmdFillRects(SDL_Renderer *renderer, const SDL_FRect * rects, const int cou
                 const int num_indices = 6 * count;
                 const int size_indices = 4;
                 int cur_indice = 0;
+                const int *rect_indice_list = renderer->rect_indice_list;
 
                 for (i = 0; i < count; ++i) {
                     float minx, miny, maxx, maxy;
@@ -570,12 +571,12 @@ QueueCmdFillRects(SDL_Renderer *renderer, const SDL_FRect * rects, const int cou
                     *ptr_xy++ = minx;
                     *ptr_xy++ = maxy;
 
-                    *ptr_indices++ = cur_indice + 0;
-                    *ptr_indices++ = cur_indice + 1;
-                    *ptr_indices++ = cur_indice + 2;
-                    *ptr_indices++ = cur_indice + 0;
-                    *ptr_indices++ = cur_indice + 2;
-                    *ptr_indices++ = cur_indice + 3;
+                    *ptr_indices++ = cur_indice + rect_indice_list[0];
+                    *ptr_indices++ = cur_indice + rect_indice_list[1];
+                    *ptr_indices++ = cur_indice + rect_indice_list[2];
+                    *ptr_indices++ = cur_indice + rect_indice_list[3];
+                    *ptr_indices++ = cur_indice + rect_indice_list[4];
+                    *ptr_indices++ = cur_indice + rect_indice_list[5];
                     cur_indice += 4;
                 }
 
@@ -1062,6 +1063,16 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
     renderer->dpi_scale.x = 1.0f;
     renderer->dpi_scale.y = 1.0f;
 
+    /* Default value, if not specified by the renderer back-end */
+    if (renderer->rect_indice_list[0] == 0 && renderer->rect_indice_list[1] == 0) {
+        renderer->rect_indice_list[0] = 0;
+        renderer->rect_indice_list[1] = 1;
+        renderer->rect_indice_list[2] = 2;
+        renderer->rect_indice_list[3] = 0;
+        renderer->rect_indice_list[4] = 2;
+        renderer->rect_indice_list[5] = 3;
+    }
+
     /* new textures start at zero, so we start at 1 so first render doesn't flush by accident. */
     renderer->render_command_generation = 1;
 
@@ -3523,7 +3534,7 @@ SDL_RenderCopyF(SDL_Renderer * renderer, SDL_Texture * texture,
         float uv[8];
         const int uv_stride = 2 * sizeof (float);
         const int num_vertices = 4;
-        const int indices[6] = {0, 1, 2, 0, 2, 3};
+        const int *indices = renderer->rect_indice_list;
         const int num_indices = 6;
         const int size_indices = 4;
         float minu, minv, maxu, maxv;
@@ -3671,7 +3682,7 @@ SDL_RenderCopyExF(SDL_Renderer * renderer, SDL_Texture * texture,
         float uv[8];
         const int uv_stride = 2 * sizeof (float);
         const int num_vertices = 4;
-        const int indices[6] = {0, 1, 2, 0, 2, 3};
+        const int *indices = renderer->rect_indice_list;
         const int num_indices = 6;
         const int size_indices = 4;
         float minu, minv, maxu, maxv;
diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h
index 86d5eaa..fb411f4 100644
--- a/src/render/SDL_sysrender.h
+++ b/src/render/SDL_sysrender.h
@@ -248,6 +248,9 @@ struct SDL_Renderer
     /* The method of drawing lines */
     SDL_RenderLineMethod line_method;
 
+    /* List of triangle indices to draw rects */
+    int rect_indice_list[6];
+
     /* Remainder from scaled relative motion */
     float xrel;
     float yrel;
diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c
index c55c387..96a3766 100644
--- a/src/render/opengl/SDL_render_gl.c
+++ b/src/render/opengl/SDL_render_gl.c
@@ -1932,6 +1932,13 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
     renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_UYVY;
 #endif
 
+    renderer->rect_indice_list[0] = 0;
+    renderer->rect_indice_list[1] = 1;
+    renderer->rect_indice_list[2] = 3;
+    renderer->rect_indice_list[3] = 1;
+    renderer->rect_indice_list[4] = 3;
+    renderer->rect_indice_list[5] = 2;
+
     if (SDL_GL_ExtensionSupported("GL_EXT_framebuffer_object")) {
         data->GL_EXT_framebuffer_object_supported = SDL_TRUE;
         data->glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC)