r300g: better describe another flush and move it closer to the real problem
[mesa.git] / src / mesa / main / texstore.c
index 7b449d03bea97b2c908acb1f07a01f128db512e3..ce05652c935f3c7e44cfd7f8f77fa6e6e71a0c4c 100644 (file)
@@ -263,17 +263,17 @@ compute_component_mapping(GLenum inFormat, GLenum outFormat,
    map[ZERO] = ZERO;
    map[ONE] = ONE;   
 
-/*
-   _mesa_printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
-               inFormat, _mesa_lookup_enum_by_nr(inFormat),
-               outFormat, _mesa_lookup_enum_by_nr(outFormat),
-               map[0], 
-               map[1], 
-               map[2], 
-               map[3], 
-               map[4], 
-               map[5]); 
-*/
+#if 0
+   printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
+         inFormat, _mesa_lookup_enum_by_nr(inFormat),
+         outFormat, _mesa_lookup_enum_by_nr(outFormat),
+         map[0], 
+         map[1], 
+         map[2], 
+         map[3], 
+         map[4], 
+         map[5]); 
+#endif
 }
 
 
@@ -347,16 +347,16 @@ make_temp_float_image(GLcontext *ctx, GLuint dims,
       GLfloat *convImage;
 
       /* pre-convolution image buffer (3D) */
-      tempImage = (GLfloat *) _mesa_malloc(srcWidth * srcHeight * srcDepth
+      tempImage = (GLfloat *) malloc(srcWidth * srcHeight * srcDepth
                                            * 4 * sizeof(GLfloat));
       if (!tempImage)
          return NULL;
 
       /* post-convolution image buffer (2D) */
-      convImage = (GLfloat *) _mesa_malloc(srcWidth * srcHeight
+      convImage = (GLfloat *) malloc(srcWidth * srcHeight
                                            * 4 * sizeof(GLfloat));
       if (!convImage) {
-         _mesa_free(tempImage);
+         free(tempImage);
          return NULL;
       }
 
@@ -419,7 +419,7 @@ make_temp_float_image(GLcontext *ctx, GLuint dims,
          }
       } /* loop over 3D image slices */
 
-      _mesa_free(convImage);
+      free(convImage);
 
       /* might need these below */
       srcWidth = convWidth;
@@ -433,7 +433,7 @@ make_temp_float_image(GLcontext *ctx, GLuint dims,
       GLfloat *dst;
       GLint img, row;
 
-      tempImage = (GLfloat *) _mesa_malloc(srcWidth * srcHeight * srcDepth
+      tempImage = (GLfloat *) malloc(srcWidth * srcHeight * srcDepth
                                            * components * sizeof(GLfloat));
       if (!tempImage)
          return NULL;
@@ -472,10 +472,10 @@ make_temp_float_image(GLcontext *ctx, GLuint dims,
        */
       ASSERT(texComponents >= logComponents);
 
-      newImage = (GLfloat *) _mesa_malloc(srcWidth * srcHeight * srcDepth
+      newImage = (GLfloat *) malloc(srcWidth * srcHeight * srcDepth
                                           * texComponents * sizeof(GLfloat));
       if (!newImage) {
-         _mesa_free(tempImage);
+         free(tempImage);
          return NULL;
       }
 
@@ -495,7 +495,7 @@ make_temp_float_image(GLcontext *ctx, GLuint dims,
          }
       }
 
-      _mesa_free(tempImage);
+      free(tempImage);
       tempImage = newImage;
    }
 
@@ -582,11 +582,11 @@ _mesa_make_temp_chan_image(GLcontext *ctx, GLuint dims,
 #endif
 
    /* unpack and transfer the source image */
-   tempImage = (GLchan *) _mesa_malloc(srcWidth * srcHeight * srcDepth
+   tempImage = (GLchan *) malloc(srcWidth * srcHeight * srcDepth
                                        * components * sizeof(GLchan));
    if (!tempImage) {
       if (freeSrcImage) {
-         _mesa_free((void *) srcAddr);
+         free((void *) srcAddr);
       }
       return NULL;
    }
@@ -611,7 +611,7 @@ _mesa_make_temp_chan_image(GLcontext *ctx, GLuint dims,
 
    /* If we made a temporary image for convolution, free it here */
    if (freeSrcImage) {
-      _mesa_free((void *) srcAddr);
+      free((void *) srcAddr);
    }
 
    if (logicalBaseFormat != textureBaseFormat) {
@@ -631,10 +631,10 @@ _mesa_make_temp_chan_image(GLcontext *ctx, GLuint dims,
        */
       ASSERT(texComponents >= logComponents);
 
-      newImage = (GLchan *) _mesa_malloc(srcWidth * srcHeight * srcDepth
+      newImage = (GLchan *) malloc(srcWidth * srcHeight * srcDepth
                                          * texComponents * sizeof(GLchan));
       if (!newImage) {
-         _mesa_free(tempImage);
+         free(tempImage);
          return NULL;
       }
 
@@ -654,7 +654,7 @@ _mesa_make_temp_chan_image(GLcontext *ctx, GLuint dims,
          }
       }
 
-      _mesa_free(tempImage);
+      free(tempImage);
       tempImage = newImage;
    }
 
@@ -884,7 +884,7 @@ _mesa_swizzle_ubyte_image(GLcontext *ctx,
    for (i = 0; i < 4; i++)
       map[i] = srctype2ubyte[swap[src2base[base2rgba[rgba2dst[i]]]]];
 
-/*    _mesa_printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]);  */
+/*    printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]);  */
 
    if (srcComponents == dstComponents &&
        srcRowStride == dstRowStride &&
@@ -1077,6 +1077,44 @@ _mesa_texstore_x8_z24(TEXSTORE_PARAMS)
 }
 
 
+/**
+ * Store a 24-bit integer depth component texture image.
+ */
+static GLboolean
+_mesa_texstore_z24_x8(TEXSTORE_PARAMS)
+{
+   const GLuint depthScale = 0xffffff;
+   const GLuint texelBytes = 4;
+
+   (void) dims;
+   ASSERT(dstFormat == MESA_FORMAT_Z24_X8);
+
+   {
+      /* general path */
+      GLint img, row;
+      for (img = 0; img < srcDepth; img++) {
+         GLubyte *dstRow = (GLubyte *) dstAddr
+            + dstImageOffsets[dstZoffset + img] * texelBytes
+            + dstYoffset * dstRowStride
+            + dstXoffset * texelBytes;
+         for (row = 0; row < srcHeight; row++) {
+            const GLvoid *src = _mesa_image_address(dims, srcPacking,
+                srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
+            GLuint *dst = (GLuint *) dstRow;
+            GLint i;
+            _mesa_unpack_depth_span(ctx, srcWidth,
+                                    GL_UNSIGNED_INT, dst,
+                                    depthScale, srcType, src, srcPacking);
+            for (i = 0; i < srcWidth; i++)
+               dst[i] <<= 8;
+            dstRow += dstRowStride;
+         }
+      }
+   }
+   return GL_TRUE;
+}
+
+
 /**
  * Store a 16-bit integer depth component texture image.
  */
@@ -1229,7 +1267,7 @@ _mesa_texstore_rgb565(TEXSTORE_PARAMS)
             dstRow += dstRowStride;
          }
       }
-      _mesa_free((void *) tempImage);
+      free((void *) tempImage);
    }
    return GL_TRUE;
 }
@@ -1357,7 +1395,7 @@ _mesa_texstore_rgba8888(TEXSTORE_PARAMS)
             dstRow += dstRowStride;
          }
       }
-      _mesa_free((void *) tempImage);
+      free((void *) tempImage);
    }
    return GL_TRUE;
 }
@@ -1368,11 +1406,12 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS)
 {
    const GLboolean littleEndian = _mesa_little_endian();
    const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
-   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+   const GLenum baseFormat = GL_RGBA;
 
    ASSERT(dstFormat == MESA_FORMAT_ARGB8888 ||
           dstFormat == MESA_FORMAT_ARGB8888_REV ||
-          dstFormat == MESA_FORMAT_XRGB8888);
+          dstFormat == MESA_FORMAT_XRGB8888 ||
+          dstFormat == MESA_FORMAT_XRGB8888_REV );
    ASSERT(texelBytes == 4);
 
    if (!ctx->_ImageTransferState &&
@@ -1393,7 +1432,8 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS)
    }
    else if (!ctx->_ImageTransferState &&
        !srcPacking->SwapBytes &&
-       dstFormat == MESA_FORMAT_ARGB8888_REV &&
+       (dstFormat == MESA_FORMAT_ARGB8888_REV ||
+        dstFormat == MESA_FORMAT_XRGB8888_REV) &&
        baseInternalFormat == GL_RGBA &&
        srcFormat == GL_BGRA &&
        ((srcType == GL_UNSIGNED_BYTE && !littleEndian) ||
@@ -1486,7 +1526,8 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS)
        */
       if ((littleEndian && dstFormat == MESA_FORMAT_ARGB8888) ||
           (littleEndian && dstFormat == MESA_FORMAT_XRGB8888) ||
-         (!littleEndian && dstFormat == MESA_FORMAT_ARGB8888_REV)) {
+         (!littleEndian && dstFormat == MESA_FORMAT_ARGB8888_REV) ||
+         (!littleEndian && dstFormat == MESA_FORMAT_XRGB8888_REV)) {
         dstmap[3] = 3;         /* alpha */
         dstmap[2] = 0;         /* red */
         dstmap[1] = 1;         /* green */
@@ -1495,6 +1536,7 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS)
       else {
         assert((littleEndian && dstFormat == MESA_FORMAT_ARGB8888_REV) ||
                (!littleEndian && dstFormat == MESA_FORMAT_ARGB8888) ||
+               (littleEndian && dstFormat == MESA_FORMAT_XRGB8888_REV) ||
                (!littleEndian && dstFormat == MESA_FORMAT_XRGB8888));
         dstmap[3] = 2;
         dstmap[2] = 1;
@@ -1564,7 +1606,7 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS)
             dstRow += dstRowStride;
          }
       }
