mesa: replace gl_texture_format with gl_format
[mesa.git] / src / mesa / drivers / dri / tdfx / tdfx_tex.c
index fe40953a1b3bbc2423f206ffeb3358f5795b1b78..427d315a01d36155924005a8b8e67a1cc326b6ee 100644 (file)
@@ -23,7 +23,6 @@
  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
-/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/tdfx_tex.c,v 1.7 2002/11/05 17:46:10 tsi Exp $ */
 
 /*
  * New fixes:
  */
 
 
-#include "enums.h"
-#include "image.h"
-#include "texcompress.h"
-#include "texformat.h"
-#include "teximage.h"
-#include "texstore.h"
-#include "texobj.h"
+#include "main/enums.h"
+#include "main/image.h"
+#include "main/mipmap.h"
+#include "main/texcompress.h"
+#include "main/texformat.h"
+#include "main/teximage.h"
+#include "main/texstore.h"
+#include "main/texobj.h"
 #include "tdfx_context.h"
 #include "tdfx_tex.h"
 #include "tdfx_texman.h"
 
 
 /* no borders! can't halve 1x1! (stride > width * comp) not allowed */
-void
+static void
 _mesa_halve2x2_teximage2d ( GLcontext *ctx,
                            struct gl_texture_image *texImage,
                            GLuint bytesPerPixel,
@@ -65,19 +65,20 @@ _mesa_halve2x2_teximage2d ( GLcontext *ctx,
    GLint srcRowStride = srcWidth * bytesPerPixel;
    GLubyte *src = (GLubyte *)srcImage;
    GLubyte *dst = dstImage;
+   GLuint dstImageOffsets = 0;
 
    GLuint bpt = 0;
    GLubyte *_s = NULL;
    GLubyte *_d = NULL;
    GLenum _t = 0;
 
-   if (texImage->TexFormat->MesaFormat == MESA_FORMAT_RGB565) {
+   if (texImage->TexFormat == MESA_FORMAT_RGB565) {
       _t = GL_UNSIGNED_SHORT_5_6_5_REV;
       bpt = bytesPerPixel;
-   } else if (texImage->TexFormat->MesaFormat == MESA_FORMAT_ARGB4444) {
+   } else if (texImage->TexFormat == MESA_FORMAT_ARGB4444) {
       _t = GL_UNSIGNED_SHORT_4_4_4_4_REV;
       bpt = bytesPerPixel;
-   } else if (texImage->TexFormat->MesaFormat == MESA_FORMAT_ARGB1555) {
+   } else if (texImage->TexFormat == MESA_FORMAT_ARGB1555) {
       _t = GL_UNSIGNED_SHORT_1_5_5_5_REV;
       bpt = bytesPerPixel;
    }
@@ -92,13 +93,13 @@ _mesa_halve2x2_teximage2d ( GLcontext *ctx,
       }
       _s = src = MALLOC(srcRowStride * srcHeight);
       _d = dst = MALLOC(dstWidth * bytesPerPixel * dstHeight);
-      _mesa_texstore_rgba8888(ctx, 2, GL_RGBA,
-                              &_mesa_texformat_rgba8888_rev, src,
-                              0, 0, 0, /* dstX/Y/Zoffset */
-                              srcRowStride, /* dstRowStride */
-                              0, /* dstImageStride */
-                              srcWidth, srcHeight, 1,
-                              texImage->_BaseFormat, _t, srcImage, &ctx->DefaultPacking);
+      _mesa_texstore(ctx, 2, GL_RGBA,
+                     MESA_FORMAT_RGBA8888_REV, src,
+                     0, 0, 0, /* dstX/Y/Zoffset */
+                     srcRowStride, /* dstRowStride */
+                     &dstImageOffsets,
+                     srcWidth, srcHeight, 1,
+                     texImage->_BaseFormat, _t, srcImage, &ctx->DefaultPacking);
    }
 
    if (srcHeight == 1) {
@@ -139,13 +140,13 @@ _mesa_halve2x2_teximage2d ( GLcontext *ctx,
    if (bpt) {
       src = _s;
       dst = _d;
-      texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,
-                                      texImage->TexFormat, dstImage,
-                                      0, 0, 0, /* dstX/Y/Zoffset */
-                                      dstWidth * bpt,
-                                      0, /* dstImageStride */
-                                      dstWidth, dstHeight, 1,
-                                      GL_BGRA, CHAN_TYPE, dst, &ctx->DefaultPacking);
+      _mesa_texstore(ctx, 2, texImage->_BaseFormat,
+                     texImage->TexFormat, dstImage,
+                     0, 0, 0, /* dstX/Y/Zoffset */
+                     dstWidth * bpt,
+                     &dstImageOffsets,
+                     dstWidth, dstHeight, 1,
+                     GL_BGRA, CHAN_TYPE, dst, &ctx->DefaultPacking);
       FREE(dst);
       FREE(src);
    }
@@ -175,6 +176,55 @@ logbase2(int n)
 }
 
 
+static void
+tdfxGenerateMipmap(GLcontext *ctx, GLenum target,
+                   struct gl_texture_object *texObj)
+{
+   GLint mipWidth, mipHeight;
+   tdfxMipMapLevel *mip;
+   struct gl_texture_image *mipImage; /* the new/next image */
+   struct gl_texture_image *texImage;
+   const GLint maxLevels = _mesa_max_texture_levels(ctx, texObj->Target);
+   GLint level = texObj->BaseLevel;
+   GLsizei width, height, texelBytes;
+   const tdfxMipMapLevel *mml;
+
+   texImage = _mesa_get_tex_image(ctx, texObj, target, level);
+   texelBytes = _mesa_get_format_bytes(texImage->TexFormat);
+   assert(!texImage->IsCompressed);
+
+   mml = TDFX_TEXIMAGE_DATA(texImage);
+
+   width = texImage->Width;
+   height = texImage->Height;
+   while (level < texObj->MaxLevel && level < maxLevels - 1) {
+      mipWidth = width / 2;
+      if (!mipWidth) {
+         mipWidth = 1;
+      }
+      mipHeight = height / 2;
+      if (!mipHeight) {
+         mipHeight = 1;
+      }
+      if ((mipWidth == width) && (mipHeight == height)) {
+         break;
+      }
+      ++level;
+      mipImage = _mesa_select_tex_image(ctx, texObj, target, level);
+      mip = TDFX_TEXIMAGE_DATA(mipImage);
+      _mesa_halve2x2_teximage2d(ctx,
+                                texImage,
+                                texelBytes,
+                                mml->width, mml->height,
+                                texImage->Data, mipImage->Data);
+      texImage = mipImage;
+      mml = mip;
+      width = mipWidth;
+      height = mipHeight;
+   }
+}
+
+
 /*
  * Compute various texture image parameters.
  * Input:  w, h - source texture width and height
@@ -592,13 +642,11 @@ tdfxIsTextureResident(GLcontext *ctx, struct gl_texture_object *tObj)
 static GrTexTable_t
 convertPalette(FxU32 data[256], const struct gl_color_table *table)
 {
-    const GLubyte *tableUB = (const GLubyte *) table->Table;
+    const GLubyte *tableUB = table->TableUB;
     GLint width = table->Size;
     FxU32 r, g, b, a;
     GLint i;
 
-    ASSERT(table->Type == GL_UNSIGNED_BYTE);
-
     switch (table->_BaseFormat) {
     case GL_INTENSITY:
         for (i = 0; i < width; i++) {
@@ -670,7 +718,7 @@ tdfxUpdateTexturePalette(GLcontext * ctx, struct gl_texture_object *tObj)
         tdfxTexInfo *ti;
         
         /* This might be a proxy texture. */
-        if (!tObj->Palette.Table)
+        if (!tObj->Palette.TableUB)
             return;
             
         if (!tObj->DriverData)
@@ -713,7 +761,7 @@ fxTexusError(const char *string, FxBool fatal)
 #endif
 
 
-static const struct gl_texture_format *
+static gl_format
 tdfxChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
                            GLenum srcFormat, GLenum srcType )
 {
@@ -727,7 +775,7 @@ tdfxChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    case GL_ALPHA12:
    case GL_ALPHA16:
    case GL_COMPRESSED_ALPHA:
-      return &_mesa_texformat_a8;
+      return MESA_FORMAT_A8;
    case 1:
    case GL_LUMINANCE:
    case GL_LUMINANCE4:
@@ -735,7 +783,7 @@ tdfxChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    case GL_LUMINANCE12:
    case GL_LUMINANCE16:
    case GL_COMPRESSED_LUMINANCE:
-      return &_mesa_texformat_l8;
+      return MESA_FORMAT_L8;
    case 2:
    case GL_LUMINANCE_ALPHA:
    case GL_LUMINANCE4_ALPHA4:
@@ -745,48 +793,47 @@ tdfxChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    case GL_LUMINANCE12_ALPHA12:
    case GL_LUMINANCE16_ALPHA16:
    case GL_COMPRESSED_LUMINANCE_ALPHA:
-      return &_mesa_texformat_al88;
+      return MESA_FORMAT_AL88;
    case GL_INTENSITY:
    case GL_INTENSITY4:
    case GL_INTENSITY8:
    case GL_INTENSITY12:
    case GL_INTENSITY16:
    case GL_COMPRESSED_INTENSITY:
-      return &_mesa_texformat_i8;
+      return MESA_FORMAT_I8;
    case GL_R3_G3_B2:
    case GL_RGB4:
    case GL_RGB5:
-      return &_mesa_texformat_rgb565;
+      return MESA_FORMAT_RGB565;
    case GL_COMPRESSED_RGB:
       /* intentional fall-through */
    case 3:
    case GL_RGB:
      if ( srcFormat == GL_RGB && srcType == GL_UNSIGNED_SHORT_5_6_5 ) {
-       return &_mesa_texformat_rgb565;
+       return MESA_FORMAT_RGB565;
      }
      /* intentional fall through */
    case GL_RGB8:
    case GL_RGB10:
    case GL_RGB12:
    case GL_RGB16:
-      return (allow32bpt) ? &_mesa_texformat_argb8888
-                          : &_mesa_texformat_rgb565;
+      return (allow32bpt) ? MESA_FORMAT_ARGB8888 : MESA_FORMAT_RGB565;
    case GL_RGBA2:
    case GL_RGBA4:
-      return &_mesa_texformat_argb4444;
+      return MESA_FORMAT_ARGB4444;
    case GL_COMPRESSED_RGBA:
       /* intentional fall-through */
    case 4:
    case GL_RGBA:
      if ( srcFormat == GL_BGRA ) {
        if ( srcType == GL_UNSIGNED_INT_8_8_8_8_REV ) {
-         return &_mesa_texformat_argb8888;
+         return MESA_FORMAT_ARGB8888;
        }
        else if ( srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ) {
-         return &_mesa_texformat_argb4444;
+         return MESA_FORMAT_ARGB4444;
        }
        else if ( srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ) {
-         return &_mesa_texformat_argb1555;
+         return MESA_FORMAT_ARGB1555;
        }
      }
      /* intentional fall through */
@@ -794,10 +841,9 @@ tdfxChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    case GL_RGB10_A2:
    case GL_RGBA12:
    case GL_RGBA16:
-      return allow32bpt ? &_mesa_texformat_argb8888
-                        : &_mesa_texformat_argb4444;
+      return allow32bpt ? MESA_FORMAT_ARGB8888 : MESA_FORMAT_ARGB4444;
    case GL_RGB5_A1:
-      return &_mesa_texformat_argb1555;
+      return MESA_FORMAT_ARGB1555;
    case GL_COLOR_INDEX:
    case GL_COLOR_INDEX1_EXT:
    case GL_COLOR_INDEX2_EXT:
@@ -805,29 +851,29 @@ tdfxChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    case GL_COLOR_INDEX8_EXT:
    case GL_COLOR_INDEX12_EXT:
    case GL_COLOR_INDEX16_EXT:
-      return &_mesa_texformat_ci8;
+      return MESA_FORMAT_CI8;
    /* GL_EXT_texture_compression_s3tc */
    /* GL_S3_s3tc */
    case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
    case GL_RGB_S3TC:
    case GL_RGB4_S3TC:
-      return &_mesa_texformat_rgb_dxt1;
+      return MESA_FORMAT_RGB_DXT1;
    case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
-      return &_mesa_texformat_rgba_dxt1;
+      return MESA_FORMAT_RGBA_DXT1;
    case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
    case GL_RGBA_S3TC:
    case GL_RGBA4_S3TC:
-      return &_mesa_texformat_rgba_dxt3;
+      return MESA_FORMAT_RGBA_DXT3;
    case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
-      return &_mesa_texformat_rgba_dxt5;
+      return MESA_FORMAT_RGBA_DXT5;
    /* GL_3DFX_texture_compression_FXT1 */
    case GL_COMPRESSED_RGB_FXT1_3DFX:
-      return &_mesa_texformat_rgb_fxt1;
+      return MESA_FORMAT_RGB_FXT1;
    case GL_COMPRESSED_RGBA_FXT1_3DFX:
-      return &_mesa_texformat_rgba_fxt1;
+      return MESA_FORMAT_RGBA_FXT1;
    default:
       _mesa_problem(ctx, "unexpected format in tdfxChooseTextureFormat");
-      return NULL;
+      return MESA_FORMAT_NONE;
    }
 }
 
