summaryrefslogtreecommitdiff
path: root/src/mesa
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2001-04-12 15:18:07 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2001-04-12 15:18:07 +0000
commit608889d18f78727753d63d0f867ec4d216e04c4c (patch)
tree3f1f30919e4d464a6e4a1f91ef2964b8e7a5e71b /src/mesa
parent93de8d3d8617e991c091f29236dc7316203a5b8d (diff)
Moved FRAC macro out of mmath.h into s_texture.c since it's only used there
and doesn't do what one might expect for negative values. Reimplemented FRAC in terms of floor() to fix glitches seen in tests/texwrap.c. Minor fix for problem with GL_CLAMP_TO_BORDER_ARB with GL_NEAREST sampling.
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/swrast/s_texture.c53
1 files changed, 41 insertions, 12 deletions
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
index 55c5277fd3..7f932f8b13 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -1,4 +1,4 @@
-/* $Id: s_texture.c,v 1.22 2001/04/10 15:25:45 brianp Exp $ */
+/* $Id: s_texture.c,v 1.23 2001/04/12 15:18:07 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -199,6 +199,15 @@
+/*
+ * Note, the FRAC macro has to work perfectly. Otherwise you'll sometimes
+ * see 1-pixel bands of improperly weighted linear-sampled texels.
+ * In particular, #define FRAC(f) ((f) - IFLOOR(f)) doesn't work.
+ * 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) - floor(f))
+
/*
* Bitflags for texture border color sampling.
@@ -285,9 +294,15 @@ sample_1d_nearest(GLcontext *ctx,
/* skip over the border, if any */
i += img->Border;
- (*img->FetchTexel)(img, i, 0, 0, (GLvoid *) rgba);
- if (img->Format == GL_COLOR_INDEX) {
- palette_sample(ctx, tObj, rgba[0], rgba);
+ if (i < 0 || i >= img->Width) {
+ /* Need this test for GL_CLAMP_TO_BORDER_ARB mode */
+ COPY_CHAN4(rgba, tObj->BorderColor);
+ }
+ else {
+ (*img->FetchTexel)(img, i, 0, 0, (GLvoid *) rgba);
+ if (img->Format == GL_COLOR_INDEX) {
+ palette_sample(ctx, tObj, rgba[0], rgba);
+ }
}
}
@@ -569,9 +584,15 @@ sample_2d_nearest(GLcontext *ctx,
i += img->Border;
j += img->Border;
- (*img->FetchTexel)(img, i, j, 0, (GLvoid *) rgba);
- if (img->Format == GL_COLOR_INDEX) {
- palette_sample(ctx, tObj, rgba[0], rgba);
+ if (i < 0 || i >= img->Width || j < 0 || j >= img->Height) {
+ /* Need this test for GL_CLAMP_TO_BORDER_ARB mode */
+ COPY_CHAN4(rgba, tObj->BorderColor);
+ }
+ else {
+ (*img->FetchTexel)(img, i, j, 0, (GLvoid *) rgba);
+ if (img->Format == GL_COLOR_INDEX) {
+ palette_sample(ctx, tObj, rgba[0], rgba);
+ }
}
}
@@ -612,8 +633,8 @@ sample_2d_linear(GLcontext *ctx,
}
{
- const GLfloat a = FRAC(u + 1.0F); /* add one in case u is just below 0 */
- const GLfloat b = FRAC(v + 1.0F);
+ const GLfloat a = FRAC(u - 1.0);
+ const GLfloat b = FRAC(v - 1.0);
/* compute sample weights in fixed point in [0,WEIGHT_SCALE] */
const GLint w00 = IROUND_POS((1.0F-a) * (1.0F-b) * WEIGHT_SCALE);
const GLint w10 = IROUND_POS( a * (1.0F-b) * WEIGHT_SCALE);
@@ -983,9 +1004,17 @@ sample_3d_nearest(GLcontext *ctx,
COMPUTE_NEAREST_TEXEL_LOCATION(tObj->WrapT, t, height, j);
COMPUTE_NEAREST_TEXEL_LOCATION(tObj->WrapR, r, depth, k);
- (*img->FetchTexel)(img, i, j, k, (GLvoid *) rgba);
- if (img->Format == GL_COLOR_INDEX) {
- palette_sample(ctx, tObj, rgba[0], rgba);
+ if (i < 0 || i >= img->Width ||
+ j < 0 || j >= img->Height ||
+ k < 0 || k >= img->Depth) {
+ /* Need this test for GL_CLAMP_TO_BORDER_ARB mode */
+ COPY_CHAN4(rgba, tObj->BorderColor);
+ }
+ else {
+ (*img->FetchTexel)(img, i, j, k, (GLvoid *) rgba);
+ if (img->Format == GL_COLOR_INDEX) {
+ palette_sample(ctx, tObj, rgba[0], rgba);
+ }
}
}