-      _mesa_free((void *) tempImage);
+      free((void *) tempImage);
    }
    return GL_TRUE;
 }
@@ -1691,7 +1733,7 @@ _mesa_texstore_rgb888(TEXSTORE_PARAMS)
             dstRow += dstRowStride;
          }
       }
-      _mesa_free((void *) tempImage);
+      free((void *) tempImage);
    }
    return GL_TRUE;
 }
@@ -1799,7 +1841,7 @@ _mesa_texstore_bgr888(TEXSTORE_PARAMS)
             dstRow += dstRowStride;
          }
       }
-      _mesa_free((void *) tempImage);
+      free((void *) tempImage);
    }
    return GL_TRUE;
 }
@@ -1870,7 +1912,7 @@ _mesa_texstore_argb4444(TEXSTORE_PARAMS)
             dstRow += dstRowStride;
          }
       }
-      _mesa_free((void *) tempImage);
+      free((void *) tempImage);
    }
    return GL_TRUE;
 }
@@ -1928,7 +1970,7 @@ _mesa_texstore_rgba5551(TEXSTORE_PARAMS)
             dstRow += dstRowStride;
          }
       }
-      _mesa_free((void *) tempImage);
+      free((void *) tempImage);
    }
    return GL_TRUE;
 }
@@ -1998,7 +2040,7 @@ _mesa_texstore_argb1555(TEXSTORE_PARAMS)
             dstRow += dstRowStride;
          }
       }
