Merge branch 'mesa_7_6_branch'
[mesa.git] / src / mesa / drivers / dri / tdfx / tdfx_tex.c
index c3fe7bebd3e8841fddfc24bfd4b08e61fa5fb39b..f6a48b3ae12a7f2fdb448ed4041eb61d9446b182 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 "mipmap.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"
@@ -177,6 +176,54 @@ 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);
+   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
@@ -1398,45 +1445,6 @@ tdfxTexImage2D(GLcontext *ctx, GLenum target, GLint level,
                                           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 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, 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;
-         }
-      }
     }
 
     RevalidateTexture(ctx, texObj);
@@ -1508,44 +1516,6 @@ tdfxTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
                                         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 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, 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;
-      }
-   }
-
     ti->reloadImages = GL_TRUE; /* signal the image needs to be reloaded */
     fxMesa->new_state |= TDFX_NEW_TEXTURE;  /* XXX this might be a bit much */
 }
@@ -1704,11 +1674,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;
@@ -1755,7 +1720,7 @@ 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:
@@ -1771,11 +1736,6 @@ tdfxCompressedTexSubImage2D( GLcontext *ctx, GLenum target,
                                 texImage->Data);
     }
 
-    /* GL_SGIS_generate_mipmap */
-    if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-       assert(!texImage->IsCompressed);
-    }
-
     RevalidateTexture(ctx, texObj);
 
     ti->reloadImages = GL_TRUE;
@@ -1822,7 +1782,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);
@@ -1915,4 +1875,5 @@ void tdfxInitTextureFuncs( struct dd_function_table *functions )
    functions->CompressedTexImage2D     = tdfxCompressedTexImage2D;
    functions->CompressedTexSubImage2D  = tdfxCompressedTexSubImage2D;
    functions->UpdateTexturePalette      = tdfxUpdateTexturePalette;
+   functions->GenerateMipmap            = tdfxGenerateMipmap;
 }