35ec7e9dcce91939b34188aeab99584549b81d72
1 /* $Id: s_alpha.c,v 1.13 2003/03/01 01:50:25 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.
38 #include "s_context.h"
42 * \fn GLint _mesa_alpha_test( const GLcontext *ctx, struct sw_span *span )
43 * \brief Apply the alpha test to a span of pixels.
45 * - "0" = all pixels in the span failed the alpha test.
46 * - "1" = one or more pixels passed the alpha test.
49 _mesa_alpha_test( const GLcontext
*ctx
, struct sw_span
*span
)
51 const GLchan (*rgba
)[4] = (const GLchan (*)[4]) span
->array
->rgba
;
53 const GLuint n
= span
->end
;
54 GLubyte
*mask
= span
->array
->mask
;
57 CLAMPED_FLOAT_TO_CHAN(ref
, ctx
->Color
.AlphaRef
);
59 if (span
->arrayMask
& SPAN_RGBA
) {
60 /* Use the array values */
61 switch (ctx
->Color
.AlphaFunc
) {
63 for (i
= 0; i
< n
; i
++)
64 mask
[i
] &= (rgba
[i
][ACOMP
] < ref
);
67 for (i
= 0; i
< n
; i
++)
68 mask
[i
] &= (rgba
[i
][ACOMP
] <= ref
);
71 for (i
= 0; i
< n
; i
++)
72 mask
[i
] &= (rgba
[i
][ACOMP
] >= ref
);
75 for (i
= 0; i
< n
; i
++)
76 mask
[i
] &= (rgba
[i
][ACOMP
] > ref
);
79 for (i
= 0; i
< n
; i
++)
80 mask
[i
] &= (rgba
[i
][ACOMP
] != ref
);
83 for (i
= 0; i
< n
; i
++)
84 mask
[i
] &= (rgba
[i
][ACOMP
] == ref
);
90 /* caller should check for zero! */
91 span
->writeAll
= GL_FALSE
;
94 _mesa_problem( ctx
, "Invalid alpha test in _mesa_alpha_test" );
99 /* Use the interpolation values */
100 #if CHAN_TYPE == GL_FLOAT
101 const GLfloat alphaStep
= span
->alphaStep
;
102 GLfloat alpha
= span
->alpha
;
103 ASSERT(span
->interpMask
& SPAN_RGBA
);
104 switch (ctx
->Color
.AlphaFunc
) {
106 for (i
= 0; i
< n
; i
++) {
107 mask
[i
] &= (alpha
< ref
);
112 for (i
= 0; i
< n
; i
++) {
113 mask
[i
] &= (alpha
<= ref
);
118 for (i
= 0; i
< n
; i
++) {
119 mask
[i
] &= (alpha
>= ref
);
124 for (i
= 0; i
< n
; i
++) {
125 mask
[i
] &= (alpha
> ref
);
130 for (i
= 0; i
< n
; i
++) {
131 mask
[i
] &= (alpha
!= ref
);
136 for (i
= 0; i
< n
; i
++) {
137 mask
[i
] &= (alpha
== ref
);
145 /* caller should check for zero! */
146 span
->writeAll
= GL_FALSE
;
149 _mesa_problem( ctx
, "Invalid alpha test in gl_alpha_test" );
153 /* 8 or 16-bit channel interpolation */
154 const GLfixed alphaStep
= span
->alphaStep
;
155 GLfixed alpha
= span
->alpha
;
156 ASSERT(span
->interpMask
& SPAN_RGBA
);
157 switch (ctx
->Color
.AlphaFunc
) {
159 for (i
= 0; i
< n
; i
++) {
160 mask
[i
] &= (FixedToChan(alpha
) < ref
);
165 for (i
= 0; i
< n
; i
++) {
166 mask
[i
] &= (FixedToChan(alpha
) <= ref
);
171 for (i
= 0; i
< n
; i
++) {
172 mask
[i
] &= (FixedToChan(alpha
) >= ref
);
177 for (i
= 0; i
< n
; i
++) {
178 mask
[i
] &= (FixedToChan(alpha
) > ref
);
183 for (i
= 0; i
< n
; i
++) {
184 mask
[i
] &= (FixedToChan(alpha
) != ref
);
189 for (i
= 0; i
< n
; i
++) {
190 mask
[i
] &= (FixedToChan(alpha
) == ref
);
198 /* caller should check for zero! */
199 span
->writeAll
= GL_FALSE
;
202 _mesa_problem( ctx
, "Invalid alpha test in gl_alpha_test" );
205 #endif /* CHAN_TYPE */
209 /* XXXX This causes conformance failures!!!! */
210 while ((span
->start
<= span
->end
) &&
211 (mask
[span
->start
] == 0))
214 while ((span
->end
>= span
->start
) &&
215 (mask
[span
->end
] == 0))
219 span
->writeAll
= GL_FALSE
;
221 if (span
->start
>= span
->end
)