switch to using driFillInModes fix depthbuffer = 0
[mesa.git] / src / mesa / swrast / s_masking.c
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 4.1
5 *
6 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 /*
28 * Implement the effect of glColorMask and glIndexMask in software.
29 */
30
31
32 #include "glheader.h"
33 #include "enums.h"
34 #include "macros.h"
35
36 #include "s_alphabuf.h"
37 #include "s_context.h"
38 #include "s_masking.h"
39 #include "s_span.h"
40
41
42
43 void
44 _swrast_mask_rgba_span( GLcontext *ctx, const struct sw_span *span,
45 GLchan rgba[][4] )
46 {
47 SWcontext *swrast = SWRAST_CONTEXT(ctx);
48 GLchan dest[MAX_WIDTH][4];
49 #if CHAN_BITS == 8
50 GLuint srcMask = *((GLuint*)ctx->Color.ColorMask);
51 GLuint dstMask = ~srcMask;
52 GLuint *rgba32 = (GLuint *) rgba;
53 GLuint *dest32 = (GLuint *) dest;
54 #else
55 const GLboolean rMask = ctx->Color.ColorMask[RCOMP];
56 const GLboolean gMask = ctx->Color.ColorMask[GCOMP];
57 const GLboolean bMask = ctx->Color.ColorMask[BCOMP];
58 const GLboolean aMask = ctx->Color.ColorMask[ACOMP];
59 #endif
60 const GLuint n = span->end;
61 GLuint i;
62
63 ASSERT(n < MAX_WIDTH);
64 ASSERT(span->arrayMask & SPAN_RGBA);
65
66 if (span->arrayMask & SPAN_XY) {
67 (*swrast->Driver.ReadRGBAPixels)(ctx, n, span->array->x, span->array->y,
68 dest, span->array->mask);
69 if (SWRAST_CONTEXT(ctx)->_RasterMask & ALPHABUF_BIT) {
70 _swrast_read_alpha_pixels(ctx, n, span->array->x, span->array->y,
71 dest, span->array->mask);
72 }
73 }
74 else {
75 _swrast_read_rgba_span(ctx, ctx->DrawBuffer, n, span->x, span->y, dest);
76 }
77
78 #if CHAN_BITS == 8
79 for (i = 0; i < n; i++) {
80 rgba32[i] = (rgba32[i] & srcMask) | (dest32[i] & dstMask);
81 }
82 #else
83 for (i = 0; i < n; i++) {
84 if (!rMask) rgba[i][RCOMP] = dest[i][RCOMP];
85 if (!gMask) rgba[i][GCOMP] = dest[i][GCOMP];
86 if (!bMask) rgba[i][BCOMP] = dest[i][BCOMP];
87 if (!aMask) rgba[i][ACOMP] = dest[i][ACOMP];
88 }
89 #endif
90 }
91
92
93
94
95 /*
96 * Apply glColorMask to a span of RGBA pixels.
97 */
98 void
99 _swrast_mask_rgba_array( GLcontext *ctx,
100 GLuint n, GLint x, GLint y, GLchan rgba[][4] )
101 {
102 GLchan dest[MAX_WIDTH][4];
103 GLuint i;
104
105 #if CHAN_BITS == 8
106
107 GLuint srcMask = *((GLuint*)ctx->Color.ColorMask);
108 GLuint dstMask = ~srcMask;
109 GLuint *rgba32 = (GLuint *) rgba;
110 GLuint *dest32 = (GLuint *) dest;
111
112 _swrast_read_rgba_span( ctx, ctx->DrawBuffer, n, x, y, dest );
113 for (i = 0; i < n; i++) {
114 rgba32[i] = (rgba32[i] & srcMask) | (dest32[i] & dstMask);
115 }
116
117 #else
118
119 const GLint rMask = ctx->Color.ColorMask[RCOMP];
120 const GLint gMask = ctx->Color.ColorMask[GCOMP];
121 const GLint bMask = ctx->Color.ColorMask[BCOMP];
122 const GLint aMask = ctx->Color.ColorMask[ACOMP];
123
124 _swrast_read_rgba_span( ctx, ctx->DrawBuffer, n, x, y, dest );
125 for (i = 0; i < n; i++) {
126 if (!rMask) rgba[i][RCOMP] = dest[i][RCOMP];
127 if (!gMask) rgba[i][GCOMP] = dest[i][GCOMP];
128 if (!bMask) rgba[i][BCOMP] = dest[i][BCOMP];
129 if (!aMask) rgba[i][ACOMP] = dest[i][ACOMP];
130 }
131
132 #endif
133 }
134
135
136
137 void
138 _swrast_mask_index_span( GLcontext *ctx, const struct sw_span *span,
139 GLuint index[] )
140 {
141 SWcontext *swrast = SWRAST_CONTEXT(ctx);
142 const GLuint msrc = ctx->Color.IndexMask;
143 const GLuint mdest = ~msrc;
144 GLuint fbindexes[MAX_WIDTH];
145 GLuint i;
146
147 ASSERT(span->arrayMask & SPAN_INDEX);
148 ASSERT(span->end < MAX_WIDTH);
149
150 if (span->arrayMask & SPAN_XY) {
151
152 (*swrast->Driver.ReadCI32Pixels)(ctx, span->end, span->array->x,
153 span->array->y, fbindexes,
154 span->array->mask);
155
156 for (i = 0; i < span->end; i++) {
157 index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
158 }
159 }
160 else {
161 _swrast_read_index_span(ctx, ctx->DrawBuffer, span->end, span->x, span->y,
162 fbindexes );
163
164 for (i = 0; i < span->end; i++) {
165 index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
166 }
167 }
168 }
169
170
171
172 /*
173 * Apply glIndexMask to a span of CI pixels.
174 */
175 void
176 _swrast_mask_index_array( GLcontext *ctx,
177 GLuint n, GLint x, GLint y, GLuint index[] )
178 {
179 GLuint i;
180 GLuint fbindexes[MAX_WIDTH];
181 GLuint msrc, mdest;
182
183 _swrast_read_index_span( ctx, ctx->DrawBuffer, n, x, y, fbindexes );
184
185 msrc = ctx->Color.IndexMask;
186 mdest = ~msrc;
187
188 for (i=0;i<n;i++) {
189 index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
190 }
191 }