fix ugly bug triggered by macro expansion
[mesa.git] / src / mesa / swrast / s_alpha.c
index d44bdb63eb9dda61018543078a930c87aa4dcb65..55c1e6a58f8621cfa55c4a76634c8798e48ffef2 100644 (file)
@@ -1,4 +1,3 @@
-/* $Id: s_alpha.c,v 1.8 2002/01/31 00:27:43 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+/**
+ * \file swrast/s_alpha.c
+ * \brief Functions to apply alpha test.
+ */
 
 #include "glheader.h"
 #include "context.h"
 #include "colormac.h"
 #include "macros.h"
-#include "mmath.h"
 
 #include "s_alpha.h"
 #include "s_context.h"
 
 
-/*
- * Apply the alpha test to a span of pixels.
- * In:  rgba - array of pixels
- * In/Out:  span -
- * Return:  0 = all pixels in the span failed the alpha test.
- *          1 = one or more pixels passed the alpha test.
+/**
+ * \fn GLint _swrast_alpha_test( const GLcontext *ctx, struct sw_span *span )
+ * \brief Apply the alpha test to a span of pixels.
+ * \return
+ *      - "0" = all pixels in the span failed the alpha test.
+ *      - "1" = one or more pixels passed the alpha test.
  */
 GLint
-_mesa_alpha_test( const GLcontext *ctx, struct sw_span *span )
+_swrast_alpha_test( const GLcontext *ctx, struct sw_span *span )
 {
-   const GLchan (*rgba)[4] = (const GLchan (*)[4]) span->color.rgba;
-   const GLchan ref = ctx->Color.AlphaRef;
+   const GLchan (*rgba)[4] = (const GLchan (*)[4]) span->array->rgba;
+   GLchan ref;
    const GLuint n = span->end;
-   GLubyte *mask = span->mask;
+   GLubyte *mask = span->array->mask;
    GLuint i;
 
+   CLAMPED_FLOAT_TO_CHAN(ref, ctx->Color.AlphaRef);
+
    if (span->arrayMask & SPAN_RGBA) {
       /* Use the array values */
       switch (ctx->Color.AlphaFunc) {
@@ -86,7 +90,7 @@ _mesa_alpha_test( const GLcontext *ctx, struct sw_span *span )
             span->writeAll = GL_FALSE;
             return 0;
          default:
-            _mesa_problem( ctx, "Invalid alpha test in _mesa_alpha_test" );
+            _mesa_problem( ctx, "Invalid alpha test in _swrast_alpha_test" );
             return 0;
       }
    }
@@ -218,64 +222,3 @@ _mesa_alpha_test( const GLcontext *ctx, struct sw_span *span )
    else
      return 1;
 }
-
-
-/*
- * Apply the alpha test to a span of pixels.
- * In:  rgba - array of pixels
- * In/Out:  mask - current pixel mask.  Pixels which fail the alpha test
- *                 will set the corresponding mask flag to 0.
- * Return:  0 = all pixels in the span failed the alpha test.
- *          1 = one or more pixels passed the alpha test.
- */
-GLint
-_old_alpha_test( const GLcontext *ctx,
-                 GLuint n, CONST GLchan rgba[][4], GLubyte mask[] )
-{
-   GLuint i;
-   const GLchan ref = ctx->Color.AlphaRef;
-
-   /* switch cases ordered from most frequent to less frequent */
-   switch (ctx->Color.AlphaFunc) {
-      case GL_LESS:
-         for (i=0;i<n;i++) {
-           mask[i] &= (rgba[i][ACOMP] < ref);
-        }
-        return 1;
-      case GL_LEQUAL:
-         for (i=0;i<n;i++)
-           mask[i] &= (rgba[i][ACOMP] <= ref);
-        return 1;
-      case GL_GEQUAL:
-         for (i=0;i<n;i++) {
-           mask[i] &= (rgba[i][ACOMP] >= ref);
-        }
-        return 1;
-      case GL_GREATER:
-         for (i=0;i<n;i++) {
-           mask[i] &= (rgba[i][ACOMP] > ref);
-        }
-        return 1;
-      case GL_NOTEQUAL:
-         for (i=0;i<n;i++) {
-           mask[i] &= (rgba[i][ACOMP] != ref);
-        }
-        return 1;
-      case GL_EQUAL:
-         for (i=0;i<n;i++) {
-           mask[i] &= (rgba[i][ACOMP] == ref);
-        }
-        return 1;
-      case GL_ALWAYS:
-        /* do nothing */
-        return 1;
-      case GL_NEVER:
-         /* caller should check for zero! */
-        return 0;
-      default:
-        _mesa_problem( ctx, "Invalid alpha test in gl_alpha_test" );
-         return 0;
-   }
-   /* Never get here */
-   /*return 1;*/
-}