1 /* $Id: s_logic.c,v 1.9 2002/02/02 17:24:11 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.
32 #include "s_alphabuf.h"
33 #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
, span
->xArray
,
180 span
->yArray
, dest
, span
->mask
);
183 (*swrast
->Driver
.ReadCI32Span
)( ctx
, span
->end
, span
->x
, span
->y
, dest
);
186 index_logicop( ctx
, span
->end
, index
, dest
, span
->mask
);
192 * Apply the current logic operator to an array of CI pixels. This is only
193 * used if the device driver can't do logic ops.
196 _mesa_logicop_ci_pixels( GLcontext
*ctx
,
197 GLuint n
, const GLint x
[], const GLint y
[],
198 GLuint index
[], const GLubyte mask
[] )
200 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
201 GLuint dest
[PB_SIZE
];
202 /* Read dest values from frame buffer */
203 (*swrast
->Driver
.ReadCI32Pixels
)( ctx
, n
, x
, y
, dest
, mask
);
204 index_logicop( ctx
, n
, index
, dest
, mask
);
210 * Apply logic operator to rgba pixels.
211 * Input: ctx - the context
212 * n - number of pixels
213 * mask - pixel mask array
214 * In/Out: src - incoming pixels which will be modified
215 * Input: dest - frame buffer values
217 * Note: Since the R, G, B, and A channels are all treated the same we
218 * process them as 4-byte GLuints instead of four GLubytes.
221 rgba_logicop_ui( const GLcontext
*ctx
, GLuint n
, const GLubyte mask
[],
222 GLuint src
[], const GLuint dest
[] )
225 switch (ctx
->Color
.LogicOp
) {
243 case GL_COPY_INVERTED
:
274 src
[i
] = ~(src
[i
] & dest
[i
]);
288 src
[i
] = ~(src
[i
] | dest
[i
]);
302 src
[i
] = ~(src
[i
] ^ dest
[i
]);
309 src
[i
] = src
[i
] & ~dest
[i
];
313 case GL_AND_INVERTED
:
316 src
[i
] = ~src
[i
] & dest
[i
];
323 src
[i
] = src
[i
] | ~dest
[i
];
330 src
[i
] = ~src
[i
] | dest
[i
];
335 /* should never happen */
336 _mesa_problem(ctx
, "Bad function in rgba_logicop");
342 * As above, but operate on GLchan values
343 * Note: need to pass n = numPixels * 4.
346 rgba_logicop_chan( const GLcontext
*ctx
, GLuint n
, const GLubyte mask
[],
347 GLchan srcPtr
[], const GLchan destPtr
[] )
349 #if CHAN_TYPE == GL_FLOAT
350 GLuint
*src
= (GLuint
*) srcPtr
;
351 const GLuint
*dest
= (const GLuint
*) destPtr
;
353 ASSERT(sizeof(GLfloat
) == sizeof(GLuint
));
355 GLchan
*src
= srcPtr
;
356 const GLchan
*dest
= destPtr
;
360 switch (ctx
->Color
.LogicOp
) {
378 case GL_COPY_INVERTED
:
409 src
[i
] = ~(src
[i
] & dest
[i
]);
423 src
[i
] = ~(src
[i
] | dest
[i
]);
437 src
[i
] = ~(src
[i
] ^ dest
[i
]);
444 src
[i
] = src
[i
] & ~dest
[i
];
448 case GL_AND_INVERTED
:
451 src
[i
] = ~src
[i
] & dest
[i
];
458 src
[i
] = src
[i
] | ~dest
[i
];
465 src
[i
] = ~src
[i
] | dest
[i
];
470 /* should never happen */
471 _mesa_problem(ctx
, "Bad function in rgba_logicop");
478 * Apply the current logic operator to a span of RGBA pixels.
479 * We can handle horizontal runs of pixels (spans) or arrays of x/y
483 _mesa_logicop_rgba_span( GLcontext
*ctx
, const struct sw_span
*span
,
486 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
487 GLchan dest
[MAX_WIDTH
][4];
489 ASSERT(span
->end
< MAX_WIDTH
);
490 ASSERT(span
->arrayMask
& SPAN_RGBA
);
492 if (span
->arrayMask
& SPAN_XY
) {
493 (*swrast
->Driver
.ReadRGBAPixels
)(ctx
, span
->end
,
494 span
->xArray
, span
->yArray
,
496 if (SWRAST_CONTEXT(ctx
)->_RasterMask
& ALPHABUF_BIT
) {
497 _mesa_read_alpha_pixels(ctx
, span
->end
, span
->xArray
, span
->yArray
,
502 _mesa_read_rgba_span(ctx
, ctx
->DrawBuffer
, span
->end
,
503 span
->x
, span
->y
, dest
);
506 if (sizeof(GLchan
) * 4 == sizeof(GLuint
)) {
507 rgba_logicop_ui(ctx
, span
->end
, span
->mask
,
508 (GLuint
*) rgba
, (const GLuint
*) dest
);
511 rgba_logicop_chan(ctx
, 4 * span
->end
, span
->mask
,
512 (GLchan
*) rgba
, (const GLchan
*) dest
);
519 * Apply the current logic operator to an array of RGBA pixels.
520 * This is only used if the device driver can't do logic ops.
523 _mesa_logicop_rgba_pixels( GLcontext
*ctx
,
524 GLuint n
, const GLint x
[], const GLint y
[],
525 GLchan rgba
[][4], const GLubyte mask
[] )
527 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
528 GLchan dest
[PB_SIZE
][4];
529 (*swrast
->Driver
.ReadRGBAPixels
)( ctx
, n
, x
, y
, dest
, mask
);
530 if (SWRAST_CONTEXT(ctx
)->_RasterMask
& ALPHABUF_BIT
) {
531 _mesa_read_alpha_pixels( ctx
, n
, x
, y
, dest
, mask
);
533 if (sizeof(GLchan
) * 4 == sizeof(GLuint
)) {
534 rgba_logicop_ui(ctx
, n
, mask
, (GLuint
*) rgba
, (const GLuint
*) dest
);
537 rgba_logicop_chan(ctx
, 4 * n
, mask
,
538 (GLchan
*) rgba
, (const GLchan
*) dest
);