init secondary color to (0,0,0,1). remove some redundant initializations.
[mesa.git] / src / mesa / main / texobj.c
index 864752b6d98581d1c2db4c04cfdc02a5c7021d3c..1829cc0c13b706297b2cfb13a8226e687887434c 100644 (file)
@@ -1,10 +1,13 @@
-/* $Id: texobj.c,v 1.67 2003/04/01 16:41:55 brianp Exp $ */
+/**
+ * \file texobj.c
+ * Texture object management.
+ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  5.1
+ * Version:  6.1
  *
- * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2004  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"),
@@ -24,6 +27,7 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+
 #include "glheader.h"
 #include "colortab.h"
 #include "context.h"
 #include "mtypes.h"
 
 
+/**********************************************************************/
+/** \name Internal functions */
+/*@{*/
+
 /**
- * Allocate and initialize a new texture object
+ * Allocate and initialize a new texture object.  But don't put it into the
+ * texture object hash table.
+ *
  * Called via ctx->Driver.NewTextureObject, unless overridden by a device
  * driver.
- * \param ctx  the rendering context
- * \param name  the integer name for the texture object
- * \param target  either GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D,
- *                GL_TEXTURE_CUBE_MAP_ARB or GL_TEXTURE_RECTANGLE_NV
- *                zero is ok for the sake of GenTextures()
- * \return  pointer to new texture object
+ * 
+ * \param shared the shared GL state structure to contain the texture object
+ * \param name integer name for the texture object
+ * \param target either GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D,
+ * GL_TEXTURE_CUBE_MAP_ARB or GL_TEXTURE_RECTANGLE_NV.  zero is ok for the sake
+ * of GenTextures()
+ *
+ * \return pointer to new texture object.
  */
 struct gl_texture_object *
 _mesa_new_texture_object( GLcontext *ctx, GLuint name, GLenum target )
 {
    struct gl_texture_object *obj;
-   obj = CALLOC_STRUCT(gl_texture_object);
+   obj = MALLOC_STRUCT(gl_texture_object);
    _mesa_initialize_texture_object(obj, name, target);
    return obj;
 }
@@ -77,6 +89,7 @@ _mesa_initialize_texture_object( struct gl_texture_object *obj,
 
    /* init the non-zero fields */
    _glthread_INIT_MUTEX(obj->Mutex);
+   _mesa_bzero(obj, sizeof(*obj));
    obj->RefCount = 1;
    obj->Name = name;
    obj->Target = target;
@@ -96,12 +109,13 @@ _mesa_initialize_texture_object( struct gl_texture_object *obj,
    obj->MagFilter = GL_LINEAR;
    obj->MinLod = -1000.0;
    obj->MaxLod = 1000.0;
+   obj->LodBias = 0.0;
    obj->BaseLevel = 0;
    obj->MaxLevel = 1000;
    obj->MaxAnisotropy = 1.0;
    obj->CompareFlag = GL_FALSE;                      /* SGIX_shadow */
    obj->CompareOperator = GL_TEXTURE_LEQUAL_R_SGIX;  /* SGIX_shadow */
-   obj->CompareMode = GL_LUMINANCE;    /* ARB_shadow */
+   obj->CompareMode = GL_NONE;         /* ARB_shadow */
    obj->CompareFunc = GL_LEQUAL;       /* ARB_shadow */
    obj->DepthMode = GL_LUMINANCE;      /* ARB_depth_texture */
    obj->ShadowAmbient = 0.0F;          /* ARB/SGIX_shadow_ambient */
@@ -109,15 +123,17 @@ _mesa_initialize_texture_object( struct gl_texture_object *obj,
 }
 
 
-/*
- * Deallocate a texture object.  It should have already been removed from
- * the texture object pool.
- * \param texObj  the texture object to deallocate
+/**
+ * Deallocate a texture object struct.  It should have already been
+ * removed from the texture object pool.
+ *
+ * \param shared the shared GL state to which the object belongs.
+ * \param texOjb the texture object to delete.
  */
 void
 _mesa_delete_texture_object( GLcontext *ctx, struct gl_texture_object *texObj )
 {
-   GLuint i;
+   GLuint i, face;
 
    (void) ctx;
 
@@ -126,9 +142,11 @@ _mesa_delete_texture_object( GLcontext *ctx, struct gl_texture_object *texObj )
    _mesa_free_colortable_data(&texObj->Palette);
 
    /* free the texture images */
-   for (i = 0; i < MAX_TEXTURE_LEVELS; i++) {
-      if (texObj->Image[i]) {
-         _mesa_delete_texture_image( texObj->Image[i] );
+   for (face = 0; face < 6; face++) {
+      for (i = 0; i < MAX_TEXTURE_LEVELS; i++) {
+        if (texObj->Image[face][i]) {
+           _mesa_delete_texture_image( texObj->Image[face][i] );
+        }
       }
    }
 
@@ -195,9 +213,11 @@ _mesa_remove_texture_object( GLcontext *ctx, struct gl_texture_object *texObj )
    }
 }
 
-
-/*
+/**
  * Copy texture object state from one texture object to another.
+ *
+ * \param dest destination texture object.
+ * \param src source texture object.
  */
 void
 _mesa_copy_texture_object( struct gl_texture_object *dest,
@@ -216,6 +236,7 @@ _mesa_copy_texture_object( struct gl_texture_object *dest,
    dest->MagFilter = src->MagFilter;
    dest->MinLod = src->MinLod;
    dest->MaxLod = src->MaxLod;
+   dest->LodBias = src->LodBias;
    dest->BaseLevel = src->BaseLevel;
    dest->MaxLevel = src->MaxLevel;
    dest->MaxAnisotropy = src->MaxAnisotropy;
@@ -230,11 +251,17 @@ _mesa_copy_texture_object( struct gl_texture_object *dest,
    dest->GenerateMipmap = src->GenerateMipmap;
    dest->Palette = src->Palette;
    dest->Complete = src->Complete;
+   dest->_IsPowerOfTwo = src->_IsPowerOfTwo;
 }
 
 
-/*
- * Report why a texture object is incomplete.  (for debug only)
+/**
+ * Report why a texture object is incomplete.  
+ *
+ * \param t texture object.
+ * \param why string describing why it's incomplete.
+ *
+ * \note For debug purposes only.
  */
 #if 0
 static void
@@ -243,13 +270,21 @@ incomplete(const struct gl_texture_object *t, const char *why)
    _mesa_printf("Texture Obj %d incomplete because: %s\n", t->Name, why);
 }
 #else
-#define incomplete(a, b)
+#define incomplete(t, why)
 #endif
 
 
-/*
+/**
  * Examine a texture object to determine if it is complete.
- * The t->Complete flag will be set to GL_TRUE or GL_FALSE accordingly.
+ *
+ * The gl_texture_object::Complete flag will be set to GL_TRUE or GL_FALSE
+ * accordingly.
+ *
+ * \param ctx GL context.
+ * \param t texture object.
+ *
+ * According to the texture target, verifies that each of the mipmaps is
+ * present and has the expected size.
  */
 void
 _mesa_test_texobj_completeness( const GLcontext *ctx,
@@ -259,33 +294,46 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
    GLint maxLog2 = 0, maxLevels = 0;
 
    t->Complete = GL_TRUE;  /* be optimistic */
+   t->_IsPowerOfTwo = GL_TRUE;  /* may be set FALSE below */
 
    /* Always need the base level image */
-   if (!t->Image[baseLevel]) {
-      incomplete(t, "Image[baseLevel] == NULL");
+   if (!t->Image[0][baseLevel]) {
+      char s[100];
+      sprintf(s, "obj %p (%d) Image[baseLevel=%d] == NULL",
+              (void *) t, t->Name, baseLevel);
+      incomplete(t, s);
+      t->Complete = GL_FALSE;
+      return;
+   }
+
+   /* Check width/height/depth for zero */
+   if (t->Image[0][baseLevel]->Width == 0 ||
+       t->Image[0][baseLevel]->Height == 0 ||
+       t->Image[0][baseLevel]->Depth == 0) {
+      incomplete(t, "texture width = 0");
       t->Complete = GL_FALSE;
       return;
    }
 
    /* Compute _MaxLevel */
    if (t->Target == GL_TEXTURE_1D) {
-      maxLog2 = t->Image[baseLevel]->WidthLog2;
+      maxLog2 = t->Image[0][baseLevel]->WidthLog2;
       maxLevels = ctx->Const.MaxTextureLevels;
    }
    else if (t->Target == GL_TEXTURE_2D) {
-      maxLog2 = MAX2(t->Image[baseLevel]->WidthLog2,
-                     t->Image[baseLevel]->HeightLog2);
+      maxLog2 = MAX2(t->Image[0][baseLevel]->WidthLog2,
+                     t->Image[0][baseLevel]->HeightLog2);
       maxLevels = ctx->Const.MaxTextureLevels;
    }
    else if (t->Target == GL_TEXTURE_3D) {
-      GLint max = MAX2(t->Image[baseLevel]->WidthLog2,
-                       t->Image[baseLevel]->HeightLog2);
-      maxLog2 = MAX2(max, (GLint)(t->Image[baseLevel]->DepthLog2));
+      GLint max = MAX2(t->Image[0][baseLevel]->WidthLog2,
+                       t->Image[0][baseLevel]->HeightLog2);
+      maxLog2 = MAX2(max, (GLint)(t->Image[0][baseLevel]->DepthLog2));
       maxLevels = ctx->Const.Max3DTextureLevels;
    }
    else if (t->Target == GL_TEXTURE_CUBE_MAP_ARB) {
-      maxLog2 = MAX2(t->Image[baseLevel]->WidthLog2,
-                     t->Image[baseLevel]->HeightLog2);
+      maxLog2 = MAX2(t->Image[0][baseLevel]->WidthLog2,
+                     t->Image[0][baseLevel]->HeightLog2);
       maxLevels = ctx->Const.MaxCubeTextureLevels;
    }
    else if (t->Target == GL_TEXTURE_RECTANGLE_NV) {
@@ -308,29 +356,26 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
 
    if (t->Target == GL_TEXTURE_CUBE_MAP_ARB) {
       /* make sure that all six cube map level 0 images are the same size */
-      const GLuint w = t->Image[baseLevel]->Width2;
-      const GLuint h = t->Image[baseLevel]->Height2;
-      if (!t->NegX[baseLevel] ||
-          t->NegX[baseLevel]->Width2 != w ||
-          t->NegX[baseLevel]->Height2 != h ||
-          !t->PosY[baseLevel] ||
-          t->PosY[baseLevel]->Width2 != w ||
-          t->PosY[baseLevel]->Height2 != h ||
-          !t->NegY[baseLevel] ||
-          t->NegY[baseLevel]->Width2 != w ||
-          t->NegY[baseLevel]->Height2 != h ||
-          !t->PosZ[baseLevel] ||
-          t->PosZ[baseLevel]->Width2 != w ||
-          t->PosZ[baseLevel]->Height2 != h ||
-          !t->NegZ[baseLevel] ||
-          t->NegZ[baseLevel]->Width2 != w ||
-          t->NegZ[baseLevel]->Height2 != h) {
-         t->Complete = GL_FALSE;
-         incomplete(t, "Non-quare cubemap image");
-         return;
+      const GLuint w = t->Image[0][baseLevel]->Width2;
+      const GLuint h = t->Image[0][baseLevel]->Height2;
+      GLuint face;
+      for (face = 1; face < 6; face++) {
+        if (t->Image[face][baseLevel] == NULL ||
+            t->Image[face][baseLevel]->Width2 != w ||
+            t->Image[face][baseLevel]->Height2 != h) {
+           t->Complete = GL_FALSE;
+           incomplete(t, "Non-quare cubemap image");
+           return;
+        }
       }
    }
 
+   /* check for non power of two */
+   if (!t->Image[0][baseLevel]->_IsPowerOfTwo) {
+      t->_IsPowerOfTwo = GL_FALSE;
+   }
+
+   /* extra checking for mipmaps */
    if (t->MinFilter != GL_NEAREST && t->MinFilter != GL_LINEAR) {
       /*
        * Mipmapping: determine if we have a complete set of mipmaps
@@ -347,13 +392,13 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
 
       /* Test dimension-independent attributes */
       for (i = minLevel; i <= maxLevel; i++) {
-         if (t->Image[i]) {
-            if (t->Image[i]->TexFormat != t->Image[baseLevel]->TexFormat) {
+         if (t->Image[0][i]) {
+            if (t->Image[0][i]->TexFormat != t->Image[0][baseLevel]->TexFormat) {
                t->Complete = GL_FALSE;
                incomplete(t, "Format[i] != Format[baseLevel]");
                return;
             }
-            if (t->Image[i]->Border != t->Image[baseLevel]->Border) {
+            if (t->Image[0][i]->Border != t->Image[0][baseLevel]->Border) {
                t->Complete = GL_FALSE;
                incomplete(t, "Border[i] != Border[baseLevel]");
                return;
@@ -364,20 +409,20 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
       /* Test things which depend on number of texture image dimensions */
       if (t->Target == GL_TEXTURE_1D) {
          /* Test 1-D mipmaps */
-         GLuint width = t->Image[baseLevel]->Width2;
+         GLuint width = t->Image[0][baseLevel]->Width2;
          for (i = baseLevel + 1; i < maxLevels; i++) {
             if (width > 1) {
                width /= 2;
             }
             if (i >= minLevel && i <= maxLevel) {
-               if (!t->Image[i]) {
+               if (!t->Image[0][i]) {
                   t->Complete = GL_FALSE;
-                  incomplete(t, "1D Image[i] == NULL");
+                  incomplete(t, "1D Image[0][i] == NULL");
                   return;
                }
-               if (t->Image[i]->Width2 != width ) {
+               if (t->Image[0][i]->Width2 != width ) {
                   t->Complete = GL_FALSE;
-                  incomplete(t, "1D Image[i] bad width");
+                  incomplete(t, "1D Image[0][i] bad width");
                   return;
                }
             }
@@ -388,8 +433,8 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
       }
       else if (t->Target == GL_TEXTURE_2D) {
          /* Test 2-D mipmaps */
-         GLuint width = t->Image[baseLevel]->Width2;
-         GLuint height = t->Image[baseLevel]->Height2;
+         GLuint width = t->Image[0][baseLevel]->Width2;
+         GLuint height = t->Image[0][baseLevel]->Height2;
          for (i = baseLevel + 1; i < maxLevels; i++) {
             if (width > 1) {
                width /= 2;
@@ -398,19 +443,19 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
                height /= 2;
             }
             if (i >= minLevel && i <= maxLevel) {
-               if (!t->Image[i]) {
+               if (!t->Image[0][i]) {
                   t->Complete = GL_FALSE;
-                  incomplete(t, "2D Image[i] == NULL");
+                  incomplete(t, "2D Image[0][i] == NULL");
                   return;
                }
-               if (t->Image[i]->Width2 != width) {
+               if (t->Image[0][i]->Width2 != width) {
                   t->Complete = GL_FALSE;
-                  incomplete(t, "2D Image[i] bad width");
+                  incomplete(t, "2D Image[0][i] bad width");
                   return;
                }
-               if (t->Image[i]->Height2 != height) {
+               if (t->Image[0][i]->Height2 != height) {
                   t->Complete = GL_FALSE;
-                  incomplete(t, "2D Image[i] bad height");
+                  incomplete(t, "2D Image[0][i] bad height");
                   return;
                }
                if (width==1 && height==1) {
@@ -421,9 +466,9 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
       }
       else if (t->Target == GL_TEXTURE_3D) {
          /* Test 3-D mipmaps */
-         GLuint width = t->Image[baseLevel]->Width2;
-         GLuint height = t->Image[baseLevel]->Height2;
-         GLuint depth = t->Image[baseLevel]->Depth2;
+         GLuint width = t->Image[0][baseLevel]->Width2;
+         GLuint height = t->Image[0][baseLevel]->Height2;
+         GLuint depth = t->Image[0][baseLevel]->Depth2;
         for (i = baseLevel + 1; i < maxLevels; i++) {
             if (width > 1) {
                width /= 2;
@@ -435,29 +480,29 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
                depth /= 2;
             }
             if (i >= minLevel && i <= maxLevel) {
-               if (!t->Image[i]) {
-                  incomplete(t, "3D Image[i] == NULL");
+               if (!t->Image[0][i]) {
+                  incomplete(t, "3D Image[0][i] == NULL");
                   t->Complete = GL_FALSE;
                   return;
                }
-               if (t->Image[i]->Format == GL_DEPTH_COMPONENT) {
+               if (t->Image[0][i]->Format == GL_DEPTH_COMPONENT) {
                   t->Complete = GL_FALSE;
                   incomplete(t, "GL_DEPTH_COMPONENT only works with 1/2D tex");
                   return;
                }
-               if (t->Image[i]->Width2 != width) {
+               if (t->Image[0][i]->Width2 != width) {
                   t->Complete = GL_FALSE;
-                  incomplete(t, "3D Image[i] bad width");
+                  incomplete(t, "3D Image[0][i] bad width");
                   return;
                }
-               if (t->Image[i]->Height2 != height) {
+               if (t->Image[0][i]->Height2 != height) {
                   t->Complete = GL_FALSE;
-                  incomplete(t, "3D Image[i] bad height");
+                  incomplete(t, "3D Image[0][i] bad height");
                   return;
                }
-               if (t->Image[i]->Depth2 != depth) {
+               if (t->Image[0][i]->Depth2 != depth) {
                   t->Complete = GL_FALSE;
-                  incomplete(t, "3D Image[i] bad depth");
+                  incomplete(t, "3D Image[0][i] bad depth");
                   return;
                }
             }
@@ -468,8 +513,8 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
       }
       else if (t->Target == GL_TEXTURE_CUBE_MAP_ARB) {
          /* make sure 6 cube faces are consistant */
-         GLuint width = t->Image[baseLevel]->Width2;
-         GLuint height = t->Image[baseLevel]->Height2;
+         GLuint width = t->Image[0][baseLevel]->Width2;
+         GLuint height = t->Image[0][baseLevel]->Height2;
         for (i = baseLevel + 1; i < maxLevels; i++) {
             if (width > 1) {
                width /= 2;
@@ -478,39 +523,36 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
                height /= 2;
             }
             if (i >= minLevel && i <= maxLevel) {
-               /* check that we have images defined */
-               if (!t->Image[i] || !t->NegX[i] ||
-                   !t->PosY[i]  || !t->NegY[i] ||
-                   !t->PosZ[i]  || !t->NegZ[i]) {
-                  t->Complete = GL_FALSE;
-                  incomplete(t, "CubeMap Image[i] == NULL");
-                  return;
-               }
-               /* Don't support GL_DEPTH_COMPONENT for cube maps */
-               if (t->Image[i]->Format == GL_DEPTH_COMPONENT) {
-                  t->Complete = GL_FALSE;
-                  incomplete(t, "GL_DEPTH_COMPONENT only works with 1/2D tex");
-                  return;
-               }
-               /* check that all six images have same size */
-               if (t->NegX[i]->Width2!=width || t->NegX[i]->Height2!=height ||
-                   t->PosY[i]->Width2!=width || t->PosY[i]->Height2!=height ||
-                   t->NegY[i]->Width2!=width || t->NegY[i]->Height2!=height ||
-                   t->PosZ[i]->Width2!=width || t->PosZ[i]->Height2!=height ||
-                   t->NegZ[i]->Width2!=width || t->NegZ[i]->Height2!=height) {
-                  t->Complete = GL_FALSE;
-                  incomplete(t, "CubeMap Image[i] bad size");
-                  return;
-               }
-            }
-            if (width == 1 && height == 1) {
-               return;  /* found smallest needed mipmap, all done! */
+              GLuint face;
+              for (face = 0; face < 6; face++) {
+                 /* check that we have images defined */
+                 if (!t->Image[face][i]) {
+                    t->Complete = GL_FALSE;
+                    incomplete(t, "CubeMap Image[n][i] == NULL");
+                    return;
+                 }
+                 /* Don't support GL_DEPTH_COMPONENT for cube maps */
+                 if (t->Image[face][i]->Format == GL_DEPTH_COMPONENT) {
+                    t->Complete = GL_FALSE;
+                    incomplete(t, "GL_DEPTH_COMPONENT only works with 1/2D tex");
+                    return;
+                 }
+                 /* check that all six images have same size */
+                 if (t->Image[face][i]->Width2!=width || 
+                     t->Image[face][i]->Height2!=height) {
+                    t->Complete = GL_FALSE;
+                    incomplete(t, "CubeMap Image[n][i] bad size");
+                    return;
+                 }
+              }
+           }
+           if (width == 1 && height == 1) {
+              return;  /* found smallest needed mipmap, all done! */
             }
          }
       }
       else if (t->Target == GL_TEXTURE_RECTANGLE_NV) {
          /* XXX special checking? */
-
       }
       else {
          /* Target = ??? */
@@ -519,14 +561,34 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
    }
 }
 
+/*@}*/
 
-_glthread_DECLARE_STATIC_MUTEX(GenTexturesLock);
 
+/***********************************************************************/
+/** \name API functions */
+/*@{*/
 
-/*
- * Execute glGenTextures
+/**
+ * Texture name generation lock.
+ *
+ * Used by _mesa_GenTextures() to guarantee that the generation and allocation
+ * of texture IDs is atomic.
  */
-void
+_glthread_DECLARE_STATIC_MUTEX(GenTexturesLock);
+
+/**
+ * Generate texture names.
+ *
+ * \param n number of texture names to be generated.
+ * \param texName an array in which will hold the generated texture names.
+ *
+ * \sa glGenTextures().
+ *
+ * While holding the GenTexturesLock lock, calls _mesa_HashFindFreeKeyBlock()
+ * to find a block of free texture IDs which are stored in \p texName.
+ * Corresponding empty texture objects are also generated.
+ */ 
+void GLAPIENTRY
 _mesa_GenTextures( GLsizei n, GLuint *texName )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -549,11 +611,6 @@ _mesa_GenTextures( GLsizei n, GLuint *texName )
 
    first = _mesa_HashFindFreeKeyBlock(ctx->Shared->TexObjects, n);
 
-   /* Return the texture names */
-   for (i=0;i<n;i++) {
-      texName[i] = first + i;
-   }
-
    /* Allocate new, empty texture objects */
    for (i = 0; i < n; i++) {
       struct gl_texture_object *texObj;
@@ -565,17 +622,25 @@ _mesa_GenTextures( GLsizei n, GLuint *texName )
          return;
       }
       _mesa_save_texture_object(ctx, texObj);
+      texName[i] = name;
    }
 
    _glthread_UNLOCK_MUTEX(GenTexturesLock);
 }
 
-
-
-/*
- * Execute glDeleteTextures
+/**
+ * Delete named textures.
+ *
+ * \param n number of textures to be deleted.
+ * \param texName array of textures names to be deleted.
+ *
+ * \sa glDeleteTextures().
+ *
+ * For each texture checks if its bound to any of the texture units, unbinding
+ * it and decrementing the reference count if so. If the texture reference
+ * count is zero, delete its object.
  */
-void
+void GLAPIENTRY
 _mesa_DeleteTextures( GLsizei n, const GLuint *texName)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -649,12 +714,22 @@ _mesa_DeleteTextures( GLsizei n, const GLuint *texName)
    }
 }
 
-
-
-/*
- * Execute glBindTexture
+/**
+ * Bind a named texture to a texturing target.
+ * 
+ * \param target texture target.
+ * \param texName texture name.
+ * 
+ * \sa glBindTexture().
+ *
+ * Determines the old texture object bound and returns immediately if rebinding
+ * the same texture.  Get the current texture which is either a default texture
+ * if name is null, a named texture from the hash, or a new texture if the
+ * given texture name is new. Increments its reference count, binds it, and
+ * calls dd_function_table::BindTexture. Decrements the old texture reference
+ * count and deletes it if it reaches zero.
  */
-void
+void GLAPIENTRY
 _mesa_BindTexture( GLenum target, GLuint texName )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -743,6 +818,14 @@ _mesa_BindTexture( GLenum target, GLuint texName )
             newTexObj->WrapT = GL_CLAMP_TO_EDGE;
             newTexObj->WrapR = GL_CLAMP_TO_EDGE;
             newTexObj->MinFilter = GL_LINEAR;
+            if (ctx->Driver.TexParameter) {
+               static const GLfloat fparam_wrap[1] = {(GLfloat) GL_CLAMP_TO_EDGE};
+               static const GLfloat fparam_filter[1] = {(GLfloat) GL_LINEAR};
+               (*ctx->Driver.TexParameter)( ctx, target, newTexObj, GL_TEXTURE_WRAP_S, fparam_wrap );
+               (*ctx->Driver.TexParameter)( ctx, target, newTexObj, GL_TEXTURE_WRAP_T, fparam_wrap );
+               (*ctx->Driver.TexParameter)( ctx, target, newTexObj, GL_TEXTURE_WRAP_R, fparam_wrap );
+               (*ctx->Driver.TexParameter)( ctx, target, newTexObj, GL_TEXTURE_MIN_FILTER, fparam_filter );
+            }
          }
       }
       else {
@@ -798,12 +881,19 @@ _mesa_BindTexture( GLenum target, GLuint texName )
    }
 }
 
-
-
-/*
- * Execute glPrioritizeTextures
+/**
+ * Set texture priorities.
+ * 
+ * \param n number of textures.
+ * \param texName texture names.
+ * \param priorities corresponding texture priorities.
+ * 
+ * \sa glPrioritizeTextures().
+ * 
+ * Looks up each texture in the hash, clamps the corresponding priority between
+ * 0.0 and 1.0, and calls dd_function_table::PrioritizeTexture.
  */
-void
+void GLAPIENTRY
 _mesa_PrioritizeTextures( GLsizei n, const GLuint *texName,
                           const GLclampf *priorities )
 {
@@ -834,12 +924,21 @@ _mesa_PrioritizeTextures( GLsizei n, const GLuint *texName,
    ctx->NewState |= _NEW_TEXTURE;
 }
 
-
-
-/*
- * Execute glAreTexturesResident
+/**
+ * See if textures are loaded in texture memory.
+ * 
+ * \param n number of textures to query.
+ * \param texName array with the texture names.
+ * \param residences array which will hold the residence status.
+ *
+ * \return GL_TRUE if all textures are resident and \p residences is left unchanged, 
+ * 
+ * \sa glAreTexturesResident().
+ *
+ * Looks up each texture in the hash and calls
+ * dd_function_table::IsTextureResident.
  */
-GLboolean
+GLboolean GLAPIENTRY
 _mesa_AreTexturesResident(GLsizei n, const GLuint *texName,
                           GLboolean *residences)
 {
@@ -888,15 +987,24 @@ _mesa_AreTexturesResident(GLsizei n, const GLuint *texName,
    return allResident;
 }
 
-
-
-/*
- * Execute glIsTexture
+/**
+ * See if a name corresponds to a texture.
+ *
+ * \param texture texture name.
+ *
+ * \return GL_TRUE if texture name corresponds to a texture, or GL_FALSE
+ * otherwise.
+ * 
+ * \sa glIsTexture().
+ *
+ * Calls _mesa_HashLookup().
  */
-GLboolean
+GLboolean GLAPIENTRY
 _mesa_IsTexture( GLuint texture )
 {
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
    return texture > 0 && _mesa_HashLookup(ctx->Shared->TexObjects, texture);
 }
+
+/*@}*/