Fixed bug 2354 - [ES 2.0] SDL_RenderClear clears render target with wrong color
authorSam Lantinga <slouken@libsdl.org>
Sun, 09 Feb 2014 01:49:01 -0800
changeset 8192 560c66a04082
parent 8191 b50f4ae6d5f2
child 8193 b4f1e02f2df6
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.
src/render/opengles2/SDL_render_gles2.c
--- a/src/render/opengles2/SDL_render_gles2.c	Fri Feb 07 12:03:02 2014 -0500
+++ b/src/render/opengles2/SDL_render_gles2.c	Sun Feb 09 01:49:01 2014 -0800
@@ -1043,16 +1043,33 @@
 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;