@@ -1079,7 +1125,9 @@ fetch_rgb_dxt1(const struct gl_texture_image *texImage,
     i = i * mml->wScale;
     j = j * mml->hScale;
 
+    /* XXX Get fetch func from _mesa_get_texel_fetch_func()
     _mesa_texformat_rgb_dxt1.FetchTexel2D(texImage, i, j, k, rgba);
+    */
 }
 
 
@@ -1092,7 +1140,9 @@ fetch_rgba_dxt1(const struct gl_texture_image *texImage,
     i = i * mml->wScale;
     j = j * mml->hScale;
 
+    /* XXX Get fetch func from _mesa_get_texel_fetch_func()
     _mesa_texformat_rgba_dxt1.FetchTexel2D(texImage, i, j, k, rgba);
+    */
 }
 
 
@@ -1105,7 +1155,9 @@ fetch_rgba_dxt3(const struct gl_texture_image *texImage,
     i = i * mml->wScale;
     j = j * mml->hScale;
 
+    /* XXX Get fetch func from _mesa_get_texel_fetch_func()
     _mesa_texformat_rgba_dxt3.FetchTexel2D(texImage, i, j, k, rgba);
+    */
 }
 
 
@@ -1118,7 +1170,9 @@ fetch_rgba_dxt5(const struct gl_texture_image *texImage,
     i = i * mml->wScale;
     j = j * mml->hScale;
 
+    /* XXX Get fetch func from _mesa_get_texel_fetch_func()
     _mesa_texformat_rgba_dxt5.FetchTexel2D(texImage, i, j, k, rgba);
+    */
 }
 
 
