Debian Codegraph @

debian/external_deps/fetk/sg/src/gl/alpha.c

raw
1 /* $Id: alpha.c,v 1.2 2000/10/27 15:21:40 mholst Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 2.2
6 * Copyright (C) 1995-1997 Brian Paul
7 *
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.
12 *
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.
17 *
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.
21 */
22
23 #include "alpha.h"
24 #include "context.h"
25 #include "types.h"
26 #include "dlist.h"
27 #include "macros.h"
28
29
30
31 void gl_AlphaFunc( GLcontext* ctx, GLenum func, GLclampf ref )
32 {
33 if (INSIDE_BEGIN_END(ctx)) {
34 gl_error( ctx, GL_INVALID_OPERATION, "glAlphaFunc" );
35 return;
36 }
37 switch (func) {
38 case GL_NEVER:
39 case GL_LESS:
40 case GL_EQUAL:
41 case GL_LEQUAL:
42 case GL_GREATER:
43 case GL_NOTEQUAL:
44 case GL_GEQUAL:
45 case GL_ALWAYS:
46 ctx->Color.AlphaFunc = func;
47 ctx->Color.AlphaRef = CLAMP( ref, 0.0F, 1.0F );
48 ctx->Color.AlphaRefUbyte = (GLubyte) (ctx->Color.AlphaRef
49 * ctx->Visual->AlphaScale);
50 break;
51 default:
52 gl_error( ctx, GL_INVALID_ENUM, "glAlphaFunc(func)" );
53 break;
54 }
55 }
56
57
58
59
60 /*
61 * Apply the alpha test to a span of pixels.
62 * In/Out: mask - current pixel mask. Pixels which fail the alpha test
63 * will set the corresponding mask flag to 0.
64 * Return: 0 = all pixels in the span failed the alpha test.
65 * 1 = one or more pixels passed the alpha test.
66 */
67 GLint gl_alpha_test( GLcontext* ctx,
68 GLuint n, const GLubyte alpha[], GLubyte mask[] )
69 {
70 GLuint i;
71 GLubyte ref = ctx->Color.AlphaRefUbyte;
72
73 /* switch cases ordered from most frequent to less frequent */
74 switch (ctx->Color.AlphaFunc) {
75 case GL_LESS:
76 for (i=0;i<n;i++) {
77 mask[i] &= (alpha[i] < ref);
78 }
79 return 1;
80 case GL_LEQUAL:
81 for (i=0;i<n;i++) {
82 mask[i] &= (alpha[i] <= ref);
83 }
84 return 1;
85 case GL_GEQUAL:
86 for (i=0;i<n;i++) {
87 mask[i] &= (alpha[i] >= ref);
88 }
89 return 1;
90 case GL_GREATER:
91 for (i=0;i<n;i++) {
92 mask[i] &= (alpha[i] > ref);
93 }
94 return 1;
95 case GL_NOTEQUAL:
96 for (i=0;i<n;i++) {
97 mask[i] &= (alpha[i] != ref);
98 }
99 return 1;
100 case GL_EQUAL:
101 for (i=0;i<n;i++) {
102 mask[i] &= (alpha[i] == ref);
103 }
104 return 1;
105 case GL_ALWAYS:
106 /* do nothing */
107 return 1;
108 case GL_NEVER:
109 /* caller should check for zero! */
110 return 0;
111 default:
112 gl_problem( ctx, "Invalid alpha test in gl_alpha_test" );
113 return 0;
114 }
115 /* Never get here */
116 return 1;
117 }