1 /* $Id: s_logic.c,v 1.12 2002/10/24 23:57:24 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #include "s_alphabuf.h"
34 #include "s_context.h"
41 * Apply logic op to array of CI pixels.
44 index_logicop( GLcontext
*ctx
, GLuint n
, GLuint index
[], const GLuint dest
[],
45 const GLubyte mask
[] )
48 switch (ctx
->Color
.LogicOp
) {
66 case GL_COPY_INVERTED
:
97 index
[i
] = ~(index
[i
] & dest
[i
]);
111 index
[i
] = ~(index
[i
] | dest
[i
]);
125 index
[i
] = ~(index
[i
] ^ dest
[i
]);
132 index
[i
] = index
[i
] & ~dest
[i
];
136 case GL_AND_INVERTED
:
139 index
[i
] = ~index
[i
] & dest
[i
];
146 index
[i
] = index
[i
] | ~dest
[i
];
153 index
[i
] = ~index
[i
] | dest
[i
];
158 _mesa_problem(ctx
, "bad mode in index_logic()");
165 * Apply the current logic operator to a span of CI pixels. This is only
166 * used if the device driver can't do logic ops.
169 _mesa_logicop_ci_span( GLcontext
*ctx
, const struct sw_span
*span
,
172 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
173 GLuint dest
[MAX_WIDTH
];
175 ASSERT(span
->end
< MAX_WIDTH
);
177 /* Read dest values from frame buffer */
178 if (span
->arrayMask
& SPAN_XY
) {
179 (*swrast
->Driver
.ReadCI32Pixels
)( ctx
, span
->end
,
180 span
->array
->x
, span
->array
->y
,
181 dest
, span
->array
->mask
);
184 (*swrast
->Driver
.ReadCI32Span
)( ctx
, span
->end
, span
->x
, span
->y
, dest
);
187 index_logicop( ctx
, span
->end
, index
, dest
, span
->array
->mask
);
193 * Apply logic operator to rgba pixels.
194 * Input: ctx - the context
195 * n - number of pixels
196 * mask - pixel mask array
197 * In/Out: src - incoming pixels which will be modified
198 * Input: dest - frame buffer values
200 * Note: Since the R, G, B, and A channels are all treated the same we
201 * process them as 4-byte GLuints instead of four GLubytes.
204 rgba_logicop_ui( const GLcontext
*ctx
, GLuint n
, const GLubyte mask
[],
205 GLuint src
[], const GLuint dest
[] )
208 switch (ctx
->Color
.LogicOp
) {
226 case GL_COPY_INVERTED
:
257 src
[i
] = ~(src
[i
] & dest
[i
]);
271 src
[i
] = ~(src
[i
] | dest
[i
]);
285 src
[i
] = ~(src
[i
] ^ dest
[i
]);
292 src
[i
] = src
[i
] & ~dest
[i
];
296 case GL_AND_INVERTED
:
299 src
[i
] = ~src
[i
] & dest
[i
];
306 src
[i
] = src
[i
] | ~dest
[i
];
313 src
[i
] = ~src
[i
] | dest
[i
];
318 /* should never happen */
319 _mesa_problem(ctx
, "Bad function in rgba_logicop");
325 * As above, but operate on GLchan values
326 * Note: need to pass n = numPixels * 4.
329 rgba_logicop_chan( const GLcontext
*ctx
, GLuint n
, const GLubyte mask
[],
330 GLchan srcPtr
[], const GLchan destPtr
[] )
332 #if CHAN_TYPE == GL_FLOAT
333 GLuint
*src
= (GLuint
*) srcPtr
;
334 const GLuint
*dest
= (const GLuint
*) destPtr
;
336 ASSERT(sizeof(GLfloat
) == sizeof(GLuint
));
338 GLchan
*src
= srcPtr
;
339 const GLchan
*dest
= destPtr
;
343 switch (ctx
->Color
.LogicOp
) {
361 case GL_COPY_INVERTED
:
392 src
[i
] = ~(src
[i
] & dest
[i
]);
406 src
[i
] = ~(src
[i
] | dest
[i
]);
420 src
[i
] = ~(src
[i
] ^ dest
[i
]);
427 src
[i
] = src
[i
] & ~dest
[i
];
431 case GL_AND_INVERTED
:
434 src
[i
] = ~src
[i
] & dest
[i
];
441 src
[i
] = src
[i
] | ~dest
[i
];
448 src
[i
] = ~src
[i
] | dest
[i
];
453 /* should never happen */
454 _mesa_problem(ctx
, "Bad function in rgba_logicop");
461 * Apply the current logic operator to a span of RGBA pixels.
462 * We can handle horizontal runs of pixels (spans) or arrays of x/y
466 _mesa_logicop_rgba_span( GLcontext
*ctx
, const struct sw_span
*span
,
469 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
470 GLchan dest
[MAX_WIDTH
][4];
472 ASSERT(span
->end
< MAX_WIDTH
);
473 ASSERT(span
->arrayMask
& SPAN_RGBA
);
475 if (span
->arrayMask
& SPAN_XY
) {
476 (*swrast
->Driver
.ReadRGBAPixels
)(ctx
, span
->end
,
477 span
->array
->x
, span
->array
->y
,
478 dest
, span
->array
->mask
);
479 if (SWRAST_CONTEXT(ctx
)->_RasterMask
& ALPHABUF_BIT
) {
480 _mesa_read_alpha_pixels(ctx
, span
->end
,
481 span
->array
->x
, span
->array
->y
,
482 dest
, span
->array
->mask
);
486 _mesa_read_rgba_span(ctx
, ctx
->DrawBuffer
, span
->end
,
487 span
->x
, span
->y
, dest
);
490 if (sizeof(GLchan
) * 4 == sizeof(GLuint
)) {
491 rgba_logicop_ui(ctx
, span
->end
, span
->array
->mask
,
492 (GLuint
*) rgba
, (const GLuint
*) dest
);
495 rgba_logicop_chan(ctx
, 4 * span
->end
, span
->array
->mask
,
496 (GLchan
*) rgba
, (const GLchan
*) dest
);