Some initial RGB and RGBA floating point texture formats.
[mesa.git] / src / mesa / main / texstate.c
index b511b1a8d366dec2576efcef96b6c87438693d93..e27c42e07b65e1effcf63bc692d82cf4e7ccddc2 100644 (file)
@@ -1,10 +1,8 @@
-/* $Id: texstate.c,v 1.91 2003/01/16 15:22:13 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
  * Version:  5.1
  *
- * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2003  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"),
 
 #include "glheader.h"
 #include "colormac.h"
+#include "colortab.h"
 #include "context.h"
 #include "enums.h"
 #include "extensions.h"
 #include "macros.h"
+#include "nvfragprog.h"
 #include "texobj.h"
 #include "teximage.h"
 #include "texstate.h"
@@ -151,7 +151,7 @@ _mesa_print_texunit_state( GLcontext *ctx, GLuint unit )
 /**********************************************************************/
 
 
-void
+void GLAPIENTRY
 _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -171,7 +171,7 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
                 mode == GL_DECAL ||
                 mode == GL_REPLACE ||
                 (mode == GL_ADD && ctx->Extensions.EXT_texture_env_add) ||
-                (mode == GL_COMBINE_EXT &&
+                (mode == GL_COMBINE &&
                  (ctx->Extensions.EXT_texture_env_combine ||
                   ctx->Extensions.ARB_texture_env_combine))) {
                /* legal */
@@ -199,7 +199,7 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
             COPY_4FV(texUnit->EnvColor, tmp);
          }
          break;
-      case GL_COMBINE_RGB_EXT:
+      case GL_COMBINE_RGB:
         if (ctx->Extensions.EXT_texture_env_combine ||
              ctx->Extensions.ARB_texture_env_combine) {
            const GLenum mode = (GLenum) (GLint) *param;
@@ -207,11 +207,11 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
            case GL_REPLACE:
            case GL_MODULATE:
            case GL_ADD:
-           case GL_ADD_SIGNED_EXT:
-           case GL_INTERPOLATE_EXT:
+           case GL_ADD_SIGNED:
+           case GL_INTERPOLATE:
                /* OK */
               break;
-            case GL_SUBTRACT_ARB:
+            case GL_SUBTRACT:
                if (!ctx->Extensions.ARB_texture_env_combine) {
                   TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
                   return;
@@ -224,13 +224,21 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
                  return;
               }
               break;
-           case GL_DOT3_RGB_ARB:
-           case GL_DOT3_RGBA_ARB:
+           case GL_DOT3_RGB:
+           case GL_DOT3_RGBA:
               if (!ctx->Extensions.ARB_texture_env_dot3) {
                   TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
                  return;
               }
               break;
+           case GL_MODULATE_ADD_ATI:
+           case GL_MODULATE_SIGNED_ADD_ATI:
+           case GL_MODULATE_SUBTRACT_ATI:
+              if (!ctx->Extensions.ATI_texture_env_combine3) {
+                  TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
+                 return;
+              }
+              break;
            default:
                TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
               return;
@@ -245,47 +253,63 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
            return;
         }
          break;
