summaryrefslogtreecommitdiff
path: root/src/mesa/swrast
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2010-03-23 17:55:41 -0600
committerBrian Paul <brianp@vmware.com>2010-03-23 17:55:43 -0600
commit2b5de09b3ea8754fb004d4f216bca29303f99490 (patch)
tree677402b55f79bae9beb5145c71f5a7aa3286c33b /src/mesa/swrast
parent8ba47561dd45e1cd737992544545d7fa0f61918b (diff)
swrast: improve depth texture mipmap selection
We still don't do proper min/mag filtering but this is better than just sampling the base mipmap level all the time. Fixes piglit depth-level-clamp test. Fixes fd.o bug 27256.
Diffstat (limited to 'src/mesa/swrast')
-rw-r--r--src/mesa/swrast/s_texfilter.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/src/mesa/swrast/s_texfilter.c b/src/mesa/swrast/s_texfilter.c
index 997c2f4bb7..3fc554c5a2 100644
--- a/src/mesa/swrast/s_texfilter.c
+++ b/src/mesa/swrast/s_texfilter.c
@@ -488,14 +488,15 @@ 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
nearest_texcoord(const struct gl_texture_object *texObj,
+ GLuint level,
const GLfloat texcoord[4],
GLint *i, GLint *j, GLint *k)
{
- const GLint baseLevel = texObj->BaseLevel;
- const struct gl_texture_image *img = texObj->Image[0][baseLevel];
+ const struct gl_texture_image *img = texObj->Image[0][level];
const GLint width = img->Width;
const GLint height = img->Height;
const GLint depth = img->Depth;
@@ -534,15 +535,16 @@ nearest_texcoord(const struct gl_texture_object *texObj,
/**
* Compute linear integer texcoords for given texobj and coordinate.
+ * NOTE: only used for depth texture sampling.
*/
static INLINE void
linear_texcoord(const struct gl_texture_object *texObj,
+ GLuint level,
const GLfloat texcoord[4],
GLint *i0, GLint *i1, GLint *j0, GLint *j1, GLint *slice,
GLfloat *wi, GLfloat *wj)
{
- const GLint baseLevel = texObj->BaseLevel;
- const struct gl_texture_image *img = texObj->Image[0][baseLevel];
+ const struct gl_texture_image *img = texObj->Image[0][level];
const GLint width = img->Width;
const GLint height = img->Height;
const GLint depth = img->Depth;
@@ -2963,7 +2965,26 @@ shadow_compare4(GLenum function, GLfloat coord,
/**
- * Sample a shadow/depth texture.
+ * Choose the mipmap level to use when sampling from a depth texture.
+ */
+static int
+choose_depth_texture_level(const struct gl_texture_object *tObj, GLfloat lambda)
+{
+ GLint level;
+
+ lambda = CLAMP(lambda, tObj->MinLod, tObj->MaxLod);
+
+ level = (GLint) lambda;
+
+ level = CLAMP(level, tObj->BaseLevel, tObj->_MaxLevel);
+
+ return level;
+}
+
+
+/**
+ * Sample a shadow/depth texture. This function is incomplete. It doesn't
+ * check for minification vs. magnification, etc.
*/
static void
sample_depth_texture( GLcontext *ctx,
@@ -2971,8 +2992,8 @@ sample_depth_texture( GLcontext *ctx,
const GLfloat texcoords[][4], const GLfloat lambda[],
GLfloat texel[][4] )
{
- const GLint baseLevel = tObj->BaseLevel;
- const struct gl_texture_image *img = tObj->Image[0][baseLevel];
+ const GLint level = choose_depth_texture_level(tObj, lambda[0]);
+ const struct gl_texture_image *img = tObj->Image[0][level];
const GLint width = img->Width;
const GLint height = img->Height;
const GLint depth = img->Depth;
@@ -2982,8 +3003,6 @@ sample_depth_texture( GLcontext *ctx,
GLenum function;
GLfloat result;
- (void) lambda;
-
ASSERT(img->_BaseFormat == GL_DEPTH_COMPONENT ||
img->_BaseFormat == GL_DEPTH_STENCIL_EXT);
@@ -3006,7 +3025,7 @@ sample_depth_texture( GLcontext *ctx,
GLfloat depthSample;
GLint col, row, slice;
- nearest_texcoord(tObj, texcoords[i], &col, &row, &slice);
+ nearest_texcoord(tObj, level, texcoords[i], &col, &row, &slice);
if (col >= 0 && row >= 0 && col < width && row < height &&
slice >= 0 && slice < depth) {
@@ -3044,7 +3063,7 @@ sample_depth_texture( GLcontext *ctx,
GLfloat wi, wj;
GLuint useBorderTexel;
- linear_texcoord(tObj, texcoords[i], &i0, &i1, &j0, &j1, &slice,
+ linear_texcoord(tObj, level, texcoords[i], &i0, &i1, &j0, &j1, &slice,
&wi, &wj);
useBorderTexel = 0;