80ee46c24be08030f89f7c37a2a365ff98124db7
2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 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.
26 #include "main/glheader.h"
27 #include "main/context.h"
28 #include "main/imports.h"
29 #include "main/macros.h"
31 #include "s_context.h"
37 * We do all logic ops on 4-byte GLuints.
38 * Depending on bytes per pixel, the mask array elements correspond to
41 #define LOGIC_OP_LOOP(MODE, MASKSTRIDE) \
46 for (i = 0; i < n; i++) { \
47 if (mask[i / MASKSTRIDE]) { \
53 for (i = 0; i < n; i++) { \
54 if (mask[i / MASKSTRIDE]) { \
62 case GL_COPY_INVERTED: \
63 for (i = 0; i < n; i++) { \
64 if (mask[i / MASKSTRIDE]) { \
70 for (i = 0; i < n; i++) { \
71 if (mask[i / MASKSTRIDE]) { \
77 for (i = 0; i < n; i++) { \
78 if (mask[i / MASKSTRIDE]) { \
84 for (i = 0; i < n; i++) { \
85 if (mask[i / MASKSTRIDE]) { \
91 for (i = 0; i < n; i++) { \
92 if (mask[i / MASKSTRIDE]) { \
93 src[i] = ~(src[i] & dest[i]); \
98 for (i = 0; i < n; i++) { \
99 if (mask[i / MASKSTRIDE]) { \
105 for (i = 0; i < n; i++) { \
106 if (mask[i / MASKSTRIDE]) { \
107 src[i] = ~(src[i] | dest[i]); \
112 for (i = 0; i < n; i++) { \
113 if (mask[i / MASKSTRIDE]) { \
119 for (i = 0; i < n; i++) { \
120 if (mask[i / MASKSTRIDE]) { \
121 src[i] = ~(src[i] ^ dest[i]); \
125 case GL_AND_REVERSE: \
126 for (i = 0; i < n; i++) { \
127 if (mask[i / MASKSTRIDE]) { \
128 src[i] = src[i] & ~dest[i]; \
132 case GL_AND_INVERTED: \
133 for (i = 0; i < n; i++) { \
134 if (mask[i / MASKSTRIDE]) { \
135 src[i] = ~src[i] & dest[i]; \
139 case GL_OR_REVERSE: \
140 for (i = 0; i < n; i++) { \
141 if (mask[i / MASKSTRIDE]) { \
142 src[i] = src[i] | ~dest[i]; \
146 case GL_OR_INVERTED: \
147 for (i = 0; i < n; i++) { \
148 if (mask[i / MASKSTRIDE]) { \
149 src[i] = ~src[i] | dest[i]; \
154 _mesa_problem(ctx, "bad logicop mode");\
161 logicop_uint1(struct gl_context
*ctx
, GLuint n
, GLuint src
[], const GLuint dest
[],
162 const GLubyte mask
[])
164 LOGIC_OP_LOOP(ctx
->Color
.LogicOp
, 1);
169 logicop_uint2(struct gl_context
*ctx
, GLuint n
, GLuint src
[], const GLuint dest
[],
170 const GLubyte mask
[])
172 LOGIC_OP_LOOP(ctx
->Color
.LogicOp
, 2);
177 logicop_uint4(struct gl_context
*ctx
, GLuint n
, GLuint src
[], const GLuint dest
[],
178 const GLubyte mask
[])
180 LOGIC_OP_LOOP(ctx
->Color
.LogicOp
, 4);
186 * Apply the current logic operator to a span of RGBA pixels.
187 * We can handle horizontal runs of pixels (spans) or arrays of x/y
191 _swrast_logicop_rgba_span(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
196 ASSERT(span
->end
< MAX_WIDTH
);
197 ASSERT(span
->arrayMask
& SPAN_RGBA
);
198 ASSERT(rb
->DataType
== span
->array
->ChanType
);
200 rbPixels
= _swrast_get_dest_rgba(ctx
, rb
, span
);
202 if (span
->array
->ChanType
== GL_UNSIGNED_BYTE
) {
203 /* treat 4*GLubyte as GLuint */
204 logicop_uint1(ctx
, span
->end
,
205 (GLuint
*) span
->array
->rgba8
,
206 (const GLuint
*) rbPixels
, span
->array
->mask
);
208 else if (span
->array
->ChanType
== GL_UNSIGNED_SHORT
) {
209 /* treat 2*GLushort as GLuint */
210 logicop_uint2(ctx
, 2 * span
->end
,
211 (GLuint
*) span
->array
->rgba16
,
212 (const GLuint
*) rbPixels
, span
->array
->mask
);
215 logicop_uint4(ctx
, 4 * span
->end
,
216 (GLuint
*) span
->array
->attribs
[FRAG_ATTRIB_COL0
],
217 (const GLuint
*) rbPixels
, span
->array
->mask
);