Do a 32-bit compare on RGBA values. Thsi should be inlined in optimized builds.
authorSam Lantinga <slouken@libsdl.org>
Sat, 05 Oct 2013 12:29:05 -0700
changeset 7785d01823d85840
parent 7784 70b305e09b4e
child 7786 cfc1285375e1
Do a 32-bit compare on RGBA values. Thsi should be inlined in optimized builds.
src/render/opengles2/SDL_render_gles2.c
     1.1 --- a/src/render/opengles2/SDL_render_gles2.c	Sat Oct 05 00:29:57 2013 -0400
     1.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Sat Oct 05 12:29:05 2013 -0700
     1.3 @@ -25,6 +25,7 @@
     1.4  #include "SDL_hints.h"
     1.5  #include "SDL_opengles2.h"
     1.6  #include "../SDL_sysrender.h"
     1.7 +#include "../../video/SDL_blit.h"
     1.8  #include "SDL_shaders_gles2.h"
     1.9  
    1.10  /* Used to re-create the window with OpenGL ES capability */
    1.11 @@ -1029,6 +1030,15 @@
    1.12                      Uint32 pixel_format, void * pixels, int pitch);
    1.13  static void GLES2_RenderPresent(SDL_Renderer *renderer);
    1.14  
    1.15 +static SDL_bool
    1.16 +CompareColors(Uint8 r1, Uint8 g1, Uint8 b1, Uint8 a1,
    1.17 +              Uint8 r2, Uint8 g2, Uint8 b2, Uint8 a2)
    1.18 +{
    1.19 +    Uint32 Pixel1, Pixel2;
    1.20 +    RGBA8888_FROM_RGBA(Pixel1, r1, g1, b1, a1);
    1.21 +    RGBA8888_FROM_RGBA(Pixel2, r2, g2, b2, a2);
    1.22 +    return (Pixel1 == Pixel2);
    1.23 +}
    1.24  
    1.25  static int
    1.26  GLES2_RenderClear(SDL_Renderer * renderer)
    1.27 @@ -1037,9 +1047,8 @@
    1.28  
    1.29      GLES2_ActivateRenderer(renderer);
    1.30  
    1.31 -    /* !!! FIXME: it'd be nice to do a single 32-bit compare here. */
    1.32 -    if ( (data->clear_r != renderer->r) || (data->clear_g != renderer->g) ||
    1.33 -         (data->clear_b != renderer->b) || (data->clear_a != renderer->a) ) {
    1.34 +    if (!CompareColors(data->clear_r, data->clear_g, data->clear_b, data->clear_a,
    1.35 +                        renderer->r, renderer->g, renderer->b, renderer->a)) {
    1.36          data->glClearColor((GLfloat) renderer->r * inv255f,
    1.37                       (GLfloat) renderer->g * inv255f,
    1.38                       (GLfloat) renderer->b * inv255f,
    1.39 @@ -1128,8 +1137,7 @@
    1.40       }
    1.41  
    1.42      program = data->current_program;
    1.43 -    /* !!! FIXME: it'd be nice to do a single 32-bit compare here. */
    1.44 -    if ( (program->color_r != r) || (program->color_g != g) || (program->color_b != b) || (program->color_a != a) ) {
    1.45 +    if (!CompareColors(program->color_r, program->color_g, program->color_b, program->color_a, r, g, b, a)) {
    1.46          /* Select the color to draw with */
    1.47          data->glUniform4f(program->uniform_locations[GLES2_UNIFORM_COLOR], r * inv255f, g * inv255f, b * inv255f, a * inv255f);
    1.48          program->color_r = r;
    1.49 @@ -1355,8 +1363,7 @@
    1.50  
    1.51      program = data->current_program;
    1.52  
    1.53 -    /* !!! FIXME: it'd be nice to do a single 32-bit compare here. */
    1.54 -    if ( (program->modulation_r != r) || (program->modulation_g != g) || (program->modulation_b != b) || (program->modulation_a != a) ) {
    1.55 +    if (!CompareColors(program->modulation_r, program->modulation_g, program->modulation_b, program->modulation_a, r, g, b, a)) {
    1.56          data->glUniform4f(program->uniform_locations[GLES2_UNIFORM_MODULATION], r * inv255f, g * inv255f, b * inv255f, a * inv255f);
    1.57          program->modulation_r = r;
    1.58          program->modulation_g = g;
    1.59 @@ -1523,8 +1530,7 @@
    1.60  
    1.61      program = data->current_program;
    1.62  
    1.63 -    /* !!! FIXME: it'd be nice to do a single 32-bit compare here. */
    1.64 -    if ( (program->modulation_r != r) || (program->modulation_g != g) || (program->modulation_b != b) || (program->modulation_a != a) ) {
    1.65 +    if (!CompareColors(program->modulation_r, program->modulation_g, program->modulation_b, program->modulation_a, r, g, b, a)) {
    1.66          data->glUniform4f(program->uniform_locations[GLES2_UNIFORM_MODULATION], r * inv255f, g * inv255f, b * inv255f, a * inv255f);
    1.67          program->modulation_r = r;
    1.68          program->modulation_g = g;