remove final imports.h and imports.c bits
[mesa.git] / src / mesa / swrast / s_texfilter.c
index 152b1ff3efa9e70a162a1a82c52b74c248900337..7f1354785a4d9e783b0935ebe2f2ba8e8ca99c8d 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.3
  *
  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
+#include "c99_math.h"
 #include "main/glheader.h"
 #include "main/context.h"
-#include "main/colormac.h"
-#include "main/imports.h"
-#include "main/texobj.h"
+
+#include "main/macros.h"
 #include "main/samplerobj.h"
+#include "main/teximage.h"
+#include "main/texobj.h"
 
 #include "s_context.h"
 #include "s_texfilter.h"
@@ -41,7 +43,7 @@
  * Also note, FRAC(x) doesn't truly return the fractional part of x for x < 0.
  * Instead, if x < 0 then FRAC(x) = 1 - true_frac(x).
  */
-#define FRAC(f)  ((f) - IFLOOR(f))
+#define FRAC(f)  ((f) - util_ifloor(f))
 
 
 
@@ -73,7 +75,7 @@ lerp_2d(GLfloat a, GLfloat b,
  * Do 3D/trilinear interpolation of float values.
  * \sa lerp_2d
  */
-static inline GLfloat
+static GLfloat
 lerp_3d(GLfloat a, GLfloat b, GLfloat c,
         GLfloat v000, GLfloat v100, GLfloat v010, GLfloat v110,
         GLfloat v001, GLfloat v101, GLfloat v011, GLfloat v111)
@@ -91,7 +93,7 @@ lerp_3d(GLfloat a, GLfloat b, GLfloat c,
 /**
  * Do linear interpolation of colors.
  */
-static inline void
+static void
 lerp_rgba(GLfloat result[4], GLfloat t, const GLfloat a[4], const GLfloat b[4])
 {
    result[0] = LERP(t, a[0], b[0]);
@@ -104,7 +106,7 @@ lerp_rgba(GLfloat result[4], GLfloat t, const GLfloat a[4], const GLfloat b[4])
 /**
  * Do bilinear interpolation of colors.
  */
-static inline void
+static void
 lerp_rgba_2d(GLfloat result[4], GLfloat a, GLfloat b,
              const GLfloat t00[4], const GLfloat t10[4],
              const GLfloat t01[4], const GLfloat t11[4])
@@ -119,7 +121,7 @@ lerp_rgba_2d(GLfloat result[4], GLfloat a, GLfloat b,
 /**
  * Do trilinear interpolation of colors.
  */
-static inline void
+static void
 lerp_rgba_3d(GLfloat result[4], GLfloat a, GLfloat b, GLfloat c,
              const GLfloat t000[4], const GLfloat t100[4],
              const GLfloat t010[4], const GLfloat t110[4],
@@ -155,7 +157,7 @@ lerp_rgba_3d(GLfloat result[4], GLfloat a, GLfloat b, GLfloat c,
  *    i0, i1 = returns two nearest texel indexes
  *    weight = returns blend factor between texels
  */
-static inline void
+static void
 linear_texel_locations(GLenum wrapMode,
                        const struct gl_texture_image *img,
                        GLint size, GLfloat s,
@@ -167,11 +169,11 @@ linear_texel_locations(GLenum wrapMode,
    case GL_REPEAT:
       u = s * size - 0.5F;
       if (swImg->_IsPowerOfTwo) {
-         *i0 = IFLOOR(u) & (size - 1);
+         *i0 = util_ifloor(u) & (size - 1);
          *i1 = (*i0 + 1) & (size - 1);
       }
       else {
-         *i0 = REMAINDER(IFLOOR(u), size);
+         *i0 = REMAINDER(util_ifloor(u), size);
          *i1 = REMAINDER(*i0 + 1, size);
       }
       break;
@@ -183,7 +185,7 @@ linear_texel_locations(GLenum wrapMode,
       else
          u = s * size;
       u -= 0.5F;
-      *i0 = IFLOOR(u);
+      *i0 = util_ifloor(u);
       *i1 = *i0 + 1;
       if (*i0 < 0)
          *i0 = 0;
@@ -201,19 +203,19 @@ linear_texel_locations(GLenum wrapMode,
          else
             u = s * size;
          u -= 0.5F;
-         *i0 = IFLOOR(u);
+         *i0 = util_ifloor(u);
          *i1 = *i0 + 1;
       }
       break;
    case GL_MIRRORED_REPEAT:
       {
-         const GLint flr = IFLOOR(s);
+         const GLint flr = util_ifloor(s);
          if (flr & 1)
             u = 1.0F - (s - (GLfloat) flr);
          else
             u = s - (GLfloat) flr;
          u = (u * size) - 0.5F;
-         *i0 = IFLOOR(u);
+         *i0 = util_ifloor(u);
          *i1 = *i0 + 1;
          if (*i0 < 0)
             *i0 = 0;
@@ -222,23 +224,23 @@ linear_texel_locations(GLenum wrapMode,
       }
       break;
    case GL_MIRROR_CLAMP_EXT:
-      u = FABSF(s);
+      u = fabsf(s);
       if (u >= 1.0F)
          u = (GLfloat) size;
       else
          u *= size;
       u -= 0.5F;
-      *i0 = IFLOOR(u);
+      *i0 = util_ifloor(u);
       *i1 = *i0 + 1;
       break;
    case GL_MIRROR_CLAMP_TO_EDGE_EXT:
-      u = FABSF(s);
+      u = fabsf(s);
       if (u >= 1.0F)
          u = (GLfloat) size;
       else
          u *= size;
       u -= 0.5F;
-      *i0 = IFLOOR(u);
+      *i0 = util_ifloor(u);
       *i1 = *i0 + 1;
       if (*i0 < 0)
          *i0 = 0;
@@ -249,7 +251,7 @@ linear_texel_locations(GLenum wrapMode,
       {
          const GLfloat min = -1.0F / (2.0F * size);
          const GLfloat max = 1.0F - min;
-         u = FABSF(s);
+         u = fabsf(s);
          if (u <= min)
             u = min * size;
          else if (u >= max)
@@ -257,7 +259,7 @@ linear_texel_locations(GLenum wrapMode,
          else
             u *= size;
          u -= 0.5F;
-         *i0 = IFLOOR(u);
+         *i0 = util_ifloor(u);
          *i1 = *i0 + 1;
       }
       break;
@@ -269,11 +271,12 @@ linear_texel_locations(GLenum wrapMode,
       else
          u = s * size;
       u -= 0.5F;
-      *i0 = IFLOOR(u);
+      *i0 = util_ifloor(u);
       *i1 = *i0 + 1;
       break;
    default:
       _mesa_problem(NULL, "Bad wrap mode");
+      *i0 = *i1 = 0;
       u = 0.0F;
       break;
    }
@@ -284,7 +287,7 @@ linear_texel_locations(GLenum wrapMode,
 /**
  * Used to compute texel location for nearest sampling.
  */
-static inline GLint
+static GLint
 nearest_texel_location(GLenum wrapMode,
                        const struct gl_texture_image *img,
                        GLint size, GLfloat s)
@@ -296,7 +299,7 @@ nearest_texel_location(GLenum wrapMode,
    case GL_REPEAT:
       /* s limited to [0,1) */
       /* i limited to [0,size-1] */
-      i = IFLOOR(s * size);
+      i = util_ifloor(s * size);
       if (swImg->_IsPowerOfTwo)
          i &= (size - 1);
       else
@@ -313,7 +316,7 @@ nearest_texel_location(GLenum wrapMode,
          else if (s > max)
             i = size - 1;
          else
-            i = IFLOOR(s * size);
+            i = util_ifloor(s * size);
       }
       return i;
    case GL_CLAMP_TO_BORDER:
@@ -327,14 +330,14 @@ nearest_texel_location(GLenum wrapMode,
          else if (s >= max)
             i = size;
          else
-            i = IFLOOR(s * size);
+            i = util_ifloor(s * size);
       }
       return i;
    case GL_MIRRORED_REPEAT:
       {
          const GLfloat min = 1.0F / (2.0F * size);
          const GLfloat max = 1.0F - min;
-         const GLint flr = IFLOOR(s);
+         const GLint flr = util_ifloor(s);
          GLfloat u;
          if (flr & 1)
             u = 1.0F - (s - (GLfloat) flr);
@@ -345,20 +348,20 @@ nearest_texel_location(GLenum wrapMode,
          else if (u > max)
             i = size - 1;
          else
-            i = IFLOOR(u * size);
+            i = util_ifloor(u * size);
       }
       return i;
    case GL_MIRROR_CLAMP_EXT:
       {
          /* s limited to [0,1] */
          /* i limited to [0,size-1] */
-         const GLfloat u = FABSF(s);
+         const GLfloat u = fabsf(s);
          if (u <= 0.0F)
             i = 0;
          else if (u >= 1.0F)
             i = size - 1;
          else
-            i = IFLOOR(u * size);
+            i = util_ifloor(u * size);
       }
       return i;
    case GL_MIRROR_CLAMP_TO_EDGE_EXT:
@@ -367,13 +370,13 @@ nearest_texel_location(GLenum wrapMode,
          /* i limited to [0, size-1] */
          const GLfloat min = 1.0F / (2.0F * size);
          const GLfloat max = 1.0F - min;
-         const GLfloat u = FABSF(s);
+         const GLfloat u = fabsf(s);
          if (u < min)
             i = 0;
          else if (u > max)
             i = size - 1;
          else
-            i = IFLOOR(u * size);
+            i = util_ifloor(u * size);
       }
       return i;
    case GL_MIRROR_CLAMP_TO_BORDER_EXT:
@@ -382,13 +385,13 @@ nearest_texel_location(GLenum wrapMode,
          /* i limited to [0, size-1] */
          const GLfloat min = -1.0F / (2.0F * size);
          const GLfloat max = 1.0F - min;
-         const GLfloat u = FABSF(s);
+         const GLfloat u = fabsf(s);
          if (u < min)
             i = -1;
          else if (u > max)
             i = size;
          else
-            i = IFLOOR(u * size);
+            i = util_ifloor(u * size);
       }
       return i;
    case GL_CLAMP:
@@ -399,7 +402,7 @@ nearest_texel_location(GLenum wrapMode,
       else if (s >= 1.0F)
          i = size - 1;
       else
-         i = IFLOOR(s * size);
+         i = util_ifloor(s * size);
       return i;
    default:
       _mesa_problem(NULL, "Bad wrap mode");
@@ -409,12 +412,12 @@ nearest_texel_location(GLenum wrapMode,
 
 
 /* Power of two image sizes only */
-static inline void
+static void
 linear_repeat_texel_location(GLuint size, GLfloat s,
                              GLint *i0, GLint *i1, GLfloat *weight)
 {
    GLfloat u = s * size - 0.5F;
-   *i0 = IFLOOR(u) & (size - 1);
+   *i0 = util_ifloor(u) & (size - 1);
    *i1 = (*i0 + 1) & (size - 1);
    *weight = FRAC(u);
 }
@@ -423,16 +426,16 @@ linear_repeat_texel_location(GLuint size, GLfloat s,
 /**
  * Do clamp/wrap for a texture rectangle coord, GL_NEAREST filter mode.
  */
-static inline GLint
+static GLint
 clamp_rect_coord_nearest(GLenum wrapMode, GLfloat coord, GLint max)
 {
    switch (wrapMode) {
    case GL_CLAMP:
-      return IFLOOR( CLAMP(coord, 0.0F, max - 1) );
+      return util_ifloor( CLAMP(coord, 0.0F, max - 1) );
    case GL_CLAMP_TO_EDGE:
-      return IFLOOR( CLAMP(coord, 0.5F, max - 0.5F) );
+      return util_ifloor( CLAMP(coord, 0.5F, max - 0.5F) );
    case GL_CLAMP_TO_BORDER:
-      return IFLOOR( CLAMP(coord, -0.5F, max + 0.5F) );
+      return util_ifloor( CLAMP(coord, -0.5F, max + 0.5F) );
    default:
       _mesa_problem(NULL, "bad wrapMode in clamp_rect_coord_nearest");
       return 0;
@@ -443,7 +446,7 @@ clamp_rect_coord_nearest(GLenum wrapMode, GLfloat coord, GLint max)
 /**
  * As above, but GL_LINEAR filtering.
  */
-static inline void
+static void
 clamp_rect_coord_linear(GLenum wrapMode, GLfloat coord, GLint max,
                         GLint *i0out, GLint *i1out, GLfloat *weight)
 {
@@ -453,13 +456,13 @@ clamp_rect_coord_linear(GLenum wrapMode, GLfloat coord, GLint max,
    case GL_CLAMP:
       /* Not exactly what the spec says, but it matches NVIDIA output */
       fcol = CLAMP(coord - 0.5F, 0.0F, max - 1);
-      i0 = IFLOOR(fcol);
+      i0 = util_ifloor(fcol);
       i1 = i0 + 1;
       break;
    case GL_CLAMP_TO_EDGE:
       fcol = CLAMP(coord, 0.5F, max - 0.5F);
       fcol -= 0.5F;
-      i0 = IFLOOR(fcol);
+      i0 = util_ifloor(fcol);
       i1 = i0 + 1;
       if (i1 > max - 1)
          i1 = max - 1;
@@ -467,7 +470,7 @@ clamp_rect_coord_linear(GLenum wrapMode, GLfloat coord, GLint max,
    case GL_CLAMP_TO_BORDER:
       fcol = CLAMP(coord, -0.5F, max + 0.5F);
       fcol -= 0.5F;
-      i0 = IFLOOR(fcol);
+      i0 = util_ifloor(fcol);
       i1 = i0 + 1;
       break;
    default:
@@ -485,10 +488,10 @@ clamp_rect_coord_linear(GLenum wrapMode, GLfloat coord, GLint max,
 /**
  * Compute slice/image to use for 1D or 2D array texture.
  */
-static inline GLint
+static GLint
 tex_array_slice(GLfloat coord, GLsizei size)
 {
-   GLint slice = IFLOOR(coord + 0.5f);
+   GLint slice = util_ifloor(coord + 0.5f);
    slice = CLAMP(slice, 0, size - 1);
    return slice;
 }
@@ -498,7 +501,7 @@ tex_array_slice(GLfloat coord, GLsizei size)
  * Compute nearest integer texcoords for given texobj and coordinate.
  * NOTE: only used for depth texture sampling.
  */
-static inline void
+static void
 nearest_texcoord(const struct gl_sampler_object *samp,
                  const struct gl_texture_object *texObj,
                  GLuint level,
@@ -547,7 +550,7 @@ nearest_texcoord(const struct gl_sampler_object *samp,
  * Compute linear integer texcoords for given texobj and coordinate.
  * NOTE: only used for depth texture sampling.
  */
-static inline void
+static void
 linear_texcoord(const struct gl_sampler_object *samp,
                 const struct gl_texture_object *texObj,
                 GLuint level,
@@ -606,7 +609,7 @@ linear_texcoord(const struct gl_sampler_object *samp,
  * For linear interpolation between mipmap levels N and N+1, this function
  * computes N.
  */
-static inline GLint
+static GLint
 linear_mipmap_level(const struct gl_texture_object *tObj, GLfloat lambda)
 {
    if (lambda < 0.0F)
@@ -621,7 +624,7 @@ linear_mipmap_level(const struct gl_texture_object *tObj, GLfloat lambda)
 /**
  * Compute the nearest mipmap level to take texels from.
  */
-static inline GLint
+static GLint
 nearest_mipmap_level(const struct gl_texture_object *tObj, GLfloat lambda)
 {
    GLfloat l;
@@ -657,7 +660,7 @@ nearest_mipmap_level(const struct gl_texture_object *tObj, GLfloat lambda)
  * will be minified, magnified, or split between the two.  This function
  * determines the subranges in [0, n-1] that are to be minified or magnified.
  */
-static inline void
+static void
 compute_min_mag_ranges(const struct gl_sampler_object *samp,
                        GLuint n, const GLfloat lambda[],
                        GLuint *minStart, GLuint *minEnd,
@@ -666,7 +669,7 @@ compute_min_mag_ranges(const struct gl_sampler_object *samp,
    GLfloat minMagThresh;
 
    /* we shouldn't be here if minfilter == magfilter */
-   ASSERT(samp->MinFilter != samp->MagFilter);
+   assert(samp->MinFilter != samp->MagFilter);
 
    /* This bit comes from the OpenGL spec: */
    if (samp->MagFilter == GL_LINEAR
@@ -688,12 +691,12 @@ compute_min_mag_ranges(const struct gl_sampler_object *samp,
       printf("lambda delta = %g\n", lambda[0] - lambda[n-1]);
       if (lambda[0] >= lambda[n-1]) { /* decreasing */
          for (i = 0; i < n - 1; i++) {
-            ASSERT((GLint) (lambda[i] * 10) >= (GLint) (lambda[i+1] * 10));
+            assert((GLint) (lambda[i] * 10) >= (GLint) (lambda[i+1] * 10));
          }
       }
       else { /* increasing */
          for (i = 0; i < n - 1; i++) {
-            ASSERT((GLint) (lambda[i] * 10) <= (GLint) (lambda[i+1] * 10));
+            assert((GLint) (lambda[i] * 10) <= (GLint) (lambda[i+1] * 10));
          }
       }
    }
@@ -747,13 +750,13 @@ compute_min_mag_ranges(const struct gl_sampler_object *samp,
       for (i = 0; i < n; i++) {
          if (lambda[i] > minMagThresh) {
             /* minification */
-            ASSERT(i >= *minStart);
-            ASSERT(i < *minEnd);
+            assert(i >= *minStart);
+            assert(i < *minEnd);
          }
          else {
             /* magnification */
-            ASSERT(i >= *magStart);
-            ASSERT(i < *magEnd);
+            assert(i >= *magStart);
+            assert(i < *magEnd);
          }
       }
    }
@@ -766,7 +769,7 @@ compute_min_mag_ranges(const struct gl_sampler_object *samp,
  * the base texture format.  Ex: if the texture base format it GL_ALPHA,
  * we return (0,0,0,BorderAlpha).
  */
-static inline void
+static void
 get_border_color(const struct gl_sampler_object *samp,
                  const struct gl_texture_image *img,
                  GLfloat rgba[4])
@@ -803,7 +806,7 @@ get_border_color(const struct gl_sampler_object *samp,
 /**
  * Put z into texel according to GL_DEPTH_MODE.
  */
-static INLINE void
+static void
 apply_depth_mode(GLenum depthMode, GLfloat z, GLfloat texel[4])
 {
    switch (depthMode) {
@@ -831,7 +834,7 @@ apply_depth_mode(GLenum depthMode, GLfloat z, GLfloat texel[4])
 static GLboolean
 is_depth_texture(const struct gl_texture_object *tObj)
 {
-   GLenum format = tObj->Image[0][tObj->BaseLevel]->_BaseFormat;
+   GLenum format = _mesa_texture_base_format(tObj);
    return format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL_EXT;
 }
 
@@ -843,7 +846,7 @@ is_depth_texture(const struct gl_texture_object *tObj)
 /**
  * Return the texture sample for coordinate (s) using GL_NEAREST filter.
  */
-static inline void
+static void
 sample_1d_nearest(struct gl_context *ctx,
                   const struct gl_sampler_object *samp,
                   const struct gl_texture_image *img,
@@ -868,7 +871,7 @@ sample_1d_nearest(struct gl_context *ctx,
 /**
  * Return the texture sample for coordinate (s) using GL_LINEAR filter.
  */
-static inline void
+static void
 sample_1d_linear(struct gl_context *ctx,
                  const struct gl_sampler_object *samp,
                  const struct gl_texture_image *img,
@@ -918,7 +921,7 @@ sample_1d_nearest_mipmap_nearest(struct gl_context *ctx,
                                  const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       GLint level = nearest_mipmap_level(tObj, lambda[i]);
       sample_1d_nearest(ctx, samp, tObj->Image[0][level], texcoord[i], rgba[i]);
@@ -934,7 +937,7 @@ sample_1d_linear_mipmap_nearest(struct gl_context *ctx,
                                 const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       GLint level = nearest_mipmap_level(tObj, lambda[i]);
       sample_1d_linear(ctx, samp, tObj->Image[0][level], texcoord[i], rgba[i]);
@@ -950,7 +953,7 @@ sample_1d_nearest_mipmap_linear(struct gl_context *ctx,
                                 const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       GLint level = linear_mipmap_level(tObj, lambda[i]);
       if (level >= tObj->_MaxLevel) {
@@ -976,7 +979,7 @@ sample_1d_linear_mipmap_linear(struct gl_context *ctx,
                                const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       GLint level = linear_mipmap_level(tObj, lambda[i]);
       if (level >= tObj->_MaxLevel) {
@@ -1003,7 +1006,7 @@ sample_nearest_1d( struct gl_context *ctx,
                    GLfloat rgba[][4] )
 {
    GLuint i;
-   struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel];
+   const struct gl_texture_image *image = _mesa_base_tex_image(tObj);
    (void) lambda;
    for (i = 0; i < n; i++) {
       sample_1d_nearest(ctx, samp, image, texcoords[i], rgba[i]);
@@ -1020,7 +1023,7 @@ sample_linear_1d( struct gl_context *ctx,
                   GLfloat rgba[][4] )
 {
    GLuint i;
-   struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel];
+   const struct gl_texture_image *image = _mesa_base_tex_image(tObj);
    (void) lambda;
    for (i = 0; i < n; i++) {
       sample_1d_linear(ctx, samp, image, texcoords[i], rgba[i]);
@@ -1040,7 +1043,7 @@ sample_lambda_1d( struct gl_context *ctx,
    GLuint magStart, magEnd;  /* texels with magnification */
    GLuint i;
 
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    compute_min_mag_ranges(samp, n, lambda,
                           &minStart, &minEnd, &magStart, &magEnd);
 
@@ -1050,12 +1053,12 @@ sample_lambda_1d( struct gl_context *ctx,
       switch (samp->MinFilter) {
       case GL_NEAREST:
          for (i = minStart; i < minEnd; i++)
-            sample_1d_nearest(ctx, samp, tObj->Image[0][tObj->BaseLevel],
+            sample_1d_nearest(ctx, samp, _mesa_base_tex_image(tObj),
                               texcoords[i], rgba[i]);
          break;
       case GL_LINEAR:
          for (i = minStart; i < minEnd; i++)
-            sample_1d_linear(ctx, samp, tObj->Image[0][tObj->BaseLevel],
+            sample_1d_linear(ctx, samp, _mesa_base_tex_image(tObj),
                              texcoords[i], rgba[i]);
          break;
       case GL_NEAREST_MIPMAP_NEAREST:
@@ -1085,12 +1088,12 @@ sample_lambda_1d( struct gl_context *ctx,
       switch (samp->MagFilter) {
       case GL_NEAREST:
          for (i = magStart; i < magEnd; i++)
-            sample_1d_nearest(ctx, samp, tObj->Image[0][tObj->BaseLevel],
+            sample_1d_nearest(ctx, samp, _mesa_base_tex_image(tObj),
                               texcoords[i], rgba[i]);
          break;
       case GL_LINEAR:
          for (i = magStart; i < magEnd; i++)
-            sample_1d_linear(ctx, samp, tObj->Image[0][tObj->BaseLevel],
+            sample_1d_linear(ctx, samp, _mesa_base_tex_image(tObj),
                              texcoords[i], rgba[i]);
          break;
       default:
@@ -1109,7 +1112,7 @@ sample_lambda_1d( struct gl_context *ctx,
 /**
  * Return the texture sample for coordinate (s,t) using GL_NEAREST filter.
  */
-static inline void
+static void
 sample_2d_nearest(struct gl_context *ctx,
                   const struct gl_sampler_object *samp,
                   const struct gl_texture_image *img,
@@ -1143,7 +1146,7 @@ sample_2d_nearest(struct gl_context *ctx,
  * Return the texture sample for coordinate (s,t) using GL_LINEAR filter.
  * New sampling code contributed by Lynn Quam <quam@ai.sri.com>.
  */
-static inline void
+static void
 sample_2d_linear(struct gl_context *ctx,
                  const struct gl_sampler_object *samp,
                  const struct gl_texture_image *img,
@@ -1208,7 +1211,7 @@ sample_2d_linear(struct gl_context *ctx,
  * As above, but we know WRAP_S == REPEAT and WRAP_T == REPEAT.
  * We don't have to worry about the texture border.
  */
-static inline void
+static void
 sample_2d_linear_repeat(struct gl_context *ctx,
                         const struct gl_sampler_object *samp,
                         const struct gl_texture_image *img,
@@ -1224,10 +1227,10 @@ sample_2d_linear_repeat(struct gl_context *ctx,
 
    (void) ctx;
 
-   ASSERT(samp->WrapS == GL_REPEAT);
-   ASSERT(samp->WrapT == GL_REPEAT);
-   ASSERT(img->Border == 0);
-   ASSERT(swImg->_IsPowerOfTwo);
+   assert(samp->WrapS == GL_REPEAT);
+   assert(samp->WrapT == GL_REPEAT);
+   assert(img->Border == 0);
+   assert(swImg->_IsPowerOfTwo);
 
    linear_repeat_texel_location(width,  texcoord[0], &i0, &i1, &wi);
    linear_repeat_texel_location(height, texcoord[1], &j0, &j1, &wj);
@@ -1264,7 +1267,7 @@ sample_2d_linear_mipmap_nearest(struct gl_context *ctx,
                                 const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       GLint level = nearest_mipmap_level(tObj, lambda[i]);
       sample_2d_linear(ctx, samp, tObj->Image[0][level], texcoord[i], rgba[i]);
@@ -1280,7 +1283,7 @@ sample_2d_nearest_mipmap_linear(struct gl_context *ctx,
                                 const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       GLint level = linear_mipmap_level(tObj, lambda[i]);
       if (level >= tObj->_MaxLevel) {
@@ -1306,7 +1309,7 @@ sample_2d_linear_mipmap_linear( struct gl_context *ctx,
                                 const GLfloat lambda[], GLfloat rgba[][4] )
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       GLint level = linear_mipmap_level(tObj, lambda[i]);
       if (level >= tObj->_MaxLevel) {
@@ -1332,9 +1335,9 @@ sample_2d_linear_mipmap_linear_repeat(struct gl_context *ctx,
                                       const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
-   ASSERT(samp->WrapS == GL_REPEAT);
-   ASSERT(samp->WrapT == GL_REPEAT);
+   assert(lambda != NULL);
+   assert(samp->WrapS == GL_REPEAT);
+   assert(samp->WrapT == GL_REPEAT);
    for (i = 0; i < n; i++) {
       GLint level = linear_mipmap_level(tObj, lambda[i]);
       if (level >= tObj->_MaxLevel) {
@@ -1363,7 +1366,7 @@ sample_nearest_2d(struct gl_context *ctx,
                   const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel];
+   const struct gl_texture_image *image = _mesa_base_tex_image(tObj);
    (void) lambda;
    for (i = 0; i < n; i++) {
       sample_2d_nearest(ctx, samp, image, texcoords[i], rgba[i]);
@@ -1380,7 +1383,7 @@ sample_linear_2d(struct gl_context *ctx,
                  const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel];
+   const struct gl_texture_image *image = _mesa_base_tex_image(tObj);
    const struct swrast_texture_image *swImg = swrast_texture_image_const(image);
    (void) lambda;
    if (samp->WrapS == GL_REPEAT &&
@@ -1403,7 +1406,7 @@ sample_linear_2d(struct gl_context *ctx,
  * Optimized 2-D texture sampling:
  *    S and T wrap mode == GL_REPEAT
  *    GL_NEAREST min/mag filter
- *    No border, 
+ *    No border,
  *    RowStride == Width,
  *    Format = GL_RGB
  */
@@ -1414,7 +1417,7 @@ opt_sample_rgb_2d(struct gl_context *ctx,
                   GLuint n, const GLfloat texcoords[][4],
                   const GLfloat lambda[], GLfloat rgba[][4])
 {
-   const struct gl_texture_image *img = tObj->Image[0][tObj->BaseLevel];
+   const struct gl_texture_image *img = _mesa_base_tex_image(tObj);
    const struct swrast_texture_image *swImg = swrast_texture_image_const(img);
    const GLfloat width = (GLfloat) img->Width;
    const GLfloat height = (GLfloat) img->Height;
@@ -1424,18 +1427,18 @@ opt_sample_rgb_2d(struct gl_context *ctx,
    GLuint k;
    (void) ctx;
    (void) lambda;
-   ASSERT(samp->WrapS==GL_REPEAT);
-   ASSERT(samp->WrapT==GL_REPEAT);
-   ASSERT(img->Border==0);
-   ASSERT(img->TexFormat == MESA_FORMAT_RGB888);
-   ASSERT(swImg->_IsPowerOfTwo);
+   assert(samp->WrapS==GL_REPEAT);
+   assert(samp->WrapT==GL_REPEAT);
+   assert(img->Border==0);
+   assert(img->TexFormat == MESA_FORMAT_BGR_UNORM8);
+   assert(swImg->_IsPowerOfTwo);
    (void) swImg;
 
    for (k=0; k<n; k++) {
-      GLint i = IFLOOR(texcoords[k][0] * width) & colMask;
-      GLint j = IFLOOR(texcoords[k][1] * height) & rowMask;
+      GLint i = util_ifloor(texcoords[k][0] * width) & colMask;
+      GLint j = util_ifloor(texcoords[k][1] * height) & rowMask;
       GLint pos = (j << shift) | i;
-      GLubyte *texel = swImg->Map + 3 * pos;
+      GLubyte *texel = (GLubyte *) swImg->ImageSlices[0] + 3 * pos;
       rgba[k][RCOMP] = UBYTE_TO_FLOAT(texel[2]);
       rgba[k][GCOMP] = UBYTE_TO_FLOAT(texel[1]);
       rgba[k][BCOMP] = UBYTE_TO_FLOAT(texel[0]);
@@ -1459,7 +1462,7 @@ opt_sample_rgba_2d(struct gl_context *ctx,
                    GLuint n, const GLfloat texcoords[][4],
                    const GLfloat lambda[], GLfloat rgba[][4])
 {
-   const struct gl_texture_image *img = tObj->Image[0][tObj->BaseLevel];
+   const struct gl_texture_image *img = _mesa_base_tex_image(tObj);
    const struct swrast_texture_image *swImg = swrast_texture_image_const(img);
    const GLfloat width = (GLfloat) img->Width;
    const GLfloat height = (GLfloat) img->Height;
@@ -1469,18 +1472,18 @@ opt_sample_rgba_2d(struct gl_context *ctx,
    GLuint i;
    (void) ctx;
    (void) lambda;
-   ASSERT(samp->WrapS==GL_REPEAT);
-   ASSERT(samp->WrapT==GL_REPEAT);
-   ASSERT(img->Border==0);
-   ASSERT(img->TexFormat == MESA_FORMAT_RGBA8888);
-   ASSERT(swImg->_IsPowerOfTwo);
+   assert(samp->WrapS==GL_REPEAT);
+   assert(samp->WrapT==GL_REPEAT);
+   assert(img->Border==0);
+   assert(img->TexFormat == MESA_FORMAT_A8B8G8R8_UNORM);
+   assert(swImg->_IsPowerOfTwo);
    (void) swImg;
 
    for (i = 0; i < n; i++) {
-      const GLint col = IFLOOR(texcoords[i][0] * width) & colMask;
-      const GLint row = IFLOOR(texcoords[i][1] * height) & rowMask;
+      const GLint col = util_ifloor(texcoords[i][0] * width) & colMask;
+      const GLint row = util_ifloor(texcoords[i][1] * height) & rowMask;
       const GLint pos = (row << shift) | col;
-      const GLuint texel = *((GLuint *) swImg->Map + pos);
+      const GLuint texel = *((GLuint *) swImg->ImageSlices[0] + pos);
       rgba[i][RCOMP] = UBYTE_TO_FLOAT( (texel >> 24)        );
       rgba[i][GCOMP] = UBYTE_TO_FLOAT( (texel >> 16) & 0xff );
       rgba[i][BCOMP] = UBYTE_TO_FLOAT( (texel >>  8) & 0xff );
@@ -1497,17 +1500,19 @@ sample_lambda_2d(struct gl_context *ctx,
                  GLuint n, const GLfloat texcoords[][4],
                  const GLfloat lambda[], GLfloat rgba[][4])
 {
-   const struct gl_texture_image *tImg = tObj->Image[0][tObj->BaseLevel];
+   const struct gl_texture_image *tImg = _mesa_base_tex_image(tObj);
    const struct swrast_texture_image *swImg = swrast_texture_image_const(tImg);
    GLuint minStart, minEnd;  /* texels with minification */
    GLuint magStart, magEnd;  /* texels with magnification */
 
    const GLboolean repeatNoBorderPOT = (samp->WrapS == GL_REPEAT)
       && (samp->WrapT == GL_REPEAT)
-      && (tImg->Border == 0 && (tImg->Width == swImg->RowStride))
+      && (tImg->Border == 0)
+      && (_mesa_format_row_stride(tImg->TexFormat, tImg->Width) ==
+          swImg->RowStride)
       && swImg->_IsPowerOfTwo;
 
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    compute_min_mag_ranges(samp, n, lambda,
                           &minStart, &minEnd, &magStart, &magEnd);
 
@@ -1518,11 +1523,11 @@ sample_lambda_2d(struct gl_context *ctx,
       case GL_NEAREST:
          if (repeatNoBorderPOT) {
             switch (tImg->TexFormat) {
-            case MESA_FORMAT_RGB888:
+            case MESA_FORMAT_BGR_UNORM8:
                opt_sample_rgb_2d(ctx, samp, tObj, m, texcoords + minStart,
                                  NULL, rgba + minStart);
                break;
-            case MESA_FORMAT_RGBA8888:
+            case MESA_FORMAT_A8B8G8R8_UNORM:
               opt_sample_rgba_2d(ctx, samp, tObj, m, texcoords + minStart,
                                   NULL, rgba + minStart);
                break;
@@ -1575,11 +1580,11 @@ sample_lambda_2d(struct gl_context *ctx,
       case GL_NEAREST:
          if (repeatNoBorderPOT) {
             switch (tImg->TexFormat) {
-            case MESA_FORMAT_RGB888:
+            case MESA_FORMAT_BGR_UNORM8:
                opt_sample_rgb_2d(ctx, samp, tObj, m, texcoords + magStart,
                                  NULL, rgba + magStart);
                break;
-            case MESA_FORMAT_RGBA8888:
+            case MESA_FORMAT_A8B8G8R8_UNORM:
               opt_sample_rgba_2d(ctx, samp, tObj, m, texcoords + magStart,
                                   NULL, rgba + magStart);
                break;
@@ -1618,12 +1623,12 @@ create_filter_table(void)
 {
    GLuint i;
    if (!weightLut) {
-      weightLut = (GLfloat *) malloc(WEIGHT_LUT_SIZE * sizeof(GLfloat));
+      weightLut = malloc(WEIGHT_LUT_SIZE * sizeof(GLfloat));
 
       for (i = 0; i < WEIGHT_LUT_SIZE; ++i) {
          GLfloat alpha = 2;
          GLfloat r2 = (GLfloat) i / (GLfloat) (WEIGHT_LUT_SIZE - 1);
-         GLfloat weight = (GLfloat) exp(-alpha * r2);
+         GLfloat weight = expf(-alpha * r2);
          weightLut[i] = weight;
       }
    }
@@ -1647,40 +1652,40 @@ sample_2d_ewa(struct gl_context *ctx,
               GLfloat rgba[])
 {
    GLint level = lod > 0 ? lod : 0;
-   GLfloat scaling = 1.0 / (1 << level);
+   GLfloat scaling = 1.0f / (1 << level);
    const struct gl_texture_image *img =        tObj->Image[0][level];
    const struct gl_texture_image *mostDetailedImage =
-      tObj->Image[0][tObj->BaseLevel];
+      _mesa_base_tex_image(tObj);
    const struct swrast_texture_image *swImg =
       swrast_texture_image_const(mostDetailedImage);
-   GLfloat tex_u=-0.5 + texcoord[0] * swImg->WidthScale * scaling;
-   GLfloat tex_v=-0.5 + texcoord[1] * swImg->HeightScale * scaling;
+   GLfloat tex_u = -0.5f + texcoord[0] * swImg->WidthScale * scaling;
+   GLfloat tex_v = -0.5f + texcoord[1] * swImg->HeightScale * scaling;
 
    GLfloat ux = dudx * scaling;
    GLfloat vx = dvdx * scaling;
    GLfloat uy = dudy * scaling;
    GLfloat vy = dvdy * scaling;
 
-   /* compute ellipse coefficients to bound the region: 
+   /* compute ellipse coefficients to bound the region:
     * A*x*x + B*x*y + C*y*y = F.
     */
    GLfloat A = vx*vx+vy*vy+1;
    GLfloat B = -2*(ux*vx+uy*vy);
    GLfloat C = ux*ux+uy*uy+1;
-   GLfloat F = A*C-B*B/4.0;
+   GLfloat F = A*C-B*B/4.0f;
 
    /* check if it is an ellipse */
-   /* ASSERT(F > 0.0); */
+   /* assert(F > 0.0); */
 
    /* Compute the ellipse's (u,v) bounding box in texture space */
-   GLfloat d = -B*B+4.0*C*A;
-   GLfloat box_u = 2.0 / d * sqrt(d*C*F); /* box_u -> half of bbox with   */
-   GLfloat box_v = 2.0 / d * sqrt(A*d*F); /* box_v -> half of bbox height */
+   GLfloat d = -B*B+4.0f*C*A;
+   GLfloat box_u = 2.0f / d * sqrtf(d*C*F); /* box_u -> half of bbox with   */
+   GLfloat box_v = 2.0f / d * sqrtf(A*d*F); /* box_v -> half of bbox height */
 
-   GLint u0 = floor(tex_u - box_u);
-   GLint u1 = ceil (tex_u + box_u);
-   GLint v0 = floor(tex_v - box_v);
-   GLint v1 = ceil (tex_v + box_v);
+   GLint u0 = (GLint) floorf(tex_u - box_u);
+   GLint u1 = (GLint) ceilf (tex_u + box_u);
+   GLint v0 = (GLint) floorf(tex_v - box_v);
+   GLint v1 = (GLint) ceilf (tex_v + box_v);
 
    GLfloat num[4] = {0.0F, 0.0F, 0.0F, 0.0F};
    GLfloat newCoord[2];
@@ -1692,7 +1697,7 @@ sample_2d_ewa(struct gl_context *ctx,
    /* Scale ellipse formula to directly index the Filter Lookup Table.
     * i.e. scale so that F = WEIGHT_LUT_SIZE-1
     */
-   double formScale = (double) (WEIGHT_LUT_SIZE - 1) / F;
+   GLfloat formScale = (GLfloat) (WEIGHT_LUT_SIZE - 1) / F;
    A *= formScale;
    B *= formScale;
    C *= formScale;
@@ -1715,7 +1720,7 @@ sample_2d_ewa(struct gl_context *ctx,
             /* as a LUT is used, q must never be negative;
              * should not happen, though
              */
-            const GLint qClamped = q >= 0.0F ? q : 0;
+            const GLint qClamped = q >= 0.0F ? (GLint) q : 0;
             GLfloat weight = weightLut[qClamped];
 
             newCoord[0] = u / ((GLfloat) img->Width2);
@@ -1795,19 +1800,19 @@ sample_2d_footprint(struct gl_context *ctx,
 
    /*  Calculate the per anisotropic sample offsets in s,t space. */
    if (Px2 > Py2) {
-      numSamples = ceil(sqrtf(Px2));
+      numSamples = (GLint) ceilf(sqrtf(Px2));
       ds = ux / ((GLfloat) img->Width2);
       dt = vx / ((GLfloat) img->Height2);
    }
    else {
-      numSamples = ceil(sqrtf(Py2));
+      numSamples = (GLint) ceilf(sqrtf(Py2));
       ds = uy / ((GLfloat) img->Width2);
       dt = vy / ((GLfloat) img->Height2);
    }
 
    for (s = 0; s<numSamples; s++) {
-      newCoord[0] = texcoord[0] + ds * ((GLfloat)(s+1) / (numSamples+1) -0.5);
-      newCoord[1] = texcoord[1] + dt * ((GLfloat)(s+1) / (numSamples+1) -0.5);
+      newCoord[0] = texcoord[0] + ds * ((GLfloat)(s+1) / (numSamples+1) -0.5f);
+      newCoord[1] = texcoord[1] + dt * ((GLfloat)(s+1) / (numSamples+1) -0.5f);
 
       sample_2d_linear(ctx, samp, img, newCoord, rgba);
       num[0] += rgba[0];
@@ -1827,7 +1832,7 @@ sample_2d_footprint(struct gl_context *ctx,
  * Returns the index of the specified texture object in the
  * gl_context texture unit array.
  */
-static inline GLuint
+static GLuint
 texture_unit_index(const struct gl_context *ctx,
                    const struct gl_texture_object *tObj)
 {
@@ -1842,7 +1847,7 @@ texture_unit_index(const struct gl_context *ctx,
    }
    if (u >= maxUnit)
       u = 0; /* not found, use 1st one; should never happen */
-   
+
    return u;
 }
 
@@ -1862,11 +1867,11 @@ sample_lambda_2d_aniso(struct gl_context *ctx,
                        GLuint n, const GLfloat texcoords[][4],
                        const GLfloat lambda_iso[], GLfloat rgba[][4])
 {
-   const struct gl_texture_image *tImg = tObj->Image[0][tObj->BaseLevel];
+   const struct gl_texture_image *tImg = _mesa_base_tex_image(tObj);
    const struct swrast_texture_image *swImg = swrast_texture_image_const(tImg);
    const GLfloat maxEccentricity =
       samp->MaxAnisotropy * samp->MaxAnisotropy;
-   
+
    /* re-calculate the lambda values so that they are usable with anisotropic
     * filtering
     */
@@ -1875,12 +1880,12 @@ sample_lambda_2d_aniso(struct gl_context *ctx,
    /* based on interpolate_texcoords(struct gl_context *ctx, SWspan *span)
     * in swrast/s_span.c
     */
-   
+
    /* find the texture unit index by looking up the current texture object
     * from the context list of available texture objects.
     */
    const GLuint u = texture_unit_index(ctx, tObj);
-   const GLuint attr = FRAG_ATTRIB_TEX0 + u;
+   const GLuint attr = VARYING_SLOT_TEX0 + u;
    GLfloat texW, texH;
 
    const GLfloat dsdx = span->attrStepX[attr][0];
@@ -1897,10 +1902,10 @@ sample_lambda_2d_aniso(struct gl_context *ctx,
    const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[u];
    const GLboolean adjustLOD =
       (texUnit->LodBias + samp->LodBias != 0.0F)
-      || (samp->MinLod != -1000.0 || samp->MaxLod != 1000.0);
+      || (samp->MinLod != -1000.0F || samp->MaxLod != 1000.0F);
 
    GLuint i;
-   
+
    /* on first access create the lookup table containing the filter weights. */
    if (!weightLut) {
       create_filter_table();
@@ -1911,13 +1916,13 @@ sample_lambda_2d_aniso(struct gl_context *ctx,
 
    for (i = 0; i < n; i++) {
       const GLfloat invQ = (q == 0.0F) ? 1.0F : (1.0F / q);
-      
+
       GLfloat dudx = texW * ((s + dsdx) / (q + dqdx) - s * invQ);
       GLfloat dvdx = texH * ((t + dtdx) / (q + dqdx) - t * invQ);
       GLfloat dudy = texW * ((s + dsdy) / (q + dqdy) - s * invQ);
       GLfloat dvdy = texH * ((t + dtdy) / (q + dqdy) - t * invQ);
-      
-      /* note: instead of working with Px and Py, we will use the 
+
+      /* note: instead of working with Px and Py, we will use the
        * squared length instead, to avoid sqrt.
        */
       GLfloat Px2 = dudx * dudx + dvdx * dvdx;
@@ -1931,7 +1936,7 @@ sample_lambda_2d_aniso(struct gl_context *ctx,
       s += dsdx;
       t += dtdx;
       q += dqdx;
-      
+
       if (Px2 < Py2) {
          Pmax2 = Py2;
          Pmin2 = Px2;
@@ -1940,7 +1945,7 @@ sample_lambda_2d_aniso(struct gl_context *ctx,
          Pmax2 = Px2;
          Pmin2 = Py2;
       }
-      
+
       /* if the eccentricity of the ellipse is too big, scale up the shorter
        * of the two vectors to limit the maximum amount of work per pixel
        */
@@ -1952,12 +1957,12 @@ sample_lambda_2d_aniso(struct gl_context *ctx,
             Pmin2 *= s; */
          Pmin2 = Pmax2 / maxEccentricity;
       }
-      
+
       /* note: we need to have Pmin=sqrt(Pmin2) here, but we can avoid
        * this since 0.5*log(x) = log(sqrt(x))
        */
-      lod = 0.5 * LOG2(Pmin2);
-      
+      lod = 0.5f * util_fast_log2(Pmin2);
+
       if (adjustLOD) {
          /* from swrast/s_texcombine.c _swrast_texture_span */
          if (texUnit->LodBias + samp->LodBias != 0.0F) {
@@ -1968,14 +1973,14 @@ sample_lambda_2d_aniso(struct gl_context *ctx,
                      ctx->Const.MaxTextureLodBias);
             lod += bias;
 
-            if (samp->MinLod != -1000.0 ||
-                samp->MaxLod != 1000.0) {
+            if (samp->MinLod != -1000.0F ||
+                samp->MaxLod != 1000.0F) {
                /* apply LOD clamping to lambda */
                lod = CLAMP(lod, samp->MinLod, samp->MaxLod);
             }
          }
       }
-      
+
       /* If the ellipse covers the whole image, we can
        * simply return the average of the whole image.
        */
@@ -1988,7 +1993,7 @@ sample_lambda_2d_aniso(struct gl_context *ctx,
           * seem to be worth the extra running time.
           */
          sample_2d_ewa(ctx, samp, tObj, texcoords[i],
-                       dudx, dvdx, dudy, dvdy, floor(lod), rgba[i]);
+                       dudx, dvdx, dudy, dvdy, (GLint) floorf(lod), rgba[i]);
 
          /* unused: */
          (void) sample_2d_footprint;
@@ -2009,7 +2014,7 @@ sample_lambda_2d_aniso(struct gl_context *ctx,
 /**
  * Return the texture sample for coordinate (s,t,r) using GL_NEAREST filter.
  */
-static inline void
+static void
 sample_3d_nearest(struct gl_context *ctx,
                   const struct gl_sampler_object *samp,
                   const struct gl_texture_image *img,
@@ -2160,7 +2165,7 @@ sample_3d_linear_mipmap_nearest(struct gl_context *ctx,
                                 const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       GLint level = nearest_mipmap_level(tObj, lambda[i]);
       sample_3d_linear(ctx, samp, tObj->Image[0][level], texcoord[i], rgba[i]);
@@ -2176,7 +2181,7 @@ sample_3d_nearest_mipmap_linear(struct gl_context *ctx,
                                 const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       GLint level = linear_mipmap_level(tObj, lambda[i]);
       if (level >= tObj->_MaxLevel) {
@@ -2202,7 +2207,7 @@ sample_3d_linear_mipmap_linear(struct gl_context *ctx,
                                const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       GLint level = linear_mipmap_level(tObj, lambda[i]);
       if (level >= tObj->_MaxLevel) {
@@ -2229,7 +2234,7 @@ sample_nearest_3d(struct gl_context *ctx,
                   GLfloat rgba[][4])
 {
    GLuint i;
-   struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel];
+   const struct gl_texture_image *image = _mesa_base_tex_image(tObj);
    (void) lambda;
    for (i = 0; i < n; i++) {
       sample_3d_nearest(ctx, samp, image, texcoords[i], rgba[i]);
@@ -2246,7 +2251,7 @@ sample_linear_3d(struct gl_context *ctx,
                 const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel];
+   const struct gl_texture_image *image = _mesa_base_tex_image(tObj);
    (void) lambda;
    for (i = 0; i < n; i++) {
       sample_3d_linear(ctx, samp, image, texcoords[i], rgba[i]);
@@ -2266,7 +2271,7 @@ sample_lambda_3d(struct gl_context *ctx,
    GLuint magStart, magEnd;  /* texels with magnification */
    GLuint i;
 
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    compute_min_mag_ranges(samp, n, lambda,
                           &minStart, &minEnd, &magStart, &magEnd);
 
@@ -2276,12 +2281,12 @@ sample_lambda_3d(struct gl_context *ctx,
       switch (samp->MinFilter) {
       case GL_NEAREST:
          for (i = minStart; i < minEnd; i++)
-            sample_3d_nearest(ctx, samp, tObj->Image[0][tObj->BaseLevel],
+            sample_3d_nearest(ctx, samp, _mesa_base_tex_image(tObj),
                               texcoords[i], rgba[i]);
          break;
       case GL_LINEAR:
          for (i = minStart; i < minEnd; i++)
-            sample_3d_linear(ctx, samp, tObj->Image[0][tObj->BaseLevel],
+            sample_3d_linear(ctx, samp, _mesa_base_tex_image(tObj),
                              texcoords[i], rgba[i]);
          break;
       case GL_NEAREST_MIPMAP_NEAREST:
@@ -2311,12 +2316,12 @@ sample_lambda_3d(struct gl_context *ctx,
       switch (samp->MagFilter) {
       case GL_NEAREST:
          for (i = magStart; i < magEnd; i++)
-            sample_3d_nearest(ctx, samp, tObj->Image[0][tObj->BaseLevel],
+            sample_3d_nearest(ctx, samp, _mesa_base_tex_image(tObj),
                               texcoords[i], rgba[i]);
          break;
       case GL_LINEAR:
          for (i = magStart; i < magEnd; i++)
-            sample_3d_linear(ctx, samp, tObj->Image[0][tObj->BaseLevel],
+            sample_3d_linear(ctx, samp, _mesa_base_tex_image(tObj),
                              texcoords[i], rgba[i]);
          break;
       default:
@@ -2354,7 +2359,7 @@ choose_cube_face(const struct gl_texture_object *texObj,
    const GLfloat rx = texcoord[0];
    const GLfloat ry = texcoord[1];
    const GLfloat rz = texcoord[2];
-   const GLfloat arx = FABSF(rx), ary = FABSF(ry), arz = FABSF(rz);
+   const GLfloat arx = fabsf(rx), ary = fabsf(ry), arz = fabsf(rz);
    GLuint face;
    GLfloat sc, tc, ma;
 
@@ -2401,7 +2406,7 @@ choose_cube_face(const struct gl_texture_object *texObj,
       }
    }
 
-   { 
+   {
       const float ima = 1.0F / ma;
       newCoord[0] = ( sc * ima + 1.0F ) * 0.5F;
       newCoord[1] = ( tc * ima + 1.0F ) * 0.5F;
@@ -2467,7 +2472,7 @@ sample_cube_nearest_mipmap_nearest(struct gl_context *ctx,
                                    const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       const struct gl_texture_image **images;
       GLfloat newCoord[4];
@@ -2502,7 +2507,7 @@ sample_cube_linear_mipmap_nearest(struct gl_context *ctx,
                                   const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       const struct gl_texture_image **images;
       GLfloat newCoord[4];
@@ -2527,7 +2532,7 @@ sample_cube_nearest_mipmap_linear(struct gl_context *ctx,
                                   const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       const struct gl_texture_image **images;
       GLfloat newCoord[4];
@@ -2562,7 +2567,7 @@ sample_cube_linear_mipmap_linear(struct gl_context *ctx,
                                  const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       const struct gl_texture_image **images;
       GLfloat newCoord[4];
@@ -2600,7 +2605,7 @@ sample_lambda_cube(struct gl_context *ctx,
    GLuint minStart, minEnd;  /* texels with minification */
    GLuint magStart, magEnd;  /* texels with magnification */
 
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    compute_min_mag_ranges(samp, n, lambda,
                           &minStart, &minEnd, &magStart, &magEnd);
 
@@ -2683,10 +2688,10 @@ sample_nearest_rect(struct gl_context *ctx,
    (void) ctx;
    (void) lambda;
 
-   ASSERT(samp->WrapS == GL_CLAMP ||
+   assert(samp->WrapS == GL_CLAMP ||
           samp->WrapS == GL_CLAMP_TO_EDGE ||
           samp->WrapS == GL_CLAMP_TO_BORDER);
-   ASSERT(samp->WrapT == GL_CLAMP ||
+   assert(samp->WrapT == GL_CLAMP ||
           samp->WrapT == GL_CLAMP_TO_EDGE ||
           samp->WrapT == GL_CLAMP_TO_BORDER);
 
@@ -2718,10 +2723,10 @@ sample_linear_rect(struct gl_context *ctx,
    (void) ctx;
    (void) lambda;
 
-   ASSERT(samp->WrapS == GL_CLAMP ||
+   assert(samp->WrapS == GL_CLAMP ||
           samp->WrapS == GL_CLAMP_TO_EDGE ||
           samp->WrapS == GL_CLAMP_TO_BORDER);
-   ASSERT(samp->WrapT == GL_CLAMP ||
+   assert(samp->WrapT == GL_CLAMP ||
           samp->WrapT == GL_CLAMP_TO_EDGE ||
           samp->WrapT == GL_CLAMP_TO_BORDER);
 
@@ -2912,7 +2917,7 @@ sample_2d_array_linear(struct gl_context *ctx,
       else {
         swImg->FetchTexel(swImg, i1, j1, array, t11);
       }
-      
+
       /* trilinear interpolation of samples */
       lerp_rgba_2d(rgba, a, b, t00, t10, t01, t11);
    }
@@ -2943,7 +2948,7 @@ sample_2d_array_linear_mipmap_nearest(struct gl_context *ctx,
                                       const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       GLint level = nearest_mipmap_level(tObj, lambda[i]);
       sample_2d_array_linear(ctx, samp, tObj->Image[0][level],
@@ -2960,7 +2965,7 @@ sample_2d_array_nearest_mipmap_linear(struct gl_context *ctx,
                                       const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       GLint level = linear_mipmap_level(tObj, lambda[i]);
       if (level >= tObj->_MaxLevel) {
@@ -2988,7 +2993,7 @@ sample_2d_array_linear_mipmap_linear(struct gl_context *ctx,
                                      const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       GLint level = linear_mipmap_level(tObj, lambda[i]);
       if (level >= tObj->_MaxLevel) {
@@ -3017,7 +3022,7 @@ sample_nearest_2d_array(struct gl_context *ctx,
                         GLfloat rgba[][4])
 {
    GLuint i;
-   struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel];
+   const struct gl_texture_image *image = _mesa_base_tex_image(tObj);
    (void) lambda;
    for (i = 0; i < n; i++) {
       sample_2d_array_nearest(ctx, samp, image, texcoords[i], rgba[i]);
@@ -3035,7 +3040,7 @@ sample_linear_2d_array(struct gl_context *ctx,
                        const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel];
+   const struct gl_texture_image *image = _mesa_base_tex_image(tObj);
    (void) lambda;
    for (i = 0; i < n; i++) {
       sample_2d_array_linear(ctx, samp, image, texcoords[i], rgba[i]);
@@ -3055,7 +3060,7 @@ sample_lambda_2d_array(struct gl_context *ctx,
    GLuint magStart, magEnd;  /* texels with magnification */
    GLuint i;
 
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    compute_min_mag_ranges(samp, n, lambda,
                           &minStart, &minEnd, &magStart, &magEnd);
 
@@ -3065,12 +3070,12 @@ sample_lambda_2d_array(struct gl_context *ctx,
       switch (samp->MinFilter) {
       case GL_NEAREST:
          for (i = minStart; i < minEnd; i++)
-            sample_2d_array_nearest(ctx, samp, tObj->Image[0][tObj->BaseLevel],
+            sample_2d_array_nearest(ctx, samp, _mesa_base_tex_image(tObj),
                                     texcoords[i], rgba[i]);
          break;
       case GL_LINEAR:
          for (i = minStart; i < minEnd; i++)
-            sample_2d_array_linear(ctx, samp, tObj->Image[0][tObj->BaseLevel],
+            sample_2d_array_linear(ctx, samp, _mesa_base_tex_image(tObj),
                                    texcoords[i], rgba[i]);
          break;
       case GL_NEAREST_MIPMAP_NEAREST:
@@ -3094,7 +3099,7 @@ sample_lambda_2d_array(struct gl_context *ctx,
       case GL_LINEAR_MIPMAP_LINEAR:
          sample_2d_array_linear_mipmap_linear(ctx, samp, tObj, m,
                                               texcoords + minStart,
-                                              lambda + minStart, 
+                                              lambda + minStart,
                                               rgba + minStart);
          break;
       default:
@@ -3108,12 +3113,12 @@ sample_lambda_2d_array(struct gl_context *ctx,
       switch (samp->MagFilter) {
       case GL_NEAREST:
          for (i = magStart; i < magEnd; i++)
-            sample_2d_array_nearest(ctx, samp, tObj->Image[0][tObj->BaseLevel],
+            sample_2d_array_nearest(ctx, samp, _mesa_base_tex_image(tObj),
                               texcoords[i], rgba[i]);
          break;
       case GL_LINEAR:
          for (i = magStart; i < magEnd; i++)
-            sample_2d_array_linear(ctx, samp, tObj->Image[0][tObj->BaseLevel],
+            sample_2d_array_linear(ctx, samp, _mesa_base_tex_image(tObj),
                                    texcoords[i], rgba[i]);
          break;
       default:
@@ -3238,7 +3243,7 @@ sample_1d_array_linear_mipmap_nearest(struct gl_context *ctx,
                                       const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       GLint level = nearest_mipmap_level(tObj, lambda[i]);
       sample_1d_array_linear(ctx, samp, tObj->Image[0][level],
@@ -3255,7 +3260,7 @@ sample_1d_array_nearest_mipmap_linear(struct gl_context *ctx,
                                       const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       GLint level = linear_mipmap_level(tObj, lambda[i]);
       if (level >= tObj->_MaxLevel) {
@@ -3281,7 +3286,7 @@ sample_1d_array_linear_mipmap_linear(struct gl_context *ctx,
                                      const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    for (i = 0; i < n; i++) {
       GLint level = linear_mipmap_level(tObj, lambda[i]);
       if (level >= tObj->_MaxLevel) {
@@ -3308,7 +3313,7 @@ sample_nearest_1d_array(struct gl_context *ctx,
                         GLfloat rgba[][4])
 {
    GLuint i;
-   struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel];
+   const struct gl_texture_image *image = _mesa_base_tex_image(tObj);
    (void) lambda;
    for (i = 0; i < n; i++) {
       sample_1d_array_nearest(ctx, samp, image, texcoords[i], rgba[i]);
@@ -3325,7 +3330,7 @@ sample_linear_1d_array(struct gl_context *ctx,
                        const GLfloat lambda[], GLfloat rgba[][4])
 {
    GLuint i;
-   struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel];
+   const struct gl_texture_image *image = _mesa_base_tex_image(tObj);
    (void) lambda;
    for (i = 0; i < n; i++) {
       sample_1d_array_linear(ctx, samp, image, texcoords[i], rgba[i]);
@@ -3345,7 +3350,7 @@ sample_lambda_1d_array(struct gl_context *ctx,
    GLuint magStart, magEnd;  /* texels with magnification */
    GLuint i;
 
-   ASSERT(lambda != NULL);
+   assert(lambda != NULL);
    compute_min_mag_ranges(samp, n, lambda,
                           &minStart, &minEnd, &magStart, &magEnd);
 
@@ -3355,12 +3360,12 @@ sample_lambda_1d_array(struct gl_context *ctx,
       switch (samp->MinFilter) {
       case GL_NEAREST:
          for (i = minStart; i < minEnd; i++)
-            sample_1d_array_nearest(ctx, samp, tObj->Image[0][tObj->BaseLevel],
+            sample_1d_array_nearest(ctx, samp, _mesa_base_tex_image(tObj),
                                     texcoords[i], rgba[i]);
          break;
       case GL_LINEAR:
          for (i = minStart; i < minEnd; i++)
-            sample_1d_array_linear(ctx, samp, tObj->Image[0][tObj->BaseLevel],
+            sample_1d_array_linear(ctx, samp, _mesa_base_tex_image(tObj),
                                    texcoords[i], rgba[i]);
          break;
       case GL_NEAREST_MIPMAP_NEAREST:
@@ -3368,7 +3373,7 @@ sample_lambda_1d_array(struct gl_context *ctx,
                                                 lambda + minStart, rgba + minStart);
          break;
       case GL_LINEAR_MIPMAP_NEAREST:
-         sample_1d_array_linear_mipmap_nearest(ctx, samp, tObj, m, 
+         sample_1d_array_linear_mipmap_nearest(ctx, samp, tObj, m,
                                                texcoords + minStart,
                                                lambda + minStart,
                                                rgba + minStart);
@@ -3378,9 +3383,9 @@ sample_lambda_1d_array(struct gl_context *ctx,
                                                lambda + minStart, rgba + minStart);
          break;
       case GL_LINEAR_MIPMAP_LINEAR:
-         sample_1d_array_linear_mipmap_linear(ctx, samp, tObj, m, 
+         sample_1d_array_linear_mipmap_linear(ctx, samp, tObj, m,
                                               texcoords + minStart,
-                                              lambda + minStart, 
+                                              lambda + minStart,
                                               rgba + minStart);
          break;
       default:
@@ -3394,12 +3399,12 @@ sample_lambda_1d_array(struct gl_context *ctx,
       switch (samp->MagFilter) {
       case GL_NEAREST:
          for (i = magStart; i < magEnd; i++)
-            sample_1d_array_nearest(ctx, samp, tObj->Image[0][tObj->BaseLevel],
+            sample_1d_array_nearest(ctx, samp, _mesa_base_tex_image(tObj),
                               texcoords[i], rgba[i]);
          break;
       case GL_LINEAR:
          for (i = magStart; i < magEnd; i++)
-            sample_1d_array_linear(ctx, samp, tObj->Image[0][tObj->BaseLevel],
+            sample_1d_array_linear(ctx, samp, _mesa_base_tex_image(tObj),
                                    texcoords[i], rgba[i]);
          break;
       default:
@@ -3413,7 +3418,7 @@ sample_lambda_1d_array(struct gl_context *ctx,
 /**
  * Compare texcoord against depth sample.  Return 1.0 or 0.0 value.
  */
-static inline GLfloat
+static GLfloat
 shadow_compare(GLenum function, GLfloat coord, GLfloat depthSample)
 {
    switch (function) {
@@ -3445,7 +3450,7 @@ shadow_compare(GLenum function, GLfloat coord, GLfloat depthSample)
 /**
  * Compare texcoord against four depth samples.
  */
-static inline GLfloat
+static GLfloat
 shadow_compare4(GLenum function, GLfloat coord,
                 GLfloat depth00, GLfloat depth01,
                 GLfloat depth10, GLfloat depth11,
@@ -3551,10 +3556,10 @@ sample_depth_texture( struct gl_context *ctx,
    GLenum function;
    GLfloat result;
 
-   ASSERT(img->_BaseFormat == GL_DEPTH_COMPONENT ||
+   assert(img->_BaseFormat == GL_DEPTH_COMPONENT ||
           img->_BaseFormat == GL_DEPTH_STENCIL_EXT);
 
-   ASSERT(tObj->Target == GL_TEXTURE_1D ||
+   assert(tObj->Target == GL_TEXTURE_1D ||
           tObj->Target == GL_TEXTURE_2D ||
           tObj->Target == GL_TEXTURE_RECTANGLE_NV ||
           tObj->Target == GL_TEXTURE_1D_ARRAY_EXT ||
@@ -3574,7 +3579,7 @@ sample_depth_texture( struct gl_context *ctx,
 
          nearest_texcoord(samp, tObj, level, texcoords[i], &col, &row, &slice);
 
-         if (col >= 0 && row >= 0 && col < width && row < height && 
+         if (col >= 0 && row >= 0 && col < width && row < height &&
              slice >= 0 && slice < depth) {
             swImg->FetchTexel(swImg, col, row, slice, &depthSample);
          }
@@ -3591,7 +3596,7 @@ sample_depth_texture( struct gl_context *ctx,
    }
    else {
       GLuint i;
-      ASSERT(samp->MagFilter == GL_LINEAR);
+      assert(samp->MagFilter == GL_LINEAR);
       for (i = 0; i < n; i++) {
          GLfloat depth00, depth01, depth10, depth11, depthRef;
          GLint i0, i1, j0, j1;
@@ -3708,7 +3713,7 @@ _swrast_choose_texture_sample_func( struct gl_context *ctx,
                                     const struct gl_sampler_object *sampler)
 {
    if (!t || !_mesa_is_texture_complete(t, sampler)) {
-      return &null_sample_func;
+      return null_sample_func;
    }
    else {
       const GLboolean needLambda =
@@ -3717,49 +3722,49 @@ _swrast_choose_texture_sample_func( struct gl_context *ctx,
       switch (t->Target) {
       case GL_TEXTURE_1D:
          if (is_depth_texture(t)) {
-            return &sample_depth_texture;
+            return sample_depth_texture;
          }
          else if (needLambda) {
-            return &sample_lambda_1d;
+            return sample_lambda_1d;
          }
          else if (sampler->MinFilter == GL_LINEAR) {
-            return &sample_linear_1d;
+            return sample_linear_1d;
          }
          else {
-            ASSERT(sampler->MinFilter == GL_NEAREST);
-            return &sample_nearest_1d;
+            assert(sampler->MinFilter == GL_NEAREST);
+            return sample_nearest_1d;
          }
       case GL_TEXTURE_2D:
          if (is_depth_texture(t)) {
-            return &sample_depth_texture;
+            return sample_depth_texture;
          }
          else if (needLambda) {
             /* Anisotropic filtering extension. Activated only if mipmaps are used */
-            if (sampler->MaxAnisotropy > 1.0 &&
+            if (sampler->MaxAnisotropy > 1.0F &&
                 sampler->MinFilter == GL_LINEAR_MIPMAP_LINEAR) {
-               return &sample_lambda_2d_aniso;
+               return sample_lambda_2d_aniso;
             }
-            return &sample_lambda_2d;
+            return sample_lambda_2d;
          }
          else if (sampler->MinFilter == GL_LINEAR) {
-            return &sample_linear_2d;
+            return sample_linear_2d;
          }
          else {
             /* check for a few optimized cases */
-            const struct gl_texture_image *img = t->Image[0][t->BaseLevel];
+            const struct gl_texture_image *img = _mesa_base_tex_image(t);
             const struct swrast_texture_image *swImg =
                swrast_texture_image_const(img);
             texture_sample_func func;
 
-            ASSERT(sampler->MinFilter == GL_NEAREST);
+            assert(sampler->MinFilter == GL_NEAREST);
             func = &sample_nearest_2d;
             if (sampler->WrapS == GL_REPEAT &&
                 sampler->WrapT == GL_REPEAT &&
                 swImg->_IsPowerOfTwo &&
                 img->Border == 0) {
-               if (img->TexFormat == MESA_FORMAT_RGB888)
+               if (img->TexFormat == MESA_FORMAT_BGR_UNORM8)
                   func = &opt_sample_rgb_2d;
-               else if (img->TexFormat == MESA_FORMAT_RGBA8888)
+               else if (img->TexFormat == MESA_FORMAT_A8B8G8R8_UNORM)
                   func = &opt_sample_rgba_2d;
             }
 
@@ -3767,72 +3772,72 @@ _swrast_choose_texture_sample_func( struct gl_context *ctx,
          }
       case GL_TEXTURE_3D:
          if (needLambda) {
-            return &sample_lambda_3d;
+            return sample_lambda_3d;
          }
          else if (sampler->MinFilter == GL_LINEAR) {
-            return &sample_linear_3d;
+            return sample_linear_3d;
          }
          else {
-            ASSERT(sampler->MinFilter == GL_NEAREST);
-            return &sample_nearest_3d;
+            assert(sampler->MinFilter == GL_NEAREST);
+            return sample_nearest_3d;
          }
       case GL_TEXTURE_CUBE_MAP:
          if (needLambda) {
-            return &sample_lambda_cube;
+            return sample_lambda_cube;
          }
          else if (sampler->MinFilter == GL_LINEAR) {
-            return &sample_linear_cube;
+            return sample_linear_cube;
          }
          else {
-            ASSERT(sampler->MinFilter == GL_NEAREST);
-            return &sample_nearest_cube;
+            assert(sampler->MinFilter == GL_NEAREST);
+            return sample_nearest_cube;
          }
       case GL_TEXTURE_RECTANGLE_NV:
          if (is_depth_texture(t)) {
-            return &sample_depth_texture;
+            return sample_depth_texture;
          }
          else if (needLambda) {
-            return &sample_lambda_rect;
+            return sample_lambda_rect;
          }
          else if (sampler->MinFilter == GL_LINEAR) {
-            return &sample_linear_rect;
+            return sample_linear_rect;
          }
          else {
-            ASSERT(sampler->MinFilter == GL_NEAREST);
-            return &sample_nearest_rect;
+            assert(sampler->MinFilter == GL_NEAREST);
+            return sample_nearest_rect;
          }
       case GL_TEXTURE_1D_ARRAY_EXT:
          if (is_depth_texture(t)) {
-            return &sample_depth_texture;
+            return sample_depth_texture;
          }
         else if (needLambda) {
-            return &sample_lambda_1d_array;
+            return sample_lambda_1d_array;
          }
          else if (sampler->MinFilter == GL_LINEAR) {
-            return &sample_linear_1d_array;
+            return sample_linear_1d_array;
          }
          else {
-            ASSERT(sampler->MinFilter == GL_NEAREST);
-            return &sample_nearest_1d_array;
+            assert(sampler->MinFilter == GL_NEAREST);
+            return sample_nearest_1d_array;
          }
       case GL_TEXTURE_2D_ARRAY_EXT:
          if (is_depth_texture(t)) {
-            return &sample_depth_texture;
+            return sample_depth_texture;
          }
         else if (needLambda) {
-            return &sample_lambda_2d_array;
+            return sample_lambda_2d_array;
          }
          else if (sampler->MinFilter == GL_LINEAR) {
-            return &sample_linear_2d_array;
+            return sample_linear_2d_array;
          }
          else {
-            ASSERT(sampler->MinFilter == GL_NEAREST);
-            return &sample_nearest_2d_array;
+            assert(sampler->MinFilter == GL_NEAREST);
+            return sample_nearest_2d_array;
          }
       default:
          _mesa_problem(ctx,
                        "invalid target in _swrast_choose_texture_sample_func");
-         return &null_sample_func;
+         return null_sample_func;
       }
    }
 }