@@ -1177,21 +1231,23 @@ adjust2DRatio (GLcontext *ctx,
    const GLint newWidth = width * mml->wScale;
    const GLint newHeight = height * mml->hScale;
    GLvoid *tempImage;
+   GLuint dstImageOffsets = 0;
 
    if (!texImage->IsCompressed) {
       GLubyte *destAddr;
+
       tempImage = MALLOC(width * height * texelBytes);
       if (!tempImage) {
          return GL_FALSE;
       }
 
-      texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,
-                                      texImage->TexFormat, tempImage,
-                                      0, 0, 0, /* dstX/Y/Zoffset */
-                                      width * texelBytes, /* dstRowStride */
-                                      0, /* dstImageStride */
-                                      width, height, 1,
-                                      format, type, pixels, packing);
+      _mesa_texstore(ctx, 2, texImage->_BaseFormat,
+                     texImage->TexFormat, tempImage,
+                     0, 0, 0, /* dstX/Y/Zoffset */
+                     width * texelBytes, /* dstRowStride */
+                     &dstImageOffsets,
+                     width, height, 1,
+                     format, type, pixels, packing);
 
       /* now rescale */
       /* compute address of dest subimage within the overal tex image */
@@ -1208,6 +1264,7 @@ adjust2DRatio (GLcontext *ctx,
    } else {
       const GLint rawBytes = 4;
       GLvoid *rawImage = MALLOC(width * height * rawBytes);
+
       if (!rawImage) {
          return GL_FALSE;
       }
@@ -1217,26 +1274,26 @@ adjust2DRatio (GLcontext *ctx,
          return GL_FALSE;
       }
       /* unpack image, apply transfer ops and store in rawImage */
-      _mesa_texstore_rgba8888(ctx, 2, GL_RGBA,
-                              &_mesa_texformat_rgba8888_rev, rawImage,
-                              0, 0, 0, /* dstX/Y/Zoffset */
-                              width * rawBytes, /* dstRowStride */
-                              0, /* dstImageStride */
-                              width, height, 1,
-                              format, type, pixels, packing);
+      _mesa_texstore(ctx, 2, GL_RGBA,
+                     MESA_FORMAT_RGBA8888_REV, rawImage,
+                     0, 0, 0, /* dstX/Y/Zoffset */
+                     width * rawBytes, /* dstRowStride */
+                     &dstImageOffsets,
+                     width, height, 1,
+                     format, type, pixels, packing);
       _mesa_rescale_teximage2d(rawBytes,
                                width,
                                newWidth * rawBytes, /* dst stride */
                                width, height, /* src */
                                newWidth, newHeight, /* dst */
                                rawImage /*src*/, tempImage /*dst*/ );
-      texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,
-                                      texImage->TexFormat, texImage->Data,
-                                      xoffset * mml->wScale, yoffset * mml->hScale, 0, /* dstX/Y/Zoffset */
-                                      dstRowStride,
-                                      0, /* dstImageStride */
-                                      newWidth, newHeight, 1,
-                                      GL_RGBA, CHAN_TYPE, tempImage, &ctx->DefaultPacking);
+      _mesa_texstore(ctx, 2, texImage->_BaseFormat,
+                     texImage->TexFormat, texImage->Data,
+                     xoffset * mml->wScale, yoffset * mml->hScale, 0, /* dstX/Y/Zoffset */
+                     dstRowStride,
+                     &dstImageOffsets,
+                     newWidth, newHeight, 1,
+                     GL_RGBA, CHAN_TYPE, tempImage, &ctx->DefaultPacking);
       FREE(rawImage);
    }
 
