1 /* $Id: s_alpha.c,v 1.5 2002/01/21 18:12:34 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
->filledMask
== GL_TRUE
);
53 ASSERT (span
->filledAlpha
== GL_TRUE
);
55 SW_SPAN_SET_FLAG(span
->testedAlpha
);
58 /* switch cases ordered from most frequent to less frequent */
59 switch (ctx
->Color
.AlphaFunc
) {
61 for (i
=span
->start
; i
<span
->end
; i
++) {
62 mask
[i
] &= (rgba
[i
][ACOMP
] < ref
);
66 for (i
=span
->start
; i
<span
->end
; i
++)
67 mask
[i
] &= (rgba
[i
][ACOMP
] <= ref
);
70 for (i
=span
->start
; i
<span
->end
; i
++) {
71 mask
[i
] &= (rgba
[i
][ACOMP
] >= ref
);
75 for (i
=span
->start
; i
<span
->end
; i
++) {
76 mask
[i
] &= (rgba
[i
][ACOMP
] > ref
);
80 for (i
=span
->start
; i
<span
->end
; i
++) {
81 mask
[i
] &= (rgba
[i
][ACOMP
] != ref
);
85 for (i
=span
->start
; i
<span
->end
; i
++) {
86 mask
[i
] &= (rgba
[i
][ACOMP
] == ref
);
93 /* caller should check for zero! */
96 _mesa_problem( ctx
, "Invalid alpha test in gl_alpha_test" );
100 while ((span
->start
<= span
->end
) &&
101 (mask
[span
->start
] == 0))
104 while ((span
->end
>= span
->start
) &&
105 (mask
[span
->end
] == 0))
108 span
->writeAll
= GL_FALSE
;
110 if (span
->start
>= span
->end
)
118 * Apply the alpha test to a span of pixels.
119 * In: rgba - array of pixels
120 * In/Out: mask - current pixel mask. Pixels which fail the alpha test
121 * will set the corresponding mask flag to 0.
122 * Return: 0 = all pixels in the span failed the alpha test.
123 * 1 = one or more pixels passed the alpha test.
126 _old_alpha_test( const GLcontext
*ctx
,
127 GLuint n
, CONST GLchan rgba
[][4], GLubyte mask
[] )
130 const GLchan ref
= ctx
->Color
.AlphaRef
;
132 /* switch cases ordered from most frequent to less frequent */
133 switch (ctx
->Color
.AlphaFunc
) {
136 mask
[i
] &= (rgba
[i
][ACOMP
] < ref
);
141 mask
[i
] &= (rgba
[i
][ACOMP
] <= ref
);
145 mask
[i
] &= (rgba
[i
][ACOMP
] >= ref
);
150 mask
[i
] &= (rgba
[i
][ACOMP
] > ref
);
155 mask
[i
] &= (rgba
[i
][ACOMP
] != ref
);
160 mask
[i
] &= (rgba
[i
][ACOMP
] == ref
);
167 /* caller should check for zero! */
170 _mesa_problem( ctx
, "Invalid alpha test in gl_alpha_test" );