-      _mesa_free((void *) tempImage);
+      free((void *) tempImage);
    }
    return GL_TRUE;
 }
@@ -2101,7 +2143,216 @@ _mesa_texstore_al88(TEXSTORE_PARAMS)
             dstRow += dstRowStride;
          }
       }
-      _mesa_free((void *) tempImage);
+      free((void *) tempImage);
+   }
+   return GL_TRUE;
+}
+
+
+static GLboolean
+_mesa_texstore_al1616(TEXSTORE_PARAMS)
+{
+   const GLboolean littleEndian = _mesa_little_endian();
+   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+   ASSERT(dstFormat == MESA_FORMAT_AL1616 ||
+          dstFormat == MESA_FORMAT_AL1616_REV);
+   ASSERT(texelBytes == 4);
+
+   if (!ctx->_ImageTransferState &&
+       !srcPacking->SwapBytes &&
+       dstFormat == MESA_FORMAT_AL1616 &&
+       baseInternalFormat == GL_LUMINANCE_ALPHA &&
+       srcFormat == GL_LUMINANCE_ALPHA &&
+       srcType == GL_UNSIGNED_SHORT &&
+       littleEndian) {
+      /* simple memcpy path */
+      memcpy_texture(ctx, dims,
+                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+                     dstRowStride,
+                     dstImageOffsets,
+                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+                     srcAddr, srcPacking);
+   }
+   else {
+      /* general path */
+      const GLfloat *tempImage = make_temp_float_image(ctx, dims,
+                                                 baseInternalFormat,
+                                                 baseFormat,
+                                                 srcWidth, srcHeight, srcDepth,
+                                                 srcFormat, srcType, srcAddr,
+                                                 srcPacking);
+      const GLfloat *src = tempImage;
+      GLint img, row, col;
+      if (!tempImage)
+         return GL_FALSE;
+      _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
+      for (img = 0; img < srcDepth; img++) {
+         GLubyte *dstRow = (GLubyte *) dstAddr
+            + dstImageOffsets[dstZoffset + img] * texelBytes
+            + dstYoffset * dstRowStride
+            + dstXoffset * texelBytes;
+         for (row = 0; row < srcHeight; row++) {
+            GLuint *dstUI = (GLuint *) dstRow;
+            if (dstFormat == MESA_FORMAT_AL1616) {
+               for (col = 0; col < srcWidth; col++) {
+                 GLushort l, a;
+
+                 UNCLAMPED_FLOAT_TO_USHORT(l, src[0]);
+                 UNCLAMPED_FLOAT_TO_USHORT(a, src[1]);
+                 dstUI[col] = PACK_COLOR_1616(a, l);
+                 src += 2;
+               }
+            }
+            else {
+               for (col = 0; col < srcWidth; col++) {
+                 GLushort l, a;
+
+                 UNCLAMPED_FLOAT_TO_USHORT(l, src[0]);
+                 UNCLAMPED_FLOAT_TO_USHORT(a, src[1]);
+                 dstUI[col] = PACK_COLOR_1616_REV(a, l);
+                 src += 2;
+               }
+            }
+            dstRow += dstRowStride;
+         }
+      }
+      free((void *) tempImage);
+   }
+   return GL_TRUE;
+}
+
+
+static GLboolean
+_mesa_texstore_rgba_16(TEXSTORE_PARAMS)
+{
+   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+   ASSERT(dstFormat == MESA_FORMAT_RGBA_16);
+   ASSERT(texelBytes == 8);
+
+   if (!ctx->_ImageTransferState &&
+       !srcPacking->SwapBytes &&
+       baseInternalFormat == GL_RGBA &&
+       srcFormat == GL_RGBA &&
+       srcType == GL_UNSIGNED_SHORT) {
+      /* simple memcpy path */
+      memcpy_texture(ctx, dims,
+                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+                     dstRowStride,
+                     dstImageOffsets,
+                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+                     srcAddr, srcPacking);
+   }
+   else {
+      /* general path */
+      const GLfloat *tempImage = make_temp_float_image(ctx, dims,
+                                                 baseInternalFormat,
+                                                 baseFormat,
+                                                 srcWidth, srcHeight, srcDepth,
+                                                 srcFormat, srcType, srcAddr,
+                                                 srcPacking);
+      const GLfloat *src = tempImage;
+      GLint img, row, col;
+      if (!tempImage)
+         return GL_FALSE;
+      _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
+      for (img = 0; img < srcDepth; img++) {
+         GLubyte *dstRow = (GLubyte *) dstAddr
+            + dstImageOffsets[dstZoffset + img] * texelBytes
+            + dstYoffset * dstRowStride
+            + dstXoffset * texelBytes;
+         for (row = 0; row < srcHeight; row++) {
+            GLushort *dstUS = (GLushort *) dstRow;
+            for (col = 0; col < srcWidth; col++) {
+               GLushort r, g, b, a;
+
+               UNCLAMPED_FLOAT_TO_USHORT(r, src[0]);
+               UNCLAMPED_FLOAT_TO_USHORT(g, src[1]);
+               UNCLAMPED_FLOAT_TO_USHORT(b, src[2]);
+               UNCLAMPED_FLOAT_TO_USHORT(a, src[3]);
+               dstUS[col*4+0] = r;
+               dstUS[col*4+1] = g;
+               dstUS[col*4+2] = b;
+               dstUS[col*4+3] = a;
+               src += 4;
+            }
+            dstRow += dstRowStride;
+         }
+      }
+      free((void *) tempImage);
+   }
+   return GL_TRUE;
+}
+
+
+static GLboolean
+_mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS)
+{
+   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+   ASSERT(dstFormat == MESA_FORMAT_SIGNED_R_16 ||
+          dstFormat == MESA_FORMAT_SIGNED_RG_16 ||
+          dstFormat == MESA_FORMAT_SIGNED_RGB_16 ||
+          dstFormat == MESA_FORMAT_SIGNED_RGBA_16);
+
+   if (!ctx->_ImageTransferState &&
+       !srcPacking->SwapBytes &&
+       baseInternalFormat == GL_RGBA &&
+       dstFormat == MESA_FORMAT_SIGNED_RGBA_16 &&
+       srcFormat == GL_RGBA &&
+       srcType == GL_SHORT) {
+      /* simple memcpy path */
+      memcpy_texture(ctx, dims,
+                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+                     dstRowStride,
+                     dstImageOffsets,
+                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+                     srcAddr, srcPacking);
+   }
+   else {
+      /* general path */
+      const GLfloat *tempImage = make_temp_float_image(ctx, dims,
+                                                 baseInternalFormat,
+                                                 baseFormat,
+                                                 srcWidth, srcHeight, srcDepth,
+                                                 srcFormat, srcType, srcAddr,
+                                                 srcPacking);
+      const GLfloat *src = tempImage;
+      const GLuint comps = _mesa_get_format_bytes(dstFormat) / 2;
+      GLint img, row, col;
+
+      if (!tempImage)
+         return GL_FALSE;
+
+      _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
+
+      /* Note: tempImage is always float[4] / RGBA.  We convert to 1, 2,
+       * 3 or 4 components/pixel here.
+       */
+      for (img = 0; img < srcDepth; img++) {
+         GLubyte *dstRow = (GLubyte *) dstAddr
+            + dstImageOffsets[dstZoffset + img] * texelBytes
+            + dstYoffset * dstRowStride
+            + dstXoffset * texelBytes;
+         for (row = 0; row < srcHeight; row++) {
+            GLshort *dstRowS = (GLshort *) dstRow;
+            for (col = 0; col < srcWidth; col++) {
+               GLuint c;
+               for (c = 0; c < comps; c++) {
+                  GLshort p;
+                  UNCLAMPED_FLOAT_TO_SHORT(p, src[col * 4 + c]);
+                  dstRowS[col * comps + c] = p;
+               }
+            }
+            dstRow += dstRowStride;
+            src += 4 * srcWidth;
+         }
+      }
+      free((void *) tempImage);
    }
    return GL_TRUE;
 }