@@ -1258,6 +1315,7 @@ tdfxTexImage2D(GLcontext *ctx, GLenum target, GLint level,
     tdfxTexInfo *ti;
     tdfxMipMapLevel *mml;
     GLint texelBytes, dstRowStride;
+    GLuint mesaFormat;
 
     /*
     printf("TexImage id=%d int 0x%x  format 0x%x  type 0x%x  %dx%d\n",
@@ -1345,23 +1403,23 @@ tdfxTexImage2D(GLcontext *ctx, GLenum target, GLint level,
     texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx,
                                      internalFormat, format, type);
     assert(texImage->TexFormat);
-    mml->glideFormat = fxGlideFormat(texImage->TexFormat->MesaFormat);
+    mesaFormat = texImage->TexFormat;
+    mml->glideFormat = fxGlideFormat(mesaFormat);
     ti->info.format = mml->glideFormat;
-    texImage->FetchTexelc = fxFetchFunction(texImage->TexFormat->MesaFormat);
-    texelBytes = texImage->TexFormat->TexelBytes;
+    texImage->FetchTexelc = fxFetchFunction(mesaFormat);
+    texelBytes = _mesa_get_format_bytes(texImage->TexFormat);
 
     if (texImage->IsCompressed) {
        texImage->CompressedSize = _mesa_compressed_texture_size(ctx,
                                                                mml->width,
                                                                mml->height,
                                                                1,
-                                                               internalFormat);
-       dstRowStride = _mesa_compressed_row_stride(internalFormat, mml->width);
+                                                               mesaFormat);
+       dstRowStride = _mesa_compressed_row_stride(texImage->TexFormat, mml->width);
        texImage->Data = _mesa_alloc_texmemory(texImage->CompressedSize);
     } else {
        dstRowStride = mml->width * texelBytes;
-       texImage->Data = _mesa_alloc_texmemory(mml->width * mml->height *
-                                             texelBytes);
+       texImage->Data = _mesa_alloc_texmemory(mml->width * mml->height * texelBytes);
     }
     if (!texImage->Data) {
        _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
@@ -1388,54 +1446,14 @@ tdfxTexImage2D(GLcontext *ctx, GLenum target, GLint level,
        else {
           /* no rescaling needed */
           /* unpack image, apply transfer ops and store in texImage->Data */
-          texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,
-                                         texImage->TexFormat, texImage->Data,
-                                         0, 0, 0, /* dstX/Y/Zoffset */
-                                         dstRowStride,
-                                         0, /* dstImageStride */
-                                         width, height, 1,
-                                         format, type, pixels, packing);
+          _mesa_texstore(ctx, 2, texImage->_BaseFormat,
+                         texImage->TexFormat, texImage->Data,
+                         0, 0, 0, /* dstX/Y/Zoffset */
+                         dstRowStride,
+                         texImage->ImageOffsets,
+                         width, height, 1,
+                         format, type, pixels, packing);
        }
