source: trunk/src/opengl/mesa/alpha.c@ 3080

Last change on this file since 3080 was 2962, checked in by jeroen, 25 years ago

* empty log message *

File size: 3.9 KB
Line 
1/* $Id: alpha.c,v 1.2 2000-03-01 18:49:22 jeroen Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version: 3.1
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#ifndef XFree86Server
34#else
35#include "GL/xf86glx.h"
36#endif
37#include "alpha.h"
38#include "types.h"
39#include "context.h"
40#include "macros.h"
41#include "mmath.h"
42#endif
43
44
45
46void gl_AlphaFunc( GLcontext* ctx, GLenum func, GLclampf ref )
47{
48 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glAlphaFunc");
49
50 switch (func) {
51 case GL_NEVER:
52 case GL_LESS:
53 case GL_EQUAL:
54 case GL_LEQUAL:
55 case GL_GREATER:
56 case GL_NOTEQUAL:
57 case GL_GEQUAL:
58 case GL_ALWAYS:
59 ctx->Color.AlphaFunc = func;
60 if (ref <= 0.0)
61 ctx->Color.AlphaRef = (GLubyte) 0;
62 else if (ref >= 1.0)
63 ctx->Color.AlphaRef = (GLubyte) 255;
64 else
65 CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Color.AlphaRef, ref);
66 if (ctx->Driver.AlphaFunc) {
67 (*ctx->Driver.AlphaFunc)(ctx, func, ctx->Color.AlphaRef);
68 }
69 break;
70 default:
71 gl_error( ctx, GL_INVALID_ENUM, "glAlphaFunc(func)" );
72 break;
73 }
74}
75
76
77
78
79/*
80 * Apply the alpha test to a span of pixels.
81 * In: rgba - array of pixels
82 * In/Out: mask - current pixel mask. Pixels which fail the alpha test
83 * will set the corresponding mask flag to 0.
84 * Return: 0 = all pixels in the span failed the alpha test.
85 * 1 = one or more pixels passed the alpha test.
86 */
87GLint gl_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}
Note: See TracBrowser for help on using the repository browser.