@@ -2156,7 +2407,7 @@ _mesa_texstore_rgb332(TEXSTORE_PARAMS)
             dstRow += dstRowStride;
          }
       }
-      _mesa_free((void *) tempImage);
+      free((void *) tempImage);
    }
    return GL_TRUE;
 }
@@ -2243,7 +2494,7 @@ _mesa_texstore_a8(TEXSTORE_PARAMS)
             src += srcWidth;
          }
       }
-      _mesa_free((void *) tempImage);
+      free((void *) tempImage);
    }
    return GL_TRUE;
 }
@@ -2401,7 +2652,7 @@ _mesa_texstore_dudv8(TEXSTORE_PARAMS)
       GLbyte *tempImage, *dst, *src;
       GLint row;
 
-      tempImage = (GLbyte *) _mesa_malloc(srcWidth * srcHeight * srcDepth
+      tempImage = (GLbyte *) malloc(srcWidth * srcHeight * srcDepth
                                           * components * sizeof(GLbyte));
       if (!tempImage)
          return GL_FALSE;
@@ -2429,11 +2680,152 @@ _mesa_texstore_dudv8(TEXSTORE_PARAMS)
          dst += dstRowStride;
          src += srcWidth * texelBytes;
       }
-      _mesa_free((void *) tempImage);
+      free((void *) tempImage);
    }
    return GL_TRUE;
 }
 
