1 /* $Id: alpha.c,v 1.5 1997/07/24 01:24:28 brianp Exp $ */
4 * Mesa 3-D graphics library
6 * Copyright (C) 1995-1997 Brian Paul
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * Revision 1.5 1997/07/24 01:24:28 brianp
27 * changed precompiled header symbol from PCH to PC_HEADER
29 * Revision 1.4 1997/05/28 03:23:09 brianp
30 * added precompiled header (PCH) support
32 * Revision 1.3 1997/03/13 03:07:53 brianp
33 * optimized gl_alpha_test() by removing conditional from inside loops
35 * Revision 1.2 1996/09/15 14:15:54 brianp
36 * now use GLframebuffer and GLvisual
38 * Revision 1.1 1996/09/13 01:38:16 brianp
56 void gl_AlphaFunc( GLcontext
* ctx
, GLenum func
, GLclampf ref
)
58 if (INSIDE_BEGIN_END(ctx
)) {
59 gl_error( ctx
, GL_INVALID_OPERATION
, "glAlphaFunc" );
71 ctx
->Color
.AlphaFunc
= func
;
72 ctx
->Color
.AlphaRef
= CLAMP( ref
, 0.0F
, 1.0F
);
73 ctx
->Color
.AlphaRefUbyte
= (GLubyte
) (ctx
->Color
.AlphaRef
74 * ctx
->Visual
->AlphaScale
);
77 gl_error( ctx
, GL_INVALID_ENUM
, "glAlphaFunc(func)" );
86 * Apply the alpha test to a span of pixels.
87 * In/Out: mask - current pixel mask. Pixels which fail the alpha test
88 * will set the corresponding mask flag to 0.
89 * Return: 0 = all pixels in the span failed the alpha test.
90 * 1 = one or more pixels passed the alpha test.
92 GLint
gl_alpha_test( GLcontext
* ctx
,
93 GLuint n
, const GLubyte alpha
[], GLubyte mask
[] )
96 GLubyte ref
= ctx
->Color
.AlphaRefUbyte
;
98 /* switch cases ordered from most frequent to less frequent */
99 switch (ctx
->Color
.AlphaFunc
) {
102 mask
[i
] &= (alpha
[i
] < ref
);
107 mask
[i
] &= (alpha
[i
] <= ref
);
112 mask
[i
] &= (alpha
[i
] >= ref
);
117 mask
[i
] &= (alpha
[i
] > ref
);
122 mask
[i
] &= (alpha
[i
] != ref
);
127 mask
[i
] &= (alpha
[i
] == ref
);
134 /* caller should check for zero! */
137 gl_problem( ctx
, "Invalid alpha test in gl_alpha_test" );