-      case GL_COMBINE_ALPHA_EXT:
+      case GL_COMBINE_ALPHA:
         if (ctx->Extensions.EXT_texture_env_combine ||
              ctx->Extensions.ARB_texture_env_combine) {
            const GLenum mode = (GLenum) (GLint) *param;
-            if (mode == GL_REPLACE ||
-                mode == GL_MODULATE ||
-                mode == GL_ADD ||
-                mode == GL_ADD_SIGNED_EXT ||
-                mode == GL_INTERPOLATE_EXT ||
-                (mode == GL_SUBTRACT_ARB &&
-                 ctx->Extensions.ARB_texture_env_combine)) {
-               /* legal */
-               if (texUnit->CombineModeA == mode)
-                  return;
-               FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-               texUnit->CombineModeA = mode;
-            }
-            else {
-               TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
+            switch (mode) {
+           case GL_REPLACE:
+           case GL_MODULATE:
+           case GL_ADD:
+           case GL_ADD_SIGNED:
+           case GL_INTERPOLATE:
+              /* OK */
+              break;
+           case GL_SUBTRACT:
+              if (!ctx->Extensions.ARB_texture_env_combine) {
+                 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
+                 return;
+              }
+              break;
+           case GL_MODULATE_ADD_ATI:
+           case GL_MODULATE_SIGNED_ADD_ATI:
+           case GL_MODULATE_SUBTRACT_ATI:
+              if (!ctx->Extensions.ATI_texture_env_combine3) {
+                  TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
+                 return;
+              }
+              break;
+           default:
+              TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
               return;
            }
+
+           if (texUnit->CombineModeA == mode)
+               return;
+           FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+           texUnit->CombineModeA = mode;
         }
         else {
             TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
            return;
         }
         break;
-      case GL_SOURCE0_RGB_EXT:
-      case GL_SOURCE1_RGB_EXT:
-      case GL_SOURCE2_RGB_EXT:
+      case GL_SOURCE0_RGB:
+      case GL_SOURCE1_RGB:
+      case GL_SOURCE2_RGB:
         if (ctx->Extensions.EXT_texture_env_combine ||
             ctx->Extensions.ARB_texture_env_combine) {
            const GLenum source = (GLenum) (GLint) *param;
-           const GLuint s = pname - GL_SOURCE0_RGB_EXT;
+           const GLuint s = pname - GL_SOURCE0_RGB;
             if (source == GL_TEXTURE ||
-                source == GL_CONSTANT_EXT ||
-                source == GL_PRIMARY_COLOR_EXT ||
-                source == GL_PREVIOUS_EXT ||
+                source == GL_CONSTANT ||
+                source == GL_PRIMARY_COLOR ||
+                source == GL_PREVIOUS ||
                 (ctx->Extensions.ARB_texture_env_crossbar &&
-                 source >= GL_TEXTURE0_ARB &&
-                 source < GL_TEXTURE0_ARB + ctx->Const.MaxTextureUnits)) {
+                 source >= GL_TEXTURE0 &&
+                 source < GL_TEXTURE0 + ctx->Const.MaxTextureUnits) ||
+                (ctx->Extensions.ATI_texture_env_combine3 &&
+                 (source == GL_ZERO || source == GL_ONE))) {
                /* legal */
                if (texUnit->CombineSourceRGB[s] == source)
                   return;
@@ -302,20 +326,22 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
            return;
         }
         break;
-      case GL_SOURCE0_ALPHA_EXT:
-      case GL_SOURCE1_ALPHA_EXT:
-      case GL_SOURCE2_ALPHA_EXT:
+      case GL_SOURCE0_ALPHA:
+      case GL_SOURCE1_ALPHA:
+      case GL_SOURCE2_ALPHA:
         if (ctx->Extensions.EXT_texture_env_combine ||
              ctx->Extensions.ARB_texture_env_combine) {
            const GLenum source = (GLenum) (GLint) *param;
-           const GLuint s = pname - GL_SOURCE0_ALPHA_EXT;
+           const GLuint s = pname - GL_SOURCE0_ALPHA;
             if (source == GL_TEXTURE ||
-                source == GL_CONSTANT_EXT ||
-                source == GL_PRIMARY_COLOR_EXT ||
-                source == GL_PREVIOUS_EXT ||
+                source == GL_CONSTANT ||
+                source == GL_PRIMARY_COLOR ||
+                source == GL_PREVIOUS ||
                 (ctx->Extensions.ARB_texture_env_crossbar &&
-                 source >= GL_TEXTURE0_ARB &&
-                 source < GL_TEXTURE0_ARB + ctx->Const.MaxTextureUnits)) {
+                 source >= GL_TEXTURE0 &&
+                 source < GL_TEXTURE0 + ctx->Const.MaxTextureUnits) ||
+               (ctx->Extensions.ATI_texture_env_combine3 &&
+                 (source == GL_ZERO || source == GL_ONE))) {
                /* legal */
               if (texUnit->CombineSourceA[s] == source)
                   return;
@@ -332,12 +358,12 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
            return;
         }
         break;
-      case GL_OPERAND0_RGB_EXT:
-      case GL_OPERAND1_RGB_EXT:
+      case GL_OPERAND0_RGB:
+      case GL_OPERAND1_RGB:
         if (ctx->Extensions.EXT_texture_env_combine ||
             ctx->Extensions.ARB_texture_env_combine) {
            const GLenum operand = (GLenum) (GLint) *param;
-           const GLuint s = pname - GL_OPERAND0_RGB_EXT;
+           const GLuint s = pname - GL_OPERAND0_RGB;
            switch (operand) {
            case GL_SRC_COLOR:
            case GL_ONE_MINUS_SRC_COLOR:
@@ -358,19 +384,19 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
            return;
         }
         break;
-      case GL_OPERAND0_ALPHA_EXT:
-      case GL_OPERAND1_ALPHA_EXT:
+      case GL_OPERAND0_ALPHA:
+      case GL_OPERAND1_ALPHA:
         if (ctx->Extensions.EXT_texture_env_combine ||
              ctx->Extensions.ARB_texture_env_combine) {
            const GLenum operand = (GLenum) (GLint) *param;
            switch (operand) {
            case GL_SRC_ALPHA:
            case GL_ONE_MINUS_SRC_ALPHA:
-              if (texUnit->CombineOperandA[pname-GL_OPERAND0_ALPHA_EXT] ==
+              if (texUnit->CombineOperandA[pname-GL_OPERAND0_ALPHA] ==
                   operand)
                  return;
               FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-              texUnit->CombineOperandA[pname-GL_OPERAND0_ALPHA_EXT] = operand;
+              texUnit->CombineOperandA[pname-GL_OPERAND0_ALPHA] = operand;
               break;
            default:
                TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand);
@@ -382,7 +408,7 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
            return;
         }
         break;
-      case GL_OPERAND2_RGB_EXT:
+      case GL_OPERAND2_RGB:
         if (ctx->Extensions.EXT_texture_env_combine ||
              ctx->Extensions.ARB_texture_env_combine) {
            const GLenum operand = (GLenum) (GLint) *param;
@@ -395,6 +421,7 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
                  return;
               FLUSH_VERTICES(ctx, _NEW_TEXTURE);
               texUnit->CombineOperandRGB[2] = operand;
+               break;
            default:
                TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand);
               return;
@@ -405,7 +432,7 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
            return;
         }
         break;
-      case GL_OPERAND2_ALPHA_EXT:
+      case GL_OPERAND2_ALPHA:
         if (ctx->Extensions.EXT_texture_env_combine ||
              ctx->Extensions.ARB_texture_env_combine) {
            const GLenum operand = (GLenum) (GLint) *param;
@@ -427,7 +454,7 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
            return;
         }
         break;
-      case GL_RGB_SCALE_EXT:
+      case GL_RGB_SCALE:
         if (ctx->Extensions.EXT_texture_env_combine ||
              ctx->Extensions.ARB_texture_env_combine) {
            GLuint newshift;
@@ -498,8 +525,7 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
         if (texUnit->LodBias == param[0])
            return;
         FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-         texUnit->LodBias = CLAMP(param[0], -ctx->Const.MaxTextureLodBias,
-                                  ctx->Const.MaxTextureLodBias);
+         texUnit->LodBias = param[0];
       }
       else {
          TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
@@ -507,8 +533,9 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
       }
    }
    else if (target == GL_POINT_SPRITE_NV) {
-      /* GL_NV_point_sprite */
-      if (!ctx->Extensions.NV_point_sprite) {
+      /* GL_ARB_point_sprite / GL_NV_point_sprite */
+      if (!ctx->Extensions.NV_point_sprite
+         && !ctx->Extensions.ARB_point_sprite) {
         _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(target=0x%x)", target );
         return;
       }
@@ -553,7 +580,7 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexEnvf( GLenum target, GLenum pname, GLfloat param )
 {
    _mesa_TexEnvfv( target, pname, &param );
@@ -561,7 +588,7 @@ _mesa_TexEnvf( GLenum target, GLenum pname, GLfloat param )
 
 
 
-void
+void GLAPIENTRY
 _mesa_TexEnvi( GLenum target, GLenum pname, GLint param )
 {
    GLfloat p[4];
@@ -571,7 +598,7 @@ _mesa_TexEnvi( GLenum target, GLenum pname, GLint param )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexEnviv( GLenum target, GLenum pname, const GLint *param )
 {
    GLfloat p[4];
@@ -589,7 +616,7 @@ _mesa_TexEnviv( GLenum target, GLenum pname, const GLint *param )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -604,7 +631,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
          case GL_TEXTURE_ENV_COLOR:
             COPY_4FV( params, texUnit->EnvColor );
             break;
-         case GL_COMBINE_RGB_EXT:
+         case GL_COMBINE_RGB:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLfloat) texUnit->CombineModeRGB;
@@ -613,7 +640,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
             }
             break;
-         case GL_COMBINE_ALPHA_EXT:
+         case GL_COMBINE_ALPHA:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLfloat) texUnit->CombineModeA;
@@ -622,7 +649,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
             }
             break;
-         case GL_SOURCE0_RGB_EXT:
+         case GL_SOURCE0_RGB:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLfloat) texUnit->CombineSourceRGB[0];
@@ -631,7 +658,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
             }
             break;
