st/mesa: only set up sampler compare mode for depth textures

The GL_ARB_shadow spec says the shadow compare mode should have no
effect when sampling a color texture.  As it was, it was up to
drivers to check for that (softpipe, llvmpipe, svga and probably
the rest don't do that).  Note: it looks like DX10 allows shadow
compare with some non-depth formats, so this case really should be
handled in the state tracker.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
This commit is contained in:
Brian Paul 2013-12-13 09:52:15 -07:00
parent 31b0e7d024
commit 19fa540219
1 changed files with 12 additions and 9 deletions

View File

@ -133,12 +133,17 @@ convert_sampler(struct st_context *st,
const struct gl_texture_object *texobj;
struct gl_context *ctx = st->ctx;
struct gl_sampler_object *msamp;
const struct gl_texture_image *teximg;
GLenum texBaseFormat;
texobj = ctx->Texture.Unit[texUnit]._Current;
if (!texobj) {
texobj = _mesa_get_fallback_texture(ctx, TEXTURE_2D_INDEX);
}
teximg = texobj->Image[0][texobj->BaseLevel];
texBaseFormat = teximg ? teximg->_BaseFormat : GL_RGBA;
msamp = _mesa_get_samplerobj(ctx, texUnit);
memset(sampler, 0, sizeof(*sampler));
@ -176,12 +181,9 @@ convert_sampler(struct st_context *st,
msamp->BorderColor.ui[2] ||
msamp->BorderColor.ui[3]) {
const struct st_texture_object *stobj = st_texture_object_const(texobj);
const struct gl_texture_image *teximg;
const GLboolean is_integer = texobj->_IsIntegerFormat;
union pipe_color_union border_color;
teximg = texobj->Image[0][texobj->BaseLevel];
if (st->apply_texture_swizzle_to_border_color && stobj->sampler_view) {
const unsigned char swz[4] =
{
@ -193,25 +195,26 @@ convert_sampler(struct st_context *st,
st_translate_color(&msamp->BorderColor,
&border_color,
teximg ? teximg->_BaseFormat : GL_RGBA, is_integer);
texBaseFormat, is_integer);
util_format_apply_color_swizzle(&sampler->border_color,
&border_color, swz, is_integer);
} else {
st_translate_color(&msamp->BorderColor,
&sampler->border_color,
teximg ? teximg->_BaseFormat : GL_RGBA, is_integer);
texBaseFormat, is_integer);
}
}
sampler->max_anisotropy = (msamp->MaxAnisotropy == 1.0 ?
0 : (GLuint) msamp->MaxAnisotropy);
/* only care about ARB_shadow, not SGI shadow */
if (msamp->CompareMode == GL_COMPARE_R_TO_TEXTURE) {
/* If sampling a depth texture and using shadow comparison */
if ((texBaseFormat == GL_DEPTH_COMPONENT ||
texBaseFormat == GL_DEPTH_STENCIL) &&
msamp->CompareMode == GL_COMPARE_R_TO_TEXTURE) {
sampler->compare_mode = PIPE_TEX_COMPARE_R_TO_TEXTURE;
sampler->compare_func
= st_compare_func_to_pipe(msamp->CompareFunc);
sampler->compare_func = st_compare_func_to_pipe(msamp->CompareFunc);
}
sampler->seamless_cube_map =