Skip to content
Browse files

Fixed bug 2354 - [ES 2.0] SDL_RenderClear clears render target with w…

…rong color


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


It appears that the clear just needs to take the render target format into consideration.

  • Loading branch information
slouken committed Feb 9, 2014
1 parent fab5c75 commit b331ada815fff35ee9028d60a08cd63df4648d35
Showing with 21 additions and 4 deletions.
  1. +21 −4 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;


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;

0 comments on commit b331ada

Please sign in to comment.