-         case GL_SOURCE1_RGB_EXT:
+         case GL_SOURCE1_RGB:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLfloat) texUnit->CombineSourceRGB[1];
@@ -640,7 +667,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
             }
             break;
-         case GL_SOURCE2_RGB_EXT:
+         case GL_SOURCE2_RGB:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLfloat) texUnit->CombineSourceRGB[2];
@@ -649,7 +676,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
             }
             break;
-         case GL_SOURCE0_ALPHA_EXT:
+         case GL_SOURCE0_ALPHA:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLfloat) texUnit->CombineSourceA[0];
@@ -658,7 +685,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
             }
             break;
-         case GL_SOURCE1_ALPHA_EXT:
+         case GL_SOURCE1_ALPHA:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLfloat) texUnit->CombineSourceA[1];
@@ -667,7 +694,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
             }
             break;
-         case GL_SOURCE2_ALPHA_EXT:
+         case GL_SOURCE2_ALPHA:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLfloat) texUnit->CombineSourceA[2];
@@ -676,7 +703,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
             }
             break;
-         case GL_OPERAND0_RGB_EXT:
+         case GL_OPERAND0_RGB:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLfloat) texUnit->CombineOperandRGB[0];
@@ -685,7 +712,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
             }
             break;
-         case GL_OPERAND1_RGB_EXT:
+         case GL_OPERAND1_RGB:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLfloat) texUnit->CombineOperandRGB[1];
@@ -694,7 +721,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
             }
             break;
-         case GL_OPERAND2_RGB_EXT:
+         case GL_OPERAND2_RGB:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLfloat) texUnit->CombineOperandRGB[2];
@@ -703,7 +730,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
             }
             break;
-         case GL_OPERAND0_ALPHA_EXT:
+         case GL_OPERAND0_ALPHA:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLfloat) texUnit->CombineOperandA[0];
@@ -712,7 +739,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
             }
             break;
-         case GL_OPERAND1_ALPHA_EXT:
+         case GL_OPERAND1_ALPHA:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLfloat) texUnit->CombineOperandA[1];
@@ -721,7 +748,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
             }
             break;
-         case GL_OPERAND2_ALPHA_EXT:
+         case GL_OPERAND2_ALPHA:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLfloat) texUnit->CombineOperandA[2];
@@ -730,7 +757,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
             }
             break;
-         case GL_RGB_SCALE_EXT:
+         case GL_RGB_SCALE:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                if (texUnit->CombineScaleShiftRGB == 0)
@@ -761,7 +788,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
             }
             break;
          default:
-            _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" );
+            _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname=0x%x)", pname);
       }
    }
    else if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
@@ -779,8 +806,9 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
       }
    }
    else if (target == GL_POINT_SPRITE_NV) {
-      /* GL_NV_point_sprite */
-      if (!ctx->Extensions.NV_point_sprite) {
+      /* GL_ARB_point_sprite / GL_NV_point_sprite */
+      if (!ctx->Extensions.NV_point_sprite
+         && !ctx->Extensions.ARB_point_sprite) {
          _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" );
          return;
       }
@@ -799,7 +827,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -817,7 +845,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
             params[2] = FLOAT_TO_INT( texUnit->EnvColor[2] );
             params[3] = FLOAT_TO_INT( texUnit->EnvColor[3] );
             break;
-         case GL_COMBINE_RGB_EXT:
+         case GL_COMBINE_RGB:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLint) texUnit->CombineModeRGB;
@@ -826,7 +854,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
             }
             break;
-         case GL_COMBINE_ALPHA_EXT:
+         case GL_COMBINE_ALPHA:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLint) texUnit->CombineModeA;
@@ -835,7 +863,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
             }
             break;
-         case GL_SOURCE0_RGB_EXT:
+         case GL_SOURCE0_RGB:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLint) texUnit->CombineSourceRGB[0];
@@ -844,7 +872,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
             }
             break;
-         case GL_SOURCE1_RGB_EXT:
+         case GL_SOURCE1_RGB:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLint) texUnit->CombineSourceRGB[1];
@@ -853,7 +881,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
             }
             break;
-         case GL_SOURCE2_RGB_EXT:
+         case GL_SOURCE2_RGB:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLint) texUnit->CombineSourceRGB[2];
@@ -862,7 +890,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
             }
             break;
-         case GL_SOURCE0_ALPHA_EXT:
+         case GL_SOURCE0_ALPHA:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLint) texUnit->CombineSourceA[0];
@@ -871,7 +899,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
             }
             break;
-         case GL_SOURCE1_ALPHA_EXT:
+         case GL_SOURCE1_ALPHA:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLint) texUnit->CombineSourceA[1];
@@ -880,7 +908,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
             }
             break;
-         case GL_SOURCE2_ALPHA_EXT:
+         case GL_SOURCE2_ALPHA:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLint) texUnit->CombineSourceA[2];
@@ -889,7 +917,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
             }
             break;
-         case GL_OPERAND0_RGB_EXT:
+         case GL_OPERAND0_RGB:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLint) texUnit->CombineOperandRGB[0];
@@ -898,7 +926,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
             }
             break;
-         case GL_OPERAND1_RGB_EXT:
+         case GL_OPERAND1_RGB:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLint) texUnit->CombineOperandRGB[1];
@@ -907,7 +935,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
             }
             break;
-         case GL_OPERAND2_RGB_EXT:
+         case GL_OPERAND2_RGB:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLint) texUnit->CombineOperandRGB[2];
@@ -916,7 +944,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
             }
             break;
-         case GL_OPERAND0_ALPHA_EXT:
+         case GL_OPERAND0_ALPHA:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLint) texUnit->CombineOperandA[0];
@@ -925,7 +953,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
             }
             break;
-         case GL_OPERAND1_ALPHA_EXT:
+         case GL_OPERAND1_ALPHA:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLint) texUnit->CombineOperandA[1];
@@ -934,7 +962,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
             }
             break;
-         case GL_OPERAND2_ALPHA_EXT:
+         case GL_OPERAND2_ALPHA:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                *params = (GLint) texUnit->CombineOperandA[2];
@@ -943,7 +971,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
                _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
             }
             break;
-         case GL_RGB_SCALE_EXT:
+         case GL_RGB_SCALE:
             if (ctx->Extensions.EXT_texture_env_combine ||
                 ctx->Extensions.ARB_texture_env_combine) {
                if (texUnit->CombineScaleShiftRGB == 0)
@@ -974,7 +1002,8 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
             }
             break;
          default:
