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 8192560c66a04082
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
     1.1 --- a/src/render/opengles2/SDL_render_gles2.c	Fri Feb 07 12:03:02 2014 -0500
     1.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Sun Feb 09 01:49:01 2014 -0800
     1.3 @@ -1043,16 +1043,33 @@
     1.4  static int
     1.5  GLES2_RenderClear(SDL_Renderer * renderer)
     1.6  {
     1.7 +    Uint8 r, g, b, a;
     1.8 +
     1.9      GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
    1.10  
    1.11      GLES2_ActivateRenderer(renderer);
    1.12  
    1.13      if (!CompareColors(data->clear_r, data->clear_g, data->clear_b, data->clear_a,
    1.14                          renderer->r, renderer->g, renderer->b, renderer->a)) {
    1.15 -        data->glClearColor((GLfloat) renderer->r * inv255f,
    1.16 -                     (GLfloat) renderer->g * inv255f,
    1.17 -                     (GLfloat) renderer->b * inv255f,
    1.18 -                     (GLfloat) renderer->a * inv255f);
    1.19 +
    1.20 +       /* Select the color to clear with */
    1.21 +       g = renderer->g;
    1.22 +       a = renderer->a;
    1.23 +   
    1.24 +       if (renderer->target &&
    1.25 +            (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 ||
    1.26 +             renderer->target->format == SDL_PIXELFORMAT_RGB888)) {
    1.27 +           r = renderer->b;
    1.28 +           b = renderer->r;
    1.29 +        } else {
    1.30 +           r = renderer->r;
    1.31 +           b = renderer->b;
    1.32 +        }
    1.33 +
    1.34 +        data->glClearColor((GLfloat) r * inv255f,
    1.35 +                     (GLfloat) g * inv255f,
    1.36 +                     (GLfloat) b * inv255f,
    1.37 +                     (GLfloat) a * inv255f);
    1.38          data->clear_r = renderer->r;
    1.39          data->clear_g = renderer->g;
    1.40          data->clear_b = renderer->b;