1 /* $Id: s_logic.c,v 1.4 2001/03/03 20:33:30 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 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 GLuint dest
[MAX_WIDTH
];
173 /* Read dest values from frame buffer */
174 (*ctx
->Driver
.ReadCI32Span
)( ctx
, n
, x
, y
, dest
);
175 index_logicop( ctx
, n
, index
, dest
, mask
);
181 * Apply the current logic operator to an array of CI pixels. This is only
182 * used if the device driver can't do logic ops.
185 _mesa_logicop_ci_pixels( GLcontext
*ctx
,
186 GLuint n
, const GLint x
[], const GLint y
[],
187 GLuint index
[], const GLubyte mask
[] )
189 GLuint dest
[PB_SIZE
];
190 /* Read dest values from frame buffer */
191 (*ctx
->Driver
.ReadCI32Pixels
)( ctx
, n
, x
, y
, dest
, mask
);
192 index_logicop( ctx
, n
, index
, dest
, mask
);
198 * Apply logic operator to rgba pixels.
199 * Input: ctx - the context
200 * n - number of pixels
201 * mask - pixel mask array
202 * In/Out: src - incoming pixels which will be modified
203 * Input: dest - frame buffer values
205 * Note: Since the R, G, B, and A channels are all treated the same we
206 * process them as 4-byte GLuints instead of four GLubytes.
208 static void rgba_logicop( const GLcontext
*ctx
, GLuint n
,
209 const GLubyte mask
[],
210 GLuint src
[], const GLuint dest
[] )
213 switch (ctx
->Color
.LogicOp
) {
231 case GL_COPY_INVERTED
:
262 src
[i
] = ~(src
[i
] & src
[i
]);
276 src
[i
] = ~(src
[i
] | dest
[i
]);
290 src
[i
] = ~(src
[i
] ^ dest
[i
]);
297 src
[i
] = src
[i
] & ~dest
[i
];
301 case GL_AND_INVERTED
:
304 src
[i
] = ~src
[i
] & dest
[i
];
311 src
[i
] = src
[i
] | ~dest
[i
];
318 src
[i
] = ~src
[i
] | dest
[i
];
323 /* should never happen */
324 _mesa_problem(ctx
, "Bad function in rgba_logicop");
331 * Apply the current logic operator to a span of RGBA pixels.
332 * This is only used if the device driver can't do logic ops.
335 _mesa_logicop_rgba_span( GLcontext
*ctx
,
336 GLuint n
, GLint x
, GLint y
,
337 GLchan rgba
[][4], const GLubyte mask
[] )
339 GLchan dest
[MAX_WIDTH
][4];
340 _mesa_read_rgba_span( ctx
, ctx
->DrawBuffer
, n
, x
, y
, dest
);
341 rgba_logicop( ctx
, n
, mask
, (GLuint
*) rgba
, (const GLuint
*) dest
);
347 * Apply the current logic operator to an array of RGBA pixels.
348 * This is only used if the device driver can't do logic ops.
351 _mesa_logicop_rgba_pixels( GLcontext
*ctx
,
352 GLuint n
, const GLint x
[], const GLint y
[],
353 GLchan rgba
[][4], const GLubyte mask
[] )
355 GLchan dest
[PB_SIZE
][4];
356 (*ctx
->Driver
.ReadRGBAPixels
)( ctx
, n
, x
, y
, dest
, mask
);
357 if (SWRAST_CONTEXT(ctx
)->_RasterMask
& ALPHABUF_BIT
) {
358 _mesa_read_alpha_pixels( ctx
, n
, x
, y
, dest
, mask
);
360 rgba_logicop( ctx
, n
, mask
, (GLuint
*) rgba
, (const GLuint
*) dest
);