diff src/render/opengles2/SDL_render_gles2.c @ 5232:9c0c4d767ef6

Reduce duplicated code in the texture update code paths
author Sam Lantinga <slouken@libsdl.org>
date Tue, 08 Feb 2011 10:38:12 -0800
parents 710d00cb3a6a
children 7a963be087ef
line wrap: on
line diff
--- a/src/render/opengles2/SDL_render_gles2.c	Tue Feb 08 10:04:09 2011 -0800
+++ b/src/render/opengles2/SDL_render_gles2.c	Tue Feb 08 10:38:12 2011 -0800
@@ -343,14 +343,14 @@
 GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
 {
     GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
-
-    GLES2_ActivateRenderer(renderer);
+    SDL_Rect rect;
 
-    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-    glActiveTexture(GL_TEXTURE0);
-    glBindTexture(tdata->texture_type, tdata->texture);
-    glTexSubImage2D(tdata->texture_type, 0, 0, 0, texture->w, texture->h,
-                    tdata->pixel_format, tdata->pixel_type, tdata->pixel_data);
+    /* We do whole texture updates, at least for now */
+    rect.x = 0;
+    rect.y = 0;
+    rect.w = texture->w;
+    rect.h = texture->h;
+    GLES2_UpdateTexture(renderer, texture, &rect, tdata->pixel_data, tdata->pitch);
 }
 
 static int
@@ -361,7 +361,6 @@
     Uint8 *blob = NULL;
     Uint8 *src;
     int srcPitch;
-    Uint8 *dest;
     int y;
 
     GLES2_ActivateRenderer(renderer);
@@ -405,7 +404,9 @@
                     tdata->pixel_format,
                     tdata->pixel_type,
                     src);
-    SDL_free(blob);
+    if (blob) {
+        SDL_free(blob);
+    }
 
     if (glGetError() != GL_NO_ERROR)
     {