Fix ARB_fp spec conformance bug WRT shadow sampling.
authorIan Romanick <idr@us.ibm.com>
Thu, 7 Jun 2007 20:38:06 +0000 (13:38 -0700)
committerIan Romanick <idr@us.ibm.com>
Thu, 7 Jun 2007 20:38:06 +0000 (13:38 -0700)
The ARB_fp (and other assembly-level fragment program specs) say that the
depth comparison function is always GL_NONE in fragment program mode.

src/mesa/main/mtypes.h
src/mesa/main/texstate.c
src/mesa/main/texstate.h
src/mesa/swrast/s_fragprog.c
src/mesa/swrast/s_texfilter.c

index 7397199..6cbbf14 100644 (file)
@@ -1426,6 +1426,10 @@ struct gl_texture_object
    GLfloat ShadowAmbient;       /**< GL_ARB_shadow_ambient */
    GLenum CompareMode;         /**< GL_ARB_shadow */
    GLenum CompareFunc;         /**< GL_ARB_shadow */
+   GLenum _Function;           /**< Comparison function derrived from 
+                                * \c CompareOperator, \c CompareMode, and
+                                * \c CompareFunc.
+                                */
    GLenum DepthMode;           /**< GL_ARB_depth_texture */
    GLint _MaxLevel;            /**< actual max mipmap level (q in the spec) */
    GLfloat _MaxLambda;         /**< = _MaxLevel - BaseLevel (q - b in spec) */
index d15af22..fb02443 100644 (file)
@@ -1178,6 +1178,36 @@ _mesa_TexParameterf( GLenum target, GLenum pname, GLfloat param )
 }
 
 
+/**
+ * Update derrived compare function state.
+ */
+void
+_mesa_update_texture_compare_function(struct gl_texture_object *tObj,
+                                     GLboolean in_frag_prog)
+{
+   if (in_frag_prog) {
+      tObj->_Function = GL_NONE;
+   }
+   else if (tObj->CompareFlag) {
+      /* GL_SGIX_shadow */
+      if (tObj->CompareOperator == GL_TEXTURE_LEQUAL_R_SGIX) {
+         tObj->_Function = GL_LEQUAL;
+      }
+      else {
+         ASSERT(tObj->CompareOperator == GL_TEXTURE_GEQUAL_R_SGIX);
+         tObj->_Function = GL_GEQUAL;
+      }
+   }
+   else if (tObj->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB) {
+      /* GL_ARB_shadow */
+      tObj->_Function = tObj->CompareFunc;
+   }
+   else {
+      tObj->_Function = GL_NONE;  /* pass depth through as grayscale */
+   }
+}
+
+
 void GLAPIENTRY
 _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
 {
@@ -1385,6 +1415,7 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
          if (ctx->Extensions.SGIX_shadow) {
             FLUSH_VERTICES(ctx, _NEW_TEXTURE);
             texObj->CompareFlag = params[0] ? GL_TRUE : GL_FALSE;
+           _mesa_update_texture_compare_function(texObj, GL_FALSE);
          }
          else {
             _mesa_error(ctx, GL_INVALID_ENUM,
@@ -1399,6 +1430,7 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
                 op == GL_TEXTURE_GEQUAL_R_SGIX) {
                FLUSH_VERTICES(ctx, _NEW_TEXTURE);
                texObj->CompareOperator = op;
+              _mesa_update_texture_compare_function(texObj, GL_FALSE);
             }
             else {
                _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(param)");
@@ -1437,6 +1469,7 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
             if (mode == GL_NONE || mode == GL_COMPARE_R_TO_TEXTURE_ARB) {
                FLUSH_VERTICES(ctx, _NEW_TEXTURE);
                texObj->CompareMode = mode;
+              _mesa_update_texture_compare_function(texObj, GL_FALSE);
             }
             else {
                _mesa_error(ctx, GL_INVALID_ENUM,
@@ -1472,6 +1505,8 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
                            "glTexParameter(bad GL_TEXTURE_COMPARE_FUNC_ARB)");
                return;
             }
+
+           _mesa_update_texture_compare_function(texObj, GL_FALSE);
          }
          else {
             _mesa_error(ctx, GL_INVALID_ENUM,
index ca29c6a..df468ec 100644 (file)
@@ -41,6 +41,10 @@ _mesa_copy_texture_state( const GLcontext *src, GLcontext *dst );
 extern void
 _mesa_print_texunit_state( GLcontext *ctx, GLuint unit );
 
+extern void
+_mesa_update_texture_compare_function(struct gl_texture_object *tObj,
+                                     GLboolean in_frag_prog);
+
 
 /**
  * \name Called from API
index e47dbbd..f5ffe41 100644 (file)
@@ -26,6 +26,7 @@
 #include "colormac.h"
 #include "context.h"
 #include "prog_instruction.h"
+#include "texstate.h"
 
 #include "s_fragprog.h"
 #include "s_span.h"
@@ -199,6 +200,7 @@ void
 _swrast_exec_fragment_program( GLcontext *ctx, SWspan *span )
 {
    const struct gl_fragment_program *program = ctx->FragmentProgram._Current;
+   GLuint i;
 
    /* incoming colors should be floats */
    if (program->Base.InputsRead & FRAG_BIT_COL0) {
@@ -207,8 +209,22 @@ _swrast_exec_fragment_program( GLcontext *ctx, SWspan *span )
 
    ctx->_CurrentProgram = GL_FRAGMENT_PROGRAM_ARB; /* or NV, doesn't matter */
 
+   for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
+      if (ctx->Texture.Unit[i]._Current != NULL) {
+         _mesa_update_texture_compare_function(ctx->Texture.Unit[i]._Current,
+                                               GL_TRUE);
+      }
+   }
+
    run_program(ctx, span, 0, span->end);
 
+   for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
+      if (ctx->Texture.Unit[i]._Current != NULL) {
+         _mesa_update_texture_compare_function(ctx->Texture.Unit[i]._Current,
+                                               GL_FALSE);
+      }
+   }
+
    if (program->Base.OutputsWritten & (1 << FRAG_RESULT_COLR)) {
       span->interpMask &= ~SPAN_RGBA;
       span->arrayMask |= SPAN_RGBA;
index 2c8e443..d4516f6 100644 (file)
@@ -2893,25 +2893,7 @@ sample_depth_texture( GLcontext *ctx,
 
    /* XXXX if tObj->MinFilter != tObj->MagFilter, we're ignoring lambda */
 
-   /* XXX this could be precomputed and saved in the texture object */
-   if (tObj->CompareFlag) {
-      /* GL_SGIX_shadow */
-      if (tObj->CompareOperator == GL_TEXTURE_LEQUAL_R_SGIX) {
-         function = GL_LEQUAL;
-      }
-      else {
-         ASSERT(tObj->CompareOperator == GL_TEXTURE_GEQUAL_R_SGIX);
-         function = GL_GEQUAL;
-      }
-   }
-   else if (tObj->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB) {
-      /* GL_ARB_shadow */
-      function = tObj->CompareFunc;
-   }
-   else {
-      function = GL_NONE;  /* pass depth through as grayscale */
-   }
-
+   function = tObj->_Function;
    if (tObj->MagFilter == GL_NEAREST) {
       GLuint i;
       for (i = 0; i < n; i++) {