-
-      /* GL_SGIS_generate_mipmap */
-      if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-         GLint mipWidth, mipHeight;
-         tdfxMipMapLevel *mip;
-         struct gl_texture_image *mipImage;
-         const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
-         const GLint maxLevels = _mesa_max_texture_levels(ctx, texObj->Target);
-   
-         assert(!texImage->IsCompressed);
-   
-         while (level < texObj->MaxLevel && level < maxLevels - 1) {
-            mipWidth = width / 2;
-            if (!mipWidth) {
-               mipWidth = 1;
-            }
-            mipHeight = height / 2;
-            if (!mipHeight) {
-               mipHeight = 1;
-            }
-            if ((mipWidth == width) && (mipHeight == height)) {
-               break;
-            }
-            _mesa_TexImage2D(target, ++level, internalFormat,
-                             mipWidth, mipHeight, border,
-                             format, type,
-                             NULL);
-            mipImage = _mesa_select_tex_image(ctx, texUnit, target, level);
-            mip = TDFX_TEXIMAGE_DATA(mipImage);
-            _mesa_halve2x2_teximage2d(ctx,
-                                      texImage,
-                                      texelBytes,
-                                      mml->width, mml->height,
-                                      texImage->Data, mipImage->Data);
-            texImage = mipImage;
-            mml = mip;
-            width = mipWidth;
-            height = mipHeight;
-         }
-      }
     }
 
     RevalidateTexture(ctx, texObj);
