Bug 683514 - Use GL_EXT_unpack_subimage when available (part 2). r=joe
authorChris Lord <chrislord.net@gmail.com>
Wed, 14 Sep 2011 10:54:54 -0700
changeset 76969 f037eaa1c8a509cbbeb11f3340315ee2a14898d1
parent 76968 7e132eee5650339e153b8936a2ff0af0adaf2d2f
child 76970 dad4626cde58d79cd21e057f2e6e73ed46fd1018
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersjoe
bugs683514
milestone9.0a1
Bug 683514 - Use GL_EXT_unpack_subimage when available (part 2). r=joe The previous patch used the extension in GLContext::TexImage2D, but not TexSubImage2D. This patch corrects that and makes sure to use the extension in both cases.
gfx/thebes/GLContext.cpp
--- a/gfx/thebes/GLContext.cpp
+++ b/gfx/thebes/GLContext.cpp
@@ -1849,19 +1849,19 @@ GLContext::TexImage2D(GLenum target, GLi
 #endif
 
     // Don't use UNPACK_ROW_LENGTH if the length would be greater than the
     // maximum texture size
     int rowLength = stride/pixelsize;
     if (rowLength > mMaxTextureSize)
       useUnpackRowLength = false;
 
-    if (useUnpackRowLength)
+    if (useUnpackRowLength) {
         fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH, rowLength);
-    else if (stride != width * pixelsize) {
+    } else if (stride != width * pixelsize) {
         // Not using the whole row of texture data and GLES doesn't 
         // support GL_UNPACK_ROW_LENGTH. We need to upload each row
         // separately.
         fTexImage2D(target,
                     border,
                     internalformat,
                     width,
                     height,
@@ -1911,19 +1911,28 @@ GLContext::TexSubImage2D(GLenum target, 
                          GLint pixelsize, GLenum format, 
                          GLenum type, const GLvoid* pixels)
 {
     fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 
                  NS_MIN(GetAddressAlignment((ptrdiff_t)pixels),
                         GetAddressAlignment((ptrdiff_t)stride)));
 
 #ifndef USE_GLES2
-    fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH, stride/pixelsize);
+    bool useUnpackRowLength = true;
 #else
-    if (stride != width * pixelsize) {
+    bool useUnpackRowLength = IsExtensionSupported(EXT_unpack_subimage);
+#endif
+
+    int rowLength = stride/pixelsize;
+    if (rowLength > mMaxTextureSize)
+      useUnpackRowLength = false;
+
+    if (useUnpackRowLength) {
+        fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH, rowLength);
+    } else if (stride != width * pixelsize) {
         // Not using the whole row of texture data and GLES doesn't 
         // support GL_UNPACK_ROW_LENGTH. We need to upload each row
         // separately.
         const unsigned char *row = (const unsigned char *)pixels; 
         for (int h = 0; h < height; h++) {
             fTexSubImage2D(target,
                            level,
                            xoffset,
@@ -1935,31 +1944,29 @@ GLContext::TexSubImage2D(GLenum target, 
                            row);
 
             row += stride;
         }
 
         fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
         return;
     }
-#endif
 
     fTexSubImage2D(target,
                    level,
                    xoffset,
                    yoffset,
                    width,
                    height,
                    format,
                    type,
                    pixels);
 
-#ifndef USE_GLES2
-    fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH, 0);
-#endif
+    if (useUnpackRowLength)
+        fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH, 0);
     fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
 }
 
 void
 GLContext::RectTriangles::addRect(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1,
                                   GLfloat tx0, GLfloat ty0, GLfloat tx1, GLfloat ty1)
 {
     vert_coord v;