Hopefully fixed crashes when creating multiple streaming textures of different sizes.
authorSam Lantinga <slouken@libsdl.org>
Thu, 24 Feb 2011 23:42:58 -0800
changeset 5397 88ff1f463134
parent 5396 109b7c071f70
child 5398 83816c8a2b58
Hopefully fixed crashes when creating multiple streaming textures of different sizes.
src/render/opengl/SDL_render_gl.c
--- a/src/render/opengl/SDL_render_gl.c	Thu Feb 24 18:11:29 2011 -0800
+++ b/src/render/opengl/SDL_render_gl.c	Thu Feb 24 23:42:58 2011 -0800
@@ -99,9 +99,6 @@
 #include "SDL_glfuncs.h"
 #undef SDL_PROC
 
-    void (*glTextureRangeAPPLE) (GLenum target, GLsizei length,
-                                 const GLvoid * pointer);
-
     /* Multitexture support */
     SDL_bool GL_ARB_multitexture_supported;
     PFNGLACTIVETEXTUREARBPROC glActiveTextureARB;
@@ -322,11 +319,6 @@
         || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
         data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
     }
-    if (SDL_GL_ExtensionSupported("GL_APPLE_texture_range")) {
-        data->glTextureRangeAPPLE =
-            (void (*)(GLenum, GLsizei, const GLvoid *))
-            SDL_GL_GetProcAddress("glTextureRangeAPPLE");
-    }
 
     /* Check for multitexture support */
     if (SDL_GL_ExtensionSupported("GL_ARB_multitexture")) {
@@ -488,10 +480,15 @@
                                     GL_STORAGE_CACHED_APPLE);
     }
     if (texture->access == SDL_TEXTUREACCESS_STREAMING
-        && texture->format == SDL_PIXELFORMAT_ARGB8888) {
+        && texture->format == SDL_PIXELFORMAT_ARGB8888
+        && (texture->w % 8) == 0) {
         renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
+        renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+        renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
+                          (data->pitch / SDL_BYTESPERPIXEL(texture->format)));
         renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
                                  texture_h, 0, format, type, data->pixels);
+        renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
     }
     else
 #endif
@@ -546,11 +543,11 @@
     GL_ActivateRenderer(renderer);
 
     renderdata->glGetError();
+    renderdata->glEnable(data->type);
+    renderdata->glBindTexture(data->type, data->texture);
     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,
                                 rect->h, data->format, data->formattype,
                                 pixels);