changeset 5052:4cb4b18cbae3

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.
author Sam Lantinga <slouken@libsdl.org>
date Wed, 19 Jan 2011 23:47:50 -0800
parents a69e36365766
children b5b42be9333c
files src/video/SDL_renderer_gles.c
diffstat 1 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/SDL_renderer_gles.c	Wed Jan 19 23:45:29 2011 -0800
+++ b/src/video/SDL_renderer_gles.c	Wed Jan 19 23:47:50 2011 -0800
@@ -557,13 +557,36 @@
     GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
     GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
     GLenum result;
+    int bpp = SDL_BYTESPERPIXEL(texture->format);
+    void * temp_buffer;
+    void * temp_ptr;
+    int i;
 
     renderdata->glGetError();
     renderdata->glEnable(data->type);
     SetupTextureUpdate(renderdata, texture, pitch);
+
+    if( rect->w * bpp == pitch ) {
+         temp_buffer = (void *)pixels; /* No need to reformat */
+    } else {
+         /* Reformatting of mem area required */
+         temp_buffer = SDL_malloc(rect->w * rect->h * bpp);
+         temp_ptr = temp_buffer;
+         for (i = 0; i < rect->h; i++) {
+             SDL_memcpy(temp_ptr, pixels, rect->w * bpp);
+             temp_ptr += rect->w * bpp;
+             pixels += pitch;
+         }
+    }
+
     renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
                                 rect->h, data->format, data->formattype,
-                                pixels);
+                                temp_buffer);
+
+    if( temp_buffer != pixels ) {
+        SDL_free(temp_buffer);
+    }
+
     renderdata->glDisable(data->type);
     result = renderdata->glGetError();
     if (result != GL_NO_ERROR) {