Fixed bug #1028
authorSam Lantinga <slouken@libsdl.org>
Wed, 19 Jan 2011 23:47:50 -0800
changeset 50524cb4b18cbae3
parent 5051 a69e36365766
child 5053 b5b42be9333c
Fixed bug #1028

pelya 2010-07-21 04:54:41 PDT

GLES_UpdateTexture() ignores pitch value, because of that some textures created
with SDL_CreateTextureFromSurface() are drawn incorrectly, especially if image
width is not multiplier of 2.
src/video/SDL_renderer_gles.c
     1.1 --- a/src/video/SDL_renderer_gles.c	Wed Jan 19 23:45:29 2011 -0800
     1.2 +++ b/src/video/SDL_renderer_gles.c	Wed Jan 19 23:47:50 2011 -0800
     1.3 @@ -557,13 +557,36 @@
     1.4      GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
     1.5      GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
     1.6      GLenum result;
     1.7 +    int bpp = SDL_BYTESPERPIXEL(texture->format);
     1.8 +    void * temp_buffer;
     1.9 +    void * temp_ptr;
    1.10 +    int i;
    1.11  
    1.12      renderdata->glGetError();
    1.13      renderdata->glEnable(data->type);
    1.14      SetupTextureUpdate(renderdata, texture, pitch);
    1.15 +
    1.16 +    if( rect->w * bpp == pitch ) {
    1.17 +         temp_buffer = (void *)pixels; /* No need to reformat */
    1.18 +    } else {
    1.19 +         /* Reformatting of mem area required */
    1.20 +         temp_buffer = SDL_malloc(rect->w * rect->h * bpp);
    1.21 +         temp_ptr = temp_buffer;
    1.22 +         for (i = 0; i < rect->h; i++) {
    1.23 +             SDL_memcpy(temp_ptr, pixels, rect->w * bpp);
    1.24 +             temp_ptr += rect->w * bpp;
    1.25 +             pixels += pitch;
    1.26 +         }
    1.27 +    }
    1.28 +
    1.29      renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
    1.30                                  rect->h, data->format, data->formattype,
    1.31 -                                pixels);
    1.32 +                                temp_buffer);
    1.33 +
    1.34 +    if( temp_buffer != pixels ) {
    1.35 +        SDL_free(temp_buffer);
    1.36 +    }
    1.37 +
    1.38      renderdata->glDisable(data->type);
    1.39      result = renderdata->glGetError();
    1.40      if (result != GL_NO_ERROR) {