1 | /* $Id: alpha.c,v 1.3 2000-05-23 20:40:20 jeroen Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Mesa 3-D graphics library
|
---|
5 | * Version: 3.3
|
---|
6 | *
|
---|
7 | * Copyright (C) 1999 Brian Paul All Rights Reserved.
|
---|
8 | *
|
---|
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:
|
---|
15 | *
|
---|
16 | * The above copyright notice and this permission notice shall be included
|
---|
17 | * in all copies or substantial portions of the Software.
|
---|
18 | *
|
---|
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.
|
---|
25 | */
|
---|
26 | /* $XFree86: xc/lib/GL/mesa/src/alpha.c,v 1.2 1999/04/04 00:20:18 dawes Exp $ */
|
---|
27 |
|
---|
28 |
|
---|
29 |
|
---|
30 | #ifdef PC_HEADER
|
---|
31 | #include "all.h"
|
---|
32 | #else
|
---|
33 | #include "glheader.h"
|
---|
34 | #include "alpha.h"
|
---|
35 | #include "types.h"
|
---|
36 | #include "context.h"
|
---|
37 | #include "macros.h"
|
---|
38 | #include "mmath.h"
|
---|
39 | #endif
|
---|
40 |
|
---|
41 |
|
---|
42 |
|
---|
43 | void
|
---|
44 | _mesa_AlphaFunc( GLenum func, GLclampf ref )
|
---|
45 | {
|
---|
46 | GET_CURRENT_CONTEXT(ctx);
|
---|
47 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glAlphaFunc");
|
---|
48 |
|
---|
49 | switch (func) {
|
---|
50 | case GL_NEVER:
|
---|
51 | case GL_LESS:
|
---|
52 | case GL_EQUAL:
|
---|
53 | case GL_LEQUAL:
|
---|
54 | case GL_GREATER:
|
---|
55 | case GL_NOTEQUAL:
|
---|
56 | case GL_GEQUAL:
|
---|
57 | case GL_ALWAYS:
|
---|
58 | ctx->Color.AlphaFunc = func;
|
---|
59 | if (ref <= 0.0)
|
---|
60 | ctx->Color.AlphaRef = (GLubyte) 0;
|
---|
61 | else if (ref >= 1.0)
|
---|
62 | ctx->Color.AlphaRef = (GLubyte) 255;
|
---|
63 | else
|
---|
64 | CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Color.AlphaRef, ref);
|
---|
65 | if (ctx->Driver.AlphaFunc) {
|
---|
66 | (*ctx->Driver.AlphaFunc)(ctx, func, ctx->Color.AlphaRef);
|
---|
67 | }
|
---|
68 | break;
|
---|
69 | default:
|
---|
70 | gl_error( ctx, GL_INVALID_ENUM, "glAlphaFunc(func)" );
|
---|
71 | break;
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 |
|
---|
77 |
|
---|
78 | /*
|
---|
79 | * Apply the alpha test to a span of pixels.
|
---|
80 | * In: rgba - array of pixels
|
---|
81 | * In/Out: mask - current pixel mask. Pixels which fail the alpha test
|
---|
82 | * will set the corresponding mask flag to 0.
|
---|
83 | * Return: 0 = all pixels in the span failed the alpha test.
|
---|
84 | * 1 = one or more pixels passed the alpha test.
|
---|
85 | */
|
---|
86 | GLint
|
---|
87 | _mesa_alpha_test( const GLcontext* ctx,
|
---|
88 | GLuint n, CONST GLubyte rgba[][4], GLubyte mask[] )
|
---|
89 | {
|
---|
90 | GLuint i;
|
---|
91 | GLubyte ref = ctx->Color.AlphaRef;
|
---|
92 |
|
---|
93 | /* switch cases ordered from most frequent to less frequent */
|
---|
94 | switch (ctx->Color.AlphaFunc) {
|
---|
95 | case GL_LESS:
|
---|
96 | for (i=0;i<n;i++) {
|
---|
97 | mask[i] &= (rgba[i][ACOMP] < ref);
|
---|
98 | }
|
---|
99 | return 1;
|
---|
100 | case GL_LEQUAL:
|
---|
101 | for (i=0;i<n;i++) {
|
---|
102 | mask[i] &= (rgba[i][ACOMP] <= ref);
|
---|
103 | }
|
---|
104 | return 1;
|
---|
105 | case GL_GEQUAL:
|
---|
106 | for (i=0;i<n;i++) {
|
---|
107 | mask[i] &= (rgba[i][ACOMP] >= ref);
|
---|
108 | }
|
---|
109 | return 1;
|
---|
110 | case GL_GREATER:
|
---|
111 | for (i=0;i<n;i++) {
|
---|
112 | mask[i] &= (rgba[i][ACOMP] > ref);
|
---|
113 | }
|
---|
114 | return 1;
|
---|
115 | case GL_NOTEQUAL:
|
---|
116 | for (i=0;i<n;i++) {
|
---|
117 | mask[i] &= (rgba[i][ACOMP] != ref);
|
---|
118 | }
|
---|
119 | return 1;
|
---|
120 | case GL_EQUAL:
|
---|
121 | for (i=0;i<n;i++) {
|
---|
122 | mask[i] &= (rgba[i][ACOMP] == ref);
|
---|
123 | }
|
---|
124 | return 1;
|
---|
125 | case GL_ALWAYS:
|
---|
126 | /* do nothing */
|
---|
127 | return 1;
|
---|
128 | case GL_NEVER:
|
---|
129 | /* caller should check for zero! */
|
---|
130 | return 0;
|
---|
131 | default:
|
---|
132 | gl_problem( ctx, "Invalid alpha test in gl_alpha_test" );
|
---|
133 | return 0;
|
---|
134 | }
|
---|
135 | /* Never get here */
|
---|
136 | /*return 1;*/
|
---|
137 | }
|
---|