2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 #include "s_context.h"
36 #define LOGIC_OP_LOOP(MODE) \
41 for (i = 0; i < n; i++) { \
48 for (i = 0; i < n; i++) { \
57 case GL_COPY_INVERTED: \
58 for (i = 0; i < n; i++) { \
65 for (i = 0; i < n; i++) { \
72 for (i = 0; i < n; i++) { \
79 for (i = 0; i < n; i++) { \
86 for (i = 0; i < n; i++) { \
88 src[i] = ~(src[i] & dest[i]); \
93 for (i = 0; i < n; i++) { \
100 for (i = 0; i < n; i++) { \
102 src[i] = ~(src[i] | dest[i]); \
107 for (i = 0; i < n; i++) { \
114 for (i = 0; i < n; i++) { \
116 src[i] = ~(src[i] ^ dest[i]); \
120 case GL_AND_REVERSE: \
121 for (i = 0; i < n; i++) { \
123 src[i] = src[i] & ~dest[i]; \
127 case GL_AND_INVERTED: \
128 for (i = 0; i < n; i++) { \
130 src[i] = ~src[i] & dest[i]; \
134 case GL_OR_REVERSE: \
135 for (i = 0; i < n; i++) { \
137 src[i] = src[i] | ~dest[i]; \
141 case GL_OR_INVERTED: \
142 for (i = 0; i < n; i++) { \
144 src[i] = ~src[i] | dest[i]; \
149 _mesa_problem(ctx, "bad logicop mode");\
156 logicop_ubyte(GLcontext
*ctx
, GLuint n
, GLubyte src
[], const GLubyte dest
[],
157 const GLubyte mask
[])
159 LOGIC_OP_LOOP(ctx
->Color
.LogicOp
);
164 logicop_ushort(GLcontext
*ctx
, GLuint n
, GLushort src
[], const GLushort dest
[],
165 const GLubyte mask
[])
167 LOGIC_OP_LOOP(ctx
->Color
.LogicOp
);
172 logicop_uint(GLcontext
*ctx
, GLuint n
, GLuint src
[], const GLuint dest
[],
173 const GLubyte mask
[])
175 LOGIC_OP_LOOP(ctx
->Color
.LogicOp
);
181 * Apply the current logic operator to a span of CI pixels. This is only
182 * used if the device driver can't do logic ops.
185 _swrast_logicop_ci_span(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
186 const struct sw_span
*span
, GLuint index
[])
188 GLuint dest
[MAX_WIDTH
];
190 ASSERT(span
->end
< MAX_WIDTH
);
191 ASSERT(rb
->DataType
== GL_UNSIGNED_INT
);
193 /* Read dest values from frame buffer */
194 if (span
->arrayMask
& SPAN_XY
) {
195 _swrast_get_values(ctx
, rb
, span
->end
, span
->array
->x
, span
->array
->y
,
196 dest
, sizeof(GLuint
));
199 rb
->GetRow(ctx
, rb
, span
->end
, span
->x
, span
->y
, dest
);
202 logicop_uint(ctx
, span
->end
, index
, dest
, span
->array
->mask
);
207 * Apply the current logic operator to a span of RGBA pixels.
208 * We can handle horizontal runs of pixels (spans) or arrays of x/y
212 _swrast_logicop_rgba_span(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
213 const struct sw_span
*span
, GLchan rgba
[][4])
215 GLchan dest
[MAX_WIDTH
][4];
217 ASSERT(span
->end
< MAX_WIDTH
);
218 ASSERT(span
->arrayMask
& SPAN_RGBA
);
219 ASSERT(rb
->DataType
== CHAN_TYPE
);
221 if (span
->arrayMask
& SPAN_XY
) {
222 _swrast_get_values(ctx
, rb
, span
->end
, span
->array
->x
, span
->array
->y
,
223 dest
, 4 * sizeof(GLchan
));
226 _swrast_read_rgba_span(ctx
, rb
, span
->end
, span
->x
, span
->y
, dest
);
229 /* XXX make this a runtime test */
230 #if CHAN_TYPE == GL_UNSIGNED_BYTE
231 /* treat 4*GLubyte as GLuint */
232 logicop_uint(ctx
, span
->end
, (GLuint
*) rgba
,
233 (const GLuint
*) dest
, span
->array
->mask
);
234 #elif CHAN_TYPE == GL_UNSIGNED_SHORT
235 logicop_ushort(ctx
, 4 * span
->end
, (GLushort
*) rgba
,
236 (const GLushort
*) dest
, span
->array
->mask
);
237 #elif CHAN_TYPE == GL_FLOAT
238 logicop_uint(ctx
, 4 * span
->end
, (GLuint
*) rgba
,
239 (const GLuint
*) dest
, span
->array
->mask
);
241 (void) logicop_ubyte
;
242 (void) logicop_ushort
;