Commit b331ada815fff35ee9028d60a08cd63df4648d35

Sam Lantinga 2014-02-09T01:49:01

Fixed bug 2354 - [ES 2.0] SDL_RenderClear clears render target with wrong color ny00 SDL_RenderClear clears a render target with the wrong color, if the opengles2 renderer driver is used and the target texture's format is SDL_PIXELFORMAT_ARGB8888. The bug is *not* reproduced if SDL_PIXELFORMAT_ABGR8888 is used as the texture format (the first from the renderer's list). It is further not reproduced using any of the following renderer drivers: opengl, opengles (apparently powered by Gallium3D), software. Finally, the correct color can be drawn using SDL_RenderFillRect (instead of SDL_RenderClear). A few details about the current setup: - OS: Ubuntu 12.04 for x86_64 - GPU: GeForce GTX 460 - GPU driver version: 331.20-0ubuntu1~xedgers~precise1 (from the xorg-edgers PPA) --- Seth Williams Sam, It appears that the clear just needs to take the render target format into consideration. Seth.

diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index b9e67cd..c0d1aeb 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -1043,16 +1043,33 @@ CompareColors(Uint8 r1, Uint8 g1, Uint8 b1, Uint8 a1,
 static int
 GLES2_RenderClear(SDL_Renderer * renderer)
 {
+    Uint8 r, g, b, a;
+
     GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
 
     GLES2_ActivateRenderer(renderer);
 
     if (!CompareColors(data->clear_r, data->clear_g, data->clear_b, data->clear_a,
                         renderer->r, renderer->g, renderer->b, renderer->a)) {
-        data->glClearColor((GLfloat) renderer->r * inv255f,
-                     (GLfloat) renderer->g * inv255f,
-                     (GLfloat) renderer->b * inv255f,
-                     (GLfloat) renderer->a * inv255f);
+
+       /* Select the color to clear with */
+       g = renderer->g;
+       a = renderer->a;
+   
+       if (renderer->target &&
+            (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 ||
+             renderer->target->format == SDL_PIXELFORMAT_RGB888)) {
+           r = renderer->b;
+           b = renderer->r;
+        } else {
+           r = renderer->r;
+           b = renderer->b;
+        }
+
+        data->glClearColor((GLfloat) r * inv255f,
+                     (GLfloat) g * inv255f,
+                     (GLfloat) b * inv255f,
+                     (GLfloat) a * inv255f);
         data->clear_r = renderer->r;
         data->clear_g = renderer->g;
         data->clear_b = renderer->b;