+
+/**
+ * Store a texture in MESA_FORMAT_SIGNED_R8 format.
+ */
+static GLboolean
+_mesa_texstore_signed_r8(TEXSTORE_PARAMS)
+{
+   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+   ASSERT(dstFormat == MESA_FORMAT_SIGNED_R8);
+   ASSERT(texelBytes == 1);
+
+   /* XXX look at adding optimized paths */
+   {
+      /* general path */
+      const GLfloat *tempImage = make_temp_float_image(ctx, dims,
+                                                 baseInternalFormat,
+                                                 baseFormat,
+                                                 srcWidth, srcHeight, srcDepth,
+                                                 srcFormat, srcType, srcAddr,
+                                                 srcPacking);
+      const GLfloat *srcRow = tempImage;
+      GLint img, row, col;
+      if (!tempImage)
+         return GL_FALSE;
+      _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
+      for (img = 0; img < srcDepth; img++) {
+         GLubyte *dstRow = (GLubyte *) dstAddr
+            + dstImageOffsets[dstZoffset + img] * texelBytes
+            + dstYoffset * dstRowStride
+            + dstXoffset * texelBytes;
+         for (row = 0; row < srcHeight; row++) {
+            GLubyte *dstB = (GLubyte *) dstRow;
+            for (col = 0; col < srcWidth; col++) {
+               dstB[col] = FLOAT_TO_BYTE_TEX(srcRow[RCOMP]);
+            }
+            dstRow += dstRowStride;
+         }
+      }
+      free((void *) tempImage);
+   }
+   return GL_TRUE;
+}
+
+
+/**
+ * Store a texture in MESA_FORMAT_SIGNED_RG88 format.
+ */
+static GLboolean
+_mesa_texstore_signed_rg88(TEXSTORE_PARAMS)
+{
+   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+   ASSERT(dstFormat == MESA_FORMAT_SIGNED_RG88);
+   ASSERT(texelBytes == 1);
+
+   /* XXX look at adding optimized paths */
+   {
+      /* general path */
+      const GLfloat *tempImage = make_temp_float_image(ctx, dims,
+                                                 baseInternalFormat,
+                                                 baseFormat,
+                                                 srcWidth, srcHeight, srcDepth,
+                                                 srcFormat, srcType, srcAddr,
+                                                 srcPacking);
+      const GLfloat *srcRow = tempImage;
+      GLint img, row, col;
+      if (!tempImage)
+         return GL_FALSE;
+      _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
+      for (img = 0; img < srcDepth; img++) {
+         GLubyte *dstRow = (GLubyte *) dstAddr
+            + dstImageOffsets[dstZoffset + img] * texelBytes
+            + dstYoffset * dstRowStride
+            + dstXoffset * texelBytes;
+         for (row = 0; row < srcHeight; row++) {
+            GLushort *dstUS = (GLushort *) dstRow;
+            for (col = 0; col < srcWidth; col++) {
+               dstUS[col] = PACK_COLOR_88(FLOAT_TO_BYTE_TEX(srcRow[RCOMP]),
+                                          FLOAT_TO_BYTE_TEX(srcRow[GCOMP]));
+            }
+            dstRow += dstRowStride;
+         }
+      }
+      free((void *) tempImage);
+   }
+   return GL_TRUE;
+}
+
+
+/**
+ * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
+ */
+static GLboolean
+_mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS)
+{
+   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+   ASSERT(dstFormat == MESA_FORMAT_SIGNED_RGBX8888);
+   ASSERT(texelBytes == 4);
+
+   {
+      /* general path */
+      const GLfloat *tempImage = make_temp_float_image(ctx, dims,
+                                                 baseInternalFormat,
+                                                 baseFormat,
+                                                 srcWidth, srcHeight, srcDepth,
+                                                 srcFormat, srcType, srcAddr,
+                                                 srcPacking);
+      const GLfloat *srcRow = tempImage;
+      GLint img, row, col;
+      if (!tempImage)
+         return GL_FALSE;
+      _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
+      for (img = 0; img < srcDepth; img++) {
+         GLubyte *dstRow = (GLubyte *) dstAddr
+            + dstImageOffsets[dstZoffset + img] * texelBytes
+            + dstYoffset * dstRowStride
+            + dstXoffset * texelBytes;
+         for (row = 0; row < srcHeight; row++) {
+            GLuint *dstUI = (GLuint *) dstRow;
+            for (col = 0; col < srcWidth; col++) {
+               dstUI[col] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow[RCOMP]),
+                                             FLOAT_TO_BYTE_TEX(srcRow[GCOMP]),
+                                             FLOAT_TO_BYTE_TEX(srcRow[BCOMP]),
+                                             0xff );
+               srcRow += 4;
+            }
+            dstRow += dstRowStride;
+         }
+      }
+      free((void *) tempImage);
+   }
+   return GL_TRUE;
+}
+
+
+
 /**
  * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or MESA_FORMAT_SIGNED_RGBA8888_REV
  */
