more work on GL_ARB_texture_compression
[mesa.git] / src / mesa / main / texstate.c
index eee5eaa0e44a7fe4a08544b1a6c9512c8c45ae6e..32ce6005630e6dc0031106de980624d3326afe7e 100644 (file)
@@ -1,10 +1,10 @@
-/* $Id: texstate.c,v 1.1 1999/08/19 00:55:41 jtg Exp $ */
+/* $Id: texstate.c,v 1.13 2000/05/23 20:10:50 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  3.1
+ * Version:  3.3
  * 
- * Copyright (C) 1999  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2000  Brian Paul   All Rights Reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  */
 
 
-
 #ifdef PC_HEADER
 #include "all.h"
 #else
-#include <assert.h>
-#include <stdio.h>
+#include "glheader.h"
 #include "context.h"
 #include "enums.h"
+#include "extensions.h"
 #include "macros.h"
 #include "matrix.h"
 #include "texobj.h"
+#include "teximage.h"
 #include "texstate.h"
 #include "texture.h"
 #include "types.h"
 #include "xform.h"
-#ifdef XFree86Server
-#include "GL/xf86glx.h"
-#endif
 #endif
 
 
 /**********************************************************************/
 
 
-void gl_TexEnvfv( GLcontext *ctx,
-                  GLenum target, GLenum pname, const GLfloat *param )
+void
+_mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
 {
+   GET_CURRENT_CONTEXT(ctx);
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
 
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexEnv");
 
-   if (target!=GL_TEXTURE_ENV) {
-      gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(target)" );
-      return;
-   }
-
-   if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
-      fprintf(stderr, "glTexEnv %s %s %.1f(%s) ...\n",  
-             gl_lookup_enum_by_nr(target),
-             gl_lookup_enum_by_nr(pname),
-             *param,
-             gl_lookup_enum_by_nr((GLenum) (GLint) *param));
-
+   if (target==GL_TEXTURE_ENV) {
 
-   if (pname==GL_TEXTURE_ENV_MODE) {
-      GLenum mode = (GLenum) (GLint) *param;
-      switch (mode) {
+      if (pname==GL_TEXTURE_ENV_MODE) {
+        GLenum mode = (GLenum) (GLint) *param;
+        switch (mode) {
+        case GL_ADD:
+           if (!ctx->Extensions.HaveTextureEnvAdd) {
+              gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(param)");
+              return;
+           }
+           /* FALL-THROUGH */
         case GL_MODULATE:
         case GL_BLEND:
         case GL_DECAL:
         case GL_REPLACE:
            /* A small optimization for drivers */ 
            if (texUnit->EnvMode == mode)
-               return;
+              return;
 
            if (MESA_VERBOSE & (VERBOSE_STATE|VERBOSE_TEXTURE))
               fprintf(stderr, "glTexEnv: old mode %s, new mode %s\n",
@@ -107,33 +100,94 @@ void gl_TexEnvfv( GLcontext *ctx,
         default:
            gl_error( ctx, GL_INVALID_VALUE, "glTexEnv(param)" );
            return;
+        }
+      }
+      else if (pname==GL_TEXTURE_ENV_COLOR) {
+        texUnit->EnvColor[0] = CLAMP( param[0], 0.0F, 1.0F );
+        texUnit->EnvColor[1] = CLAMP( param[1], 0.0F, 1.0F );
+        texUnit->EnvColor[2] = CLAMP( param[2], 0.0F, 1.0F );
+        texUnit->EnvColor[3] = CLAMP( param[3], 0.0F, 1.0F );
       }
+      else {
+        gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
+        return;
+      }
+
    }
-   else if (pname==GL_TEXTURE_ENV_COLOR) {
-      texUnit->EnvColor[0] = CLAMP( param[0], 0.0, 1.0 );
-      texUnit->EnvColor[1] = CLAMP( param[1], 0.0, 1.0 );
-      texUnit->EnvColor[2] = CLAMP( param[2], 0.0, 1.0 );
-      texUnit->EnvColor[3] = CLAMP( param[3], 0.0, 1.0 );
+   else if (target==GL_TEXTURE_FILTER_CONTROL_EXT) {
+
+      if (!ctx->Extensions.HaveTextureLodBias) {
+        gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
+        return;
+      }
+
+      if (pname==GL_TEXTURE_LOD_BIAS_EXT) {
+        texUnit->LodBias = param[0];
+      }
+      else {
+        gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
+        return;
+      }
+
    }
    else {
-      gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
+      gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(target)" );
       return;
    }
 
+   if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
+      fprintf(stderr, "glTexEnv %s %s %.1f(%s) ...\n",  
+             gl_lookup_enum_by_nr(target),
+             gl_lookup_enum_by_nr(pname),
+             *param,
+             gl_lookup_enum_by_nr((GLenum) (GLint) *param));
+
    /* Tell device driver about the new texture environment */
    if (ctx->Driver.TexEnv) {
-      (*ctx->Driver.TexEnv)( ctx, pname, param );
+      (*ctx->Driver.TexEnv)( ctx, target, pname, param );
    }
+
 }
 
 
+void
+_mesa_TexEnvf( GLenum target, GLenum pname, GLfloat param )
+{
+   _mesa_TexEnvfv( target, pname, &param );
+}
 
 
 
-void gl_GetTexEnvfv( GLcontext *ctx,
-                     GLenum target, GLenum pname, GLfloat *params )
+void
+_mesa_TexEnvi( GLenum target, GLenum pname, GLint param )
 {
+   GLfloat p[4];
+   p[0] = (GLfloat) param;
+   p[1] = p[2] = p[3] = 0.0;
+   _mesa_TexEnvfv( target, pname, p );
+}
+
+
+void
+_mesa_TexEnviv( GLenum target, GLenum pname, const GLint *param )
+{
+   GLfloat p[4];
+   p[0] = INT_TO_FLOAT( param[0] );
+   p[1] = INT_TO_FLOAT( param[1] );
+   p[2] = INT_TO_FLOAT( param[2] );
+   p[3] = INT_TO_FLOAT( param[3] );
+   _mesa_TexEnvfv( target, pname, p );
+}
+
+
+void
+_mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
+{
+   GET_CURRENT_CONTEXT(ctx);
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexEnvfv");
+
    if (target!=GL_TEXTURE_ENV) {
       gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" );
       return;
@@ -151,10 +205,14 @@ void gl_GetTexEnvfv( GLcontext *ctx,
 }
 
 
-void gl_GetTexEnviv( GLcontext *ctx,
-                     GLenum target, GLenum pname, GLint *params )
+void
+_mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
 {
+   GET_CURRENT_CONTEXT(ctx);
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexEnviv");
+
    if (target!=GL_TEXTURE_ENV) {
       gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" );
       return;
@@ -182,13 +240,23 @@ void gl_GetTexEnviv( GLcontext *ctx,
 /**********************************************************************/
 
 
-void gl_TexParameterfv( GLcontext *ctx,
-                        GLenum target, GLenum pname, const GLfloat *params )
+void
+_mesa_TexParameterf( GLenum target, GLenum pname, GLfloat param )
+{
+   _mesa_TexParameterfv(target, pname, &param);
+}
+
+
+void
+_mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
 {
+   GET_CURRENT_CONTEXT(ctx);
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
    GLenum eparam = (GLenum) (GLint) params[0];
    struct gl_texture_object *texObj;
 
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexParameterfv");
+
    if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
       fprintf(stderr, "texPARAM %s %s %d...\n", 
              gl_lookup_enum_by_nr(target),
@@ -206,6 +274,12 @@ void gl_TexParameterfv( GLcontext *ctx,
       case GL_TEXTURE_3D_EXT:
          texObj = texUnit->CurrentD[3];
          break;
+      case GL_TEXTURE_CUBE_MAP_ARB:
+         if (ctx->Extensions.HaveTextureCubeMap) {
+            texObj = texUnit->CurrentCubeMap;
+            break;
+         }
+         /* fallthrough */
       default:
          gl_error( ctx, GL_INVALID_ENUM, "glTexParameter(target)" );
          return;
@@ -283,10 +357,10 @@ void gl_TexParameterfv( GLcontext *ctx,
          }
          break;
       case GL_TEXTURE_BORDER_COLOR:
-         texObj->BorderColor[0] = CLAMP((GLint)(params[0]*255.0), 0, 255);
-         texObj->BorderColor[1] = CLAMP((GLint)(params[1]*255.0), 0, 255);
-         texObj->BorderColor[2] = CLAMP((GLint)(params[2]*255.0), 0, 255);
-         texObj->BorderColor[3] = CLAMP((GLint)(params[3]*255.0), 0, 255);
+         texObj->BorderColor[0] = (GLubyte) CLAMP((GLint)(params[0]*255.0), 0, 255);
+         texObj->BorderColor[1] = (GLubyte) CLAMP((GLint)(params[1]*255.0), 0, 255);
+         texObj->BorderColor[2] = (GLubyte) CLAMP((GLint)(params[2]*255.0), 0, 255);
+         texObj->BorderColor[3] = (GLubyte) CLAMP((GLint)(params[3]*255.0), 0, 255);
          break;
       case GL_TEXTURE_MIN_LOD:
          texObj->MinLod = params[0];
@@ -314,7 +388,7 @@ void gl_TexParameterfv( GLcontext *ctx,
          break;
       case GL_TEXTURE_PRIORITY:
          /* (keithh@netcomuk.co.uk) */
-         texObj->Priority = CLAMP( params[0], 0.0, 1.0 );
+         texObj->Priority = CLAMP( params[0], 0.0F, 1.0F );
          break;
       default:
          gl_error( ctx, GL_INVALID_ENUM, "glTexParameter(pname)" );
@@ -329,59 +403,82 @@ void gl_TexParameterfv( GLcontext *ctx,
 }
 
 
+void
+_mesa_TexParameteri( GLenum target, GLenum pname, const GLint param )
+{
+   GLfloat fparam[4];
+   fparam[0] = (GLfloat) param;
+   fparam[1] = fparam[2] = fparam[3] = 0.0;
+   _mesa_TexParameterfv(target, pname, fparam);
+}
 
-void gl_GetTexLevelParameterfv( GLcontext *ctx, GLenum target, GLint level,
-                                GLenum pname, GLfloat *params )
+void
+_mesa_TexParameteriv( GLenum target, GLenum pname, const GLint *params )
+{
+   GLfloat fparam[4];
+   fparam[0] = (GLfloat) params[0];
+   fparam[1] = fparam[2] = fparam[3] = 0.0;
+   _mesa_TexParameterfv(target, pname, fparam);
+}
+
+
+void
+_mesa_GetTexLevelParameterfv( GLenum target, GLint level,
+                              GLenum pname, GLfloat *params )
 {
    GLint iparam;
-   gl_GetTexLevelParameteriv( ctx, target, level, pname, &iparam );
+   _mesa_GetTexLevelParameteriv( target, level, pname, &iparam );
    *params = (GLfloat) iparam;
 }
 
 
+static GLuint
+tex_image_dimensions(GLcontext *ctx, GLenum target)
+{
+   switch (target) {
+      case GL_TEXTURE_1D:
+      case GL_PROXY_TEXTURE_1D:
+         return 1;
+      case GL_TEXTURE_2D:
+      case GL_PROXY_TEXTURE_2D:
+         return 2;
+      case GL_TEXTURE_3D:
+      case GL_PROXY_TEXTURE_3D:
+         return 3;
+      case GL_TEXTURE_CUBE_MAP_ARB:
+      case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
+         return ctx->Extensions.HaveTextureCubeMap ? 2 : 0;
+      default:
+         gl_problem(ctx, "bad target in _mesa_tex_target_dimensions()");
+         return 0;
+   }
+}
+
 
-void gl_GetTexLevelParameteriv( GLcontext *ctx, GLenum target, GLint level,
-                                GLenum pname, GLint *params )
+void
+_mesa_GetTexLevelParameteriv( GLenum target, GLint level,
+                              GLenum pname, GLint *params )
 {
+   GET_CURRENT_CONTEXT(ctx);
    const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
    const struct gl_texture_image *img = NULL;
    GLuint dimensions;
+   GLboolean isProxy;
+
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexLevelParameter");
 
    if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
       gl_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
       return;
    }
 
-   switch (target) {
-      case GL_TEXTURE_1D:
-         img = texUnit->CurrentD[1]->Image[level];
-         dimensions = 1;
-         break;
-      case GL_TEXTURE_2D:
-         img = texUnit->CurrentD[2]->Image[level];
-         dimensions = 2;
-         break;
-      case GL_TEXTURE_3D:
-         img = texUnit->CurrentD[3]->Image[level];
-         dimensions = 3; 
-        break;
-      case GL_PROXY_TEXTURE_1D:
-         img = ctx->Texture.Proxy1D->Image[level];
-         dimensions = 1;
-         break;
-      case GL_PROXY_TEXTURE_2D:
-         img = ctx->Texture.Proxy2D->Image[level];
-         dimensions = 2;
-         break;
-      case GL_PROXY_TEXTURE_3D:
-         img = ctx->Texture.Proxy3D->Image[level];
-         dimensions = 3;
-         break;
-      default:
-        gl_error(ctx, GL_INVALID_ENUM, "glGetTexLevelParameter[if]v(target)");
-         return;
+   dimensions = tex_image_dimensions(ctx, target);  /* 1, 2 or 3 */
+   if (dimensions == 0) {
+      gl_error(ctx, GL_INVALID_ENUM, "glGetTexLevelParameter[if]v(target)");
+      return;
    }
 
+   img = _mesa_select_tex_image(ctx, texUnit, target, level);
    if (!img) {
       if (pname == GL_TEXTURE_COMPONENTS)
          *params = 1;
@@ -390,6 +487,11 @@ void gl_GetTexLevelParameteriv( GLcontext *ctx, GLenum target, GLint level,
       return;
    }
 
+   isProxy = (target == GL_PROXY_TEXTURE_1D) ||
+             (target == GL_PROXY_TEXTURE_2D) ||
+             (target == GL_PROXY_TEXTURE_3D) ||
+             (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB);
+
    switch (pname) {
       case GL_TEXTURE_WIDTH:
          *params = img->Width;
@@ -439,34 +541,49 @@ void gl_GetTexLevelParameteriv( GLcontext *ctx, GLenum target, GLint level,
       case GL_TEXTURE_INDEX_SIZE_EXT:
          *params = img->IndexBits;
          return;
+
+      /* GL_ARB_texture_compression */
+      case GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB:
+         if (ctx->Extensions.HaveTextureCompression) {
+            if (img->IsCompressed && !isProxy)
+               *params = img->CompressedSize;
+            else
+               gl_error(ctx, GL_INVALID_OPERATION,
+                        "glGetTexLevelParameter[if]v(pname)");
+         }
+         else {
+            gl_error(ctx, GL_INVALID_ENUM, "glGetTexLevelParameter[if]v(pname)");
+         }
+         return;
+      case GL_TEXTURE_COMPRESSED_ARB:
+         if (ctx->Extensions.HaveTextureCompression) {
+            *params = (GLint) img->IsCompressed;
+         }
+         else {
+            gl_error(ctx, GL_INVALID_ENUM, "glGetTexLevelParameter[if]v(pname)");
+         }
+         return;
+
       default:
-         gl_error( ctx, GL_INVALID_ENUM,
-                   "glGetTexLevelParameter[if]v(pname)" );
+         gl_error(ctx, GL_INVALID_ENUM, "glGetTexLevelParameter[if]v(pname)");
    }
 }
 
 
 
-
-void gl_GetTexParameterfv( GLcontext *ctx,
-                           GLenum target, GLenum pname, GLfloat *params )
+void
+_mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
 {
+   GET_CURRENT_CONTEXT(ctx);
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
    struct gl_texture_object *obj;
 
-   switch (target) {
-      case GL_TEXTURE_1D:
-         obj = texUnit->CurrentD[1];
-         break;
-      case GL_TEXTURE_2D:
-         obj = texUnit->CurrentD[2];
-         break;
-      case GL_TEXTURE_3D_EXT:
-         obj = texUnit->CurrentD[3];
-         break;
-      default:
-         gl_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(target)");
-         return;
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexParameterfv");
+
+   obj = _mesa_select_tex_object(ctx, texUnit, target);
+   if (!obj) {
+      gl_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(target)");
+      return;
    }
 
    switch (pname) {
@@ -504,10 +621,10 @@ void gl_GetTexParameterfv( GLcontext *ctx,
          *params = obj->MaxLod;
          break;
       case GL_TEXTURE_BASE_LEVEL:
-         *params = obj->BaseLevel;
+         *params = (GLfloat) obj->BaseLevel;
          break;
       case GL_TEXTURE_MAX_LEVEL:
-         *params = obj->MaxLevel;
+         *params = (GLfloat) obj->MaxLevel;
          break;
       default:
          gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname)" );
@@ -515,25 +632,19 @@ void gl_GetTexParameterfv( GLcontext *ctx,
 }
 
 
-void gl_GetTexParameteriv( GLcontext *ctx,
-                           GLenum target, GLenum pname, GLint *params )
+void
+_mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
 {
+   GET_CURRENT_CONTEXT(ctx);
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
    struct gl_texture_object *obj;
 
-   switch (target) {
-      case GL_TEXTURE_1D:
-         obj = texUnit->CurrentD[1];
-         break;
-      case GL_TEXTURE_2D:
-         obj = texUnit->CurrentD[2];
-         break;
-      case GL_TEXTURE_3D_EXT:
-         obj = texUnit->CurrentD[3];
-         break;
-      default:
-         gl_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(target)");
-         return;
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexParameteriv");
+
+   obj = _mesa_select_tex_object(ctx, texUnit, target);
+   if (!obj) {
+      gl_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(target)");
+      return;
    }
 
    switch (pname) {
@@ -555,10 +666,10 @@ void gl_GetTexParameteriv( GLcontext *ctx,
       case GL_TEXTURE_BORDER_COLOR:
          {
             GLfloat color[4];
-            color[0] = obj->BorderColor[0]/255.0;
-            color[1] = obj->BorderColor[1]/255.0;
-            color[2] = obj->BorderColor[2]/255.0;
-            color[3] = obj->BorderColor[3]/255.0;
+            color[0] = obj->BorderColor[0] / 255.0F;
+            color[1] = obj->BorderColor[1] / 255.0F;
+            color[2] = obj->BorderColor[2] / 255.0F;
+            color[3] = obj->BorderColor[3] / 255.0F;
             params[0] = FLOAT_TO_INT( color[0] );
             params[1] = FLOAT_TO_INT( color[1] );
             params[2] = FLOAT_TO_INT( color[2] );
@@ -596,9 +707,10 @@ void gl_GetTexParameteriv( GLcontext *ctx,
 /**********************************************************************/
 
 
-void gl_TexGenfv( GLcontext *ctx,
-                  GLenum coord, GLenum pname, const GLfloat *params )
+void
+_mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
 {
+   GET_CURRENT_CONTEXT(ctx);
    GLuint tUnit = ctx->Texture.CurrentTransformUnit;
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexGenfv");
@@ -609,7 +721,7 @@ void gl_TexGenfv( GLcontext *ctx,
              gl_lookup_enum_by_nr(pname),
              *(int *)params);
 
-   switch( coord ) {
+   switch (coord) {
       case GL_S:
          if (pname==GL_TEXTURE_GEN_MODE) {
            GLenum mode = (GLenum) (GLint) *params;
@@ -661,30 +773,30 @@ void gl_TexGenfv( GLcontext *ctx,
       case GL_T:
          if (pname==GL_TEXTURE_GEN_MODE) {
            GLenum mode = (GLenum) (GLint) *params;
-           switch(mode) {
-           case GL_OBJECT_LINEAR:
-              texUnit->GenModeT = GL_OBJECT_LINEAR;
-              texUnit->GenBitT = TEXGEN_OBJ_LINEAR;
-              break;
-           case GL_EYE_LINEAR:
-              texUnit->GenModeT = GL_EYE_LINEAR;
-              texUnit->GenBitT = TEXGEN_EYE_LINEAR;
-              break;
-           case GL_REFLECTION_MAP_NV:
-              texUnit->GenModeT = GL_REFLECTION_MAP_NV;
-              texUnit->GenBitT = TEXGEN_REFLECTION_MAP_NV;
-              break;
-           case GL_NORMAL_MAP_NV:
-              texUnit->GenModeT = GL_NORMAL_MAP_NV;
-              texUnit->GenBitT = TEXGEN_NORMAL_MAP_NV;
-              break;
-           case GL_SPHERE_MAP:
-              texUnit->GenModeT = GL_SPHERE_MAP;
-              texUnit->GenBitT = TEXGEN_SPHERE_MAP;
-              break;
-           default:
-              gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
-              return;
+           switch (mode) {
+               case GL_OBJECT_LINEAR:
+                  texUnit->GenModeT = GL_OBJECT_LINEAR;
+                  texUnit->GenBitT = TEXGEN_OBJ_LINEAR;
+                  break;
+               case GL_EYE_LINEAR:
+                  texUnit->GenModeT = GL_EYE_LINEAR;
+                  texUnit->GenBitT = TEXGEN_EYE_LINEAR;
+                  break;
+               case GL_REFLECTION_MAP_NV:
+                  texUnit->GenModeT = GL_REFLECTION_MAP_NV;
+                  texUnit->GenBitT = TEXGEN_REFLECTION_MAP_NV;
+                  break;
+               case GL_NORMAL_MAP_NV:
+                  texUnit->GenModeT = GL_NORMAL_MAP_NV;
+                  texUnit->GenBitT = TEXGEN_NORMAL_MAP_NV;
+                  break;
+               case GL_SPHERE_MAP:
+                  texUnit->GenModeT = GL_SPHERE_MAP;
+                  texUnit->GenBitT = TEXGEN_SPHERE_MAP;
+                  break;
+               default:
+                  gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
+                  return;
            }
         }
         else if (pname==GL_OBJECT_PLANE) {
@@ -795,16 +907,63 @@ void gl_TexGenfv( GLcontext *ctx,
 }
 
 
+void
+_mesa_TexGeniv(GLenum coord, GLenum pname, const GLint *params )
+{
+   GLfloat p[4];
+   p[0] = params[0];
+   p[1] = params[1];
+   p[2] = params[2];
+   p[3] = params[3];
+   _mesa_TexGenfv(coord, pname, p);
+}
+
 
-void gl_GetTexGendv( GLcontext *ctx,
-                     GLenum coord, GLenum pname, GLdouble *params )
+void
+_mesa_TexGend(GLenum coord, GLenum pname, GLdouble param )
 {
+   GLfloat p = (GLfloat) param;
+   _mesa_TexGenfv( coord, pname, &p );
+}
+
+
+void
+_mesa_TexGendv(GLenum coord, GLenum pname, const GLdouble *params )
+{
+   GLfloat p[4];
+   p[0] = params[0];
+   p[1] = params[1];
+   p[2] = params[2];
+   p[3] = params[3];
+   _mesa_TexGenfv( coord, pname, p );
+}
+
+
+void
+_mesa_TexGenf( GLenum coord, GLenum pname, GLfloat param )
+{
+   _mesa_TexGenfv(coord, pname, &param);
+}
+
+
+void
+_mesa_TexGeni( GLenum coord, GLenum pname, GLint param )
+{
+   _mesa_TexGeniv( coord, pname, &param );
+}
+
+
+
+void
+_mesa_GetTexGendv( GLenum coord, GLenum pname, GLdouble *params )
+{
+   GET_CURRENT_CONTEXT(ctx);
    GLuint tUnit = ctx->Texture.CurrentTransformUnit;
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
 
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexGendv");
 
-   switch( coord ) {
+   switch (coord) {
       case GL_S:
          if (pname==GL_TEXTURE_GEN_MODE) {
             params[0] = ENUM_TO_DOUBLE(texUnit->GenModeS);
@@ -873,15 +1032,16 @@ void gl_GetTexGendv( GLcontext *ctx,
 
 
 
-void gl_GetTexGenfv( GLcontext *ctx,
-                     GLenum coord, GLenum pname, GLfloat *params )
+void
+_mesa_GetTexGenfv( GLenum coord, GLenum pname, GLfloat *params )
 {
+   GET_CURRENT_CONTEXT(ctx);
    GLuint tUnit = ctx->Texture.CurrentTransformUnit;
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
 
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexGenfv");
 
-   switch( coord ) {
+   switch (coord) {
       case GL_S:
          if (pname==GL_TEXTURE_GEN_MODE) {
             params[0] = ENUM_TO_FLOAT(texUnit->GenModeS);
@@ -950,24 +1110,31 @@ void gl_GetTexGenfv( GLcontext *ctx,
 
 
 
-void gl_GetTexGeniv( GLcontext *ctx,
-                     GLenum coord, GLenum pname, GLint *params )
+void
+_mesa_GetTexGeniv( GLenum coord, GLenum pname, GLint *params )
 {
+   GET_CURRENT_CONTEXT(ctx);
    GLuint tUnit = ctx->Texture.CurrentTransformUnit;
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
 
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexGeniv");
 
-   switch( coord ) {
+   switch (coord) {
       case GL_S:
          if (pname==GL_TEXTURE_GEN_MODE) {
             params[0] = texUnit->GenModeS;
         }
         else if (pname==GL_OBJECT_PLANE) {
-            COPY_4V( params, texUnit->ObjectPlaneS );
+            params[0] = (GLint) texUnit->ObjectPlaneS[0];
+            params[1] = (GLint) texUnit->ObjectPlaneS[1];
+            params[2] = (GLint) texUnit->ObjectPlaneS[2];
+            params[3] = (GLint) texUnit->ObjectPlaneS[3];
         }
         else if (pname==GL_EYE_PLANE) {
-            COPY_4V( params, texUnit->EyePlaneS );
+            params[0] = (GLint) texUnit->EyePlaneS[0];
+            params[1] = (GLint) texUnit->EyePlaneS[1];
+            params[2] = (GLint) texUnit->EyePlaneS[2];
+            params[3] = (GLint) texUnit->EyePlaneS[3];
         }
         else {
            gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
@@ -979,10 +1146,16 @@ void gl_GetTexGeniv( GLcontext *ctx,
             params[0] = texUnit->GenModeT;
         }
         else if (pname==GL_OBJECT_PLANE) {
-            COPY_4V( params, texUnit->ObjectPlaneT );
+            params[0] = (GLint) texUnit->ObjectPlaneT[0];
+            params[1] = (GLint) texUnit->ObjectPlaneT[1];
+            params[2] = (GLint) texUnit->ObjectPlaneT[2];
+            params[3] = (GLint) texUnit->ObjectPlaneT[3];
         }
         else if (pname==GL_EYE_PLANE) {
-            COPY_4V( params, texUnit->EyePlaneT );
+            params[0] = (GLint) texUnit->EyePlaneT[0];
+            params[1] = (GLint) texUnit->EyePlaneT[1];
+            params[2] = (GLint) texUnit->EyePlaneT[2];
+            params[3] = (GLint) texUnit->EyePlaneT[3];
         }
         else {
            gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
@@ -994,10 +1167,16 @@ void gl_GetTexGeniv( GLcontext *ctx,
             params[0] = texUnit->GenModeR;
         }
         else if (pname==GL_OBJECT_PLANE) {
-            COPY_4V( params, texUnit->ObjectPlaneR );
+            params[0] = (GLint) texUnit->ObjectPlaneR[0];
+            params[1] = (GLint) texUnit->ObjectPlaneR[1];
+            params[2] = (GLint) texUnit->ObjectPlaneR[2];
+            params[3] = (GLint) texUnit->ObjectPlaneR[3];
         }
         else if (pname==GL_EYE_PLANE) {
-            COPY_4V( params, texUnit->EyePlaneR );
+            params[0] = (GLint) texUnit->EyePlaneR[0];
+            params[1] = (GLint) texUnit->EyePlaneR[1];
+            params[2] = (GLint) texUnit->EyePlaneR[2];
+            params[3] = (GLint) texUnit->EyePlaneR[3];
         }
         else {
            gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
@@ -1009,11 +1188,17 @@ void gl_GetTexGeniv( GLcontext *ctx,
             params[0] = texUnit->GenModeQ;
         }
         else if (pname==GL_OBJECT_PLANE) {
-            COPY_4V( params, texUnit->ObjectPlaneQ );
+            params[0] = (GLint) texUnit->ObjectPlaneQ[0];
+            params[1] = (GLint) texUnit->ObjectPlaneQ[1];
+            params[2] = (GLint) texUnit->ObjectPlaneQ[2];
+            params[3] = (GLint) texUnit->ObjectPlaneQ[3];
         }
         else if (pname==GL_EYE_PLANE) {
-            COPY_4V( params, texUnit->EyePlaneQ );
-        }
+            params[0] = (GLint) texUnit->EyePlaneQ[0];
+            params[1] = (GLint) texUnit->EyePlaneQ[1];
+            params[2] = (GLint) texUnit->EyePlaneQ[2];
+            params[3] = (GLint) texUnit->EyePlaneQ[3];
+         }
         else {
            gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
            return;
@@ -1027,8 +1212,10 @@ void gl_GetTexGeniv( GLcontext *ctx,
 
 
 /* GL_ARB_multitexture */
-void gl_ActiveTexture( GLcontext *ctx, GLenum target )
+void
+_mesa_ActiveTextureARB( GLenum target )
 {
+   GET_CURRENT_CONTEXT(ctx);
    GLint maxUnits = ctx->Const.MaxTextureUnits;
 
    ASSERT_OUTSIDE_BEGIN_END( ctx, "glActiveTextureARB" );
@@ -1039,7 +1226,6 @@ void gl_ActiveTexture( GLcontext *ctx, GLenum target )
 
    if (target >= GL_TEXTURE0_ARB && target < GL_TEXTURE0_ARB + maxUnits) {
       GLint texUnit = target - GL_TEXTURE0_ARB;
-      ctx->TexCoordUnit = texUnit;
       ctx->Texture.CurrentUnit = texUnit;
       ctx->Texture.CurrentTransformUnit = texUnit;
       if (ctx->Driver.ActiveTexture) {
@@ -1053,8 +1239,10 @@ void gl_ActiveTexture( GLcontext *ctx, GLenum target )
 
 
 /* GL_ARB_multitexture */
-void gl_ClientActiveTexture( GLcontext *ctx, GLenum target )
+void
+_mesa_ClientActiveTextureARB( GLenum target )
 {
+   GET_CURRENT_CONTEXT(ctx);
    GLint maxUnits = ctx->Const.MaxTextureUnits;
 
    ASSERT_OUTSIDE_BEGIN_END( ctx, "glClientActiveTextureARB" );
@@ -1130,15 +1318,15 @@ void gl_remove_texobj_from_dirty_list( struct gl_shared_state *shared,
 
 /*
  * This is called by gl_update_state() if the NEW_TEXTURING bit in
- * ctx->NewState is unit.
+ * ctx->NewState is set.
  */
 void gl_update_dirty_texobjs( GLcontext *ctx )
 {
    struct gl_texture_object *t, *next;
    for (t = ctx->Shared->DirtyTexObjList; t; t = next) {
       next = t->NextDirty;
-      gl_test_texture_object_completeness(ctx, t);
-      gl_set_texture_sampler(t);
+      _mesa_test_texobj_completeness(ctx, t);
+      _mesa_set_texture_sampler(t);
       t->NextDirty = NULL;
       t->Dirty = GL_FALSE;
    }