Merge branch 'master' into gallium-0.2
[mesa.git] / src / mesa / swrast / s_texfilter.c
index a5594ac6232dc64b2f7ba9ef2bed9acbce979e9f..9e44fba3daf146c4c39634acef67a1278f595dac 100644 (file)
  */
 
 
-#include "glheader.h"
-#include "context.h"
-#include "colormac.h"
-#include "imports.h"
-#include "texformat.h"
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/colormac.h"
+#include "main/imports.h"
+#include "main/texformat.h"
 
 #include "s_context.h"
 #include "s_texfilter.h"
@@ -342,6 +342,7 @@ lerp_rgba_3d(GLchan result[4], GLfloat a, GLfloat b, GLfloat c,
       break;                                                           \
    default:                                                            \
       _mesa_problem(ctx, "Bad wrap mode");                             \
+      return;                                                          \
    }                                                                   \
 }
 
@@ -462,6 +463,7 @@ lerp_rgba_3d(GLchan result[4], GLfloat a, GLfloat b, GLfloat c,
       break;                                                           \
    default:                                                            \
       _mesa_problem(ctx, "Bad wrap mode");                             \
+      return;                                                          \
    }                                                                   \
 }
 
@@ -1854,8 +1856,19 @@ sample_cube_nearest_mipmap_nearest(GLcontext *ctx,
    for (i = 0; i < n; i++) {
       const struct gl_texture_image **images;
       GLfloat newCoord[4];
-      GLint level = nearest_mipmap_level(tObj, lambda[i]);
+      GLint level;
       images = choose_cube_face(tObj, texcoord[i], newCoord);
+
+      /* XXX we actually need to recompute lambda here based on the newCoords.
+       * But we would need the texcoords of adjacent fragments to compute that
+       * properly, and we don't have those here.
+       * For now, do an approximation:  subtracting 1 from the chosen mipmap
+       * level seems to work in some test cases.
+       * The same adjustment is done in the next few functions.
+      */
+      level = nearest_mipmap_level(tObj, lambda[i]);
+      level = MAX2(level - 1, 0);
+
       sample_2d_nearest(ctx, tObj, images[level], newCoord, rgba[i]);
    }
 }
@@ -1873,6 +1886,7 @@ sample_cube_linear_mipmap_nearest(GLcontext *ctx,
       const struct gl_texture_image **images;
       GLfloat newCoord[4];
       GLint level = nearest_mipmap_level(tObj, lambda[i]);
+      level = MAX2(level - 1, 0); /* see comment above */
       images = choose_cube_face(tObj, texcoord[i], newCoord);
       sample_2d_linear(ctx, tObj, images[level], newCoord, rgba[i]);
    }
@@ -1891,6 +1905,7 @@ sample_cube_nearest_mipmap_linear(GLcontext *ctx,
       const struct gl_texture_image **images;
       GLfloat newCoord[4];
       GLint level = linear_mipmap_level(tObj, lambda[i]);
+      level = MAX2(level - 1, 0); /* see comment above */
       images = choose_cube_face(tObj, texcoord[i], newCoord);
       if (level >= tObj->_MaxLevel) {
          sample_2d_nearest(ctx, tObj, images[tObj->_MaxLevel],
@@ -1919,6 +1934,7 @@ sample_cube_linear_mipmap_linear(GLcontext *ctx,
       const struct gl_texture_image **images;
       GLfloat newCoord[4];
       GLint level = linear_mipmap_level(tObj, lambda[i]);
+      level = MAX2(level - 1, 0); /* see comment above */
       images = choose_cube_face(tObj, texcoord[i], newCoord);
       if (level >= tObj->_MaxLevel) {
          sample_2d_linear(ctx, tObj, images[tObj->_MaxLevel],