@@ -2550,18 +2942,19 @@ _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS)
             dstRow += dstRowStride;
          }
       }
-      _mesa_free((void *) tempImage);
+      free((void *) tempImage);
    }
    return GL_TRUE;
 }
 
+
 /**
  * Store a combined depth/stencil texture image.
  */
 static GLboolean
 _mesa_texstore_z24_s8(TEXSTORE_PARAMS)
 {
-   const GLfloat depthScale = (GLfloat) 0xffffff;
+   const GLuint depthScale = 0xffffff;
    const GLint srcRowStride
       = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
       / sizeof(GLuint);
@@ -2635,7 +3028,7 @@ _mesa_texstore_z24_s8(TEXSTORE_PARAMS)
             _mesa_unpack_depth_span(ctx, srcWidth,
                                     GL_UNSIGNED_INT_24_8_EXT, /* dst type */
                                     dstRow, /* dst addr */
-                                    (GLuint) depthScale,
+                                    depthScale,
                                     srcType, src, srcPacking);
             /* get the 8-bit stencil values */
             _mesa_unpack_stencil_span(ctx, srcWidth,
@@ -2802,13 +3195,13 @@ _mesa_texstore_rgba_float32(TEXSTORE_PARAMS)
             + dstYoffset * dstRowStride
             + dstXoffset * texelBytes;
          for (row = 0; row < srcHeight; row++) {
-            _mesa_memcpy(dstRow, srcRow, bytesPerRow);
+            memcpy(dstRow, srcRow, bytesPerRow);
             dstRow += dstRowStride;
             srcRow += srcWidth * components;
          }
       }
 
-      _mesa_free((void *) tempImage);
+      free((void *) tempImage);
    }
    return GL_TRUE;
 }
