pelya 2010-07-12 03:53:48 PDT
authorSam Lantinga <slouken@libsdl.org>
Wed, 14 Jul 2010 07:31:35 -0700
changeset 45253abf0b9cafad
parent 4524 a256e1dadf3f
child 4526 c04dd942610d
pelya 2010-07-12 03:53:48 PDT

In function GLES_RenderCopy() in SDL_renderer_gles.c:819 there is one memcpy()
that can be avoided if we're updating whole texture.
Because of that the SDL 1.3 in compatibility mode is working even slower than
software rendering in SDL 1.2.
src/video/SDL_renderer_gles.c
     1.1 --- a/src/video/SDL_renderer_gles.c	Wed Jul 14 07:25:07 2010 -0700
     1.2 +++ b/src/video/SDL_renderer_gles.c	Wed Jul 14 07:31:35 2010 -0700
     1.3 @@ -822,20 +822,25 @@
     1.4                 maybe it'd be a good idea to keep a temp buffer around
     1.5                 for this purpose rather than allocating it each time
     1.6               */
     1.7 -            temp_buffer = SDL_malloc(rect->w * rect->h * bpp);
     1.8 -            temp_ptr = temp_buffer;
     1.9 -            for (i = 0; i < rect->h; i++) {
    1.10 -                SDL_memcpy(temp_ptr, pixels, rect->w * bpp);
    1.11 -                temp_ptr += rect->w * bpp;
    1.12 -                pixels += pitch;
    1.13 +            if( rect->x == 0 && rect->w * bpp == pitch ) {
    1.14 +                temp_buffer = pixels; /* Updating whole texture, no need to reformat */
    1.15 +            } else {
    1.16 +                temp_buffer = SDL_malloc(rect->w * rect->h * bpp);
    1.17 +                temp_ptr = temp_buffer;
    1.18 +                for (i = 0; i < rect->h; i++) {
    1.19 +                    SDL_memcpy(temp_ptr, pixels, rect->w * bpp);
    1.20 +                    temp_ptr += rect->w * bpp;
    1.21 +                    pixels += pitch;
    1.22 +                }
    1.23              }
    1.24  
    1.25              data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
    1.26                                    rect->w, rect->h, texturedata->format,
    1.27                                    texturedata->formattype, temp_buffer);
    1.28  
    1.29 -            SDL_free(temp_buffer);
    1.30 -
    1.31 +            if( temp_buffer != pixels ) {
    1.32 +                SDL_free(temp_buffer);
    1.33 +            }
    1.34          }
    1.35          SDL_ClearDirtyRects(&texturedata->dirty);
    1.36      }