1 /* $Id: s_alpha.c,v 1.12 2002/10/04 19:10:12 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * \file swrast/s_alpha.c
29 * \brief Functions to apply alpha test.
39 #include "s_context.h"
43 * \fn GLint _mesa_alpha_test( const GLcontext *ctx, struct sw_span *span )
44 * \brief Apply the alpha test to a span of pixels.
46 * - "0" = all pixels in the span failed the alpha test.
47 * - "1" = one or more pixels passed the alpha test.
50 _mesa_alpha_test( const GLcontext
*ctx
, struct sw_span
*span
)
52 const GLchan (*rgba
)[4] = (const GLchan (*)[4]) span
->array
->rgba
;
54 const GLuint n
= span
->end
;
55 GLubyte
*mask
= span
->array
->mask
;
58 CLAMPED_FLOAT_TO_CHAN(ref
, ctx
->Color
.AlphaRef
);
60 if (span
->arrayMask
& SPAN_RGBA
) {
61 /* Use the array values */
62 switch (ctx
->Color
.AlphaFunc
) {
64 for (i
= 0; i
< n
; i
++)
65 mask
[i
] &= (rgba
[i
][ACOMP
] < ref
);
68 for (i
= 0; i
< n
; i
++)
69 mask
[i
] &= (rgba
[i
][ACOMP
] <= ref
);
72 for (i
= 0; i
< n
; i
++)
73 mask
[i
] &= (rgba
[i
][ACOMP
] >= ref
);
76 for (i
= 0; i
< n
; i
++)
77 mask
[i
] &= (rgba
[i
][ACOMP
] > ref
);
80 for (i
= 0; i
< n
; i
++)
81 mask
[i
] &= (rgba
[i
][ACOMP
] != ref
);
84 for (i
= 0; i
< n
; i
++)
85 mask
[i
] &= (rgba
[i
][ACOMP
] == ref
);
91 /* caller should check for zero! */
92 span
->writeAll
= GL_FALSE
;
95 _mesa_problem( ctx
, "Invalid alpha test in _mesa_alpha_test" );
100 /* Use the interpolation values */
101 #if CHAN_TYPE == GL_FLOAT
102 const GLfloat alphaStep
= span
->alphaStep
;
103 GLfloat alpha
= span
->alpha
;
104 ASSERT(span
->interpMask
& SPAN_RGBA
);
105 switch (ctx
->Color
.AlphaFunc
) {
107 for (i
= 0; i
< n
; i
++) {
108 mask
[i
] &= (alpha
< ref
);
113 for (i
= 0; i
< n
; i
++) {
114 mask
[i
] &= (alpha
<= ref
);
119 for (i
= 0; i
< n
; i
++) {
120 mask
[i
] &= (alpha
>= ref
);
125 for (i
= 0; i
< n
; i
++) {
126 mask
[i
] &= (alpha
> ref
);
131 for (i
= 0; i
< n
; i
++) {
132 mask
[i
] &= (alpha
!= ref
);
137 for (i
= 0; i
< n
; i
++) {
138 mask
[i
] &= (alpha
== ref
);
146 /* caller should check for zero! */
147 span
->writeAll
= GL_FALSE
;
150 _mesa_problem( ctx
, "Invalid alpha test in gl_alpha_test" );
154 /* 8 or 16-bit channel interpolation */
155 const GLfixed alphaStep
= span
->alphaStep
;
156 GLfixed alpha
= span
->alpha
;
157 ASSERT(span
->interpMask
& SPAN_RGBA
);
158 switch (ctx
->Color
.AlphaFunc
) {
160 for (i
= 0; i
< n
; i
++) {
161 mask
[i
] &= (FixedToChan(alpha
) < ref
);
166 for (i
= 0; i
< n
; i
++) {
167 mask
[i
] &= (FixedToChan(alpha
) <= ref
);
172 for (i
= 0; i
< n
; i
++) {
173 mask
[i
] &= (FixedToChan(alpha
) >= ref
);
178 for (i
= 0; i
< n
; i
++) {
179 mask
[i
] &= (FixedToChan(alpha
) > ref
);
184 for (i
= 0; i
< n
; i
++) {
185 mask
[i
] &= (FixedToChan(alpha
) != ref
);
190 for (i
= 0; i
< n
; i
++) {
191 mask
[i
] &= (FixedToChan(alpha
) == ref
);
199 /* caller should check for zero! */
200 span
->writeAll
= GL_FALSE
;
203 _mesa_problem( ctx
, "Invalid alpha test in gl_alpha_test" );
206 #endif /* CHAN_TYPE */
210 /* XXXX This causes conformance failures!!!! */
211 while ((span
->start
<= span
->end
) &&
212 (mask
[span
->start
] == 0))
215 while ((span
->end
>= span
->start
) &&
216 (mask
[span
->end
] == 0))
220 span
->writeAll
= GL_FALSE
;
222 if (span
->start
>= span
->end
)