@@ -1473,9 +1491,9 @@ tdfxTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
     assert(texImage->Data);    /* must have an existing texture image! */
     assert(texImage->_BaseFormat);
 
-    texelBytes = texImage->TexFormat->TexelBytes;
+    texelBytes = _mesa_get_format_bytes(texImage->TexFormat);
     if (texImage->IsCompressed) {
-       dstRowStride = _mesa_compressed_row_stride(texImage->InternalFormat, mml->width);
+       dstRowStride = _mesa_compressed_row_stride(texImage->TexFormat, mml->width);
     } else {
        dstRowStride = mml->width * texelBytes;
     }
@@ -1498,54 +1516,15 @@ tdfxTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
     }
     else {
         /* no rescaling needed */
-        texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,
-                                    texImage->TexFormat, texImage->Data,
-                                    xoffset, yoffset, 0,
-                                    dstRowStride,
-                                    0, /* dstImageStride */
-                                    width, height, 1,
-                                    format, type, pixels, packing);
+       _mesa_texstore(ctx, 2, texImage->_BaseFormat,
+                      texImage->TexFormat, texImage->Data,
+                      xoffset, yoffset, 0,
+                      dstRowStride,
+                      texImage->ImageOffsets,
+                      width, height, 1,
+                      format, type, pixels, packing);
     }
 