@@ -2879,7 +3272,7 @@ _mesa_texstore_rgba_float16(TEXSTORE_PARAMS)
          }
       }
 
-      _mesa_free((void *) tempImage);
+      free((void *) tempImage);
    }
    return GL_TRUE;
 }
@@ -3012,7 +3405,7 @@ _mesa_texstore_sla8(TEXSTORE_PARAMS)
  * Table mapping MESA_FORMAT_8 to _mesa_texstore_*()
  * XXX this is somewhat temporary.
  */
-static struct {
+static const struct {
    gl_format Name;
    StoreTexImageFunc Store;
 }
@@ -3024,6 +3417,7 @@ texstore_funcs[MESA_FORMAT_COUNT] =
    { MESA_FORMAT_ARGB8888, _mesa_texstore_argb8888 },
    { MESA_FORMAT_ARGB8888_REV, _mesa_texstore_argb8888 },
    { MESA_FORMAT_XRGB8888, _mesa_texstore_argb8888 },
+   { MESA_FORMAT_XRGB8888_REV, _mesa_texstore_argb8888 },
    { MESA_FORMAT_RGB888, _mesa_texstore_rgb888 },
    { MESA_FORMAT_BGR888, _mesa_texstore_bgr888 },
    { MESA_FORMAT_RGB565, _mesa_texstore_rgb565 },
@@ -3035,6 +3429,8 @@ texstore_funcs[MESA_FORMAT_COUNT] =
    { MESA_FORMAT_ARGB1555_REV, _mesa_texstore_argb1555 },
    { MESA_FORMAT_AL88, _mesa_texstore_al88 },
    { MESA_FORMAT_AL88_REV, _mesa_texstore_al88 },
+   { MESA_FORMAT_AL1616, _mesa_texstore_al1616 },
+   { MESA_FORMAT_AL1616_REV, _mesa_texstore_al1616 },
    { MESA_FORMAT_RGB332, _mesa_texstore_rgb332 },
    { MESA_FORMAT_A8, _mesa_texstore_a8 },
    { MESA_FORMAT_L8, _mesa_texstore_a8 },
@@ -3046,6 +3442,7 @@ texstore_funcs[MESA_FORMAT_COUNT] =
    { MESA_FORMAT_S8_Z24, _mesa_texstore_s8_z24 },
    { MESA_FORMAT_Z16, _mesa_texstore_z16 },
    { MESA_FORMAT_X8_Z24, _mesa_texstore_x8_z24 },
+   { MESA_FORMAT_Z24_X8, _mesa_texstore_z24_x8 },
    { MESA_FORMAT_Z32, _mesa_texstore_z32 },
    { MESA_FORMAT_S8, NULL/*_mesa_texstore_s8*/ },
    { MESA_FORMAT_SRGB8, _mesa_texstore_srgb8 },
@@ -3076,9 +3473,19 @@ texstore_funcs[MESA_FORMAT_COUNT] =
    { MESA_FORMAT_INTENSITY_FLOAT32, _mesa_texstore_rgba_float32 },
    { MESA_FORMAT_INTENSITY_FLOAT16, _mesa_texstore_rgba_float16 },
    { MESA_FORMAT_DUDV8, _mesa_texstore_dudv8 },
+
+   { MESA_FORMAT_SIGNED_R8, _mesa_texstore_signed_r8 },
+   { MESA_FORMAT_SIGNED_RG88, _mesa_texstore_signed_rg88 },
+   { MESA_FORMAT_SIGNED_RGBX8888, _mesa_texstore_signed_rgbx8888 },
+
    { MESA_FORMAT_SIGNED_RGBA8888, _mesa_texstore_signed_rgba8888 },
    { MESA_FORMAT_SIGNED_RGBA8888_REV, _mesa_texstore_signed_rgba8888 },
-   { MESA_FORMAT_SIGNED_RGBA_16, NULL },
+
+   { MESA_FORMAT_SIGNED_R_16, _mesa_texstore_signed_rgba_16 },
+   { MESA_FORMAT_SIGNED_RG_16, _mesa_texstore_signed_rgba_16 },
+   { MESA_FORMAT_SIGNED_RGB_16, _mesa_texstore_signed_rgba_16 },
+   { MESA_FORMAT_SIGNED_RGBA_16, _mesa_texstore_signed_rgba_16 },
+   { MESA_FORMAT_RGBA_16, _mesa_texstore_rgba_16 }
 };
 
 
@@ -3108,8 +3515,8 @@ _mesa_texstore_null(TEXSTORE_PARAMS)
 static StoreTexImageFunc
 _mesa_get_texstore_func(gl_format format)
 {
-   GLuint i;
 #ifdef DEBUG
+   GLuint i;
    for (i = 0; i < MESA_FORMAT_COUNT; i++) {
       ASSERT(texstore_funcs[i].Name == i);
    }
@@ -3595,7 +4002,7 @@ _mesa_store_compressed_teximage2d(GLcontext *ctx, GLenum target, GLint level,
       return;
 
    /* copy the data */
-   MEMCPY(texImage->Data, data, imageSize);
+   memcpy(texImage->Data, data, imageSize);
 
    _mesa_unmap_teximage_pbo(ctx, &ctx->Unpack);
 }
@@ -3702,7 +4109,7 @@ _mesa_store_compressed_texsubimage2d(GLcontext *ctx, GLenum target,
 
    /* copy rows of blocks */
    for (i = 0; i < rows; i++) {
-      MEMCPY(dest, src, bytesPerRow);
+      memcpy(dest, src, bytesPerRow);
       dest += destRowStride;
       src += srcRowStride;
    }