diff options
author | Brian Paul <[email protected]> | 2002-03-23 16:33:53 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2002-03-23 16:33:53 +0000 |
commit | 636b2801d981872d3111be0cd11aa79b4cc8643b (patch) | |
tree | ab7122796a842806af56f5059db5c28ba8c80ca9 /src | |
parent | 25b85bf02a7b8c0c689b7505a1e4dae7f445a8f2 (diff) |
Test implementation of proposed GL_EXT_shadow_funcs extension. This just
generalizes the R/texture comparision operators to include all eight of
the depth test comparisons.
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/main/extensions.c | 4 | ||||
-rw-r--r-- | src/mesa/main/mtypes.h | 3 | ||||
-rw-r--r-- | src/mesa/main/texstate.c | 12 | ||||
-rw-r--r-- | src/mesa/swrast/s_texture.c | 158 |
4 files changed, 119 insertions, 58 deletions
diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index 9f0542395c8..f9cdf071681 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -1,4 +1,4 @@ -/* $Id: extensions.c,v 1.70 2002/03/13 04:33:16 brianp Exp $ */ +/* $Id: extensions.c,v 1.71 2002/03/23 16:33:53 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -90,6 +90,7 @@ static struct { { ON, "GL_EXT_polygon_offset", F(EXT_polygon_offset) }, { ON, "GL_EXT_rescale_normal", F(EXT_rescale_normal) }, { OFF, "GL_EXT_secondary_color", F(EXT_secondary_color) }, + { OFF, "GL_EXT_shadow_funcs", F(EXT_shadow_funcs) }, { OFF, "GL_EXT_shared_texture_palette", F(EXT_shared_texture_palette) }, { OFF, "GL_EXT_stencil_wrap", F(EXT_stencil_wrap) }, { ON, "GL_EXT_texture3D", F(EXT_texture3D) }, @@ -159,6 +160,7 @@ _mesa_enable_sw_extensions(GLcontext *ctx) "GL_EXT_histogram", "GL_EXT_paletted_texture", "GL_EXT_point_parameters", + "GL_EXT_shadow_funcs", "GL_EXT_secondary_color", "GL_EXT_shared_texture_palette", "GL_EXT_stencil_wrap", diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 807a7b24ccd..a47b472c280 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1,4 +1,4 @@ -/* $Id: mtypes.h,v 1.67 2002/03/16 00:53:15 brianp Exp $ */ +/* $Id: mtypes.h,v 1.68 2002/03/23 16:33:53 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -1408,6 +1408,7 @@ struct gl_extensions { GLboolean EXT_point_parameters; GLboolean EXT_polygon_offset; GLboolean EXT_rescale_normal; + GLboolean EXT_shadow_funcs; GLboolean EXT_secondary_color; GLboolean EXT_shared_texture_palette; GLboolean EXT_stencil_wrap; diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c index 373cfdcce2f..3eadc53e735 100644 --- a/src/mesa/main/texstate.c +++ b/src/mesa/main/texstate.c @@ -1,4 +1,4 @@ -/* $Id: texstate.c,v 1.65 2002/03/23 01:48:18 brianp Exp $ */ +/* $Id: texstate.c,v 1.66 2002/03/23 16:33:53 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -1125,6 +1125,16 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params ) FLUSH_VERTICES(ctx, _NEW_TEXTURE); texObj->CompareFunc = params[0]; } + else if (ctx->Extensions.EXT_shadow_funcs && + (func == GL_EQUAL || + func == GL_NOTEQUAL || + func == GL_LESS || + func == GL_GREATER || + func == GL_ALWAYS || + func == GL_NEVER)) { + FLUSH_VERTICES(ctx, _NEW_TEXTURE); + texObj->CompareFunc = params[0]; + } else { _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(bad GL_TEXTURE_COMPARE_FUNC_ARB)"); diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c index a487bd8970d..e1ba9584177 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.56 2002/03/16 18:02:08 brianp Exp $ */ +/* $Id: s_texture.c,v 1.57 2002/03/23 16:33:53 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -2030,7 +2030,7 @@ sample_depth_texture( GLcontext *ctx, GLuint unit, const GLuint width = texImage->Width; const GLuint height = texImage->Height; const GLchan ambient = tObj->ShadowAmbient; - GLboolean lequal, gequal; + GLenum function; GLchan result; (void) unit; @@ -2044,29 +2044,19 @@ sample_depth_texture( GLcontext *ctx, GLuint unit, if (tObj->CompareFlag) { /* GL_SGIX_shadow */ if (tObj->CompareOperator == GL_TEXTURE_LEQUAL_R_SGIX) { - lequal = GL_TRUE; - gequal = GL_FALSE; + function = GL_LEQUAL; } else { ASSERT(tObj->CompareOperator == GL_TEXTURE_GEQUAL_R_SGIX); - lequal = GL_FALSE; - gequal = GL_TRUE; + function = GL_GEQUAL; } } else if (tObj->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB) { /* GL_ARB_shadow */ - if (tObj->CompareFunc == GL_LEQUAL) { - lequal = GL_TRUE; - gequal = GL_FALSE; - } - else { - ASSERT(tObj->CompareFunc == GL_GEQUAL); - lequal = GL_FALSE; - gequal = GL_TRUE; - } + function = tObj->CompareFunc; } else { - lequal = gequal = GL_FALSE; + function = GL_NONE; /* pass depth through as grayscale */ } if (tObj->MagFilter == GL_NEAREST) { @@ -2078,21 +2068,37 @@ sample_depth_texture( GLcontext *ctx, GLuint unit, COMPUTE_NEAREST_TEXEL_LOCATION(tObj->WrapT, texcoords[i][1], height, row); depthSample = *((const GLfloat *) texImage->Data + row * width + col); - if (lequal) { - if (texcoords[i][2] <= depthSample) - result = CHAN_MAX; - else - result = ambient; - } - else if (gequal) { - if (texcoords[i][2] >= depthSample) - result = CHAN_MAX; - else - result = ambient; - } - else { - /* no comparison */ + switch (function) { + case GL_LEQUAL: + result = (texcoords[i][2] <= depthSample) ? CHAN_MAX : ambient; + break; + case GL_GEQUAL: + result = (texcoords[i][2] >= depthSample) ? CHAN_MAX : ambient; + break; + case GL_LESS: + result = (texcoords[i][2] < depthSample) ? CHAN_MAX : ambient; + break; + case GL_GREATER: + result = (texcoords[i][2] > depthSample) ? CHAN_MAX : ambient; + break; + case GL_EQUAL: + result = (texcoords[i][2] == depthSample) ? CHAN_MAX : ambient; + break; + case GL_NOTEQUAL: + result = (texcoords[i][2] != depthSample) ? CHAN_MAX : ambient; + break; + case GL_ALWAYS: + result = CHAN_MAX; + break; + case GL_NEVER: + result = ambient; + break; + case GL_NONE: CLAMPED_FLOAT_TO_CHAN(result, depthSample); + break; + default: + _mesa_problem(ctx, "Bad compare func in sample_depth_texture"); + return; } switch (tObj->DepthMode) { @@ -2181,8 +2187,8 @@ sample_depth_texture( GLcontext *ctx, GLuint unit, const GLfloat w11 = ( a) * ( b); const GLfloat depthSample = w00 * depth00 + w10 * depth10 + w01 * depth01 + w11 * depth11; - if ((depthSample <= texcoords[i][2] && lequal) || - (depthSample >= texcoords[i][2] && gequal)) { + if ((depthSample <= texcoords[i][2] && function == GL_LEQUAL) || + (depthSample >= texcoords[i][2] && function == GL_GEQUAL)) { result = ambient; } else { @@ -2196,31 +2202,73 @@ sample_depth_texture( GLcontext *ctx, GLuint unit, */ const GLfloat d = (CHAN_MAXF - (GLfloat) ambient) * 0.25F; GLfloat luminance = CHAN_MAXF; - if (lequal) { - if (depth00 <= texcoords[i][2]) luminance -= d; - if (depth01 <= texcoords[i][2]) luminance -= d; - if (depth10 <= texcoords[i][2]) luminance -= d; - if (depth11 <= texcoords[i][2]) luminance -= d; + + switch (function) { + case GL_LEQUAL: + if (depth00 <= texcoords[i][2]) luminance -= d; + if (depth01 <= texcoords[i][2]) luminance -= d; + if (depth10 <= texcoords[i][2]) luminance -= d; + if (depth11 <= texcoords[i][2]) luminance -= d; result = (GLchan) luminance; - } - else if (gequal) { - if (depth00 >= texcoords[i][2]) luminance -= d; - if (depth01 >= texcoords[i][2]) luminance -= d; - if (depth10 >= texcoords[i][2]) luminance -= d; - if (depth11 >= texcoords[i][2]) luminance -= d; + break; + case GL_GEQUAL: + if (depth00 >= texcoords[i][2]) luminance -= d; + if (depth01 >= texcoords[i][2]) luminance -= d; + if (depth10 >= texcoords[i][2]) luminance -= d; + if (depth11 >= texcoords[i][2]) luminance -= d; result = (GLchan) luminance; - } - else { - /* no comparison, just bilinear sampling */ - const GLfloat a = FRAC(u + 1.0F); - const GLfloat b = FRAC(v + 1.0F); - const GLfloat w00 = (1.0F - a) * (1.0F - b); - const GLfloat w10 = ( a) * (1.0F - b); - const GLfloat w01 = (1.0F - a) * ( b); - const GLfloat w11 = ( a) * ( b); - const GLfloat depthSample = w00 * depth00 + w10 * depth10 - + w01 * depth01 + w11 * depth11; - CLAMPED_FLOAT_TO_CHAN(result, depthSample); + break; + case GL_LESS: + if (depth00 < texcoords[i][2]) luminance -= d; + if (depth01 < texcoords[i][2]) luminance -= d; + if (depth10 < texcoords[i][2]) luminance -= d; + if (depth11 < texcoords[i][2]) luminance -= d; + result = (GLchan) luminance; + break; + case GL_GREATER: + if (depth00 > texcoords[i][2]) luminance -= d; + if (depth01 > texcoords[i][2]) luminance -= d; + if (depth10 > texcoords[i][2]) luminance -= d; + if (depth11 > texcoords[i][2]) luminance -= d; + result = (GLchan) luminance; + break; + case GL_EQUAL: + if (depth00 == texcoords[i][2]) luminance -= d; + if (depth01 == texcoords[i][2]) luminance -= d; + if (depth10 == texcoords[i][2]) luminance -= d; + if (depth11 == texcoords[i][2]) luminance -= d; + result = (GLchan) luminance; + break; + case GL_NOTEQUAL: + if (depth00 != texcoords[i][2]) luminance -= d; + if (depth01 != texcoords[i][2]) luminance -= d; + if (depth10 != texcoords[i][2]) luminance -= d; + if (depth11 != texcoords[i][2]) luminance -= d; + result = (GLchan) luminance; + break; + case GL_ALWAYS: + result = 0; + break; + case GL_NEVER: + result = CHAN_MAXF; + break; + case GL_NONE: + /* ordinary bilinear filtering */ + { + const GLfloat a = FRAC(u + 1.0F); + const GLfloat b = FRAC(v + 1.0F); + const GLfloat w00 = (1.0F - a) * (1.0F - b); + const GLfloat w10 = ( a) * (1.0F - b); + const GLfloat w01 = (1.0F - a) * ( b); + const GLfloat w11 = ( a) * ( b); + const GLfloat depthSample = w00 * depth00 + w10 * depth10 + + w01 * depth01 + w11 * depth11; + CLAMPED_FLOAT_TO_CHAN(result, depthSample); + } + break; + default: + _mesa_problem(ctx, "Bad compare func in sample_depth_texture"); + return; } } |