-            _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)" );
+            _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname=0x%x)",
+                        pname);
       }
    }
    else if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
@@ -992,8 +1021,9 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
       }
    }
    else if (target == GL_POINT_SPRITE_NV) {
-      /* GL_NV_point_sprite */
-      if (!ctx->Extensions.NV_point_sprite) {
+      /* GL_ARB_point_sprite / GL_NV_point_sprite */
+      if (!ctx->Extensions.NV_point_sprite
+         && !ctx->Extensions.ARB_point_sprite) {
          _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" );
          return;
       }
@@ -1018,15 +1048,44 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
 /*                       Texture Parameters                           */
 /**********************************************************************/
 
+static GLboolean 
+_mesa_validate_texture_wrap_mode(GLcontext * ctx,
+                                GLenum target, GLenum eparam)
+{
+   const struct gl_extensions * const e = & ctx->Extensions;
 
-void
+   if (eparam == GL_CLAMP || eparam == GL_CLAMP_TO_EDGE ||
+       (eparam == GL_CLAMP_TO_BORDER && e->ARB_texture_border_clamp)) {
+      /* any texture target */
+      return GL_TRUE;
+   }
+   else if (target != GL_TEXTURE_RECTANGLE_NV &&
+           (eparam == GL_REPEAT ||
+            (eparam == GL_MIRRORED_REPEAT &&
+             e->ARB_texture_mirrored_repeat) ||
+            (eparam == GL_MIRROR_CLAMP_EXT &&
+             (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
+            (eparam == GL_MIRROR_CLAMP_TO_EDGE_EXT &&
+             (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
+            (eparam == GL_MIRROR_CLAMP_TO_BORDER_EXT &&
+             (e->EXT_texture_mirror_clamp)))) {
+      /* non-rectangle texture */
+      return GL_TRUE;
+   }
+
+   _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
+   return GL_FALSE;
+}
+
+
+void GLAPIENTRY
 _mesa_TexParameterf( GLenum target, GLenum pname, GLfloat param )
 {
    _mesa_TexParameterfv(target, pname, &param);
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -1036,10 +1095,11 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
-      _mesa_debug(ctx, "texPARAM %s %s %d...\n",
+      _mesa_debug(ctx, "glTexParameter %s %s %.1f(%s)...\n",
                   _mesa_lookup_enum_by_nr(target),
                   _mesa_lookup_enum_by_nr(pname),
-                  eparam);
+                  *params,
+                 _mesa_lookup_enum_by_nr(eparam));
 
 
    switch (target) {
@@ -1049,10 +1109,10 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
       case GL_TEXTURE_2D:
          texObj = texUnit->Current2D;
          break;
-      case GL_TEXTURE_3D_EXT:
+      case GL_TEXTURE_3D:
          texObj = texUnit->Current3D;
          break;
-      case GL_TEXTURE_CUBE_MAP_ARB:
+      case GL_TEXTURE_CUBE_MAP:
          if (!ctx->Extensions.ARB_texture_cube_map) {
             _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(target)" );
             return;
@@ -1110,81 +1170,34 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
       case GL_TEXTURE_WRAP_S:
          if (texObj->WrapS == eparam)
             return;
-         if (eparam == GL_CLAMP || eparam == GL_CLAMP_TO_EDGE ||
-             (eparam == GL_CLAMP_TO_BORDER_ARB &&
-              ctx->Extensions.ARB_texture_border_clamp)) {
-            /* any texture target */
-            FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-            texObj->WrapS = eparam;
-         }
-         else if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
-                  (eparam == GL_REPEAT ||
-                   (eparam == GL_MIRRORED_REPEAT_ARB &&
-                    ctx->Extensions.ARB_texture_mirrored_repeat) ||
-                   (eparam == GL_MIRROR_CLAMP_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once) ||
-                   (eparam == GL_MIRROR_CLAMP_TO_EDGE_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once))) {
-            /* non-rectangle texture */
+         if (_mesa_validate_texture_wrap_mode(ctx, texObj->Target, eparam)) {
             FLUSH_VERTICES(ctx, _NEW_TEXTURE);
             texObj->WrapS = eparam;
          }
          else {
-            _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
             return;
          }
          break;
       case GL_TEXTURE_WRAP_T:
          if (texObj->WrapT == eparam)
             return;
-         if (eparam == GL_CLAMP || eparam == GL_CLAMP_TO_EDGE ||
-             (eparam == GL_CLAMP_TO_BORDER_ARB &&
-              ctx->Extensions.ARB_texture_border_clamp)) {
-            /* any texture target */
-            FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-            texObj->WrapT = eparam;
-         }
-         else if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
-                  (eparam == GL_REPEAT ||
-                   (eparam == GL_MIRRORED_REPEAT_ARB &&
-                    ctx->Extensions.ARB_texture_mirrored_repeat) ||
-                   (eparam == GL_MIRROR_CLAMP_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once) ||
-                   (eparam == GL_MIRROR_CLAMP_TO_EDGE_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once))) {
-            /* non-rectangle texture */
+         if (_mesa_validate_texture_wrap_mode(ctx, texObj->Target, eparam)) {
             FLUSH_VERTICES(ctx, _NEW_TEXTURE);
             texObj->WrapT = eparam;
          }
          else {
-            _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
             return;
          }
          break;
-      case GL_TEXTURE_WRAP_R_EXT:
+      case GL_TEXTURE_WRAP_R:
          if (texObj->WrapR == eparam)
             return;
-         if (eparam == GL_CLAMP || eparam == GL_CLAMP_TO_EDGE ||
-             (eparam == GL_CLAMP_TO_BORDER_ARB &&
-              ctx->Extensions.ARB_texture_border_clamp)) {
-            /* any texture target */
-            FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-            texObj->WrapR = eparam;
-         }
-         else if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
-                  (eparam == GL_REPEAT ||
-                   (eparam == GL_MIRRORED_REPEAT_ARB &&
-                    ctx->Extensions.ARB_texture_mirrored_repeat) ||
-                   (eparam == GL_MIRROR_CLAMP_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once) ||
-                   (eparam == GL_MIRROR_CLAMP_TO_EDGE_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once))) {
-            /* non-rectangle texture */
+         if (_mesa_validate_texture_wrap_mode(ctx, texObj->Target, eparam)) {
             FLUSH_VERTICES(ctx, _NEW_TEXTURE);
             texObj->WrapR = eparam;
          }
          else {
-            _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
+           return;
          }
          break;
       case GL_TEXTURE_BORDER_COLOR:
@@ -1367,6 +1380,15 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
             return;
          }
          break;
+      case GL_TEXTURE_LOD_BIAS:
+         /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias*/
+         if (ctx->Extensions.EXT_texture_lod_bias) {
+            if (texObj->LodBias != params[0]) {
+               FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+               texObj->LodBias = params[0];
+            }
+         }
+         break;
 
       default:
          _mesa_error(ctx, GL_INVALID_ENUM,
@@ -1382,17 +1404,20 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexParameteri( GLenum target, GLenum pname, GLint param )
 {
    GLfloat fparam[4];
-   fparam[0] = (GLfloat) param;
+   if (pname == GL_TEXTURE_PRIORITY)
+      fparam[0] = INT_TO_FLOAT(param);
+   else
+      fparam[0] = (GLfloat) param;
    fparam[1] = fparam[2] = fparam[3] = 0.0;
    _mesa_TexParameterfv(target, pname, fparam);
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexParameteriv( GLenum target, GLenum pname, const GLint *params )
 {
    GLfloat fparam[4];
@@ -1403,14 +1428,17 @@ _mesa_TexParameteriv( GLenum target, GLenum pname, const GLint *params )
       fparam[3] = INT_TO_FLOAT(params[3]);
    }
    else {
-      fparam[0] = (GLfloat) params[0];
+      if (pname == GL_TEXTURE_PRIORITY)
+         fparam[0] = INT_TO_FLOAT(params[0]);
+      else
+         fparam[0] = (GLfloat) params[0];
       fparam[1] = fparam[2] = fparam[3] = 0.0F;
    }
    _mesa_TexParameterfv(target, pname, fparam);
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
                               GLenum pname, GLfloat *params )
 {
@@ -1433,14 +1461,14 @@ tex_image_dimensions(GLcontext *ctx, GLenum target)
       case GL_TEXTURE_3D:
       case GL_PROXY_TEXTURE_3D:
          return 3;
-      case GL_TEXTURE_CUBE_MAP_ARB:
-      case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
-      case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
-      case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
-      case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
-      case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
-      case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
-      case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
+      case GL_TEXTURE_CUBE_MAP:
+      case GL_PROXY_TEXTURE_CUBE_MAP:
+      case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+      case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+      case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+      case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+      case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+      case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
          return ctx->Extensions.ARB_texture_cube_map ? 2 : 0;
       case GL_TEXTURE_RECTANGLE_NV:
       case GL_PROXY_TEXTURE_RECTANGLE_NV:
@@ -1452,7 +1480,7 @@ tex_image_dimensions(GLcontext *ctx, GLenum target)
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
                               GLenum pname, GLint *params )
 {
@@ -1482,13 +1510,13 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
    case GL_PROXY_TEXTURE_3D:
       maxLevels = ctx->Const.Max3DTextureLevels;
       break;
-   case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
-   case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
-   case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
-   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
-   case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
-   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
-   case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
+   case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+   case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+   case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+   case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+   case GL_PROXY_TEXTURE_CUBE_MAP:
       maxLevels = ctx->Const.MaxCubeTextureLevels;
       break;
    case GL_TEXTURE_RECTANGLE_NV:
@@ -1518,7 +1546,7 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
    isProxy = (target == GL_PROXY_TEXTURE_1D) ||
              (target == GL_PROXY_TEXTURE_2D) ||
              (target == GL_PROXY_TEXTURE_3D) ||
-             (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) ||
+             (target == GL_PROXY_TEXTURE_CUBE_MAP) ||
              (target == GL_PROXY_TEXTURE_RECTANGLE_NV);
 
    switch (pname) {
@@ -1597,7 +1625,7 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
          return;
 
       /* GL_ARB_texture_compression */
-      case GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB:
+      case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
          if (ctx->Extensions.ARB_texture_compression) {
             if (img->IsCompressed && !isProxy)
                *params = img->CompressedSize;
@@ -1610,7 +1638,7 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
                         "glGetTexLevelParameter[if]v(pname)");
          }
          return;
-      case GL_TEXTURE_COMPRESSED_ARB:
+      case GL_TEXTURE_COMPRESSED:
          if (ctx->Extensions.ARB_texture_compression) {
             *params = (GLint) img->IsCompressed;
          }
@@ -1628,7 +1656,7 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
 
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -1655,7 +1683,7 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
       case GL_TEXTURE_WRAP_T:
          *params = ENUM_TO_FLOAT(obj->WrapT);
          return;
-      case GL_TEXTURE_WRAP_R_EXT:
+      case GL_TEXTURE_WRAP_R:
          *params = ENUM_TO_FLOAT(obj->WrapR);
          return;
       case GL_TEXTURE_BORDER_COLOR:
@@ -1737,15 +1765,22 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
             return;
          }
          break;
+      case GL_TEXTURE_LOD_BIAS:
+         if (ctx->Extensions.EXT_texture_lod_bias) {
+            *params = obj->LodBias;
+            break;
+         }
+         break;
       default:
          ; /* silence warnings */
    }
    /* If we get here, pname was an unrecognized enum */
-   _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname)" );
+   _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname=0x%x)",
+               pname);
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -1762,6 +1797,12 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
    switch (pname) {
       case GL_TEXTURE_MAG_FILTER:
          *params = (GLint) obj->MagFilter;
+      case GL_TEXTURE_LOD_BIAS:
+         if (ctx->Extensions.EXT_texture_lod_bias) {
+            *params = (GLint) obj->LodBias;
+            break;
+         }
+         break;
          return;
       case GL_TEXTURE_MIN_FILTER:
          *params = (GLint) obj->MinFilter;
@@ -1772,7 +1813,7 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
       case GL_TEXTURE_WRAP_T:
          *params = (GLint) obj->WrapT;
          return;
-      case GL_TEXTURE_WRAP_R_EXT:
+      case GL_TEXTURE_WRAP_R:
          *params = (GLint) obj->WrapR;
          return;
       case GL_TEXTURE_BORDER_COLOR:
@@ -1799,7 +1840,7 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
          }
          return;
       case GL_TEXTURE_PRIORITY:
-         *params = (GLint) obj->Priority;
+         *params = FLOAT_TO_INT(obj->Priority);
          return;
       case GL_TEXTURE_MIN_LOD:
          *params = (GLint) obj->MinLod;
@@ -1865,7 +1906,7 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
          ; /* silence warnings */
    }
    /* If we get here, pname was an unrecognized enum */
-   _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname)" );
+   _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname=0x%x)", pname);
 }
 
 
@@ -1875,8 +1916,8 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
 /*                    Texture Coord Generation                        */
 /**********************************************************************/
 
-
-void
+#if FEATURE_texgen
+void GLAPIENTRY
 _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -1885,10 +1926,11 @@ _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
-      _mesa_debug(ctx, "texGEN %s %s %x...\n",
+      _mesa_debug(ctx, "glTexGen %s %s %.1f(%s)...\n",
                   _mesa_lookup_enum_by_nr(coord),
                   _mesa_lookup_enum_by_nr(pname),
-                  *(int *)params);
+                  *params,
+                 _mesa_lookup_enum_by_nr((GLenum) (GLint) *params));
 
    switch (coord) {
       case GL_S:
@@ -2114,19 +2156,24 @@ _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexGeniv(GLenum coord, GLenum pname, const GLint *params )
 {
    GLfloat p[4];
    p[0] = (GLfloat) params[0];
-   p[1] = (GLfloat) params[1];
-   p[2] = (GLfloat) params[2];
-   p[3] = (GLfloat) params[3];
+   if (pname == GL_TEXTURE_GEN_MODE) {
+      p[1] = p[2] = p[3] = 0.0F;
+   }
+   else {
+      p[1] = (GLfloat) params[1];
+      p[2] = (GLfloat) params[2];
+      p[3] = (GLfloat) params[3];
+   }
    _mesa_TexGenfv(coord, pname, p);
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexGend(GLenum coord, GLenum pname, GLdouble param )
 {
    GLfloat p = (GLfloat) param;
@@ -2134,26 +2181,31 @@ _mesa_TexGend(GLenum coord, GLenum pname, GLdouble param )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexGendv(GLenum coord, GLenum pname, const GLdouble *params )
 {
    GLfloat p[4];
    p[0] = (GLfloat) params[0];
-   p[1] = (GLfloat) params[1];
-   p[2] = (GLfloat) params[2];
-   p[3] = (GLfloat) params[3];
+   if (pname == GL_TEXTURE_GEN_MODE) {
+      p[1] = p[2] = p[3] = 0.0F;
+   }
+   else {
+      p[1] = (GLfloat) params[1];
+      p[2] = (GLfloat) params[2];
+      p[3] = (GLfloat) params[3];
+   }
    _mesa_TexGenfv( coord, pname, p );
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexGenf( GLenum coord, GLenum pname, GLfloat param )
 {
    _mesa_TexGenfv(coord, pname, &param);
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexGeni( GLenum coord, GLenum pname, GLint param )
 {
    _mesa_TexGeniv( coord, pname, &param );
@@ -2161,7 +2213,7 @@ _mesa_TexGeni( GLenum coord, GLenum pname, GLint param )
 
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexGendv( GLenum coord, GLenum pname, GLdouble *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -2238,7 +2290,7 @@ _mesa_GetTexGendv( GLenum coord, GLenum pname, GLdouble *params )
 
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexGenfv( GLenum coord, GLenum pname, GLfloat *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -2315,7 +2367,7 @@ _mesa_GetTexGenfv( GLenum coord, GLenum pname, GLfloat *params )
 
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexGeniv( GLenum coord, GLenum pname, GLint *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -2413,14 +2465,14 @@ _mesa_GetTexGeniv( GLenum coord, GLenum pname, GLint *params )
         return;
    }
 }
-
+#endif
 
 /* GL_ARB_multitexture */
-void
+void GLAPIENTRY
 _mesa_ActiveTextureARB( GLenum target )
 {
    GET_CURRENT_CONTEXT(ctx);
-   GLuint texUnit = target - GL_TEXTURE0_ARB;
+   const GLuint texUnit = target - GL_TEXTURE0;
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
@@ -2429,10 +2481,13 @@ _mesa_ActiveTextureARB( GLenum target )
 
    /* Cater for texture unit 0 is first, therefore use >= */
    if (texUnit >= ctx->Const.MaxTextureUnits) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glActiveTextureARB(target)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glActiveTexture(target)");
       return;
    }
 
+   if (ctx->Texture.CurrentUnit == texUnit)
+      return;
+
    FLUSH_VERTICES(ctx, _NEW_TEXTURE);
 
    ctx->Texture.CurrentUnit = texUnit;
@@ -2448,15 +2503,15 @@ _mesa_ActiveTextureARB( GLenum target )
 
 
 /* GL_ARB_multitexture */
-void
+void GLAPIENTRY
 _mesa_ClientActiveTextureARB( GLenum target )
 {
    GET_CURRENT_CONTEXT(ctx);
-   GLuint texUnit = target - GL_TEXTURE0_ARB;
+   GLuint texUnit = target - GL_TEXTURE0;
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (texUnit > ctx->Const.MaxTextureUnits) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glClientActiveTextureARB(target)");
+      _mesa_error(ctx, GL_INVALID_ENUM, "glClientActiveTexture(target)");
       return;
    }
 
@@ -2470,7 +2525,7 @@ _mesa_ClientActiveTextureARB( GLenum target )
 /*                     Pixel Texgen Extensions                        */
 /**********************************************************************/
 
-void
+void GLAPIENTRY
 _mesa_PixelTexGenSGIX(GLenum mode)
 {
    GLenum newRgbSource, newAlphaSource;
@@ -2509,21 +2564,21 @@ _mesa_PixelTexGenSGIX(GLenum mode)
 }
 
 
-void
+void GLAPIENTRY
 _mesa_PixelTexGenParameterfSGIS(GLenum target, GLfloat value)
 {
    _mesa_PixelTexGenParameteriSGIS(target, (GLint) value);
 }
 
 
-void
+void GLAPIENTRY
 _mesa_PixelTexGenParameterfvSGIS(GLenum target, const GLfloat *value)
 {
    _mesa_PixelTexGenParameteriSGIS(target, (GLint) *value);
 }
 
 
-void
+void GLAPIENTRY
 _mesa_PixelTexGenParameteriSGIS(GLenum target, GLint value)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -2554,14 +2609,14 @@ _mesa_PixelTexGenParameteriSGIS(GLenum target, GLint value)
 }
 
 
-void
+void GLAPIENTRY
 _mesa_PixelTexGenParameterivSGIS(GLenum target, const GLint *value)
 {
   _mesa_PixelTexGenParameteriSGIS(target, *value);
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetPixelTexGenParameterfvSGIS(GLenum target, GLfloat *value)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -2579,7 +2634,7 @@ _mesa_GetPixelTexGenParameterfvSGIS(GLenum target, GLfloat *value)
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetPixelTexGenParameterivSGIS(GLenum target, GLint *value)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -2595,3 +2650,351 @@ _mesa_GetPixelTexGenParameterivSGIS(GLenum target, GLint *value)
       _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelTexGenParameterivSGIS(target)");
    }
 }
+
+
+
+/**********************************************************************/
+/*****                    State management                        *****/
+/**********************************************************************/
+
+
+/**
+ * \note This routine refers to derived texture attribute values to
+ * compute the ENABLE_TEXMAT flags, but is only called on
+ * _NEW_TEXTURE_MATRIX.  On changes to _NEW_TEXTURE, the ENABLE_TEXMAT
+ * flags are updated by _mesa_update_textures(), below.
+ *
+ * \param ctx GL context.
+ */
+static void
+update_texture_matrices( GLcontext *ctx )
+{
+   GLuint i;
+
+   ctx->Texture._TexMatEnabled = 0;
+
+   for (i=0; i < ctx->Const.MaxTextureUnits; i++) {
+      if (ctx->TextureMatrixStack[i].Top->flags & MAT_DIRTY) {
+        _math_matrix_analyse( ctx->TextureMatrixStack[i].Top );
+
+        if (ctx->Texture.Unit[i]._ReallyEnabled &&
+            ctx->TextureMatrixStack[i].Top->type != MATRIX_IDENTITY)
+           ctx->Texture._TexMatEnabled |= ENABLE_TEXMAT(i);
+
+        if (ctx->Driver.TextureMatrix)
+           ctx->Driver.TextureMatrix( ctx, i, ctx->TextureMatrixStack[i].Top);
+      }
+   }
+}
+
+
+
+
+/**
+ * \note This routine refers to derived texture matrix values to
+ * compute the ENABLE_TEXMAT flags, but is only called on
+ * _NEW_TEXTURE.  On changes to _NEW_TEXTURE_MATRIX, the ENABLE_TEXMAT
+ * flags are updated by _mesa_update_texture_matrices, above.
+ *
+ * \param ctx GL context.
+ */
+static void
+update_texture_state( GLcontext *ctx )
+{
+   GLuint unit;
+
+   ctx->NewState |= _NEW_TEXTURE; /* TODO: only set this if there are 
+                                  * actual changes. 
+                                  */
+
+   ctx->Texture._EnabledUnits = 0;
+   ctx->Texture._GenFlags = 0;
+   ctx->Texture._TexMatEnabled = 0;
+   ctx->Texture._TexGenEnabled = 0;
+
+   /* Update texture unit state.
+    * XXX this loop should probably be broken into separate loops for
+    * texture coord units and texture image units.
+    */
+   for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
+      struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
+      GLuint enableBits;
+
+      texUnit->_Current = NULL;
+      texUnit->_ReallyEnabled = 0;
+      texUnit->_GenFlags = 0;
+
+      /* Get the bitmask of texture enables */
+      if (ctx->FragmentProgram.Enabled && ctx->FragmentProgram.Current) {
+         enableBits = ctx->FragmentProgram.Current->TexturesUsed[unit];
+      }
+      else {
+         if (!texUnit->Enabled)
+            continue;
+         enableBits = texUnit->Enabled;
+      }
+
+      /* Look for the highest-priority texture target that's enabled and
+       * complete.  That's the one we'll use for texturing.  If we're using
+       * a fragment program we're guaranteed that bitcount(enabledBits) <= 1.
+       */
+      if (enableBits & TEXTURE_CUBE_BIT) {
+         struct gl_texture_object *texObj = texUnit->CurrentCubeMap;
+         if (!texObj->Complete) {
+            _mesa_test_texobj_completeness(ctx, texObj);
+         }
+         if (texObj->Complete) {
+            texUnit->_ReallyEnabled = TEXTURE_CUBE_BIT;
+            texUnit->_Current = texObj;
+         }
+      }
+
+      if (!texUnit->_ReallyEnabled && (enableBits & TEXTURE_3D_BIT)) {
+         struct gl_texture_object *texObj = texUnit->Current3D;
+         if (!texObj->Complete) {
+            _mesa_test_texobj_completeness(ctx, texObj);
+         }
+         if (texObj->Complete) {
+            texUnit->_ReallyEnabled = TEXTURE_3D_BIT;
+            texUnit->_Current = texObj;
+         }
+      }
+
+      if (!texUnit->_ReallyEnabled && (enableBits & TEXTURE_RECT_BIT)) {
+         struct gl_texture_object *texObj = texUnit->CurrentRect;
+         if (!texObj->Complete) {
+            _mesa_test_texobj_completeness(ctx, texObj);
+         }
+         if (texObj->Complete) {
+            texUnit->_ReallyEnabled = TEXTURE_RECT_BIT;
+            texUnit->_Current = texObj;
+         }
+      }
+
+      if (!texUnit->_ReallyEnabled && (enableBits & TEXTURE_2D_BIT)) {
+         struct gl_texture_object *texObj = texUnit->Current2D;
+         if (!texObj->Complete) {
+            _mesa_test_texobj_completeness(ctx, texObj);
+         }
+         if (texObj->Complete) {
+            texUnit->_ReallyEnabled = TEXTURE_2D_BIT;
+            texUnit->_Current = texObj;
+         }
+      }
+
+      if (!texUnit->_ReallyEnabled && (enableBits & TEXTURE_1D_BIT)) {
+         struct gl_texture_object *texObj = texUnit->Current1D;
+         if (!texObj->Complete) {
+            _mesa_test_texobj_completeness(ctx, texObj);
+         }
+         if (texObj->Complete) {
+            texUnit->_ReallyEnabled = TEXTURE_1D_BIT;
+            texUnit->_Current = texObj;
+         }
+      }
+
+      if (!texUnit->_ReallyEnabled) {
+         continue;
+      }
+
+      if (texUnit->_ReallyEnabled)
+         ctx->Texture._EnabledUnits |= (1 << unit);
+
+      if (texUnit->TexGenEnabled) {
+        if (texUnit->TexGenEnabled & S_BIT) {
+           texUnit->_GenFlags |= texUnit->_GenBitS;
+        }
+        if (texUnit->TexGenEnabled & T_BIT) {
+           texUnit->_GenFlags |= texUnit->_GenBitT;
+        }
+        if (texUnit->TexGenEnabled & Q_BIT) {
+           texUnit->_GenFlags |= texUnit->_GenBitQ;
+        }
+        if (texUnit->TexGenEnabled & R_BIT) {
+           texUnit->_GenFlags |= texUnit->_GenBitR;
+        }
+
+        ctx->Texture._TexGenEnabled |= ENABLE_TEXGEN(unit);
+        ctx->Texture._GenFlags |= texUnit->_GenFlags;
+      }
+
+      if (ctx->TextureMatrixStack[unit].Top->type != MATRIX_IDENTITY)
+        ctx->Texture._TexMatEnabled |= ENABLE_TEXMAT(unit);
+   }
+
+   ctx->Texture._EnabledCoordUnits = ctx->Texture._EnabledUnits;
+   /* Fragment programs may need texture coordinates but not the
+    * corresponding texture images.
+    */
+   if (ctx->FragmentProgram.Enabled && ctx->FragmentProgram.Current) {
+      ctx->Texture._EnabledCoordUnits |=
+         (ctx->FragmentProgram.Current->InputsRead >> FRAG_ATTRIB_TEX0);
+   }
+}
+
+
+void _mesa_update_texture( GLcontext *ctx, GLuint new_state )
+{
+   if (new_state & _NEW_TEXTURE_MATRIX)
+      update_texture_matrices( ctx );
+
+   if (new_state & (_NEW_TEXTURE | _NEW_PROGRAM))
+      update_texture_state( ctx );
+}
+
+/**********************************************************************/
+/*****                      Initialization                        *****/
+/**********************************************************************/
+
+/**
+ * Allocate the proxy textures for the given context.
+ * 
+ * \param ctx the context to allocate proxies for.
+ * 
+ * \return GL_TRUE on success, or GL_FALSE on failure
+ * 
+ * If run out of memory part way through the allocations, clean up and return
+ * GL_FALSE.
+ */
+static GLboolean
+alloc_proxy_textures( GLcontext *ctx )
+{
+   ctx->Texture.Proxy1D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D);
+   if (!ctx->Texture.Proxy1D)
+      goto cleanup;
+
+   ctx->Texture.Proxy2D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D);
+   if (!ctx->Texture.Proxy2D)
+      goto cleanup;
+
+   ctx->Texture.Proxy3D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_3D);
+   if (!ctx->Texture.Proxy3D)
+      goto cleanup;
+
+   ctx->Texture.ProxyCubeMap = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_CUBE_MAP_ARB);
+   if (!ctx->Texture.ProxyCubeMap)
+      goto cleanup;
+
+   ctx->Texture.ProxyRect = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_RECTANGLE_NV);
+   if (!ctx->Texture.ProxyRect)
+      goto cleanup;
+
+   return GL_TRUE;
+
+ cleanup:
+   if (ctx->Texture.Proxy1D)
+      (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy1D);
+   if (ctx->Texture.Proxy2D)
+      (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy2D);
+   if (ctx->Texture.Proxy3D)
+      (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy3D);
+   if (ctx->Texture.ProxyCubeMap)
+      (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyCubeMap);
+   if (ctx->Texture.ProxyRect)
+      (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyRect);
+   return GL_FALSE;
+}
+
+
+/**
+ * Initialize a texture unit.
+ *
+ * \param ctx GL context.
+ * \param unit texture unit number to be initialized.
+ */
+static void
+init_texture_unit( GLcontext *ctx, GLuint unit )
+{
+   struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
+
+   texUnit->EnvMode = GL_MODULATE;
+   ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
+
+   texUnit->CombineModeRGB = GL_MODULATE;
+   texUnit->CombineModeA = GL_MODULATE;
+   texUnit->CombineSourceRGB[0] = GL_TEXTURE;
+   texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT;
+   texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT;
+   texUnit->CombineSourceA[0] = GL_TEXTURE;
+   texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT;
+   texUnit->CombineSourceA[2] = GL_CONSTANT_EXT;
+   texUnit->CombineOperandRGB[0] = GL_SRC_COLOR;
+   texUnit->CombineOperandRGB[1] = GL_SRC_COLOR;
+   texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA;
+   texUnit->CombineOperandA[0] = GL_SRC_ALPHA;
+   texUnit->CombineOperandA[1] = GL_SRC_ALPHA;
+   texUnit->CombineOperandA[2] = GL_SRC_ALPHA;
+   texUnit->CombineScaleShiftRGB = 0;
+   texUnit->CombineScaleShiftA = 0;
+
+   texUnit->TexGenEnabled = 0;
+   texUnit->GenModeS = GL_EYE_LINEAR;
+   texUnit->GenModeT = GL_EYE_LINEAR;
+   texUnit->GenModeR = GL_EYE_LINEAR;
+   texUnit->GenModeQ = GL_EYE_LINEAR;
+   texUnit->_GenBitS = TEXGEN_EYE_LINEAR;
+   texUnit->_GenBitT = TEXGEN_EYE_LINEAR;
+   texUnit->_GenBitR = TEXGEN_EYE_LINEAR;
+   texUnit->_GenBitQ = TEXGEN_EYE_LINEAR;
+
+   /* Yes, these plane coefficients are correct! */
+   ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
+   ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
+   ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
+   ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
+   ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
+   ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
+   ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
+   ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
+
+   texUnit->Current1D = ctx->Shared->Default1D;
+   texUnit->Current2D = ctx->Shared->Default2D;
+   texUnit->Current3D = ctx->Shared->Default3D;
+   texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
+   texUnit->CurrentRect = ctx->Shared->DefaultRect;
+}
+
+
+GLboolean _mesa_init_texture( GLcontext * ctx )
+{
+   int i;
+
+   assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
+   assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
+
+   /* Effectively bind the default textures to all texture units */
+   ctx->Shared->Default1D->RefCount += MAX_TEXTURE_UNITS;
+   ctx->Shared->Default2D->RefCount += MAX_TEXTURE_UNITS;
+   ctx->Shared->Default3D->RefCount += MAX_TEXTURE_UNITS;
+   ctx->Shared->DefaultCubeMap->RefCount += MAX_TEXTURE_UNITS;
+   ctx->Shared->DefaultRect->RefCount += MAX_TEXTURE_UNITS;
+
+   /* Texture group */
+   ctx->Texture.CurrentUnit = 0;      /* multitexture */
+   ctx->Texture._EnabledUnits = 0;
+   for (i=0; i<MAX_TEXTURE_UNITS; i++)
+      init_texture_unit( ctx, i );
+   ctx->Texture.SharedPalette = GL_FALSE;
+   _mesa_init_colortable(&ctx->Texture.Palette);
+
+   /* Allocate proxy textures */
+   if (!alloc_proxy_textures( ctx ))
+      return GL_FALSE;
+
+   return GL_TRUE;
+}
+
+void _mesa_free_texture_data( GLcontext *ctx )
+{
+   int i;
+
+   /* Free proxy texture objects */
+   (ctx->Driver.DeleteTexture)(ctx,  ctx->Texture.Proxy1D );
+   (ctx->Driver.DeleteTexture)(ctx,  ctx->Texture.Proxy2D );
+   (ctx->Driver.DeleteTexture)(ctx,  ctx->Texture.Proxy3D );
+   (ctx->Driver.DeleteTexture)(ctx,  ctx->Texture.ProxyCubeMap );
+   (ctx->Driver.DeleteTexture)(ctx,  ctx->Texture.ProxyRect );
+
+   for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++)
+      _mesa_free_colortable_data( &ctx->Texture.Unit[i].ColorTable );
+}