mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-22 22:10:10 +01:00
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.
This commit is contained in:
parent
93de8d3d86
commit
608889d18f
1 changed files with 41 additions and 12 deletions
|
|
@ -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
|
* 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.
|
* Bitflags for texture border color sampling.
|
||||||
|
|
@ -285,11 +294,17 @@ sample_1d_nearest(GLcontext *ctx,
|
||||||
/* skip over the border, if any */
|
/* skip over the border, if any */
|
||||||
i += img->Border;
|
i += img->Border;
|
||||||
|
|
||||||
|
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);
|
(*img->FetchTexel)(img, i, 0, 0, (GLvoid *) rgba);
|
||||||
if (img->Format == GL_COLOR_INDEX) {
|
if (img->Format == GL_COLOR_INDEX) {
|
||||||
palette_sample(ctx, tObj, rgba[0], rgba);
|
palette_sample(ctx, tObj, rgba[0], rgba);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -569,11 +584,17 @@ sample_2d_nearest(GLcontext *ctx,
|
||||||
i += img->Border;
|
i += img->Border;
|
||||||
j += img->Border;
|
j += img->Border;
|
||||||
|
|
||||||
|
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);
|
(*img->FetchTexel)(img, i, j, 0, (GLvoid *) rgba);
|
||||||
if (img->Format == GL_COLOR_INDEX) {
|
if (img->Format == GL_COLOR_INDEX) {
|
||||||
palette_sample(ctx, tObj, rgba[0], rgba);
|
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 a = FRAC(u - 1.0);
|
||||||
const GLfloat b = FRAC(v + 1.0F);
|
const GLfloat b = FRAC(v - 1.0);
|
||||||
/* compute sample weights in fixed point in [0,WEIGHT_SCALE] */
|
/* 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 w00 = IROUND_POS((1.0F-a) * (1.0F-b) * WEIGHT_SCALE);
|
||||||
const GLint w10 = IROUND_POS( a * (1.0F-b) * WEIGHT_SCALE);
|
const GLint w10 = IROUND_POS( a * (1.0F-b) * WEIGHT_SCALE);
|
||||||
|
|
@ -983,11 +1004,19 @@ sample_3d_nearest(GLcontext *ctx,
|
||||||
COMPUTE_NEAREST_TEXEL_LOCATION(tObj->WrapT, t, height, j);
|
COMPUTE_NEAREST_TEXEL_LOCATION(tObj->WrapT, t, height, j);
|
||||||
COMPUTE_NEAREST_TEXEL_LOCATION(tObj->WrapR, r, depth, k);
|
COMPUTE_NEAREST_TEXEL_LOCATION(tObj->WrapR, r, depth, k);
|
||||||
|
|
||||||
|
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);
|
(*img->FetchTexel)(img, i, j, k, (GLvoid *) rgba);
|
||||||
if (img->Format == GL_COLOR_INDEX) {
|
if (img->Format == GL_COLOR_INDEX) {
|
||||||
palette_sample(ctx, tObj, rgba[0], rgba);
|
palette_sample(ctx, tObj, rgba[0], rgba);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue