xref: /reactos/dll/opengl/mesa/masking.c (revision 5f2bebf7)
1 /* $Id: masking.c,v 1.5 1997/07/24 01:23:16 brianp Exp $ */
2 
3 /*
4  * Mesa 3-D graphics library
5  * Version:  2.4
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 
24 /*
25  * $Log: masking.c,v $
26  * Revision 1.5  1997/07/24 01:23:16  brianp
27  * changed precompiled header symbol from PCH to PC_HEADER
28  *
29  * Revision 1.4  1997/05/28 03:25:43  brianp
30  * added precompiled header (PCH) support
31  *
32  * Revision 1.3  1996/11/06 04:19:40  brianp
33  * now call gl_read_color/index_span() instead of device driver function
34  *
35  * Revision 1.2  1996/10/25 00:07:46  brianp
36  * changed MAX_WIDTH to PB_SIZE in gl_mask_index_pixels()
37  *
38  * Revision 1.1  1996/09/13 01:38:16  brianp
39  * Initial revision
40  *
41  */
42 
43 
44 /*
45  * Implement the effect of glColorMask and glIndexMask in software.
46  */
47 
48 
49 #ifdef PC_HEADER
50 #include "all.h"
51 #else
52 #include <string.h>
53 #include "alphabuf.h"
54 #include "context.h"
55 #include "macros.h"
56 #include "masking.h"
57 #include "pb.h"
58 #include "span.h"
59 #include "types.h"
60 #endif
61 
62 
63 
gl_IndexMask(GLcontext * ctx,GLuint mask)64 void gl_IndexMask( GLcontext *ctx, GLuint mask )
65 {
66    if (INSIDE_BEGIN_END(ctx)) {
67       gl_error( ctx, GL_INVALID_OPERATION, "glIndexMask" );
68       return;
69    }
70    ctx->Color.IndexMask = mask;
71    ctx->NewState |= NEW_RASTER_OPS;
72 }
73 
74 
75 
gl_ColorMask(GLcontext * ctx,GLboolean red,GLboolean green,GLboolean blue,GLboolean alpha)76 void gl_ColorMask( GLcontext *ctx, GLboolean red, GLboolean green,
77                    GLboolean blue, GLboolean alpha )
78 {
79    if (INSIDE_BEGIN_END(ctx)) {
80       gl_error( ctx, GL_INVALID_OPERATION, "glColorMask" );
81       return;
82    }
83    ctx->Color.ColorMask = (red << 3) | (green << 2) | (blue << 1) | alpha;
84    ctx->NewState |= NEW_RASTER_OPS;
85 }
86 
87 
88 
89 
90 /*
91  * Apply glColorMask to a span of RGBA pixels.
92  */
gl_mask_color_span(GLcontext * ctx,GLuint n,GLint x,GLint y,GLubyte red[],GLubyte green[],GLubyte blue[],GLubyte alpha[])93 void gl_mask_color_span( GLcontext *ctx,
94                          GLuint n, GLint x, GLint y,
95                          GLubyte red[], GLubyte green[],
96                          GLubyte blue[], GLubyte alpha[] )
97 {
98    GLubyte r[MAX_WIDTH], g[MAX_WIDTH], b[MAX_WIDTH], a[MAX_WIDTH];
99 
100    gl_read_color_span( ctx, n, x, y, r, g, b, a );
101 
102    if ((ctx->Color.ColorMask & 8) == 0) {
103       /* replace source reds with frame buffer reds */
104       MEMCPY( red, r, n );
105    }
106    if ((ctx->Color.ColorMask & 4) == 0) {
107       /* replace source greens with frame buffer greens */
108       MEMCPY( green, g, n );
109    }
110    if ((ctx->Color.ColorMask & 2) == 0) {
111       /* replace source blues with frame buffer blues */
112       MEMCPY( blue, b, n );
113    }
114    if ((ctx->Color.ColorMask & 1) == 0) {
115       /* replace source alphas with frame buffer alphas */
116       MEMCPY( alpha, a, n );
117    }
118 }
119 
120 
121 
122 /*
123  * Apply glColorMask to an array of RGBA pixels.
124  */
gl_mask_color_pixels(GLcontext * ctx,GLuint n,const GLint x[],const GLint y[],GLubyte red[],GLubyte green[],GLubyte blue[],GLubyte alpha[],const GLubyte mask[])125 void gl_mask_color_pixels( GLcontext *ctx,
126                            GLuint n, const GLint x[], const GLint y[],
127                            GLubyte red[], GLubyte green[],
128                            GLubyte blue[], GLubyte alpha[],
129                            const GLubyte mask[] )
130 {
131    GLubyte r[PB_SIZE], g[PB_SIZE], b[PB_SIZE], a[PB_SIZE];
132 
133    (*ctx->Driver.ReadColorPixels)( ctx, n, x, y, r, g, b, a, mask );
134    if (ctx->RasterMask & ALPHABUF_BIT) {
135       gl_read_alpha_pixels( ctx, n, x, y, a, mask );
136    }
137 
138    if ((ctx->Color.ColorMask & 8) == 0) {
139       /* replace source reds with frame buffer reds */
140       MEMCPY( red, r, n );
141    }
142    if ((ctx->Color.ColorMask & 4) == 0) {
143       /* replace source greens with frame buffer greens */
144       MEMCPY( green, g, n );
145    }
146    if ((ctx->Color.ColorMask & 2) == 0) {
147       /* replace source blues with frame buffer blues */
148       MEMCPY( blue, b, n );
149    }
150    if ((ctx->Color.ColorMask & 1) == 0) {
151       /* replace source alphas with frame buffer alphas */
152       MEMCPY( alpha, a, n );
153    }
154 }
155 
156 
157 
158 /*
159  * Apply glIndexMask to a span of CI pixels.
160  */
gl_mask_index_span(GLcontext * ctx,GLuint n,GLint x,GLint y,GLuint index[])161 void gl_mask_index_span( GLcontext *ctx,
162                          GLuint n, GLint x, GLint y, GLuint index[] )
163 {
164    GLuint i;
165    GLuint fbindexes[MAX_WIDTH];
166    GLuint msrc, mdest;
167 
168    gl_read_index_span( ctx, n, x, y, fbindexes );
169 
170    msrc = ctx->Color.IndexMask;
171    mdest = ~msrc;
172 
173    for (i=0;i<n;i++) {
174       index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
175    }
176 }
177 
178 
179 
180 /*
181  * Apply glIndexMask to an array of CI pixels.
182  */
gl_mask_index_pixels(GLcontext * ctx,GLuint n,const GLint x[],const GLint y[],GLuint index[],const GLubyte mask[])183 void gl_mask_index_pixels( GLcontext *ctx,
184                            GLuint n, const GLint x[], const GLint y[],
185                            GLuint index[], const GLubyte mask[] )
186 {
187    GLuint i;
188    GLuint fbindexes[PB_SIZE];
189    GLuint msrc, mdest;
190 
191    (*ctx->Driver.ReadIndexPixels)( ctx, n, x, y, fbindexes, mask );
192 
193    msrc = ctx->Color.IndexMask;
194    mdest = ~msrc;
195 
196    for (i=0;i<n;i++) {
197       index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
198    }
199 }
200 
201