mesa: fix image unpacking when storing compressed textures
authorBrian Paul <brianp@vmware.com>
Fri, 7 Oct 2011 14:14:46 +0000 (08:14 -0600)
committerBrian Paul <brianp@vmware.com>
Fri, 7 Oct 2011 14:14:46 +0000 (08:14 -0600)
This fixes failures found with the new piglit texsubimage test.

Two things were broken:
1. The dxt code doesn't handle sources images where width != row stride.
   Check for that and take the _mesa_make_temp_ubyte_image() path to get
   an image where width = rowstride.
2. If we don't take the _mesa_make_temp_ubyte_image() path we need to
   take the source image unpacking parameters into account in order to
   get the proper starting memory address of the source texels.

Note: This is a candidate for the 7.11 branch.

src/mesa/main/texcompress_fxt1.c
src/mesa/main/texcompress_s3tc.c

index b6d8ae01655feb9e927cf949c5b873124e5cba17..41630a47c6433cac555f320ab16f50b1e4ada216 100644 (file)
@@ -76,6 +76,7 @@ _mesa_texstore_rgb_fxt1(TEXSTORE_PARAMS)
    if (srcFormat != GL_RGB ||
        srcType != GL_UNSIGNED_BYTE ||
        ctx->_ImageTransferState ||
+       srcPacking->RowLength != srcWidth ||
        srcPacking->SwapBytes) {
       /* convert image to RGB/GLubyte */
       tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
@@ -91,7 +92,9 @@ _mesa_texstore_rgb_fxt1(TEXSTORE_PARAMS)
       srcFormat = GL_RGB;
    }
    else {
-      pixels = (const GLubyte *) srcAddr;
+      pixels = _mesa_image_address2d(srcPacking, srcAddr, srcWidth, srcHeight,
+                                     srcFormat, srcType, 0, 0);
+
       srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
                                             srcType) / sizeof(GLubyte);
    }
@@ -146,7 +149,9 @@ _mesa_texstore_rgba_fxt1(TEXSTORE_PARAMS)
       srcFormat = GL_RGBA;
    }
    else {
-      pixels = (const GLubyte *) srcAddr;
+      pixels = _mesa_image_address2d(srcPacking, srcAddr, srcWidth, srcHeight,
+                                     srcFormat, srcType, 0, 0);
+
       srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
                                             srcType) / sizeof(GLubyte);
    }
index b180c80f0fb40b1d358d71d3dbdab1bb5f80e5d8..904aa457ecc9df210ac2bed9723596303b22169a 100644 (file)
@@ -178,6 +178,7 @@ _mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS)
    if (srcFormat != GL_RGB ||
        srcType != GL_UNSIGNED_BYTE ||
        ctx->_ImageTransferState ||
+       srcPacking->RowLength != srcWidth ||
        srcPacking->SwapBytes) {
       /* convert image to RGB/GLubyte */
       tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
@@ -192,7 +193,8 @@ _mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS)
       srcFormat = GL_RGB;
    }
    else {
-      pixels = (const GLubyte *) srcAddr;
+      pixels = _mesa_image_address2d(srcPacking, srcAddr, srcWidth, srcHeight,
+                                     srcFormat, srcType, 0, 0);
    }
 
    dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
@@ -236,6 +238,7 @@ _mesa_texstore_rgba_dxt1(TEXSTORE_PARAMS)
    if (srcFormat != GL_RGBA ||
        srcType != GL_UNSIGNED_BYTE ||
        ctx->_ImageTransferState ||
+       srcPacking->RowLength != srcWidth ||
        srcPacking->SwapBytes) {
       /* convert image to RGBA/GLubyte */
       tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
@@ -250,7 +253,8 @@ _mesa_texstore_rgba_dxt1(TEXSTORE_PARAMS)
       srcFormat = GL_RGBA;
    }
    else {
-      pixels = (const GLubyte *) srcAddr;
+      pixels = _mesa_image_address2d(srcPacking, srcAddr, srcWidth, srcHeight,
+                                     srcFormat, srcType, 0, 0);
    }
 
    dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
@@ -293,6 +297,7 @@ _mesa_texstore_rgba_dxt3(TEXSTORE_PARAMS)
    if (srcFormat != GL_RGBA ||
        srcType != GL_UNSIGNED_BYTE ||
        ctx->_ImageTransferState ||
+       srcPacking->RowLength != srcWidth ||
        srcPacking->SwapBytes) {
       /* convert image to RGBA/GLubyte */
       tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
@@ -306,7 +311,8 @@ _mesa_texstore_rgba_dxt3(TEXSTORE_PARAMS)
       pixels = tempImage;
    }
    else {
-      pixels = (const GLubyte *) srcAddr;
+      pixels = _mesa_image_address2d(srcPacking, srcAddr, srcWidth, srcHeight,
+                                     srcFormat, srcType, 0, 0);
    }
 
    dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
@@ -349,6 +355,7 @@ _mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS)
    if (srcFormat != GL_RGBA ||
        srcType != GL_UNSIGNED_BYTE ||
        ctx->_ImageTransferState ||
+       srcPacking->RowLength != srcWidth ||
        srcPacking->SwapBytes) {
       /* convert image to RGBA/GLubyte */
       tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
@@ -362,7 +369,8 @@ _mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS)
       pixels = tempImage;
    }
    else {
-      pixels = (const GLubyte *) srcAddr;
+      pixels = _mesa_image_address2d(srcPacking, srcAddr, srcWidth, srcHeight,
+                                     srcFormat, srcType, 0, 0);
    }
 
    dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,