src/render/opengl/SDL_render_gl.c
changeset 5227 9c0c4d767ef6
parent 5226 710d00cb3a6a
child 5228 811beeb698f9
--- a/src/render/opengl/SDL_render_gl.c	Tue Feb 08 10:04:09 2011 -0800
+++ b/src/render/opengl/SDL_render_gl.c	Tue Feb 08 10:38:12 2011 -0800
@@ -106,6 +106,7 @@
     GLenum formattype;
     void *pixels;
     int pitch;
+    SDL_Rect locked_rect;
 } GL_TextureData;
 
 
@@ -448,15 +449,6 @@
     return 0;
 }
 
-static void
-SetupTextureUpdate(GL_RenderData * renderdata, SDL_Texture * texture,
-                   int pitch)
-{
-    renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-    renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
-                              (pitch / SDL_BYTESPERPIXEL(texture->format)));
-}
-
 static int
 GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
                  const SDL_Rect * rect, const void *pixels, int pitch)
@@ -468,7 +460,9 @@
     GL_ActivateRenderer(renderer);
 
     renderdata->glGetError();
-    SetupTextureUpdate(renderdata, texture, pitch);
+    renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+    renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
+                              (pitch / SDL_BYTESPERPIXEL(texture->format)));
     renderdata->glEnable(data->type);
     renderdata->glBindTexture(data->type, data->texture);
     renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
@@ -489,7 +483,8 @@
 {
     GL_TextureData *data = (GL_TextureData *) texture->driverdata;
 
-    *pixels =
+    data->locked_rect = *rect;
+    *pixels = 
         (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
                   rect->x * SDL_BYTESPERPIXEL(texture->format));
     *pitch = data->pitch;
@@ -499,17 +494,15 @@
 static void
 GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
 {
-    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
     GL_TextureData *data = (GL_TextureData *) texture->driverdata;
-
-    GL_ActivateRenderer(renderer);
+    const SDL_Rect *rect;
+    void *pixels;
 
-    SetupTextureUpdate(renderdata, texture, data->pitch);
-    renderdata->glEnable(data->type);
-    renderdata->glBindTexture(data->type, data->texture);
-    renderdata->glTexSubImage2D(data->type, 0, 0, 0, texture->w, texture->h,
-                                data->format, data->formattype, data->pixels);
-    renderdata->glDisable(data->type);
+    rect = &data->locked_rect;
+    pixels = 
+        (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
+                  rect->x * SDL_BYTESPERPIXEL(texture->format));
+    GL_UpdateTexture(renderer, texture, rect, pixels, data->pitch);
 }
 
 static void