Debian Codegraph @

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

raw
1 /* $Id: masking.c,v 1.2 2000/10/27 15:21:40 mholst Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 2.1
6 * Copyright (C) 1995-1996 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 * Implement the effect of glColorMask and glIndexMask in software.
25 */
26
27
28
29 #include <string.h>
30 #include "alphabuf.h"
31 #include "context.h"
32 #include "macros.h"
33 #include "masking.h"
34 #include "pb.h"
35 #include "span.h"
36 #include "types.h"
37
38
39
40 void gl_IndexMask( GLcontext *ctx, GLuint mask )
41 {
42 if (INSIDE_BEGIN_END(ctx)) {
43 gl_error( ctx, GL_INVALID_OPERATION, "glIndexMask" );
44 return;
45 }
46 ctx->Color.IndexMask = mask;
47 ctx->NewState |= NEW_RASTER_OPS;
48 }
49
50
51
52 void gl_ColorMask( GLcontext *ctx, GLboolean red, GLboolean green,
53 GLboolean blue, GLboolean alpha )
54 {
55 if (INSIDE_BEGIN_END(ctx)) {
56 gl_error( ctx, GL_INVALID_OPERATION, "glColorMask" );
57 return;
58 }
59 ctx->Color.ColorMask = (red << 3) | (green << 2) | (blue << 1) | alpha;
60 ctx->NewState |= NEW_RASTER_OPS;
61 }
62
63
64
65
66 /*
67 * Apply glColorMask to a span of RGBA pixels.
68 */
69 void gl_mask_color_span( GLcontext *ctx,
70 GLuint n, GLint x, GLint y,
71 GLubyte red[], GLubyte green[],
72 GLubyte blue[], GLubyte alpha[] )
73 {
74 GLubyte r[MAX_WIDTH], g[MAX_WIDTH], b[MAX_WIDTH], a[MAX_WIDTH];
75
76 gl_read_color_span( ctx, n, x, y, r, g, b, a );
77
78 if ((ctx->Color.ColorMask & 8) == 0) {
79 /* replace source reds with frame buffer reds */
80 MEMCPY( red, r, n );
81 }
82 if ((ctx->Color.ColorMask & 4) == 0) {
83 /* replace source greens with frame buffer greens */
84 MEMCPY( green, g, n );
85 }
86 if ((ctx->Color.ColorMask & 2) == 0) {
87 /* replace source blues with frame buffer blues */
88 MEMCPY( blue, b, n );
89 }
90 if ((ctx->Color.ColorMask & 1) == 0) {
91 /* replace source alphas with frame buffer alphas */
92 MEMCPY( alpha, a, n );
93 }
94 }
95
96
97
98 /*
99 * Apply glColorMask to an array of RGBA pixels.
100 */
101 void gl_mask_color_pixels( GLcontext *ctx,
102 GLuint n, const GLint x[], const GLint y[],
103 GLubyte red[], GLubyte green[],
104 GLubyte blue[], GLubyte alpha[],
105 const GLubyte mask[] )
106 {
107 GLubyte r[PB_SIZE], g[PB_SIZE], b[PB_SIZE], a[PB_SIZE];
108
109 (*ctx->Driver.ReadColorPixels)( ctx, n, x, y, r, g, b, a, mask );
110 if (ctx->RasterMask & ALPHABUF_BIT) {
111 gl_read_alpha_pixels( ctx, n, x, y, a, mask );
112 }
113
114 if ((ctx->Color.ColorMask & 8) == 0) {
115 /* replace source reds with frame buffer reds */
116 MEMCPY( red, r, n );
117 }
118 if ((ctx->Color.ColorMask & 4) == 0) {
119 /* replace source greens with frame buffer greens */
120 MEMCPY( green, g, n );
121 }
122 if ((ctx->Color.ColorMask & 2) == 0) {
123 /* replace source blues with frame buffer blues */
124 MEMCPY( blue, b, n );
125 }
126 if ((ctx->Color.ColorMask & 1) == 0) {
127 /* replace source alphas with frame buffer alphas */
128 MEMCPY( alpha, a, n );
129 }
130 }
131
132
133
134 /*
135 * Apply glIndexMask to a span of CI pixels.
136 */
137 void gl_mask_index_span( GLcontext *ctx,
138 GLuint n, GLint x, GLint y, GLuint index[] )
139 {
140 GLuint i;
141 GLuint fbindexes[MAX_WIDTH];
142 GLuint msrc, mdest;
143
144 gl_read_index_span( ctx, n, x, y, fbindexes );
145
146 msrc = ctx->Color.IndexMask;
147 mdest = ~msrc;
148
149 for (i=0;i<n;i++) {
150 index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
151 }
152 }
153
154
155
156 /*
157 * Apply glIndexMask to an array of CI pixels.
158 */
159 void gl_mask_index_pixels( GLcontext *ctx,
160 GLuint n, const GLint x[], const GLint y[],
161 GLuint index[], const GLubyte mask[] )
162 {
163 GLuint i;
164 GLuint fbindexes[PB_SIZE];
165 GLuint msrc, mdest;
166
167 (*ctx->Driver.ReadIndexPixels)( ctx, n, x, y, fbindexes, mask );
168
169 msrc = ctx->Color.IndexMask;
170 mdest = ~msrc;
171
172 for (i=0;i<n;i++) {
173 index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
174 }
175 }
176