1 /* $Id: s_logic.c,v 1.8 2001/07/13 20:07:37 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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.
43 static void index_logicop( GLcontext
*ctx
, GLuint n
,
44 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
, GLuint n
, GLint x
, GLint y
,
170 GLuint index
[], const GLubyte mask
[] )
172 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
173 GLuint dest
[MAX_WIDTH
];
174 /* Read dest values from frame buffer */
175 (*swrast
->Driver
.ReadCI32Span
)( ctx
, n
, x
, y
, dest
);
176 index_logicop( ctx
, n
, index
, dest
, mask
);
182 * Apply the current logic operator to an array of CI pixels. This is only
183 * used if the device driver can't do logic ops.
186 _mesa_logicop_ci_pixels( GLcontext
*ctx
,
187 GLuint n
, const GLint x
[], const GLint y
[],
188 GLuint index
[], const GLubyte mask
[] )
190 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
191 GLuint dest
[PB_SIZE
];
192 /* Read dest values from frame buffer */
193 (*swrast
->Driver
.ReadCI32Pixels
)( ctx
, n
, x
, y
, dest
, mask
);
194 index_logicop( ctx
, n
, index
, dest
, mask
);
200 * Apply logic operator to rgba pixels.
201 * Input: ctx - the context
202 * n - number of pixels
203 * mask - pixel mask array
204 * In/Out: src - incoming pixels which will be modified
205 * Input: dest - frame buffer values
207 * Note: Since the R, G, B, and A channels are all treated the same we
208 * process them as 4-byte GLuints instead of four GLubytes.
210 static void rgba_logicop_ui( const GLcontext
*ctx
, GLuint n
,
211 const GLubyte mask
[],
212 GLuint src
[], const GLuint dest
[] )
215 switch (ctx
->Color
.LogicOp
) {
233 case GL_COPY_INVERTED
:
264 src
[i
] = ~(src
[i
] & dest
[i
]);
278 src
[i
] = ~(src
[i
] | dest
[i
]);
292 src
[i
] = ~(src
[i
] ^ dest
[i
]);
299 src
[i
] = src
[i
] & ~dest
[i
];
303 case GL_AND_INVERTED
:
306 src
[i
] = ~src
[i
] & dest
[i
];
313 src
[i
] = src
[i
] | ~dest
[i
];
320 src
[i
] = ~src
[i
] | dest
[i
];
325 /* should never happen */
326 _mesa_problem(ctx
, "Bad function in rgba_logicop");
332 * As above, but operate on GLchan values
333 * Note: need to pass n = numPixels * 4.
335 static void rgba_logicop_chan( const GLcontext
*ctx
, GLuint n
,
336 const GLubyte mask
[],
337 GLchan srcPtr
[], const GLchan destPtr
[] )
339 #if CHAN_TYPE == GL_FLOAT
340 GLuint
*src
= (GLuint
*) srcPtr
;
341 const GLuint
*dest
= (const GLuint
*) destPtr
;
343 ASSERT(sizeof(GLfloat
) == sizeof(GLuint
));
345 GLchan
*src
= srcPtr
;
346 const GLchan
*dest
= destPtr
;
350 switch (ctx
->Color
.LogicOp
) {
368 case GL_COPY_INVERTED
:
399 src
[i
] = ~(src
[i
] & dest
[i
]);
413 src
[i
] = ~(src
[i
] | dest
[i
]);
427 src
[i
] = ~(src
[i
] ^ dest
[i
]);
434 src
[i
] = src
[i
] & ~dest
[i
];
438 case GL_AND_INVERTED
:
441 src
[i
] = ~src
[i
] & dest
[i
];
448 src
[i
] = src
[i
] | ~dest
[i
];
455 src
[i
] = ~src
[i
] | dest
[i
];
460 /* should never happen */
461 _mesa_problem(ctx
, "Bad function in rgba_logicop");
468 * Apply the current logic operator to a span of RGBA pixels.
469 * This is only used if the device driver can't do logic ops.
472 _mesa_logicop_rgba_span( GLcontext
*ctx
,
473 GLuint n
, GLint x
, GLint y
,
474 GLchan rgba
[][4], const GLubyte mask
[] )
476 GLchan dest
[MAX_WIDTH
][4];
477 _mesa_read_rgba_span( ctx
, ctx
->DrawBuffer
, n
, x
, y
, dest
);
478 if (sizeof(GLchan
) * 4 == sizeof(GLuint
)) {
479 rgba_logicop_ui(ctx
, n
, mask
, (GLuint
*) rgba
, (const GLuint
*) dest
);
482 rgba_logicop_chan(ctx
, 4 * n
, mask
,
483 (GLchan
*) rgba
, (const GLchan
*) dest
);
490 * Apply the current logic operator to an array of RGBA pixels.
491 * This is only used if the device driver can't do logic ops.
494 _mesa_logicop_rgba_pixels( GLcontext
*ctx
,
495 GLuint n
, const GLint x
[], const GLint y
[],
496 GLchan rgba
[][4], const GLubyte mask
[] )
498 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
499 GLchan dest
[PB_SIZE
][4];
500 (*swrast
->Driver
.ReadRGBAPixels
)( ctx
, n
, x
, y
, dest
, mask
);
501 if (SWRAST_CONTEXT(ctx
)->_RasterMask
& ALPHABUF_BIT
) {
502 _mesa_read_alpha_pixels( ctx
, n
, x
, y
, dest
, mask
);
504 if (sizeof(GLchan
) * 4 == sizeof(GLuint
)) {
505 rgba_logicop_ui(ctx
, n
, mask
, (GLuint
*) rgba
, (const GLuint
*) dest
);
508 rgba_logicop_chan(ctx
, 4 * n
, mask
,
509 (GLchan
*) rgba
, (const GLchan
*) dest
);