summaryrefslogtreecommitdiff
path: root/src/mesa/swrast/s_texfilter.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/swrast/s_texfilter.c')
-rw-r--r--src/mesa/swrast/s_texfilter.c72
1 files changed, 34 insertions, 38 deletions
diff --git a/src/mesa/swrast/s_texfilter.c b/src/mesa/swrast/s_texfilter.c
index bb0fc823e7..1b44fddc41 100644
--- a/src/mesa/swrast/s_texfilter.c
+++ b/src/mesa/swrast/s_texfilter.c
@@ -1,6 +1,6 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5.3
+ * Version: 7.0.3
*
* Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
*
@@ -213,17 +213,10 @@ lerp_rgba_3d(GLchan result[4], GLfloat a, GLfloat b, GLfloat c,
/**
- * Compute the remainder of a divided by b, but be careful with
- * negative values so that GL_REPEAT mode works right.
+ * If A is a signed integer, A % B doesn't give the right value for A < 0
+ * (in terms of texture repeat). Just casting to unsigned fixes that.
*/
-static INLINE GLint
-repeat_remainder(GLint a, GLint b)
-{
- if (a >= 0)
- return a % b;
- else
- return (a + 1) % b + b - 1;
-}
+#define REMAINDER(A, B) ((unsigned) (A) % (unsigned) (B))
/**
@@ -246,8 +239,8 @@ repeat_remainder(GLint a, GLint b)
I1 = (I0 + 1) & (SIZE - 1); \
} \
else { \
- I0 = repeat_remainder(IFLOOR(U), SIZE); \
- I1 = repeat_remainder(I0 + 1, SIZE); \
+ I0 = REMAINDER(IFLOOR(U), SIZE); \
+ I1 = REMAINDER(I0 + 1, SIZE); \
} \
break; \
case GL_CLAMP_TO_EDGE: \
@@ -366,7 +359,7 @@ repeat_remainder(GLint a, GLint b)
if (img->_IsPowerOfTwo) \
I &= (SIZE - 1); \
else \
- I = repeat_remainder(I, SIZE); \
+ I = REMAINDER(I, SIZE); \
break; \
case GL_CLAMP_TO_EDGE: \
{ \
@@ -1043,7 +1036,7 @@ sample_2d_linear_repeat(GLcontext *ctx,
ASSERT(tObj->WrapS == GL_REPEAT);
ASSERT(tObj->WrapT == GL_REPEAT);
ASSERT(img->Border == 0);
- ASSERT(img->_BaseFormat != GL_COLOR_INDEX);
+ ASSERT(img->TexFormat->BaseFormat != GL_COLOR_INDEX);
ASSERT(img->_IsPowerOfTwo);
COMPUTE_LINEAR_REPEAT_TEXEL_LOCATION(texcoord[0], u, width, i0, i1);
@@ -1198,7 +1191,8 @@ sample_linear_2d( GLcontext *ctx,
(void) lambda;
if (tObj->WrapS == GL_REPEAT &&
tObj->WrapT == GL_REPEAT &&
- image->_IsPowerOfTwo) {
+ image->_IsPowerOfTwo &&
+ image->Border == 0) {
for (i=0;i<n;i++) {
sample_2d_linear_repeat(ctx, tObj, image, texcoords[i], rgba[i]);
}
@@ -1237,7 +1231,7 @@ opt_sample_rgb_2d( GLcontext *ctx,
ASSERT(tObj->WrapS==GL_REPEAT);
ASSERT(tObj->WrapT==GL_REPEAT);
ASSERT(img->Border==0);
- ASSERT(img->_BaseFormat==GL_RGB);
+ ASSERT(img->TexFormat->MesaFormat==MESA_FORMAT_RGB);
ASSERT(img->_IsPowerOfTwo);
for (k=0; k<n; k++) {
@@ -1278,7 +1272,7 @@ opt_sample_rgba_2d( GLcontext *ctx,
ASSERT(tObj->WrapS==GL_REPEAT);
ASSERT(tObj->WrapT==GL_REPEAT);
ASSERT(img->Border==0);
- ASSERT(img->_BaseFormat==GL_RGBA);
+ ASSERT(img->TexFormat->MesaFormat==MESA_FORMAT_RGBA);
ASSERT(img->_IsPowerOfTwo);
for (i = 0; i < n; i++) {
@@ -1308,7 +1302,7 @@ sample_lambda_2d( GLcontext *ctx,
const GLboolean repeatNoBorderPOT = (tObj->WrapS == GL_REPEAT)
&& (tObj->WrapT == GL_REPEAT)
&& (tImg->Border == 0 && (tImg->Width == tImg->RowStride))
- && (tImg->_BaseFormat != GL_COLOR_INDEX)
+ && (tImg->TexFormat->BaseFormat != GL_COLOR_INDEX)
&& tImg->_IsPowerOfTwo;
ASSERT(lambda != NULL);
@@ -1323,16 +1317,10 @@ sample_lambda_2d( GLcontext *ctx,
if (repeatNoBorderPOT) {
switch (tImg->TexFormat->MesaFormat) {
case MESA_FORMAT_RGB:
- case MESA_FORMAT_RGB888:
- /*case MESA_FORMAT_BGR888:*/
opt_sample_rgb_2d(ctx, tObj, m, texcoords + minStart,
NULL, rgba + minStart);
break;
case MESA_FORMAT_RGBA:
- case MESA_FORMAT_RGBA8888:
- case MESA_FORMAT_ARGB8888:
- /*case MESA_FORMAT_ABGR8888:*/
- /*case MESA_FORMAT_BGRA8888:*/
opt_sample_rgba_2d(ctx, tObj, m, texcoords + minStart,
NULL, rgba + minStart);
break;
@@ -1386,16 +1374,10 @@ sample_lambda_2d( GLcontext *ctx,
if (repeatNoBorderPOT) {
switch (tImg->TexFormat->MesaFormat) {
case MESA_FORMAT_RGB:
- case MESA_FORMAT_RGB888:
- /*case MESA_FORMAT_BGR888:*/
opt_sample_rgb_2d(ctx, tObj, m, texcoords + magStart,
NULL, rgba + magStart);
break;
case MESA_FORMAT_RGBA:
- case MESA_FORMAT_RGBA8888:
- case MESA_FORMAT_ARGB8888:
- /*case MESA_FORMAT_ABGR8888:*/
- /*case MESA_FORMAT_BGRA8888:*/
opt_sample_rgba_2d(ctx, tObj, m, texcoords + magStart,
NULL, rgba + magStart);
break;
@@ -1872,8 +1854,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]);
}
}
@@ -1891,6 +1884,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]);
}
@@ -1909,6 +1903,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],
@@ -1937,6 +1932,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],
@@ -2102,7 +2098,7 @@ sample_nearest_rect(GLcontext *ctx,
ASSERT(tObj->WrapT == GL_CLAMP ||
tObj->WrapT == GL_CLAMP_TO_EDGE ||
tObj->WrapT == GL_CLAMP_TO_BORDER);
- ASSERT(img->_BaseFormat != GL_COLOR_INDEX);
+ ASSERT(img->TexFormat->BaseFormat != GL_COLOR_INDEX);
for (i = 0; i < n; i++) {
GLint row, col;
@@ -2138,7 +2134,7 @@ sample_linear_rect(GLcontext *ctx,
ASSERT(tObj->WrapT == GL_CLAMP ||
tObj->WrapT == GL_CLAMP_TO_EDGE ||
tObj->WrapT == GL_CLAMP_TO_BORDER);
- ASSERT(img->_BaseFormat != GL_COLOR_INDEX);
+ ASSERT(img->TexFormat->BaseFormat != GL_COLOR_INDEX);
/* XXX lots of opportunity for optimization in this loop */
for (i = 0; i < n; i++) {
@@ -2880,8 +2876,8 @@ sample_depth_texture( GLcontext *ctx,
(void) lambda;
- ASSERT(tObj->Image[0][tObj->BaseLevel]->_BaseFormat == GL_DEPTH_COMPONENT ||
- tObj->Image[0][tObj->BaseLevel]->_BaseFormat == GL_DEPTH_STENCIL_EXT);
+ ASSERT(img->TexFormat->BaseFormat == GL_DEPTH_COMPONENT ||
+ img->TexFormat->BaseFormat == GL_DEPTH_STENCIL_EXT);
ASSERT(tObj->Target == GL_TEXTURE_1D ||
tObj->Target == GL_TEXTURE_2D ||
@@ -3249,7 +3245,7 @@ sample_depth_texture2(const GLcontext *ctx,
* GL_TEXTURE_COMPARE_SGIX == GL_TRUE but the current texture object
* isn't a depth texture.
*/
- if (texImage->_BaseFormat != GL_DEPTH_COMPONENT) {
+ if (texImage->TexFormat->BaseFormat != GL_DEPTH_COMPONENT) {
_mesa_problem(ctx,"GL_TEXTURE_COMPARE_SGIX enabled with non-depth texture");
return;
}
@@ -3352,7 +3348,7 @@ _swrast_choose_texture_sample_func( GLcontext *ctx,
}
else {
const GLboolean needLambda = (GLboolean) (t->MinFilter != t->MagFilter);
- const GLenum format = t->Image[0][t->BaseLevel]->_BaseFormat;
+ const GLenum format = t->Image[0][t->BaseLevel]->TexFormat->BaseFormat;
switch (t->Target) {
case GL_TEXTURE_1D: