More span clean-up, mostly texture-related.
[mesa.git] / src / mesa / swrast / s_depth.c
1 /* $Id: s_depth.c,v 1.13 2002/01/28 00:07:33 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 4.1
6 *
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 */
26
27
28 #include "glheader.h"
29 #include "context.h"
30 #include "macros.h"
31 #include "mem.h"
32
33 #include "s_depth.h"
34 #include "s_context.h"
35 #include "s_pb.h"
36
37
38
39
40 /*
41 * Return address of depth buffer value for given window coord.
42 */
43 GLvoid *
44 _mesa_zbuffer_address(GLcontext *ctx, GLint x, GLint y)
45 {
46 if (ctx->Visual.depthBits <= 16)
47 return (GLushort *) ctx->DrawBuffer->DepthBuffer + ctx->DrawBuffer->Width * y + x;
48 else
49 return (GLuint *) ctx->DrawBuffer->DepthBuffer + ctx->DrawBuffer->Width * y + x;
50 }
51
52
53 #define Z_ADDRESS16( CTX, X, Y ) \
54 ( ((GLushort *) (CTX)->DrawBuffer->DepthBuffer) \
55 + (CTX)->DrawBuffer->Width * (Y) + (X) )
56
57 #define Z_ADDRESS32( CTX, X, Y ) \
58 ( ((GLuint *) (CTX)->DrawBuffer->DepthBuffer) \
59 + (CTX)->DrawBuffer->Width * (Y) + (X) )
60
61
62
63 /**********************************************************************/
64 /***** Depth Testing Functions *****/
65 /**********************************************************************/
66
67
68 /*
69 * Do depth test for an array of fragments. This is used both for
70 * software and hardware Z buffers.
71 * Input: zbuffer - array of z values in the zbuffer
72 * z - array of fragment z values
73 * Return: number of fragments which pass the test.
74 */
75 static GLuint
76 depth_test_span16( GLcontext *ctx, GLuint n, GLint x, GLint y,
77 GLushort zbuffer[], const GLdepth z[], GLubyte mask[] )
78 {
79 GLuint passed = 0;
80
81 /* switch cases ordered from most frequent to less frequent */
82 switch (ctx->Depth.Func) {
83 case GL_LESS:
84 if (ctx->Depth.Mask) {
85 /* Update Z buffer */
86 GLuint i;
87 for (i=0; i<n; i++) {
88 if (mask[i]) {
89 if (z[i] < zbuffer[i]) {
90 /* pass */
91 zbuffer[i] = z[i];
92 passed++;
93 }
94 else {
95 /* fail */
96 mask[i] = 0;
97 }
98 }
99 }
100 }
101 else {
102 /* Don't update Z buffer */
103 GLuint i;
104 for (i=0; i<n; i++) {
105 if (mask[i]) {
106 if (z[i] < zbuffer[i]) {
107 /* pass */
108 passed++;
109 }
110 else {
111 mask[i] = 0;
112 }
113 }
114 }
115 }
116 break;
117 case GL_LEQUAL:
118 if (ctx->Depth.Mask) {
119 /* Update Z buffer */
120 GLuint i;
121 for (i=0;i<n;i++) {
122 if (mask[i]) {
123 if (z[i] <= zbuffer[i]) {
124 zbuffer[i] = z[i];
125 passed++;
126 }
127 else {
128 mask[i] = 0;
129 }
130 }
131 }
132 }
133 else {
134 /* Don't update Z buffer */
135 GLuint i;
136 for (i=0;i<n;i++) {
137 if (mask[i]) {
138 if (z[i] <= zbuffer[i]) {
139 /* pass */
140 passed++;
141 }
142 else {
143 mask[i] = 0;
144 }
145 }
146 }
147 }
148 break;
149 case GL_GEQUAL:
150 if (ctx->Depth.Mask) {
151 /* Update Z buffer */
152 GLuint i;
153 for (i=0;i<n;i++) {
154 if (mask[i]) {
155 if (z[i] >= zbuffer[i]) {
156 zbuffer[i] = z[i];
157 passed++;
158 }
159 else {
160 mask[i] = 0;
161 }
162 }
163 }
164 }
165 else {
166 /* Don't update Z buffer */
167 GLuint i;
168 for (i=0;i<n;i++) {
169 if (mask[i]) {
170 if (z[i] >= zbuffer[i]) {
171 /* pass */
172 passed++;
173 }
174 else {
175 mask[i] = 0;
176 }
177 }
178 }
179 }
180 break;
181 case GL_GREATER:
182 if (ctx->Depth.Mask) {
183 /* Update Z buffer */
184 GLuint i;
185 for (i=0;i<n;i++) {
186 if (mask[i]) {
187 if (z[i] > zbuffer[i]) {
188 zbuffer[i] = z[i];
189 passed++;
190 }
191 else {
192 mask[i] = 0;
193 }
194 }
195 }
196 }
197 else {
198 /* Don't update Z buffer */
199 GLuint i;
200 for (i=0;i<n;i++) {
201 if (mask[i]) {
202 if (z[i] > zbuffer[i]) {
203 /* pass */
204 passed++;
205 }
206 else {
207 mask[i] = 0;
208 }
209 }
210 }
211 }
212 break;
213 case GL_NOTEQUAL:
214 if (ctx->Depth.Mask) {
215 /* Update Z buffer */
216 GLuint i;
217 for (i=0;i<n;i++) {
218 if (mask[i]) {
219 if (z[i] != zbuffer[i]) {
220 zbuffer[i] = z[i];
221 passed++;
222 }
223 else {
224 mask[i] = 0;
225 }
226 }
227 }
228 }
229 else {
230 /* Don't update Z buffer */
231 GLuint i;
232 for (i=0;i<n;i++) {
233 if (mask[i]) {
234 if (z[i] != zbuffer[i]) {
235 /* pass */
236 passed++;
237 }
238 else {
239 mask[i] = 0;
240 }
241 }
242 }
243 }
244 break;
245 case GL_EQUAL:
246 if (ctx->Depth.Mask) {
247 /* Update Z buffer */
248 GLuint i;
249 for (i=0;i<n;i++) {
250 if (mask[i]) {
251 if (z[i] == zbuffer[i]) {
252 zbuffer[i] = z[i];
253 passed++;
254 }
255 else {
256 mask[i] = 0;
257 }
258 }
259 }
260 }
261 else {
262 /* Don't update Z buffer */
263 GLuint i;
264 for (i=0;i<n;i++) {
265 if (mask[i]) {
266 if (z[i] == zbuffer[i]) {
267 /* pass */
268 passed++;
269 }
270 else {
271 mask[i] = 0;
272 }
273 }
274 }
275 }
276 break;
277 case GL_ALWAYS:
278 if (ctx->Depth.Mask) {
279 /* Update Z buffer */
280 GLuint i;
281 for (i=0;i<n;i++) {
282 if (mask[i]) {
283 zbuffer[i] = z[i];
284 passed++;
285 }
286 }
287 }
288 else {
289 /* Don't update Z buffer or mask */
290 passed = n;
291 }
292 break;
293 case GL_NEVER:
294 BZERO(mask, n * sizeof(GLubyte));
295 break;
296 default:
297 _mesa_problem(ctx, "Bad depth func in depth_test_span16");
298 }
299
300 return passed;
301 }
302
303
304 static GLuint
305 depth_test_span32( GLcontext *ctx, GLuint n, GLint x, GLint y,
306 GLuint zbuffer[], const GLdepth z[], GLubyte mask[] )
307 {
308 GLuint passed = 0;
309
310 /* switch cases ordered from most frequent to less frequent */
311 switch (ctx->Depth.Func) {
312 case GL_LESS:
313 if (ctx->Depth.Mask) {
314 /* Update Z buffer */
315 GLuint i;
316 for (i=0; i<n; i++) {
317 if (mask[i]) {
318 if (z[i] < zbuffer[i]) {
319 /* pass */
320 zbuffer[i] = z[i];
321 passed++;
322 }
323 else {
324 /* fail */
325 mask[i] = 0;
326 }
327 }
328 }
329 }
330 else {
331 /* Don't update Z buffer */
332 GLuint i;
333 for (i=0; i<n; i++) {
334 if (mask[i]) {
335 if (z[i] < zbuffer[i]) {
336 /* pass */
337 passed++;
338 }
339 else {
340 mask[i] = 0;
341 }
342 }
343 }
344 }
345 break;
346 case GL_LEQUAL:
347 if (ctx->Depth.Mask) {
348 /* Update Z buffer */
349 GLuint i;
350 for (i=0;i<n;i++) {
351 if (mask[i]) {
352 if (z[i] <= zbuffer[i]) {
353 zbuffer[i] = z[i];
354 passed++;
355 }
356 else {
357 mask[i] = 0;
358 }
359 }
360 }
361 }
362 else {
363 /* Don't update Z buffer */
364 GLuint i;
365 for (i=0;i<n;i++) {
366 if (mask[i]) {
367 if (z[i] <= zbuffer[i]) {
368 /* pass */
369 passed++;
370 }
371 else {
372 mask[i] = 0;
373 }
374 }
375 }
376 }
377 break;
378 case GL_GEQUAL:
379 if (ctx->Depth.Mask) {
380 /* Update Z buffer */
381 GLuint i;
382 for (i=0;i<n;i++) {
383 if (mask[i]) {
384 if (z[i] >= zbuffer[i]) {
385 zbuffer[i] = z[i];
386 passed++;
387 }
388 else {
389 mask[i] = 0;
390 }
391 }
392 }
393 }
394 else {
395 /* Don't update Z buffer */
396 GLuint i;
397 for (i=0;i<n;i++) {
398 if (mask[i]) {
399 if (z[i] >= zbuffer[i]) {
400 /* pass */
401 passed++;
402 }
403 else {
404 mask[i] = 0;
405 }
406 }
407 }
408 }
409 break;
410 case GL_GREATER:
411 if (ctx->Depth.Mask) {
412 /* Update Z buffer */
413 GLuint i;
414 for (i=0;i<n;i++) {
415 if (mask[i]) {
416 if (z[i] > zbuffer[i]) {
417 zbuffer[i] = z[i];
418 passed++;
419 }
420 else {
421 mask[i] = 0;
422 }
423 }
424 }
425 }
426 else {
427 /* Don't update Z buffer */
428 GLuint i;
429 for (i=0;i<n;i++) {
430 if (mask[i]) {
431 if (z[i] > zbuffer[i]) {
432 /* pass */
433 passed++;
434 }
435 else {
436 mask[i] = 0;
437 }
438 }
439 }
440 }
441 break;
442 case GL_NOTEQUAL:
443 if (ctx->Depth.Mask) {
444 /* Update Z buffer */
445 GLuint i;
446 for (i=0;i<n;i++) {
447 if (mask[i]) {
448 if (z[i] != zbuffer[i]) {
449 zbuffer[i] = z[i];
450 passed++;
451 }
452 else {
453 mask[i] = 0;
454 }
455 }
456 }
457 }
458 else {
459 /* Don't update Z buffer */
460 GLuint i;
461 for (i=0;i<n;i++) {
462 if (mask[i]) {
463 if (z[i] != zbuffer[i]) {
464 /* pass */
465 passed++;
466 }
467 else {
468 mask[i] = 0;
469 }
470 }
471 }
472 }
473 break;
474 case GL_EQUAL:
475 if (ctx->Depth.Mask) {
476 /* Update Z buffer */
477 GLuint i;
478 for (i=0;i<n;i++) {
479 if (mask[i]) {
480 if (z[i] == zbuffer[i]) {
481 zbuffer[i] = z[i];
482 passed++;
483 }
484 else {
485 mask[i] = 0;
486 }
487 }
488 }
489 }
490 else {
491 /* Don't update Z buffer */
492 GLuint i;
493 for (i=0;i<n;i++) {
494 if (mask[i]) {
495 if (z[i] == zbuffer[i]) {
496 /* pass */
497 passed++;
498 }
499 else {
500 mask[i] = 0;
501 }
502 }
503 }
504 }
505 break;
506 case GL_ALWAYS:
507 if (ctx->Depth.Mask) {
508 /* Update Z buffer */
509 GLuint i;
510 for (i=0;i<n;i++) {
511 if (mask[i]) {
512 zbuffer[i] = z[i];
513 passed++;
514 }
515 }
516 }
517 else {
518 /* Don't update Z buffer or mask */
519 passed = n;
520 }
521 break;
522 case GL_NEVER:
523 BZERO(mask, n * sizeof(GLubyte));
524 break;
525 default:
526 _mesa_problem(ctx, "Bad depth func in depth_test_span32");
527 }
528
529 return passed;
530 }
531
532
533
534 /*
535 * Apply depth test to span of fragments. Hardware or software z buffer.
536 */
537 GLuint
538 _old_depth_test_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
539 const GLdepth z[], GLubyte mask[] )
540 {
541 SWcontext *swrast = SWRAST_CONTEXT(ctx);
542 if (swrast->Driver.ReadDepthSpan) {
543 /* hardware-based depth buffer */
544 GLdepth zbuffer[MAX_WIDTH];
545 GLuint passed;
546 (*swrast->Driver.ReadDepthSpan)(ctx, n, x, y, zbuffer);
547 passed = depth_test_span32(ctx, n, x, y, zbuffer, z, mask);
548 assert(swrast->Driver.WriteDepthSpan);
549 (*swrast->Driver.WriteDepthSpan)(ctx, n, x, y, zbuffer, mask);
550 return passed;
551 }
552 else {
553 /* software depth buffer */
554 if (ctx->Visual.depthBits <= 16) {
555 GLushort *zptr = (GLushort *) Z_ADDRESS16(ctx, x, y);
556 GLuint passed = depth_test_span16(ctx, n, x, y, zptr, z, mask);
557 return passed;
558 }
559 else {
560 GLuint *zptr = (GLuint *) Z_ADDRESS32(ctx, x, y);
561 GLuint passed = depth_test_span32(ctx, n, x, y, zptr, z, mask);
562 return passed;
563 }
564 }
565 }
566
567 /*
568 * Apply depth test to span of fragments. Hardware or software z buffer.
569 */
570 GLuint
571 _mesa_depth_test_span( GLcontext *ctx, struct sw_span *span)
572 {
573 SWcontext *swrast = SWRAST_CONTEXT(ctx);
574
575 ASSERT(span->arrayMask & SPAN_Z);
576
577 if (swrast->Driver.ReadDepthSpan) {
578 /* hardware-based depth buffer */
579 GLdepth zbuffer[MAX_WIDTH];
580 GLuint passed;
581 (*swrast->Driver.ReadDepthSpan)(ctx, span->end, span->x, span->y, zbuffer);
582 passed = depth_test_span32(ctx, span->end, span->x, span->y,
583 zbuffer, span->zArray, span->mask);
584 ASSERT(swrast->Driver.WriteDepthSpan);
585 (*swrast->Driver.WriteDepthSpan)(ctx, span->end, span->x, span->y, zbuffer, span->mask);
586 if (passed < span->end)
587 span->writeAll = GL_FALSE;
588 return passed;
589 }
590 else {
591 GLuint passed;
592 /* software depth buffer */
593 if (ctx->Visual.depthBits <= 16) {
594 GLushort *zptr = (GLushort *) Z_ADDRESS16(ctx, span->x, span->y);
595 passed = depth_test_span16(ctx, span->end, span->x, span->y, zptr, span->zArray, span->mask);
596 }
597 else {
598 GLuint *zptr = (GLuint *) Z_ADDRESS32(ctx, span->x, span->y);
599 passed = depth_test_span32(ctx, span->end, span->x, span->y, zptr, span->zArray, span->mask);
600 }
601 if (passed < span->end)
602 span->writeAll = GL_FALSE;
603 return passed;
604 }
605 }
606
607
608
609
610 /*
611 * Do depth testing for an array of fragments using software Z buffer.
612 */
613 static void
614 software_depth_test_pixels16( GLcontext *ctx, GLuint n,
615 const GLint x[], const GLint y[],
616 const GLdepth z[], GLubyte mask[] )
617 {
618 /* switch cases ordered from most frequent to less frequent */
619 switch (ctx->Depth.Func) {
620 case GL_LESS:
621 if (ctx->Depth.Mask) {
622 /* Update Z buffer */
623 GLuint i;
624 for (i=0; i<n; i++) {
625 if (mask[i]) {
626 GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
627 if (z[i] < *zptr) {
628 /* pass */
629 *zptr = z[i];
630 }
631 else {
632 /* fail */
633 mask[i] = 0;
634 }
635 }
636 }
637 }
638 else {
639 /* Don't update Z buffer */
640 GLuint i;
641 for (i=0; i<n; i++) {
642 if (mask[i]) {
643 GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
644 if (z[i] < *zptr) {
645 /* pass */
646 }
647 else {
648 /* fail */
649 mask[i] = 0;
650 }
651 }
652 }
653 }
654 break;
655 case GL_LEQUAL:
656 if (ctx->Depth.Mask) {
657 /* Update Z buffer */
658 GLuint i;
659 for (i=0; i<n; i++) {
660 if (mask[i]) {
661 GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
662 if (z[i] <= *zptr) {
663 /* pass */
664 *zptr = z[i];
665 }
666 else {
667 /* fail */
668 mask[i] = 0;
669 }
670 }
671 }
672 }
673 else {
674 /* Don't update Z buffer */
675 GLuint i;
676 for (i=0; i<n; i++) {
677 if (mask[i]) {
678 GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
679 if (z[i] <= *zptr) {
680 /* pass */
681 }
682 else {
683 /* fail */
684 mask[i] = 0;
685 }
686 }
687 }
688 }
689 break;
690 case GL_GEQUAL:
691 if (ctx->Depth.Mask) {
692 /* Update Z buffer */
693 GLuint i;
694 for (i=0; i<n; i++) {
695 if (mask[i]) {
696 GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
697 if (z[i] >= *zptr) {
698 /* pass */
699 *zptr = z[i];
700 }
701 else {
702 /* fail */
703 mask[i] = 0;
704 }
705 }
706 }
707 }
708 else {
709 /* Don't update Z buffer */
710 GLuint i;
711 for (i=0; i<n; i++) {
712 if (mask[i]) {
713 GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
714 if (z[i] >= *zptr) {
715 /* pass */
716 }
717 else {
718 /* fail */
719 mask[i] = 0;
720 }
721 }
722 }
723 }
724 break;
725 case GL_GREATER:
726 if (ctx->Depth.Mask) {
727 /* Update Z buffer */
728 GLuint i;
729 for (i=0; i<n; i++) {
730 if (mask[i]) {
731 GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
732 if (z[i] > *zptr) {
733 /* pass */
734 *zptr = z[i];
735 }
736 else {
737 /* fail */
738 mask[i] = 0;
739 }
740 }
741 }
742 }
743 else {
744 /* Don't update Z buffer */
745 GLuint i;
746 for (i=0; i<n; i++) {
747 if (mask[i]) {
748 GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
749 if (z[i] > *zptr) {
750 /* pass */
751 }
752 else {
753 /* fail */
754 mask[i] = 0;
755 }
756 }
757 }
758 }
759 break;
760 case GL_NOTEQUAL:
761 if (ctx->Depth.Mask) {
762 /* Update Z buffer */
763 GLuint i;
764 for (i=0; i<n; i++) {
765 if (mask[i]) {
766 GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
767 if (z[i] != *zptr) {
768 /* pass */
769 *zptr = z[i];
770 }
771 else {
772 /* fail */
773 mask[i] = 0;
774 }
775 }
776 }
777 }
778 else {
779 /* Don't update Z buffer */
780 GLuint i;
781 for (i=0; i<n; i++) {
782 if (mask[i]) {
783 GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
784 if (z[i] != *zptr) {
785 /* pass */
786 }
787 else {
788 /* fail */
789 mask[i] = 0;
790 }
791 }
792 }
793 }
794 break;
795 case GL_EQUAL:
796 if (ctx->Depth.Mask) {
797 /* Update Z buffer */
798 GLuint i;
799 for (i=0; i<n; i++) {
800 if (mask[i]) {
801 GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
802 if (z[i] == *zptr) {
803 /* pass */
804 *zptr = z[i];
805 }
806 else {
807 /* fail */
808 mask[i] = 0;
809 }
810 }
811 }
812 }
813 else {
814 /* Don't update Z buffer */
815 GLuint i;
816 for (i=0; i<n; i++) {
817 if (mask[i]) {
818 GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
819 if (z[i] == *zptr) {
820 /* pass */
821 }
822 else {
823 /* fail */
824 mask[i] = 0;
825 }
826 }
827 }
828 }
829 break;
830 case GL_ALWAYS:
831 if (ctx->Depth.Mask) {
832 /* Update Z buffer */
833 GLuint i;
834 for (i=0; i<n; i++) {
835 if (mask[i]) {
836 GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
837 *zptr = z[i];
838 }
839 }
840 }
841 else {
842 /* Don't update Z buffer or mask */
843 }
844 break;
845 case GL_NEVER:
846 /* depth test never passes */
847 BZERO(mask, n * sizeof(GLubyte));
848 break;
849 default:
850 _mesa_problem(ctx, "Bad depth func in software_depth_test_pixels");
851 }
852 }
853
854
855
856 /*
857 * Do depth testing for an array of fragments using software Z buffer.
858 */
859 static void
860 software_depth_test_pixels32( GLcontext *ctx, GLuint n,
861 const GLint x[], const GLint y[],
862 const GLdepth z[], GLubyte mask[] )
863 {
864 /* switch cases ordered from most frequent to less frequent */
865 switch (ctx->Depth.Func) {
866 case GL_LESS:
867 if (ctx->Depth.Mask) {
868 /* Update Z buffer */
869 GLuint i;
870 for (i=0; i<n; i++) {
871 if (mask[i]) {
872 GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
873 if (z[i] < *zptr) {
874 /* pass */
875 *zptr = z[i];
876 }
877 else {
878 /* fail */
879 mask[i] = 0;
880 }
881 }
882 }
883 }
884 else {
885 /* Don't update Z buffer */
886 GLuint i;
887 for (i=0; i<n; i++) {
888 if (mask[i]) {
889 GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
890 if (z[i] < *zptr) {
891 /* pass */
892 }
893 else {
894 /* fail */
895 mask[i] = 0;
896 }
897 }
898 }
899 }
900 break;
901 case GL_LEQUAL:
902 if (ctx->Depth.Mask) {
903 /* Update Z buffer */
904 GLuint i;
905 for (i=0; i<n; i++) {
906 if (mask[i]) {
907 GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
908 if (z[i] <= *zptr) {
909 /* pass */
910 *zptr = z[i];
911 }
912 else {
913 /* fail */
914 mask[i] = 0;
915 }
916 }
917 }
918 }
919 else {
920 /* Don't update Z buffer */
921 GLuint i;
922 for (i=0; i<n; i++) {
923 if (mask[i]) {
924 GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
925 if (z[i] <= *zptr) {
926 /* pass */
927 }
928 else {
929 /* fail */
930 mask[i] = 0;
931 }
932 }
933 }
934 }
935 break;
936 case GL_GEQUAL:
937 if (ctx->Depth.Mask) {
938 /* Update Z buffer */
939 GLuint i;
940 for (i=0; i<n; i++) {
941 if (mask[i]) {
942 GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
943 if (z[i] >= *zptr) {
944 /* pass */
945 *zptr = z[i];
946 }
947 else {
948 /* fail */
949 mask[i] = 0;
950 }
951 }
952 }
953 }
954 else {
955 /* Don't update Z buffer */
956 GLuint i;
957 for (i=0; i<n; i++) {
958 if (mask[i]) {
959 GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
960 if (z[i] >= *zptr) {
961 /* pass */
962 }
963 else {
964 /* fail */
965 mask[i] = 0;
966 }
967 }
968 }
969 }
970 break;
971 case GL_GREATER:
972 if (ctx->Depth.Mask) {
973 /* Update Z buffer */
974 GLuint i;
975 for (i=0; i<n; i++) {
976 if (mask[i]) {
977 GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
978 if (z[i] > *zptr) {
979 /* pass */
980 *zptr = z[i];
981 }
982 else {
983 /* fail */
984 mask[i] = 0;
985 }
986 }
987 }
988 }
989 else {
990 /* Don't update Z buffer */
991 GLuint i;
992 for (i=0; i<n; i++) {
993 if (mask[i]) {
994 GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
995 if (z[i] > *zptr) {
996 /* pass */
997 }
998 else {
999 /* fail */
1000 mask[i] = 0;
1001 }
1002 }
1003 }
1004 }
1005 break;
1006 case GL_NOTEQUAL:
1007 if (ctx->Depth.Mask) {
1008 /* Update Z buffer */
1009 GLuint i;
1010 for (i=0; i<n; i++) {
1011 if (mask[i]) {
1012 GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
1013 if (z[i] != *zptr) {
1014 /* pass */
1015 *zptr = z[i];
1016 }
1017 else {
1018 /* fail */
1019 mask[i] = 0;
1020 }
1021 }
1022 }
1023 }
1024 else {
1025 /* Don't update Z buffer */
1026 GLuint i;
1027 for (i=0; i<n; i++) {
1028 if (mask[i]) {
1029 GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
1030 if (z[i] != *zptr) {
1031 /* pass */
1032 }
1033 else {
1034 /* fail */
1035 mask[i] = 0;
1036 }
1037 }
1038 }
1039 }
1040 break;
1041 case GL_EQUAL:
1042 if (ctx->Depth.Mask) {
1043 /* Update Z buffer */
1044 GLuint i;
1045 for (i=0; i<n; i++) {
1046 if (mask[i]) {
1047 GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
1048 if (z[i] == *zptr) {
1049 /* pass */
1050 *zptr = z[i];
1051 }
1052 else {
1053 /* fail */
1054 mask[i] = 0;
1055 }
1056 }
1057 }
1058 }
1059 else {
1060 /* Don't update Z buffer */
1061 GLuint i;
1062 for (i=0; i<n; i++) {
1063 if (mask[i]) {
1064 GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
1065 if (z[i] == *zptr) {
1066 /* pass */
1067 }
1068 else {
1069 /* fail */
1070 mask[i] = 0;
1071 }
1072 }
1073 }
1074 }
1075 break;
1076 case GL_ALWAYS:
1077 if (ctx->Depth.Mask) {
1078 /* Update Z buffer */
1079 GLuint i;
1080 for (i=0; i<n; i++) {
1081 if (mask[i]) {
1082 GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
1083 *zptr = z[i];
1084 }
1085 }
1086 }
1087 else {
1088 /* Don't update Z buffer or mask */
1089 }
1090 break;
1091 case GL_NEVER:
1092 /* depth test never passes */
1093 BZERO(mask, n * sizeof(GLubyte));
1094 break;
1095 default:
1096 _mesa_problem(ctx, "Bad depth func in software_depth_test_pixels");
1097 }
1098 }
1099
1100
1101
1102 /*
1103 * Do depth testing for an array of pixels using hardware Z buffer.
1104 * Input/output: zbuffer - array of depth values from Z buffer
1105 * Input: z - array of fragment z values.
1106 */
1107 static void
1108 hardware_depth_test_pixels( GLcontext *ctx, GLuint n, GLdepth zbuffer[],
1109 const GLdepth z[], GLubyte mask[] )
1110 {
1111 /* switch cases ordered from most frequent to less frequent */
1112 switch (ctx->Depth.Func) {
1113 case GL_LESS:
1114 if (ctx->Depth.Mask) {
1115 /* Update Z buffer */
1116 GLuint i;
1117 for (i=0; i<n; i++) {
1118 if (mask[i]) {
1119 if (z[i] < zbuffer[i]) {
1120 /* pass */
1121 zbuffer[i] = z[i];
1122 }
1123 else {
1124 /* fail */
1125 mask[i] = 0;
1126 }
1127 }
1128 }
1129 }
1130 else {
1131 /* Don't update Z buffer */
1132 GLuint i;
1133 for (i=0; i<n; i++) {
1134 if (mask[i]) {
1135 if (z[i] < zbuffer[i]) {
1136 /* pass */
1137 }
1138 else {
1139 /* fail */
1140 mask[i] = 0;
1141 }
1142 }
1143 }
1144 }
1145 break;
1146 case GL_LEQUAL:
1147 if (ctx->Depth.Mask) {
1148 /* Update Z buffer */
1149 GLuint i;
1150 for (i=0; i<n; i++) {
1151 if (mask[i]) {
1152 if (z[i] <= zbuffer[i]) {
1153 /* pass */
1154 zbuffer[i] = z[i];
1155 }
1156 else {
1157 /* fail */
1158 mask[i] = 0;
1159 }
1160 }
1161 }
1162 }
1163 else {
1164 /* Don't update Z buffer */
1165 GLuint i;
1166 for (i=0; i<n; i++) {
1167 if (mask[i]) {
1168 if (z[i] <= zbuffer[i]) {
1169 /* pass */
1170 }
1171 else {
1172 /* fail */
1173 mask[i] = 0;
1174 }
1175 }
1176 }
1177 }
1178 break;
1179 case GL_GEQUAL:
1180 if (ctx->Depth.Mask) {
1181 /* Update Z buffer */
1182 GLuint i;
1183 for (i=0; i<n; i++) {
1184 if (mask[i]) {
1185 if (z[i] >= zbuffer[i]) {
1186 /* pass */
1187 zbuffer[i] = z[i];
1188 }
1189 else {
1190 /* fail */
1191 mask[i] = 0;
1192 }
1193 }
1194 }
1195 }
1196 else {
1197 /* Don't update Z buffer */
1198 GLuint i;
1199 for (i=0; i<n; i++) {
1200 if (mask[i]) {
1201 if (z[i] >= zbuffer[i]) {
1202 /* pass */
1203 }
1204 else {
1205 /* fail */
1206 mask[i] = 0;
1207 }
1208 }
1209 }
1210 }
1211 break;
1212 case GL_GREATER:
1213 if (ctx->Depth.Mask) {
1214 /* Update Z buffer */
1215 GLuint i;
1216 for (i=0; i<n; i++) {
1217 if (mask[i]) {
1218 if (z[i] > zbuffer[i]) {
1219 /* pass */
1220 zbuffer[i] = z[i];
1221 }
1222 else {
1223 /* fail */
1224 mask[i] = 0;
1225 }
1226 }
1227 }
1228 }
1229 else {
1230 /* Don't update Z buffer */
1231 GLuint i;
1232 for (i=0; i<n; i++) {
1233 if (mask[i]) {
1234 if (z[i] > zbuffer[i]) {
1235 /* pass */
1236 }
1237 else {
1238 /* fail */
1239 mask[i] = 0;
1240 }
1241 }
1242 }
1243 }
1244 break;
1245 case GL_NOTEQUAL:
1246 if (ctx->Depth.Mask) {
1247 /* Update Z buffer */
1248 GLuint i;
1249 for (i=0; i<n; i++) {
1250 if (mask[i]) {
1251 if (z[i] != zbuffer[i]) {
1252 /* pass */
1253 zbuffer[i] = z[i];
1254 }
1255 else {
1256 /* fail */
1257 mask[i] = 0;
1258 }
1259 }
1260 }
1261 }
1262 else {
1263 /* Don't update Z buffer */
1264 GLuint i;
1265 for (i=0; i<n; i++) {
1266 if (mask[i]) {
1267 if (z[i] != zbuffer[i]) {
1268 /* pass */
1269 }
1270 else {
1271 /* fail */
1272 mask[i] = 0;
1273 }
1274 }
1275 }
1276 }
1277 break;
1278 case GL_EQUAL:
1279 if (ctx->Depth.Mask) {
1280 /* Update Z buffer */
1281 GLuint i;
1282 for (i=0; i<n; i++) {
1283 if (mask[i]) {
1284 if (z[i] == zbuffer[i]) {
1285 /* pass */
1286 zbuffer[i] = z[i];
1287 }
1288 else {
1289 /* fail */
1290 mask[i] = 0;
1291 }
1292 }
1293 }
1294 }
1295 else {
1296 /* Don't update Z buffer */
1297 GLuint i;
1298 for (i=0; i<n; i++) {
1299 if (mask[i]) {
1300 if (z[i] == zbuffer[i]) {
1301 /* pass */
1302 }
1303 else {
1304 /* fail */
1305 mask[i] = 0;
1306 }
1307 }
1308 }
1309 }
1310 break;
1311 case GL_ALWAYS:
1312 if (ctx->Depth.Mask) {
1313 /* Update Z buffer */
1314 GLuint i;
1315 for (i=0; i<n; i++) {
1316 if (mask[i]) {
1317 zbuffer[i] = z[i];
1318 }
1319 }
1320 }
1321 else {
1322 /* Don't update Z buffer or mask */
1323 }
1324 break;
1325 case GL_NEVER:
1326 /* depth test never passes */
1327 BZERO(mask, n * sizeof(GLubyte));
1328 break;
1329 default:
1330 _mesa_problem(ctx, "Bad depth func in hardware_depth_test_pixels");
1331 }
1332 }
1333
1334
1335
1336 void
1337 _mesa_depth_test_pixels( GLcontext *ctx,
1338 GLuint n, const GLint x[], const GLint y[],
1339 const GLdepth z[], GLubyte mask[] )
1340 {
1341 SWcontext *swrast = SWRAST_CONTEXT(ctx);
1342 if (swrast->Driver.ReadDepthPixels) {
1343 /* read depth values from hardware Z buffer */
1344 GLdepth zbuffer[PB_SIZE];
1345 (*swrast->Driver.ReadDepthPixels)(ctx, n, x, y, zbuffer);
1346
1347 hardware_depth_test_pixels( ctx, n, zbuffer, z, mask );
1348
1349 /* update hardware Z buffer with new values */
1350 assert(swrast->Driver.WriteDepthPixels);
1351 (*swrast->Driver.WriteDepthPixels)(ctx, n, x, y, zbuffer, mask );
1352 }
1353 else {
1354 /* software depth testing */
1355 if (ctx->Visual.depthBits <= 16)
1356 software_depth_test_pixels16(ctx, n, x, y, z, mask);
1357 else
1358 software_depth_test_pixels32(ctx, n, x, y, z, mask);
1359 }
1360 }
1361
1362
1363
1364
1365
1366 /**********************************************************************/
1367 /***** Read Depth Buffer *****/
1368 /**********************************************************************/
1369
1370
1371 /*
1372 * Read a span of depth values from the depth buffer.
1373 * This function does clipping before calling the device driver function.
1374 */
1375 void
1376 _mesa_read_depth_span( GLcontext *ctx,
1377 GLint n, GLint x, GLint y, GLdepth depth[] )
1378 {
1379 SWcontext *swrast = SWRAST_CONTEXT(ctx);
1380
1381 if (y < 0 || y >= ctx->DrawBuffer->Height ||
1382 x + (GLint) n <= 0 || x >= ctx->DrawBuffer->Width) {
1383 /* span is completely outside framebuffer */
1384 GLint i;
1385 for (i = 0; i < n; i++)
1386 depth[i] = 0;
1387 return;
1388 }
1389
1390 if (x < 0) {
1391 GLint dx = -x;
1392 GLint i;
1393 for (i = 0; i < dx; i++)
1394 depth[i] = 0;
1395 x = 0;
1396 n -= dx;
1397 depth += dx;
1398 }
1399 if (x + n > ctx->DrawBuffer->Width) {
1400 GLint dx = x + n - ctx->DrawBuffer->Width;
1401 GLint i;
1402 for (i = 0; i < dx; i++)
1403 depth[n - i - 1] = 0;
1404 n -= dx;
1405 }
1406 if (n <= 0) {
1407 return;
1408 }
1409
1410 if (ctx->DrawBuffer->DepthBuffer) {
1411 /* read from software depth buffer */
1412 if (ctx->Visual.depthBits <= 16) {
1413 const GLushort *zptr = Z_ADDRESS16( ctx, x, y );
1414 GLint i;
1415 for (i = 0; i < n; i++) {
1416 depth[i] = zptr[i];
1417 }
1418 }
1419 else {
1420 const GLuint *zptr = Z_ADDRESS32( ctx, x, y );
1421 GLint i;
1422 for (i = 0; i < n; i++) {
1423 depth[i] = zptr[i];
1424 }
1425 }
1426 }
1427 else if (swrast->Driver.ReadDepthSpan) {
1428 /* read from hardware depth buffer */
1429 (*swrast->Driver.ReadDepthSpan)( ctx, n, x, y, depth );
1430 }
1431 else {
1432 /* no depth buffer */
1433 BZERO(depth, n * sizeof(GLfloat));
1434 }
1435
1436 }
1437
1438
1439
1440
1441 /*
1442 * Return a span of depth values from the depth buffer as floats in [0,1].
1443 * This is used for both hardware and software depth buffers.
1444 * Input: n - how many pixels
1445 * x,y - location of first pixel
1446 * Output: depth - the array of depth values
1447 */
1448 void
1449 _mesa_read_depth_span_float( GLcontext *ctx,
1450 GLint n, GLint x, GLint y, GLfloat depth[] )
1451 {
1452 SWcontext *swrast = SWRAST_CONTEXT(ctx);
1453 const GLfloat scale = 1.0F / ctx->DepthMaxF;
1454
1455 if (y < 0 || y >= ctx->DrawBuffer->Height ||
1456 x + (GLint) n <= 0 || x >= ctx->DrawBuffer->Width) {
1457 /* span is completely outside framebuffer */
1458 GLint i;
1459 for (i = 0; i < n; i++)
1460 depth[i] = 0.0F;
1461 return;
1462 }
1463
1464 if (x < 0) {
1465 GLint dx = -x;
1466 GLint i;
1467 for (i = 0; i < dx; i++)
1468 depth[i] = 0.0F;
1469 n -= dx;
1470 x = 0;
1471 }
1472 if (x + n > ctx->DrawBuffer->Width) {
1473 GLint dx = x + n - ctx->DrawBuffer->Width;
1474 GLint i;
1475 for (i = 0; i < dx; i++)
1476 depth[n - i - 1] = 0.0F;
1477 n -= dx;
1478 }
1479 if (n <= 0) {
1480 return;
1481 }
1482
1483 if (ctx->DrawBuffer->DepthBuffer) {
1484 /* read from software depth buffer */
1485 if (ctx->Visual.depthBits <= 16) {
1486 const GLushort *zptr = Z_ADDRESS16( ctx, x, y );
1487 GLint i;
1488 for (i = 0; i < n; i++) {
1489 depth[i] = (GLfloat) zptr[i] * scale;
1490 }
1491 }
1492 else {
1493 const GLuint *zptr = Z_ADDRESS32( ctx, x, y );
1494 GLint i;
1495 for (i = 0; i < n; i++) {
1496 depth[i] = (GLfloat) zptr[i] * scale;
1497 }
1498 }
1499 }
1500 else if (swrast->Driver.ReadDepthSpan) {
1501 /* read from hardware depth buffer */
1502 GLdepth d[MAX_WIDTH];
1503 GLint i;
1504 assert(n <= MAX_WIDTH);
1505 (*swrast->Driver.ReadDepthSpan)( ctx, n, x, y, d );
1506 for (i = 0; i < n; i++) {
1507 depth[i] = d[i] * scale;
1508 }
1509 }
1510 else {
1511 /* no depth buffer */
1512 BZERO(depth, n * sizeof(GLfloat));
1513 }
1514 }
1515
1516
1517
1518 /**********************************************************************/
1519 /***** Allocate and Clear Depth Buffer *****/
1520 /**********************************************************************/
1521
1522
1523
1524 /*
1525 * Allocate a new depth buffer. If there's already a depth buffer allocated
1526 * it will be free()'d. The new depth buffer will be uniniitalized.
1527 * This function is only called through Driver.alloc_depth_buffer.
1528 */
1529 void
1530 _mesa_alloc_depth_buffer( GLcontext *ctx )
1531 {
1532 /* deallocate current depth buffer if present */
1533 if (ctx->DrawBuffer->UseSoftwareDepthBuffer) {
1534 GLint bytesPerValue;
1535
1536 if (ctx->DrawBuffer->DepthBuffer) {
1537 FREE(ctx->DrawBuffer->DepthBuffer);
1538 ctx->DrawBuffer->DepthBuffer = NULL;
1539 }
1540
1541 /* allocate new depth buffer, but don't initialize it */
1542 if (ctx->Visual.depthBits <= 16)
1543 bytesPerValue = sizeof(GLushort);
1544 else
1545 bytesPerValue = sizeof(GLuint);
1546
1547 ctx->DrawBuffer->DepthBuffer = MALLOC( ctx->DrawBuffer->Width
1548 * ctx->DrawBuffer->Height
1549 * bytesPerValue );
1550
1551 if (!ctx->DrawBuffer->DepthBuffer) {
1552 /* out of memory */
1553 ctx->Depth.Test = GL_FALSE;
1554 ctx->NewState |= _NEW_DEPTH;
1555 _mesa_error( ctx, GL_OUT_OF_MEMORY, "Couldn't allocate depth buffer" );
1556 }
1557 }
1558 }
1559
1560
1561
1562
1563 /*
1564 * Clear the depth buffer. If the depth buffer doesn't exist yet we'll
1565 * allocate it now.
1566 * This function is only called through Driver.clear_depth_buffer.
1567 */
1568 void
1569 _mesa_clear_depth_buffer( GLcontext *ctx )
1570 {
1571 if (ctx->Visual.depthBits == 0
1572 || !ctx->DrawBuffer->DepthBuffer
1573 || !ctx->Depth.Mask) {
1574 /* no depth buffer, or writing to it is disabled */
1575 return;
1576 }
1577
1578 /* The loops in this function have been written so the IRIX 5.3
1579 * C compiler can unroll them. Hopefully other compilers can too!
1580 */
1581
1582 if (ctx->Scissor.Enabled) {
1583 /* only clear scissor region */
1584 if (ctx->Visual.depthBits <= 16) {
1585 const GLushort clearValue = (GLushort) (ctx->Depth.Clear * ctx->DepthMax);
1586 const GLint rows = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
1587 const GLint cols = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
1588 const GLint rowStride = ctx->DrawBuffer->Width;
1589 GLushort *dRow = (GLushort *) ctx->DrawBuffer->DepthBuffer
1590 + ctx->DrawBuffer->_Ymin * rowStride + ctx->DrawBuffer->_Xmin;
1591 GLint i, j;
1592 for (i = 0; i < rows; i++) {
1593 for (j = 0; j < cols; j++) {
1594 dRow[j] = clearValue;
1595 }
1596 dRow += rowStride;
1597 }
1598 }
1599 else {
1600 const GLuint clearValue = (GLuint) (ctx->Depth.Clear * ctx->DepthMax);
1601 const GLint rows = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
1602 const GLint cols = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
1603 const GLint rowStride = ctx->DrawBuffer->Width;
1604 GLuint *dRow = (GLuint *) ctx->DrawBuffer->DepthBuffer
1605 + ctx->DrawBuffer->_Ymin * rowStride + ctx->DrawBuffer->_Xmin;
1606 GLint i, j;
1607 for (i = 0; i < rows; i++) {
1608 for (j = 0; j < cols; j++) {
1609 dRow[j] = clearValue;
1610 }
1611 dRow += rowStride;
1612 }
1613 }
1614 }
1615 else {
1616 /* clear whole buffer */
1617 if (ctx->Visual.depthBits <= 16) {
1618 const GLushort clearValue = (GLushort) (ctx->Depth.Clear * ctx->DepthMax);
1619 if ((clearValue & 0xff) == (clearValue >> 8)) {
1620 if (clearValue == 0) {
1621 BZERO(ctx->DrawBuffer->DepthBuffer,
1622 2*ctx->DrawBuffer->Width*ctx->DrawBuffer->Height);
1623 }
1624 else {
1625 /* lower and upper bytes of clear_value are same, use MEMSET */
1626 MEMSET( ctx->DrawBuffer->DepthBuffer, clearValue & 0xff,
1627 2 * ctx->DrawBuffer->Width * ctx->DrawBuffer->Height);
1628 }
1629 }
1630 else {
1631 GLushort *d = (GLushort *) ctx->DrawBuffer->DepthBuffer;
1632 GLint n = ctx->DrawBuffer->Width * ctx->DrawBuffer->Height;
1633 while (n >= 16) {
1634 d[0] = clearValue; d[1] = clearValue;
1635 d[2] = clearValue; d[3] = clearValue;
1636 d[4] = clearValue; d[5] = clearValue;
1637 d[6] = clearValue; d[7] = clearValue;
1638 d[8] = clearValue; d[9] = clearValue;
1639 d[10] = clearValue; d[11] = clearValue;
1640 d[12] = clearValue; d[13] = clearValue;
1641 d[14] = clearValue; d[15] = clearValue;
1642 d += 16;
1643 n -= 16;
1644 }
1645 while (n > 0) {
1646 *d++ = clearValue;
1647 n--;
1648 }
1649 }
1650 }
1651 else {
1652 /* >16 bit depth buffer */
1653 const GLuint clearValue = (GLuint) (ctx->Depth.Clear * ctx->DepthMax);
1654 if (clearValue == 0) {
1655 BZERO(ctx->DrawBuffer->DepthBuffer,
1656 ctx->DrawBuffer->Width*ctx->DrawBuffer->Height*sizeof(GLuint));
1657 }
1658 else {
1659 GLint n = ctx->DrawBuffer->Width * ctx->DrawBuffer->Height;
1660 GLuint *d = (GLuint *) ctx->DrawBuffer->DepthBuffer;
1661 while (n >= 16) {
1662 d[0] = clearValue; d[1] = clearValue;
1663 d[2] = clearValue; d[3] = clearValue;
1664 d[4] = clearValue; d[5] = clearValue;
1665 d[6] = clearValue; d[7] = clearValue;
1666 d[8] = clearValue; d[9] = clearValue;
1667 d[10] = clearValue; d[11] = clearValue;
1668 d[12] = clearValue; d[13] = clearValue;
1669 d[14] = clearValue; d[15] = clearValue;
1670 d += 16;
1671 n -= 16;
1672 }
1673 while (n > 0) {
1674 *d++ = clearValue;
1675 n--;
1676 }
1677 }
1678 }
1679 }
1680 }