-   /* GL_SGIS_generate_mipmap */
-   if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      GLint mipWidth, mipHeight;
-      tdfxMipMapLevel *mip;
-      struct gl_texture_image *mipImage;
-      const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
-      const GLint maxLevels = _mesa_max_texture_levels(ctx, texObj->Target);
-
-      assert(!texImage->IsCompressed);
-
-      width = texImage->Width;
-      height = texImage->Height;
-      while (level < texObj->MaxLevel && level < maxLevels - 1) {
-         mipWidth = width / 2;
-         if (!mipWidth) {
-            mipWidth = 1;
-         }
-         mipHeight = height / 2;
-         if (!mipHeight) {
-            mipHeight = 1;
-         }
-         if ((mipWidth == width) && (mipHeight == height)) {
-            break;
-         }
-         ++level;
-         mipImage = _mesa_select_tex_image(ctx, texUnit, target, level);
-         mip = TDFX_TEXIMAGE_DATA(mipImage);
-         _mesa_halve2x2_teximage2d(ctx,
-                                   texImage,
-                                   texelBytes,
-                                   mml->width, mml->height,
-                                   texImage->Data, mipImage->Data);
-         texImage = mipImage;
-         mml = mip;
-         width = mipWidth;
-         height = mipHeight;
-      }
-   }
-
     ti->reloadImages = GL_TRUE; /* signal the image needs to be reloaded */
     fxMesa->new_state |= TDFX_NEW_TEXTURE;  /* XXX this might be a bit much */
 }
