Debian Codegraph @

debian/external_deps/fetk/sg/src/gl/logic.c

raw
1 /* $Id: logic.c,v 1.2 2000/10/27 15:21:40 mholst Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 2.2
6 * Copyright (C) 1995-1997 Brian Paul
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include <stdlib.h>
24 #include "alphabuf.h"
25 #include "context.h"
26 #include "dlist.h"
27 #include "logic.h"
28 #include "macros.h"
29 #include "pb.h"
30 #include "span.h"
31 #include "types.h"
32
33
34
35 void gl_LogicOp( GLcontext *ctx, GLenum opcode )
36 {
37 if (INSIDE_BEGIN_END(ctx)) {
38 gl_error( ctx, GL_INVALID_OPERATION, "glLogicOp" );
39 return;
40 }
41 switch (opcode) {
42 case GL_CLEAR:
43 case GL_SET:
44 case GL_COPY:
45 case GL_COPY_INVERTED:
46 case GL_NOOP:
47 case GL_INVERT:
48 case GL_AND:
49 case GL_NAND:
50 case GL_OR:
51 case GL_NOR:
52 case GL_XOR:
53 case GL_EQUIV:
54 case GL_AND_REVERSE:
55 case GL_AND_INVERTED:
56 case GL_OR_REVERSE:
57 case GL_OR_INVERTED:
58 ctx->Color.LogicOp = opcode;
59 ctx->NewState |= NEW_RASTER_OPS;
60 return;
61 default:
62 gl_error( ctx, GL_INVALID_ENUM, "glLogicOp" );
63 return;
64 }
65 }
66
67
68
69
70 /*
71 * Apply the current logic operator to a span of CI pixels. This is only
72 * used if the device driver can't do logic ops.
73 */
74 void gl_logicop_ci_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
75 GLuint index[], GLubyte mask[] )
76 {
77 GLuint dest[MAX_WIDTH];
78 GLuint i;
79
80 /* Read dest values from frame buffer */
81 (*ctx->Driver.ReadIndexSpan)( ctx, n, x, y, dest );
82
83 switch (ctx->Color.LogicOp) {
84 case GL_CLEAR:
85 for (i=0;i<n;i++) {
86 if (mask[i]) {
87 index[i] = 0;
88 }
89 }
90 break;
91 case GL_SET:
92 for (i=0;i<n;i++) {
93 if (mask[i]) {
94 index[i] = 1;
95 }
96 }
97 break;
98 case GL_COPY:
99 /* do nothing */
100 break;
101 case GL_COPY_INVERTED:
102 for (i=0;i<n;i++) {
103 if (mask[i]) {
104 index[i] = ~index[i];
105 }
106 }
107 break;
108 case GL_NOOP:
109 for (i=0;i<n;i++) {
110 if (mask[i]) {
111 index[i] = dest[i];
112 }
113 }
114 break;
115 case GL_INVERT:
116 for (i=0;i<n;i++) {
117 if (mask[i]) {
118 index[i] = ~dest[i];
119 }
120 }
121 break;
122 case GL_AND:
123 for (i=0;i<n;i++) {
124 if (mask[i]) {
125 index[i] &= dest[i];
126 }
127 }
128 break;
129 case GL_NAND:
130 for (i=0;i<n;i++) {
131 if (mask[i]) {
132 index[i] = ~(index[i] & dest[i]);
133 }
134 }
135 break;
136 case GL_OR:
137 for (i=0;i<n;i++) {
138 if (mask[i]) {
139 index[i] |= dest[i];
140 }
141 }
142 break;
143 case GL_NOR:
144 for (i=0;i<n;i++) {
145 if (mask[i]) {
146 index[i] = ~(index[i] | dest[i]);
147 }
148 }
149 break;
150 case GL_XOR:
151 for (i=0;i<n;i++) {
152 if (mask[i]) {
153 index[i] ^= dest[i];
154 }
155 }
156 break;
157 case GL_EQUIV:
158 for (i=0;i<n;i++) {
159 if (mask[i]) {
160 index[i] = ~(index[i] ^ dest[i]);
161 }
162 }
163 break;
164 case GL_AND_REVERSE:
165 for (i=0;i<n;i++) {
166 if (mask[i]) {
167 index[i] = index[i] & ~dest[i];
168 }
169 }
170 break;
171 case GL_AND_INVERTED:
172 for (i=0;i<n;i++) {
173 if (mask[i]) {
174 index[i] = ~index[i] & dest[i];
175 }
176 }
177 break;
178 case GL_OR_REVERSE:
179 for (i=0;i<n;i++) {
180 if (mask[i]) {
181 index[i] = index[i] | ~dest[i];
182 }
183 }
184 break;
185 case GL_OR_INVERTED:
186 for (i=0;i<n;i++) {
187 if (mask[i]) {
188 index[i] = ~index[i] | dest[i];
189 }
190 }
191 break;
192 default:
193 gl_error( ctx, GL_INVALID_ENUM, "gl_logic error" );
194 }
195 }
196
197
198
199 /*
200 * Apply the current logic operator to an array of CI pixels. This is only
201 * used if the device driver can't do logic ops.
202 */
203 void gl_logicop_ci_pixels( GLcontext *ctx,
204 GLuint n, const GLint x[], const GLint y[],
205 GLuint index[], GLubyte mask[] )
206 {
207 GLuint dest[PB_SIZE];
208 GLuint i;
209
210 /* Read dest values from frame buffer */
211 (*ctx->Driver.ReadIndexPixels)( ctx, n, x, y, dest, mask );
212
213 switch (ctx->Color.LogicOp) {
214 case GL_CLEAR:
215 for (i=0;i<n;i++) {
216 if (mask[i]) {
217 index[i] = 0;
218 }
219 }
220 break;
221 case GL_SET:
222 for (i=0;i<n;i++) {
223 if (mask[i]) {
224 index[i] = 1;
225 }
226 }
227 break;
228 case GL_COPY:
229 /* do nothing */
230 break;
231 case GL_COPY_INVERTED:
232 for (i=0;i<n;i++) {
233 if (mask[i]) {
234 index[i] = ~index[i];
235 }
236 }
237 break;
238 case GL_NOOP:
239 for (i=0;i<n;i++) {
240 if (mask[i]) {
241 index[i] = dest[i];
242 }
243 }
244 break;
245 case GL_INVERT:
246 for (i=0;i<n;i++) {
247 if (mask[i]) {
248 index[i] = ~dest[i];
249 }
250 }
251 break;
252 case GL_AND:
253 for (i=0;i<n;i++) {
254 if (mask[i]) {
255 index[i] &= dest[i];
256 }
257 }
258 break;
259 case GL_NAND:
260 for (i=0;i<n;i++) {
261 if (mask[i]) {
262 index[i] = ~(index[i] & dest[i]);
263 }
264 }
265 break;
266 case GL_OR:
267 for (i=0;i<n;i++) {
268 if (mask[i]) {
269 index[i] |= dest[i];
270 }
271 }
272 break;
273 case GL_NOR:
274 for (i=0;i<n;i++) {
275 if (mask[i]) {
276 index[i] = ~(index[i] | dest[i]);
277 }
278 }
279 break;
280 case GL_XOR:
281 for (i=0;i<n;i++) {
282 if (mask[i]) {
283 index[i] ^= dest[i];
284 }
285 }
286 break;
287 case GL_EQUIV:
288 for (i=0;i<n;i++) {
289 if (mask[i]) {
290 index[i] = ~(index[i] ^ dest[i]);
291 }
292 }
293 break;
294 case GL_AND_REVERSE:
295 for (i=0;i<n;i++) {
296 if (mask[i]) {
297 index[i] = index[i] & ~dest[i];
298 }
299 }
300 break;
301 case GL_AND_INVERTED:
302 for (i=0;i<n;i++) {
303 if (mask[i]) {
304 index[i] = ~index[i] & dest[i];
305 }
306 }
307 break;
308 case GL_OR_REVERSE:
309 for (i=0;i<n;i++) {
310 if (mask[i]) {
311 index[i] = index[i] | ~dest[i];
312 }
313 }
314 break;
315 case GL_OR_INVERTED:
316 for (i=0;i<n;i++) {
317 if (mask[i]) {
318 index[i] = ~index[i] | dest[i];
319 }
320 }
321 break;
322 default:
323 gl_error( ctx, GL_INVALID_ENUM, "gl_logic_pixels error" );
324 }
325 }
326
327
328
329 /*
330 * Apply the current logic operator to a span of RGBA pixels. This is only
331 * used if the device driver can't do logic ops.
332 */
333 void gl_logicop_rgba_span( GLcontext *ctx,
334 GLuint n, GLint x, GLint y,
335 GLubyte red[], GLubyte green[],
336 GLubyte blue[], GLubyte alpha[],
337 GLubyte mask[] )
338 {
339 GLubyte rdest[MAX_WIDTH], gdest[MAX_WIDTH];
340 GLubyte bdest[MAX_WIDTH], adest[MAX_WIDTH];
341 GLuint i;
342
343 /* Read span of current frame buffer pixels */
344 gl_read_color_span( ctx, n, x, y, rdest, gdest, bdest, adest );
345
346 /* apply logic op */
347 switch (ctx->Color.LogicOp) {
348 case GL_CLEAR:
349 for (i=0;i<n;i++) {
350 if (mask[i]) {
351 red[i] = green[i] = blue[i] = alpha[i] = 0;
352 }
353 }
354 break;
355 case GL_SET:
356 {
357 GLubyte r = (GLint) ctx->Visual->RedScale;
358 GLubyte g = (GLint) ctx->Visual->GreenScale;
359 GLubyte b = (GLint) ctx->Visual->BlueScale;
360 GLubyte a = (GLint) ctx->Visual->AlphaScale;
361 for (i=0;i<n;i++) {
362 if (mask[i]) {
363 red[i] = r;
364 green[i] = g;
365 blue[i] = b;
366 alpha[i] = a;
367 }
368 }
369 }
370 break;
371 case GL_COPY:
372 /* do nothing */
373 break;
374 case GL_COPY_INVERTED:
375 for (i=0;i<n;i++) {
376 if (mask[i]) {
377 red[i] = ~red[i];
378 green[i] = ~green[i];
379 blue[i] = ~blue[i];
380 alpha[i] = ~alpha[i];
381 }
382 }
383 break;
384 case GL_NOOP:
385 for (i=0;i<n;i++) {
386 if (mask[i]) {
387 red[i] = rdest[i];
388 green[i] = gdest[i];
389 blue[i] = bdest[i];
390 alpha[i] = adest[i];
391 }
392 }
393 break;
394 case GL_INVERT:
395 for (i=0;i<n;i++) {
396 if (mask[i]) {
397 red[i] = ~rdest[i];
398 green[i] = ~gdest[i];
399 blue[i] = ~bdest[i];
400 alpha[i] = ~adest[i];
401 }
402 }
403 break;
404 case GL_AND:
405 for (i=0;i<n;i++) {
406 if (mask[i]) {
407 red[i] &= rdest[i];
408 green[i] &= gdest[i];
409 blue[i] &= bdest[i];
410 alpha[i] &= adest[i];
411 }
412 }
413 break;
414 case GL_NAND:
415 for (i=0;i<n;i++) {
416 if (mask[i]) {
417 red[i] = ~(red[i] & rdest[i]);
418 green[i] = ~(green[i] & gdest[i]);
419 blue[i] = ~(blue[i] & bdest[i]);
420 alpha[i] = ~(alpha[i] & adest[i]);
421 }
422 }
423 break;
424 case GL_OR:
425 for (i=0;i<n;i++) {
426 if (mask[i]) {
427 red[i] |= rdest[i];
428 green[i] |= gdest[i];
429 blue[i] |= bdest[i];
430 alpha[i] |= adest[i];
431 }
432 }
433 break;
434 case GL_NOR:
435 for (i=0;i<n;i++) {
436 if (mask[i]) {
437 red[i] = ~(red[i] | rdest[i]);
438 green[i] = ~(green[i] | gdest[i]);
439 blue[i] = ~(blue[i] | bdest[i]);
440 alpha[i] = ~(alpha[i] | adest[i]);
441 }
442 }
443 break;
444 case GL_XOR:
445 for (i=0;i<n;i++) {
446 if (mask[i]) {
447 red[i] ^= rdest[i];
448 green[i] ^= gdest[i];
449 blue[i] ^= bdest[i];
450 alpha[i] ^= adest[i];
451 }
452 }
453 break;
454 case GL_EQUIV:
455 for (i=0;i<n;i++) {
456 if (mask[i]) {
457 red[i] = ~(red[i] ^ rdest[i]);
458 green[i] = ~(green[i] ^ gdest[i]);
459 blue[i] = ~(blue[i] ^ bdest[i]);
460 alpha[i] = ~(alpha[i] ^ adest[i]);
461 }
462 }
463 break;
464 case GL_AND_REVERSE:
465 for (i=0;i<n;i++) {
466 if (mask[i]) {
467 red[i] = red[i] & ~rdest[i];
468 green[i] = green[i] & ~gdest[i];
469 blue[i] = blue[i] & ~bdest[i];
470 alpha[i] = alpha[i] & ~adest[i];
471 }
472 }
473 break;
474 case GL_AND_INVERTED:
475 for (i=0;i<n;i++) {
476 if (mask[i]) {
477 red[i] = ~red[i] & rdest[i];
478 green[i] = ~green[i] & gdest[i];
479 blue[i] = ~blue[i] & bdest[i];
480 alpha[i] = ~alpha[i] & adest[i];
481 }
482 }
483 break;
484 case GL_OR_REVERSE:
485 for (i=0;i<n;i++) {
486 if (mask[i]) {
487 red[i] = red[i] | ~rdest[i];
488 green[i] = green[i] | ~gdest[i];
489 blue[i] = blue[i] | ~bdest[i];
490 alpha[i] = alpha[i] | ~adest[i];
491 }
492 }
493 break;
494 case GL_OR_INVERTED:
495 for (i=0;i<n;i++) {
496 if (mask[i]) {
497 red[i] = ~red[i] | rdest[i];
498 green[i] = ~green[i] | gdest[i];
499 blue[i] = ~blue[i] | bdest[i];
500 alpha[i] = ~alpha[i] | adest[i];
501 }
502 }
503 break;
504 default:
505 /* should never happen */
506 abort();
507 }
508 }
509
510
511
512 /*
513 * Apply the current logic operator to an array of RGBA pixels. This is only
514 * used if the device driver can't do logic ops.
515 */
516 void gl_logicop_rgba_pixels( GLcontext *ctx,
517 GLuint n, const GLint x[], const GLint y[],
518 GLubyte red[], GLubyte green[],
519 GLubyte blue[], GLubyte alpha[],
520 GLubyte mask[] )
521 {
522 GLubyte rdest[PB_SIZE], gdest[PB_SIZE], bdest[PB_SIZE], adest[PB_SIZE];
523 GLuint i;
524
525 /* Read pixels from current color buffer */
526 (*ctx->Driver.ReadColorPixels)( ctx, n, x, y, rdest, gdest, bdest, adest, mask );
527 if (ctx->RasterMask & ALPHABUF_BIT) {
528 gl_read_alpha_pixels( ctx, n, x, y, adest, mask );
529 }
530
531 /* apply logic op */
532 switch (ctx->Color.LogicOp) {
533 case GL_CLEAR:
534 for (i=0;i<n;i++) {
535 if (mask[i]) {
536 red[i] = green[i] = blue[i] = alpha[i] = 0;
537 }
538 }
539 break;
540 case GL_SET:
541 {
542 GLubyte r = (GLint) ctx->Visual->RedScale;
543 GLubyte g = (GLint) ctx->Visual->GreenScale;
544 GLubyte b = (GLint) ctx->Visual->BlueScale;
545 GLubyte a = (GLint) ctx->Visual->AlphaScale;
546 for (i=0;i<n;i++) {
547 if (mask[i]) {
548 red[i] = r;
549 green[i] = g;
550 blue[i] = b;
551 alpha[i] = a;
552 }
553 }
554 }
555 break;
556 case GL_COPY:
557 /* do nothing */
558 break;
559 case GL_COPY_INVERTED:
560 for (i=0;i<n;i++) {
561 if (mask[i]) {
562 red[i] = ~red[i];
563 green[i] = ~green[i];
564 blue[i] = ~blue[i];
565 alpha[i] = ~alpha[i];
566 }
567 }
568 break;
569 case GL_NOOP:
570 for (i=0;i<n;i++) {
571 if (mask[i]) {
572 red[i] = rdest[i];
573 green[i] = gdest[i];
574 blue[i] = bdest[i];
575 alpha[i] = adest[i];
576 }
577 }
578 break;
579 case GL_INVERT:
580 for (i=0;i<n;i++) {
581 if (mask[i]) {
582 red[i] = ~rdest[i];
583 green[i] = ~gdest[i];
584 blue[i] = ~bdest[i];
585 alpha[i] = ~adest[i];
586 }
587 }
588 break;
589 case GL_AND:
590 for (i=0;i<n;i++) {
591 if (mask[i]) {
592 red[i] &= rdest[i];
593 green[i] &= gdest[i];
594 blue[i] &= bdest[i];
595 alpha[i] &= adest[i];
596 }
597 }
598 break;
599 case GL_NAND:
600 for (i=0;i<n;i++) {
601 if (mask[i]) {
602 red[i] = ~(red[i] & rdest[i]);
603 green[i] = ~(green[i] & gdest[i]);
604 blue[i] = ~(blue[i] & bdest[i]);
605 alpha[i] = ~(alpha[i] & adest[i]);
606 }
607 }
608 break;
609 case GL_OR:
610 for (i=0;i<n;i++) {
611 if (mask[i]) {
612 red[i] |= rdest[i];
613 green[i] |= gdest[i];
614 blue[i] |= bdest[i];
615 alpha[i] |= adest[i];
616 }
617 }
618 break;
619 case GL_NOR:
620 for (i=0;i<n;i++) {
621 if (mask[i]) {
622 red[i] = ~(red[i] | rdest[i]);
623 green[i] = ~(green[i] | gdest[i]);
624 blue[i] = ~(blue[i] | bdest[i]);
625 alpha[i] = ~(alpha[i] | adest[i]);
626 }
627 }
628 break;
629 case GL_XOR:
630 for (i=0;i<n;i++) {
631 if (mask[i]) {
632 red[i] ^= rdest[i];
633 green[i] ^= gdest[i];
634 blue[i] ^= bdest[i];
635 alpha[i] ^= adest[i];
636 }
637 }
638 break;
639 case GL_EQUIV:
640 for (i=0;i<n;i++) {
641 if (mask[i]) {
642 red[i] = ~(red[i] ^ rdest[i]);
643 green[i] = ~(green[i] ^ gdest[i]);
644 blue[i] = ~(blue[i] ^ bdest[i]);
645 alpha[i] = ~(alpha[i] ^ adest[i]);
646 }
647 }
648 break;
649 case GL_AND_REVERSE:
650 for (i=0;i<n;i++) {
651 if (mask[i]) {
652 red[i] = red[i] & ~rdest[i];
653 green[i] = green[i] & ~gdest[i];
654 blue[i] = blue[i] & ~bdest[i];
655 alpha[i] = alpha[i] & ~adest[i];
656 }
657 }
658 break;
659 case GL_AND_INVERTED:
660 for (i=0;i<n;i++) {
661 if (mask[i]) {
662 red[i] = ~red[i] & rdest[i];
663 green[i] = ~green[i] & gdest[i];
664 blue[i] = ~blue[i] & bdest[i];
665 alpha[i] = ~alpha[i] & adest[i];
666 }
667 }
668 break;
669 case GL_OR_REVERSE:
670 for (i=0;i<n;i++) {
671 if (mask[i]) {
672 red[i] = red[i] | ~rdest[i];
673 green[i] = green[i] | ~gdest[i];
674 blue[i] = blue[i] | ~bdest[i];
675 alpha[i] = alpha[i] | ~adest[i];
676 }
677 }
678 break;
679 case GL_OR_INVERTED:
680 for (i=0;i<n;i++) {
681 if (mask[i]) {
682 red[i] = ~red[i] | rdest[i];
683 green[i] = ~green[i] | gdest[i];
684 blue[i] = ~blue[i] | bdest[i];
685 alpha[i] = ~alpha[i] | adest[i];
686 }
687 }
688 break;
689 default:
690 /* should never happen */
691 abort();
692 }
693 }
694
695