1 /* $Id: s_alpha.c,v 1.7 2002/01/28 00:07:33 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.
38 * Apply the alpha test to a span of pixels.
39 * In: rgba - array of pixels
41 * Return: 0 = all pixels in the span failed the alpha test.
42 * 1 = one or more pixels passed the alpha test.
45 _mesa_alpha_test( const GLcontext
*ctx
, struct sw_span
*span
,
46 CONST GLchan rgba
[][4])
49 const GLchan ref
= ctx
->Color
.AlphaRef
;
50 GLubyte
*mask
= span
->mask
;
52 ASSERT(span
->arrayMask
& SPAN_RGBA
);
54 /* switch cases ordered from most frequent to less frequent */
55 switch (ctx
->Color
.AlphaFunc
) {
57 for (i
=span
->start
; i
<span
->end
; i
++) {
58 mask
[i
] &= (rgba
[i
][ACOMP
] < ref
);
62 for (i
=span
->start
; i
<span
->end
; i
++)
63 mask
[i
] &= (rgba
[i
][ACOMP
] <= ref
);
66 for (i
=span
->start
; i
<span
->end
; i
++) {
67 mask
[i
] &= (rgba
[i
][ACOMP
] >= ref
);
71 for (i
=span
->start
; i
<span
->end
; i
++) {
72 mask
[i
] &= (rgba
[i
][ACOMP
] > ref
);
76 for (i
=span
->start
; i
<span
->end
; i
++) {
77 mask
[i
] &= (rgba
[i
][ACOMP
] != ref
);
81 for (i
=span
->start
; i
<span
->end
; i
++) {
82 mask
[i
] &= (rgba
[i
][ACOMP
] == ref
);
89 /* caller should check for zero! */
92 _mesa_problem( ctx
, "Invalid alpha test in gl_alpha_test" );
97 /* XXXX This causes conformance failures!!!! */
98 while ((span
->start
<= span
->end
) &&
99 (mask
[span
->start
] == 0))
102 while ((span
->end
>= span
->start
) &&
103 (mask
[span
->end
] == 0))
106 span
->writeAll
= GL_FALSE
;
108 if (span
->start
>= span
->end
)
116 * Apply the alpha test to a span of pixels.
117 * In: rgba - array of pixels
118 * In/Out: mask - current pixel mask. Pixels which fail the alpha test
119 * will set the corresponding mask flag to 0.
120 * Return: 0 = all pixels in the span failed the alpha test.
121 * 1 = one or more pixels passed the alpha test.
124 _old_alpha_test( const GLcontext
*ctx
,
125 GLuint n
, CONST GLchan rgba
[][4], GLubyte mask
[] )
128 const GLchan ref
= ctx
->Color
.AlphaRef
;
130 /* switch cases ordered from most frequent to less frequent */
131 switch (ctx
->Color
.AlphaFunc
) {
134 mask
[i
] &= (rgba
[i
][ACOMP
] < ref
);
139 mask
[i
] &= (rgba
[i
][ACOMP
] <= ref
);
143 mask
[i
] &= (rgba
[i
][ACOMP
] >= ref
);
148 mask
[i
] &= (rgba
[i
][ACOMP
] > ref
);
153 mask
[i
] &= (rgba
[i
][ACOMP
] != ref
);
158 mask
[i
] &= (rgba
[i
][ACOMP
] == ref
);
165 /* caller should check for zero! */
168 _mesa_problem( ctx
, "Invalid alpha test in gl_alpha_test" );