@@ -1602,6 +1581,7 @@ tdfxCompressedTexImage2D (GLcontext *ctx, GLenum target,
     tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
     tdfxTexInfo *ti;
     tdfxMipMapLevel *mml;
+    GLuint mesaFormat;
 
     if (TDFX_DEBUG & DEBUG_VERBOSE_DRI) {
         fprintf(stderr, "tdfxCompressedTexImage2D: id=%d int 0x%x  %dx%d\n",
@@ -1653,9 +1633,10 @@ tdfxCompressedTexImage2D (GLcontext *ctx, GLenum target,
     /* Determine the appropriate Glide texel format,
      * given the user's internal texture format hint.
      */
-    mml->glideFormat = fxGlideFormat(texImage->TexFormat->MesaFormat);
+    mesaFormat = texImage->TexFormat;
+    mml->glideFormat = fxGlideFormat(mesaFormat);
     ti->info.format = mml->glideFormat;
-    texImage->FetchTexelc = fxFetchFunction(texImage->TexFormat->MesaFormat);
+    texImage->FetchTexelc = fxFetchFunction(mesaFormat);
 
     /* allocate new storage for texture image, if needed */
     if (!texImage->Data) {
@@ -1663,7 +1644,7 @@ tdfxCompressedTexImage2D (GLcontext *ctx, GLenum target,
                                                                 mml->width,
                                                                 mml->height,
                                                                 1,
-                                                                internalFormat);
+                                                                mesaFormat);
        texImage->Data = _mesa_alloc_texmemory(texImage->CompressedSize);
        if (!texImage->Data) {
           _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D");
@@ -1687,9 +1668,10 @@ tdfxCompressedTexImage2D (GLcontext *ctx, GLenum target,
         *    we replicate the data over the padded area.
         * For now, we take 2) + 3) but texelfetchers will be wrong!
         */
-       GLuint srcRowStride = _mesa_compressed_row_stride(internalFormat, width);
+       const GLuint mesaFormat = texImage->TexFormat;
+       GLuint srcRowStride = _mesa_compressed_row_stride(mesaFormat, width);
  
-       GLuint destRowStride = _mesa_compressed_row_stride(internalFormat,
+       GLuint destRowStride = _mesa_compressed_row_stride(mesaFormat,
                                                    mml->width);
  
        _mesa_upscale_teximage2d(srcRowStride, (height+3) / 4,
@@ -1701,11 +1683,6 @@ tdfxCompressedTexImage2D (GLcontext *ctx, GLenum target,
        MEMCPY(texImage->Data, data, texImage->CompressedSize);
     }
 
-    /* GL_SGIS_generate_mipmap */
-    if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-       assert(!texImage->IsCompressed);
-    }
-
     RevalidateTexture(ctx, texObj);
 
     ti->reloadImages = GL_TRUE;
@@ -1728,6 +1705,7 @@ tdfxCompressedTexSubImage2D( GLcontext *ctx, GLenum target,
     GLint destRowStride, srcRowStride;
     GLint i, rows;
     GLubyte *dest;
+    const GLuint mesaFormat = texImage->TexFormat;
 
     if (TDFX_DEBUG & DEBUG_VERBOSE_DRI) {
         fprintf(stderr, "tdfxCompressedTexSubImage2D: id=%d\n", texObj->Name);
@@ -1738,12 +1716,11 @@ tdfxCompressedTexSubImage2D( GLcontext *ctx, GLenum target,
     mml = TDFX_TEXIMAGE_DATA(texImage);
     assert(mml);
 
-    srcRowStride = _mesa_compressed_row_stride(texImage->InternalFormat, width);
+    srcRowStride = _mesa_compressed_row_stride(mesaFormat, width);
 
-    destRowStride = _mesa_compressed_row_stride(texImage->InternalFormat,
-                                                mml->width);
+    destRowStride = _mesa_compressed_row_stride(mesaFormat, mml->width);
     dest = _mesa_compressed_image_address(xoffset, yoffset, 0,
-                                          texImage->InternalFormat,
+                                          mesaFormat,
                                           mml->width,
                                (GLubyte*) texImage->Data);
 
@@ -1752,28 +1729,22 @@ tdfxCompressedTexSubImage2D( GLcontext *ctx, GLenum target,
     for (i = 0; i < rows; i++) {
        MEMCPY(dest, data, srcRowStride);
        dest += destRowStride;
-       data = (GLvoid *)((GLuint)data + (GLuint)srcRowStride);
+       data = (GLvoid *)((intptr_t)data + (intptr_t)srcRowStride);
     }
 
     /* [dBorca] Hack alert:
      * see fxDDCompressedTexImage2D for caveats
      */
     if (mml->wScale != 1 || mml->hScale != 1) {
-       srcRowStride = _mesa_compressed_row_stride(texImage->InternalFormat, texImage->Width);
+       srcRowStride = _mesa_compressed_row_stride(mesaFormat, texImage->Width);
  
-       destRowStride = _mesa_compressed_row_stride(texImage->InternalFormat,
-                                                mml->width);
+       destRowStride = _mesa_compressed_row_stride(mesaFormat, mml->width);
        _mesa_upscale_teximage2d(srcRowStride, texImage->Height / 4,
                                 destRowStride, mml->height / 4,
                                 1, texImage->Data, destRowStride,
                                 texImage->Data);
     }
 
-    /* GL_SGIS_generate_mipmap */
-    if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-       assert(!texImage->IsCompressed);
-    }
-
     RevalidateTexture(ctx, texObj);
 
     ti->reloadImages = GL_TRUE;
@@ -1820,7 +1791,7 @@ tdfxTestProxyTexImage(GLcontext *ctx, GLenum target,
             tdfxTexInfo *ti;
             int memNeeded;
 
-            tObj = ctx->Texture.Proxy2D;
+            tObj = ctx->Texture.ProxyTex[TEXTURE_2D_INDEX];
             if (!tObj->DriverData)
                 tObj->DriverData = fxAllocTexObjData(fxMesa);
             ti = TDFX_TEXTURE_DATA(tObj);
@@ -1913,4 +1884,5 @@ void tdfxInitTextureFuncs( struct dd_function_table *functions )
    functions->CompressedTexImage2D     = tdfxCompressedTexImage2D;
    functions->CompressedTexSubImage2D  = tdfxCompressedTexSubImage2D;
    functions->UpdateTexturePalette      = tdfxUpdateTexturePalette;
+   functions->GenerateMipmap            = tdfxGenerateMipmap;
 }