3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * \file swrast/s_alpha.c
28 * \brief Functions to apply alpha test.
37 #include "s_context.h"
41 * \fn GLint _swrast_alpha_test( const GLcontext *ctx, struct sw_span *span )
42 * \brief Apply the alpha test to a span of pixels.
44 * - "0" = all pixels in the span failed the alpha test.
45 * - "1" = one or more pixels passed the alpha test.
48 _swrast_alpha_test( const GLcontext
*ctx
, struct sw_span
*span
)
50 const GLchan (*rgba
)[4] = (const GLchan (*)[4]) span
->array
->rgba
;
52 const GLuint n
= span
->end
;
53 GLubyte
*mask
= span
->array
->mask
;
56 CLAMPED_FLOAT_TO_CHAN(ref
, ctx
->Color
.AlphaRef
);
58 if (span
->arrayMask
& SPAN_RGBA
) {
59 /* Use the array values */
60 switch (ctx
->Color
.AlphaFunc
) {
62 for (i
= 0; i
< n
; i
++)
63 mask
[i
] &= (rgba
[i
][ACOMP
] < ref
);
66 for (i
= 0; i
< n
; i
++)
67 mask
[i
] &= (rgba
[i
][ACOMP
] <= ref
);
70 for (i
= 0; i
< n
; i
++)
71 mask
[i
] &= (rgba
[i
][ACOMP
] >= ref
);
74 for (i
= 0; i
< n
; i
++)
75 mask
[i
] &= (rgba
[i
][ACOMP
] > ref
);
78 for (i
= 0; i
< n
; i
++)
79 mask
[i
] &= (rgba
[i
][ACOMP
] != ref
);
82 for (i
= 0; i
< n
; i
++)
83 mask
[i
] &= (rgba
[i
][ACOMP
] == ref
);
89 /* caller should check for zero! */
90 span
->writeAll
= GL_FALSE
;
93 _mesa_problem( ctx
, "Invalid alpha test in _swrast_alpha_test" );
98 /* Use the interpolation values */
99 #if CHAN_TYPE == GL_FLOAT
100 const GLfloat alphaStep
= span
->alphaStep
;
101 GLfloat alpha
= span
->alpha
;
102 ASSERT(span
->interpMask
& SPAN_RGBA
);
103 switch (ctx
->Color
.AlphaFunc
) {
105 for (i
= 0; i
< n
; i
++) {
106 mask
[i
] &= (alpha
< ref
);
111 for (i
= 0; i
< n
; i
++) {
112 mask
[i
] &= (alpha
<= ref
);
117 for (i
= 0; i
< n
; i
++) {
118 mask
[i
] &= (alpha
>= ref
);
123 for (i
= 0; i
< n
; i
++) {
124 mask
[i
] &= (alpha
> ref
);
129 for (i
= 0; i
< n
; i
++) {
130 mask
[i
] &= (alpha
!= ref
);
135 for (i
= 0; i
< n
; i
++) {
136 mask
[i
] &= (alpha
== ref
);
144 /* caller should check for zero! */
145 span
->writeAll
= GL_FALSE
;
148 _mesa_problem( ctx
, "Invalid alpha test in gl_alpha_test" );
152 /* 8 or 16-bit channel interpolation */
153 const GLfixed alphaStep
= span
->alphaStep
;
154 GLfixed alpha
= span
->alpha
;
155 ASSERT(span
->interpMask
& SPAN_RGBA
);
156 switch (ctx
->Color
.AlphaFunc
) {
158 for (i
= 0; i
< n
; i
++) {
159 mask
[i
] &= (FixedToChan(alpha
) < ref
);
164 for (i
= 0; i
< n
; i
++) {
165 mask
[i
] &= (FixedToChan(alpha
) <= ref
);
170 for (i
= 0; i
< n
; i
++) {
171 mask
[i
] &= (FixedToChan(alpha
) >= ref
);
176 for (i
= 0; i
< n
; i
++) {
177 mask
[i
] &= (FixedToChan(alpha
) > ref
);
182 for (i
= 0; i
< n
; i
++) {
183 mask
[i
] &= (FixedToChan(alpha
) != ref
);
188 for (i
= 0; i
< n
; i
++) {
189 mask
[i
] &= (FixedToChan(alpha
) == ref
);
197 /* caller should check for zero! */
198 span
->writeAll
= GL_FALSE
;
201 _mesa_problem( ctx
, "Invalid alpha test in gl_alpha_test" );
204 #endif /* CHAN_TYPE */
208 /* XXXX This causes conformance failures!!!! */
209 while ((span
->start
<= span
->end
) &&
210 (mask
[span
->start
] == 0))
213 while ((span
->end
>= span
->start
) &&
214 (mask
[span
->end
] == 0))
218 span
->writeAll
= GL_FALSE
;
220 if (span
->start
>= span
->end
)