swrast: stop using _swrast_get_values() in z/depth code
[mesa.git] / src / mesa / swrast / s_depth.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.2.1
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #include "main/glheader.h"
27 #include "main/context.h"
28 #include "main/formats.h"
29 #include "main/format_unpack.h"
30 #include "main/format_pack.h"
31 #include "main/macros.h"
32 #include "main/imports.h"
33
34 #include "s_depth.h"
35 #include "s_span.h"
36
37
38 /**
39 * Do depth test for a horizontal span of fragments.
40 * Input: zbuffer - array of z values in the zbuffer
41 * z - array of fragment z values
42 * Return: number of fragments which pass the test.
43 */
44 static GLuint
45 depth_test_span16( struct gl_context *ctx, GLuint n,
46 GLushort zbuffer[], const GLuint z[], GLubyte mask[] )
47 {
48 GLuint passed = 0;
49
50 /* switch cases ordered from most frequent to less frequent */
51 switch (ctx->Depth.Func) {
52 case GL_LESS:
53 if (ctx->Depth.Mask) {
54 /* Update Z buffer */
55 GLuint i;
56 for (i=0; i<n; i++) {
57 if (mask[i]) {
58 if (z[i] < zbuffer[i]) {
59 /* pass */
60 zbuffer[i] = z[i];
61 passed++;
62 }
63 else {
64 /* fail */
65 mask[i] = 0;
66 }
67 }
68 }
69 }
70 else {
71 /* Don't update Z buffer */
72 GLuint i;
73 for (i=0; i<n; i++) {
74 if (mask[i]) {
75 if (z[i] < zbuffer[i]) {
76 /* pass */
77 passed++;
78 }
79 else {
80 mask[i] = 0;
81 }
82 }
83 }
84 }
85 break;
86 case GL_LEQUAL:
87 if (ctx->Depth.Mask) {
88 /* Update Z buffer */
89 GLuint i;
90 for (i=0;i<n;i++) {
91 if (mask[i]) {
92 if (z[i] <= zbuffer[i]) {
93 zbuffer[i] = z[i];
94 passed++;
95 }
96 else {
97 mask[i] = 0;
98 }
99 }
100 }
101 }
102 else {
103 /* Don't update Z buffer */
104 GLuint i;
105 for (i=0;i<n;i++) {
106 if (mask[i]) {
107 if (z[i] <= zbuffer[i]) {
108 /* pass */
109 passed++;
110 }
111 else {
112 mask[i] = 0;
113 }
114 }
115 }
116 }
117 break;
118 case GL_GEQUAL:
119 if (ctx->Depth.Mask) {
120 /* Update Z buffer */
121 GLuint i;
122 for (i=0;i<n;i++) {
123 if (mask[i]) {
124 if (z[i] >= zbuffer[i]) {
125 zbuffer[i] = z[i];
126 passed++;
127 }
128 else {
129 mask[i] = 0;
130 }
131 }
132 }
133 }
134 else {
135 /* Don't update Z buffer */
136 GLuint i;
137 for (i=0;i<n;i++) {
138 if (mask[i]) {
139 if (z[i] >= zbuffer[i]) {
140 /* pass */
141 passed++;
142 }
143 else {
144 mask[i] = 0;
145 }
146 }
147 }
148 }
149 break;
150 case GL_GREATER:
151 if (ctx->Depth.Mask) {
152 /* Update Z buffer */
153 GLuint i;
154 for (i=0;i<n;i++) {
155 if (mask[i]) {
156 if (z[i] > zbuffer[i]) {
157 zbuffer[i] = z[i];
158 passed++;
159 }
160 else {
161 mask[i] = 0;
162 }
163 }
164 }
165 }
166 else {
167 /* Don't update Z buffer */
168 GLuint i;
169 for (i=0;i<n;i++) {
170 if (mask[i]) {
171 if (z[i] > zbuffer[i]) {
172 /* pass */
173 passed++;
174 }
175 else {
176 mask[i] = 0;
177 }
178 }
179 }
180 }
181 break;
182 case GL_NOTEQUAL:
183 if (ctx->Depth.Mask) {
184 /* Update Z buffer */
185 GLuint i;
186 for (i=0;i<n;i++) {
187 if (mask[i]) {
188 if (z[i] != zbuffer[i]) {
189 zbuffer[i] = z[i];
190 passed++;
191 }
192 else {
193 mask[i] = 0;
194 }
195 }
196 }
197 }
198 else {
199 /* Don't update Z buffer */
200 GLuint i;
201 for (i=0;i<n;i++) {
202 if (mask[i]) {
203 if (z[i] != zbuffer[i]) {
204 /* pass */
205 passed++;
206 }
207 else {
208 mask[i] = 0;
209 }
210 }
211 }
212 }
213 break;
214 case GL_EQUAL:
215 if (ctx->Depth.Mask) {
216 /* Update Z buffer */
217 GLuint i;
218 for (i=0;i<n;i++) {
219 if (mask[i]) {
220 if (z[i] == zbuffer[i]) {
221 zbuffer[i] = z[i];
222 passed++;
223 }
224 else {
225 mask[i] = 0;
226 }
227 }
228 }
229 }
230 else {
231 /* Don't update Z buffer */
232 GLuint i;
233 for (i=0;i<n;i++) {
234 if (mask[i]) {
235 if (z[i] == zbuffer[i]) {
236 /* pass */
237 passed++;
238 }
239 else {
240 mask[i] = 0;
241 }
242 }
243 }
244 }
245 break;
246 case GL_ALWAYS:
247 if (ctx->Depth.Mask) {
248 /* Update Z buffer */
249 GLuint i;
250 for (i=0;i<n;i++) {
251 if (mask[i]) {
252 zbuffer[i] = z[i];
253 passed++;
254 }
255 }
256 }
257 else {
258 /* Don't update Z buffer or mask */
259 passed = n;
260 }
261 break;
262 case GL_NEVER:
263 memset(mask, 0, n * sizeof(GLubyte));
264 break;
265 default:
266 _mesa_problem(ctx, "Bad depth func in depth_test_span16");
267 }
268
269 return passed;
270 }
271
272
273 static GLuint
274 depth_test_span32( struct gl_context *ctx, GLuint n,
275 GLuint zbuffer[], const GLuint z[], GLubyte mask[] )
276 {
277 GLuint passed = 0;
278
279 /* switch cases ordered from most frequent to less frequent */
280 switch (ctx->Depth.Func) {
281 case GL_LESS:
282 if (ctx->Depth.Mask) {
283 /* Update Z buffer */
284 GLuint i;
285 for (i=0; i<n; i++) {
286 if (mask[i]) {
287 if (z[i] < zbuffer[i]) {
288 /* pass */
289 zbuffer[i] = z[i];
290 passed++;
291 }
292 else {
293 /* fail */
294 mask[i] = 0;
295 }
296 }
297 }
298 }
299 else {
300 /* Don't update Z buffer */
301 GLuint i;
302 for (i=0; i<n; i++) {
303 if (mask[i]) {
304 if (z[i] < zbuffer[i]) {
305 /* pass */
306 passed++;
307 }
308 else {
309 mask[i] = 0;
310 }
311 }
312 }
313 }
314 break;
315 case GL_LEQUAL:
316 if (ctx->Depth.Mask) {
317 /* Update Z buffer */
318 GLuint i;
319 for (i=0;i<n;i++) {
320 if (mask[i]) {
321 if (z[i] <= zbuffer[i]) {
322 zbuffer[i] = z[i];
323 passed++;
324 }
325 else {
326 mask[i] = 0;
327 }
328 }
329 }
330 }
331 else {
332 /* Don't update Z buffer */
333 GLuint i;
334 for (i=0;i<n;i++) {
335 if (mask[i]) {
336 if (z[i] <= zbuffer[i]) {
337 /* pass */
338 passed++;
339 }
340 else {
341 mask[i] = 0;
342 }
343 }
344 }
345 }
346 break;
347 case GL_GEQUAL:
348 if (ctx->Depth.Mask) {
349 /* Update Z buffer */
350 GLuint i;
351 for (i=0;i<n;i++) {
352 if (mask[i]) {
353 if (z[i] >= zbuffer[i]) {
354 zbuffer[i] = z[i];
355 passed++;
356 }
357 else {
358 mask[i] = 0;
359 }
360 }
361 }
362 }
363 else {
364 /* Don't update Z buffer */
365 GLuint i;
366 for (i=0;i<n;i++) {
367 if (mask[i]) {
368 if (z[i] >= zbuffer[i]) {
369 /* pass */
370 passed++;
371 }
372 else {
373 mask[i] = 0;
374 }
375 }
376 }
377 }
378 break;
379 case GL_GREATER:
380 if (ctx->Depth.Mask) {
381 /* Update Z buffer */
382 GLuint i;
383 for (i=0;i<n;i++) {
384 if (mask[i]) {
385 if (z[i] > zbuffer[i]) {
386 zbuffer[i] = z[i];
387 passed++;
388 }
389 else {
390 mask[i] = 0;
391 }
392 }
393 }
394 }
395 else {
396 /* Don't update Z buffer */
397 GLuint i;
398 for (i=0;i<n;i++) {
399 if (mask[i]) {
400 if (z[i] > zbuffer[i]) {
401 /* pass */
402 passed++;
403 }
404 else {
405 mask[i] = 0;
406 }
407 }
408 }
409 }
410 break;
411 case GL_NOTEQUAL:
412 if (ctx->Depth.Mask) {
413 /* Update Z buffer */
414 GLuint i;
415 for (i=0;i<n;i++) {
416 if (mask[i]) {
417 if (z[i] != zbuffer[i]) {
418 zbuffer[i] = z[i];
419 passed++;
420 }
421 else {
422 mask[i] = 0;
423 }
424 }
425 }
426 }
427 else {
428 /* Don't update Z buffer */
429 GLuint i;
430 for (i=0;i<n;i++) {
431 if (mask[i]) {
432 if (z[i] != zbuffer[i]) {
433 /* pass */
434 passed++;
435 }
436 else {
437 mask[i] = 0;
438 }
439 }
440 }
441 }
442 break;
443 case GL_EQUAL:
444 if (ctx->Depth.Mask) {
445 /* Update Z buffer */
446 GLuint i;
447 for (i=0;i<n;i++) {
448 if (mask[i]) {
449 if (z[i] == zbuffer[i]) {
450 zbuffer[i] = z[i];
451 passed++;
452 }
453 else {
454 mask[i] = 0;
455 }
456 }
457 }
458 }
459 else {
460 /* Don't update Z buffer */
461 GLuint i;
462 for (i=0;i<n;i++) {
463 if (mask[i]) {
464 if (z[i] == zbuffer[i]) {
465 /* pass */
466 passed++;
467 }
468 else {
469 mask[i] = 0;
470 }
471 }
472 }
473 }
474 break;
475 case GL_ALWAYS:
476 if (ctx->Depth.Mask) {
477 /* Update Z buffer */
478 GLuint i;
479 for (i=0;i<n;i++) {
480 if (mask[i]) {
481 zbuffer[i] = z[i];
482 passed++;
483 }
484 }
485 }
486 else {
487 /* Don't update Z buffer or mask */
488 passed = n;
489 }
490 break;
491 case GL_NEVER:
492 memset(mask, 0, n * sizeof(GLubyte));
493 break;
494 default:
495 _mesa_problem(ctx, "Bad depth func in depth_test_span32");
496 }
497
498 return passed;
499 }
500
501
502
503 /**
504 * Clamp fragment Z values to the depth near/far range (glDepthRange()).
505 * This is used when GL_ARB_depth_clamp/GL_DEPTH_CLAMP is turned on.
506 * In that case, vertexes are not clipped against the near/far planes
507 * so rasterization will produce fragment Z values outside the usual
508 * [0,1] range.
509 */
510 void
511 _swrast_depth_clamp_span( struct gl_context *ctx, SWspan *span )
512 {
513 struct gl_framebuffer *fb = ctx->DrawBuffer;
514 const GLuint count = span->end;
515 GLint *zValues = (GLint *) span->array->z; /* sign change */
516 GLint min, max;
517 GLfloat min_f, max_f;
518 GLuint i;
519
520 if (ctx->Viewport.Near < ctx->Viewport.Far) {
521 min_f = ctx->Viewport.Near;
522 max_f = ctx->Viewport.Far;
523 } else {
524 min_f = ctx->Viewport.Far;
525 max_f = ctx->Viewport.Near;
526 }
527
528 /* Convert floating point values in [0,1] to device Z coordinates in
529 * [0, DepthMax].
530 * ex: If the Z buffer has 24 bits, DepthMax = 0xffffff.
531 *
532 * XXX this all falls apart if we have 31 or more bits of Z because
533 * the triangle rasterization code produces unsigned Z values. Negative
534 * vertex Z values come out as large fragment Z uints.
535 */
536 min = (GLint) (min_f * fb->_DepthMaxF);
537 max = (GLint) (max_f * fb->_DepthMaxF);
538 if (max < 0)
539 max = 0x7fffffff; /* catch over flow for 30-bit z */
540
541 /* Note that we do the comparisons here using signed integers.
542 */
543 for (i = 0; i < count; i++) {
544 if (zValues[i] < min)
545 zValues[i] = min;
546 if (zValues[i] > max)
547 zValues[i] = max;
548 }
549 }
550
551
552 /**
553 * Get array of 16-bit z values from the depth buffer. With clipping.
554 */
555 static void
556 get_z16_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
557 GLuint count, const GLint x[], const GLint y[],
558 GLushort zbuffer[])
559 {
560 const GLint w = rb->Width, h = rb->Height;
561 const GLubyte *map = (const GLubyte *) rb->Data;
562 GLuint i;
563
564 if (rb->Format == MESA_FORMAT_Z16) {
565 const GLuint rowStride = rb->RowStride * 2;
566 for (i = 0; i < count; i++) {
567 if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
568 zbuffer[i] = *((GLushort *) (map + y[i] * rowStride + x[i] * 2));
569 }
570 }
571 }
572 else {
573 const GLuint bpp = _mesa_get_format_bytes(rb->Format);
574 const GLuint rowStride = rb->RowStride * bpp;
575 for (i = 0; i < count; i++) {
576 if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
577 GLuint d32;
578 const GLubyte *src = map + y[i] * rowStride + x[i] * bpp;
579 _mesa_unpack_uint_z_row(rb->Format, 1, src, &d32);
580 zbuffer[i] = d32 >> 16;
581 }
582 }
583 }
584 }
585
586
587 /**
588 * Get array of 32-bit z values from the depth buffer. With clipping.
589 */
590 static void
591 get_z32_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
592 GLuint count, const GLint x[], const GLint y[],
593 GLuint zbuffer[])
594 {
595 const GLint w = rb->Width, h = rb->Height;
596 const GLubyte *map = (const GLubyte *) rb->Data;
597 GLuint i;
598
599 if (rb->Format == MESA_FORMAT_Z32) {
600 const GLuint rowStride = rb->RowStride * 4;
601 for (i = 0; i < count; i++) {
602 if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
603 zbuffer[i] = *((GLuint *) (map + y[i] * rowStride + x[i] * 4));
604 }
605 }
606 }
607 else {
608 const GLuint bpp = _mesa_get_format_bytes(rb->Format);
609 const GLuint rowStride = rb->RowStride * bpp;
610 for (i = 0; i < count; i++) {
611 if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
612 const GLubyte *src = map + y[i] * rowStride+ x[i] * bpp;
613 _mesa_unpack_uint_z_row(rb->Format, 1, src, &zbuffer[i]);
614 }
615 }
616 }
617 }
618
619
620
621 /*
622 * Apply depth test to span of fragments.
623 */
624 static GLuint
625 depth_test_span( struct gl_context *ctx, SWspan *span)
626 {
627 struct gl_framebuffer *fb = ctx->DrawBuffer;
628 struct gl_renderbuffer *rb = fb->_DepthBuffer;
629 const GLint x = span->x;
630 const GLint y = span->y;
631 const GLuint count = span->end;
632 const GLuint *zValues = span->array->z;
633 GLubyte *mask = span->array->mask;
634 GLuint passed;
635
636 ASSERT((span->arrayMask & SPAN_XY) == 0);
637 ASSERT(span->arrayMask & SPAN_Z);
638
639 if (rb->GetPointer(ctx, rb, 0, 0)) {
640 /* Directly access buffer */
641 if (rb->DataType == GL_UNSIGNED_SHORT) {
642 GLushort *zbuffer = (GLushort *) rb->GetPointer(ctx, rb, x, y);
643 passed = depth_test_span16(ctx, count, zbuffer, zValues, mask);
644 }
645 else {
646 GLuint *zbuffer = (GLuint *) rb->GetPointer(ctx, rb, x, y);
647 ASSERT(rb->DataType == GL_UNSIGNED_INT);
648 passed = depth_test_span32(ctx, count, zbuffer, zValues, mask);
649 }
650 }
651 else {
652 /* read depth values from buffer, test, write back */
653 if (rb->DataType == GL_UNSIGNED_SHORT) {
654 GLushort zbuffer[MAX_WIDTH];
655 rb->GetRow(ctx, rb, count, x, y, zbuffer);
656 passed = depth_test_span16(ctx, count, zbuffer, zValues, mask);
657 rb->PutRow(ctx, rb, count, x, y, zbuffer, mask);
658 }
659 else {
660 GLuint zbuffer[MAX_WIDTH];
661 ASSERT(rb->DataType == GL_UNSIGNED_INT);
662 rb->GetRow(ctx, rb, count, x, y, zbuffer);
663 passed = depth_test_span32(ctx, count, zbuffer, zValues, mask);
664 rb->PutRow(ctx, rb, count, x, y, zbuffer, mask);
665 }
666 }
667
668 if (passed < count) {
669 span->writeAll = GL_FALSE;
670 }
671 return passed;
672 }
673
674
675
676 #define Z_ADDRESS(X, Y) (zStart + (Y) * stride + (X))
677
678
679 /*
680 * Do depth testing for an array of fragments at assorted locations.
681 */
682 static void
683 direct_depth_test_pixels16(struct gl_context *ctx, GLushort *zStart, GLuint stride,
684 GLuint n, const GLint x[], const GLint y[],
685 const GLuint z[], GLubyte mask[] )
686 {
687 /* switch cases ordered from most frequent to less frequent */
688 switch (ctx->Depth.Func) {
689 case GL_LESS:
690 if (ctx->Depth.Mask) {
691 /* Update Z buffer */
692 GLuint i;
693 for (i=0; i<n; i++) {
694 if (mask[i]) {
695 GLushort *zptr = Z_ADDRESS(x[i], y[i]);
696 if (z[i] < *zptr) {
697 /* pass */
698 *zptr = z[i];
699 }
700 else {
701 /* fail */
702 mask[i] = 0;
703 }
704 }
705 }
706 }
707 else {
708 /* Don't update Z buffer */
709 GLuint i;
710 for (i=0; i<n; i++) {
711 if (mask[i]) {
712 GLushort *zptr = Z_ADDRESS(x[i], y[i]);
713 if (z[i] < *zptr) {
714 /* pass */
715 }
716 else {
717 /* fail */
718 mask[i] = 0;
719 }
720 }
721 }
722 }
723 break;
724 case GL_LEQUAL:
725 if (ctx->Depth.Mask) {
726 /* Update Z buffer */
727 GLuint i;
728 for (i=0; i<n; i++) {
729 if (mask[i]) {
730 GLushort *zptr = Z_ADDRESS(x[i], y[i]);
731 if (z[i] <= *zptr) {
732 /* pass */
733 *zptr = z[i];
734 }
735 else {
736 /* fail */
737 mask[i] = 0;
738 }
739 }
740 }
741 }
742 else {
743 /* Don't update Z buffer */
744 GLuint i;
745 for (i=0; i<n; i++) {
746 if (mask[i]) {
747 GLushort *zptr = Z_ADDRESS(x[i], y[i]);
748 if (z[i] <= *zptr) {
749 /* pass */
750 }
751 else {
752 /* fail */
753 mask[i] = 0;
754 }
755 }
756 }
757 }
758 break;
759 case GL_GEQUAL:
760 if (ctx->Depth.Mask) {
761 /* Update Z buffer */
762 GLuint i;
763 for (i=0; i<n; i++) {
764 if (mask[i]) {
765 GLushort *zptr = Z_ADDRESS(x[i], y[i]);
766 if (z[i] >= *zptr) {
767 /* pass */
768 *zptr = z[i];
769 }
770 else {
771 /* fail */
772 mask[i] = 0;
773 }
774 }
775 }
776 }
777 else {
778 /* Don't update Z buffer */
779 GLuint i;
780 for (i=0; i<n; i++) {
781 if (mask[i]) {
782 GLushort *zptr = Z_ADDRESS(x[i], y[i]);
783 if (z[i] >= *zptr) {
784 /* pass */
785 }
786 else {
787 /* fail */
788 mask[i] = 0;
789 }
790 }
791 }
792 }
793 break;
794 case GL_GREATER:
795 if (ctx->Depth.Mask) {
796 /* Update Z buffer */
797 GLuint i;
798 for (i=0; i<n; i++) {
799 if (mask[i]) {
800 GLushort *zptr = Z_ADDRESS(x[i], y[i]);
801 if (z[i] > *zptr) {
802 /* pass */
803 *zptr = z[i];
804 }
805 else {
806 /* fail */
807 mask[i] = 0;
808 }
809 }
810 }
811 }
812 else {
813 /* Don't update Z buffer */
814 GLuint i;
815 for (i=0; i<n; i++) {
816 if (mask[i]) {
817 GLushort *zptr = Z_ADDRESS(x[i], y[i]);
818 if (z[i] > *zptr) {
819 /* pass */
820 }
821 else {
822 /* fail */
823 mask[i] = 0;
824 }
825 }
826 }
827 }
828 break;
829 case GL_NOTEQUAL:
830 if (ctx->Depth.Mask) {
831 /* Update Z buffer */
832 GLuint i;
833 for (i=0; i<n; i++) {
834 if (mask[i]) {
835 GLushort *zptr = Z_ADDRESS(x[i], y[i]);
836 if (z[i] != *zptr) {
837 /* pass */
838 *zptr = z[i];
839 }
840 else {
841 /* fail */
842 mask[i] = 0;
843 }
844 }
845 }
846 }
847 else {
848 /* Don't update Z buffer */
849 GLuint i;
850 for (i=0; i<n; i++) {
851 if (mask[i]) {
852 GLushort *zptr = Z_ADDRESS(x[i], y[i]);
853 if (z[i] != *zptr) {
854 /* pass */
855 }
856 else {
857 /* fail */
858 mask[i] = 0;
859 }
860 }
861 }
862 }
863 break;
864 case GL_EQUAL:
865 if (ctx->Depth.Mask) {
866 /* Update Z buffer */
867 GLuint i;
868 for (i=0; i<n; i++) {
869 if (mask[i]) {
870 GLushort *zptr = Z_ADDRESS(x[i], y[i]);
871 if (z[i] == *zptr) {
872 /* pass */
873 *zptr = z[i];
874 }
875 else {
876 /* fail */
877 mask[i] = 0;
878 }
879 }
880 }
881 }
882 else {
883 /* Don't update Z buffer */
884 GLuint i;
885 for (i=0; i<n; i++) {
886 if (mask[i]) {
887 GLushort *zptr = Z_ADDRESS(x[i], y[i]);
888 if (z[i] == *zptr) {
889 /* pass */
890 }
891 else {
892 /* fail */
893 mask[i] = 0;
894 }
895 }
896 }
897 }
898 break;
899 case GL_ALWAYS:
900 if (ctx->Depth.Mask) {
901 /* Update Z buffer */
902 GLuint i;
903 for (i=0; i<n; i++) {
904 if (mask[i]) {
905 GLushort *zptr = Z_ADDRESS(x[i], y[i]);
906 *zptr = z[i];
907 }
908 }
909 }
910 else {
911 /* Don't update Z buffer or mask */
912 }
913 break;
914 case GL_NEVER:
915 /* depth test never passes */
916 memset(mask, 0, n * sizeof(GLubyte));
917 break;
918 default:
919 _mesa_problem(ctx, "Bad depth func in direct_depth_test_pixels");
920 }
921 }
922
923
924
925 /*
926 * Do depth testing for an array of fragments with direct access to zbuffer.
927 */
928 static void
929 direct_depth_test_pixels32(struct gl_context *ctx, GLuint *zStart, GLuint stride,
930 GLuint n, const GLint x[], const GLint y[],
931 const GLuint z[], GLubyte mask[] )
932 {
933 /* switch cases ordered from most frequent to less frequent */
934 switch (ctx->Depth.Func) {
935 case GL_LESS:
936 if (ctx->Depth.Mask) {
937 /* Update Z buffer */
938 GLuint i;
939 for (i=0; i<n; i++) {
940 if (mask[i]) {
941 GLuint *zptr = Z_ADDRESS(x[i], y[i]);
942 if (z[i] < *zptr) {
943 /* pass */
944 *zptr = z[i];
945 }
946 else {
947 /* fail */
948 mask[i] = 0;
949 }
950 }
951 }
952 }
953 else {
954 /* Don't update Z buffer */
955 GLuint i;
956 for (i=0; i<n; i++) {
957 if (mask[i]) {
958 GLuint *zptr = Z_ADDRESS(x[i], y[i]);
959 if (z[i] < *zptr) {
960 /* pass */
961 }
962 else {
963 /* fail */
964 mask[i] = 0;
965 }
966 }
967 }
968 }
969 break;
970 case GL_LEQUAL:
971 if (ctx->Depth.Mask) {
972 /* Update Z buffer */
973 GLuint i;
974 for (i=0; i<n; i++) {
975 if (mask[i]) {
976 GLuint *zptr = Z_ADDRESS(x[i], y[i]);
977 if (z[i] <= *zptr) {
978 /* pass */
979 *zptr = z[i];
980 }
981 else {
982 /* fail */
983 mask[i] = 0;
984 }
985 }
986 }
987 }
988 else {
989 /* Don't update Z buffer */
990 GLuint i;
991 for (i=0; i<n; i++) {
992 if (mask[i]) {
993 GLuint *zptr = Z_ADDRESS(x[i], y[i]);
994 if (z[i] <= *zptr) {
995 /* pass */
996 }
997 else {
998 /* fail */
999 mask[i] = 0;
1000 }
1001 }
1002 }
1003 }
1004 break;
1005 case GL_GEQUAL:
1006 if (ctx->Depth.Mask) {
1007 /* Update Z buffer */
1008 GLuint i;
1009 for (i=0; i<n; i++) {
1010 if (mask[i]) {
1011 GLuint *zptr = Z_ADDRESS(x[i], y[i]);
1012 if (z[i] >= *zptr) {
1013 /* pass */
1014 *zptr = z[i];
1015 }
1016 else {
1017 /* fail */
1018 mask[i] = 0;
1019 }
1020 }
1021 }
1022 }
1023 else {
1024 /* Don't update Z buffer */
1025 GLuint i;
1026 for (i=0; i<n; i++) {
1027 if (mask[i]) {
1028 GLuint *zptr = Z_ADDRESS(x[i], y[i]);
1029 if (z[i] >= *zptr) {
1030 /* pass */
1031 }
1032 else {
1033 /* fail */
1034 mask[i] = 0;
1035 }
1036 }
1037 }
1038 }
1039 break;
1040 case GL_GREATER:
1041 if (ctx->Depth.Mask) {
1042 /* Update Z buffer */
1043 GLuint i;
1044 for (i=0; i<n; i++) {
1045 if (mask[i]) {
1046 GLuint *zptr = Z_ADDRESS(x[i], y[i]);
1047 if (z[i] > *zptr) {
1048 /* pass */
1049 *zptr = z[i];
1050 }
1051 else {
1052 /* fail */
1053 mask[i] = 0;
1054 }
1055 }
1056 }
1057 }
1058 else {
1059 /* Don't update Z buffer */
1060 GLuint i;
1061 for (i=0; i<n; i++) {
1062 if (mask[i]) {
1063 GLuint *zptr = Z_ADDRESS(x[i], y[i]);
1064 if (z[i] > *zptr) {
1065 /* pass */
1066 }
1067 else {
1068 /* fail */
1069 mask[i] = 0;
1070 }
1071 }
1072 }
1073 }
1074 break;
1075 case GL_NOTEQUAL:
1076 if (ctx->Depth.Mask) {
1077 /* Update Z buffer */
1078 GLuint i;
1079 for (i=0; i<n; i++) {
1080 if (mask[i]) {
1081 GLuint *zptr = Z_ADDRESS(x[i], y[i]);
1082 if (z[i] != *zptr) {
1083 /* pass */
1084 *zptr = z[i];
1085 }
1086 else {
1087 /* fail */
1088 mask[i] = 0;
1089 }
1090 }
1091 }
1092 }
1093 else {
1094 /* Don't update Z buffer */
1095 GLuint i;
1096 for (i=0; i<n; i++) {
1097 if (mask[i]) {
1098 GLuint *zptr = Z_ADDRESS(x[i], y[i]);
1099 if (z[i] != *zptr) {
1100 /* pass */
1101 }
1102 else {
1103 /* fail */
1104 mask[i] = 0;
1105 }
1106 }
1107 }
1108 }
1109 break;
1110 case GL_EQUAL:
1111 if (ctx->Depth.Mask) {
1112 /* Update Z buffer */
1113 GLuint i;
1114 for (i=0; i<n; i++) {
1115 if (mask[i]) {
1116 GLuint *zptr = Z_ADDRESS(x[i], y[i]);
1117 if (z[i] == *zptr) {
1118 /* pass */
1119 *zptr = z[i];
1120 }
1121 else {
1122 /* fail */
1123 mask[i] = 0;
1124 }
1125 }
1126 }
1127 }
1128 else {
1129 /* Don't update Z buffer */
1130 GLuint i;
1131 for (i=0; i<n; i++) {
1132 if (mask[i]) {
1133 GLuint *zptr = Z_ADDRESS(x[i], y[i]);
1134 if (z[i] == *zptr) {
1135 /* pass */
1136 }
1137 else {
1138 /* fail */
1139 mask[i] = 0;
1140 }
1141 }
1142 }
1143 }
1144 break;
1145 case GL_ALWAYS:
1146 if (ctx->Depth.Mask) {
1147 /* Update Z buffer */
1148 GLuint i;
1149 for (i=0; i<n; i++) {
1150 if (mask[i]) {
1151 GLuint *zptr = Z_ADDRESS(x[i], y[i]);
1152 *zptr = z[i];
1153 }
1154 }
1155 }
1156 else {
1157 /* Don't update Z buffer or mask */
1158 }
1159 break;
1160 case GL_NEVER:
1161 /* depth test never passes */
1162 memset(mask, 0, n * sizeof(GLubyte));
1163 break;
1164 default:
1165 _mesa_problem(ctx, "Bad depth func in direct_depth_test_pixels");
1166 }
1167 }
1168
1169
1170
1171
1172 static GLuint
1173 depth_test_pixels( struct gl_context *ctx, SWspan *span )
1174 {
1175 struct gl_framebuffer *fb = ctx->DrawBuffer;
1176 struct gl_renderbuffer *rb = fb->_DepthBuffer;
1177 const GLuint count = span->end;
1178 const GLint *x = span->array->x;
1179 const GLint *y = span->array->y;
1180 const GLuint *z = span->array->z;
1181 GLubyte *mask = span->array->mask;
1182
1183 if (rb->GetPointer(ctx, rb, 0, 0)) {
1184 /* Directly access values */
1185 if (rb->DataType == GL_UNSIGNED_SHORT) {
1186 GLushort *zStart = (GLushort *) rb->Data;
1187 GLuint stride = rb->Width;
1188 direct_depth_test_pixels16(ctx, zStart, stride, count, x, y, z, mask);
1189 }
1190 else {
1191 GLuint *zStart = (GLuint *) rb->Data;
1192 GLuint stride = rb->Width;
1193 ASSERT(rb->DataType == GL_UNSIGNED_INT);
1194 direct_depth_test_pixels32(ctx, zStart, stride, count, x, y, z, mask);
1195 }
1196 }
1197 else {
1198 /* read depth values from buffer, test, write back */
1199 if (rb->DataType == GL_UNSIGNED_SHORT) {
1200 GLushort zbuffer[MAX_WIDTH];
1201 get_z16_values(ctx, rb, count, x, y, zbuffer);
1202 depth_test_span16(ctx, count, zbuffer, z, mask);
1203 rb->PutValues(ctx, rb, count, x, y, zbuffer, mask);
1204 }
1205 else {
1206 GLuint zbuffer[MAX_WIDTH];
1207 ASSERT(rb->DataType == GL_UNSIGNED_INT);
1208 get_z32_values(ctx, rb, count, x, y, zbuffer);
1209 depth_test_span32(ctx, count, zbuffer, z, mask);
1210 rb->PutValues(ctx, rb, count, x, y, zbuffer, mask);
1211 }
1212 }
1213
1214 return count; /* not really correct, but OK */
1215 }
1216
1217
1218 /**
1219 * Apply depth (Z) buffer testing to the span.
1220 * \return approx number of pixels that passed (only zero is reliable)
1221 */
1222 GLuint
1223 _swrast_depth_test_span( struct gl_context *ctx, SWspan *span)
1224 {
1225 if (span->arrayMask & SPAN_XY)
1226 return depth_test_pixels(ctx, span);
1227 else
1228 return depth_test_span(ctx, span);
1229 }
1230
1231
1232 /**
1233 * GL_EXT_depth_bounds_test extension.
1234 * Discard fragments depending on whether the corresponding Z-buffer
1235 * values are outside the depth bounds test range.
1236 * Note: we test the Z buffer values, not the fragment Z values!
1237 * \return GL_TRUE if any fragments pass, GL_FALSE if no fragments pass
1238 */
1239 GLboolean
1240 _swrast_depth_bounds_test( struct gl_context *ctx, SWspan *span )
1241 {
1242 struct gl_framebuffer *fb = ctx->DrawBuffer;
1243 struct gl_renderbuffer *rb = fb->_DepthBuffer;
1244 GLuint zMin = (GLuint) (ctx->Depth.BoundsMin * fb->_DepthMaxF + 0.5F);
1245 GLuint zMax = (GLuint) (ctx->Depth.BoundsMax * fb->_DepthMaxF + 0.5F);
1246 GLubyte *mask = span->array->mask;
1247 const GLuint count = span->end;
1248 GLuint i;
1249 GLboolean anyPass = GL_FALSE;
1250
1251 if (rb->DataType == GL_UNSIGNED_SHORT) {
1252 /* get 16-bit values */
1253 GLushort zbuffer16[MAX_WIDTH], *zbuffer;
1254 if (span->arrayMask & SPAN_XY) {
1255 get_z16_values(ctx, rb, count, span->array->x, span->array->y,
1256 zbuffer16);
1257 zbuffer = zbuffer16;
1258 }
1259 else {
1260 zbuffer = (GLushort*) rb->GetPointer(ctx, rb, span->x, span->y);
1261 if (!zbuffer) {
1262 rb->GetRow(ctx, rb, count, span->x, span->y, zbuffer16);
1263 zbuffer = zbuffer16;
1264 }
1265 }
1266 assert(zbuffer);
1267
1268 /* Now do the tests */
1269 for (i = 0; i < count; i++) {
1270 if (mask[i]) {
1271 if (zbuffer[i] < zMin || zbuffer[i] > zMax)
1272 mask[i] = GL_FALSE;
1273 else
1274 anyPass = GL_TRUE;
1275 }
1276 }
1277 }
1278 else {
1279 /* get 32-bit values */
1280 GLuint zbuffer32[MAX_WIDTH], *zbuffer;
1281 ASSERT(rb->DataType == GL_UNSIGNED_INT);
1282 if (span->arrayMask & SPAN_XY) {
1283 get_z32_values(ctx, rb, count, span->array->x, span->array->y,
1284 zbuffer32);
1285 zbuffer = zbuffer32;
1286 }
1287 else {
1288 zbuffer = (GLuint*) rb->GetPointer(ctx, rb, span->x, span->y);
1289 if (!zbuffer) {
1290 rb->GetRow(ctx, rb, count, span->x, span->y, zbuffer32);
1291 zbuffer = zbuffer32;
1292 }
1293 }
1294 assert(zbuffer);
1295
1296 /* Now do the tests */
1297 for (i = 0; i < count; i++) {
1298 if (mask[i]) {
1299 if (zbuffer[i] < zMin || zbuffer[i] > zMax)
1300 mask[i] = GL_FALSE;
1301 else
1302 anyPass = GL_TRUE;
1303 }
1304 }
1305 }
1306
1307 return anyPass;
1308 }
1309
1310
1311
1312 /**********************************************************************/
1313 /***** Read Depth Buffer *****/
1314 /**********************************************************************/
1315
1316
1317 /**
1318 * Read a span of depth values from the given depth renderbuffer, returning
1319 * the values as GLfloats.
1320 * This function does clipping to prevent reading outside the depth buffer's
1321 * bounds.
1322 */
1323 void
1324 _swrast_read_depth_span_float( struct gl_context *ctx, struct gl_renderbuffer *rb,
1325 GLint n, GLint x, GLint y, GLfloat depth[] )
1326 {
1327 const GLfloat scale = 1.0F / ctx->DrawBuffer->_DepthMaxF;
1328
1329 if (!rb) {
1330 /* really only doing this to prevent FP exceptions later */
1331 memset(depth, 0, n * sizeof(GLfloat));
1332 return;
1333 }
1334
1335 ASSERT(rb->_BaseFormat == GL_DEPTH_COMPONENT);
1336
1337 if (y < 0 || y >= (GLint) rb->Height ||
1338 x + n <= 0 || x >= (GLint) rb->Width) {
1339 /* span is completely outside framebuffer */
1340 memset(depth, 0, n * sizeof(GLfloat));
1341 return;
1342 }
1343
1344 if (x < 0) {
1345 GLint dx = -x;
1346 GLint i;
1347 for (i = 0; i < dx; i++)
1348 depth[i] = 0.0;
1349 x = 0;
1350 n -= dx;
1351 depth += dx;
1352 }
1353 if (x + n > (GLint) rb->Width) {
1354 GLint dx = x + n - (GLint) rb->Width;
1355 GLint i;
1356 for (i = 0; i < dx; i++)
1357 depth[n - i - 1] = 0.0;
1358 n -= dx;
1359 }
1360 if (n <= 0) {
1361 return;
1362 }
1363
1364 if (rb->DataType == GL_UNSIGNED_INT) {
1365 GLuint temp[MAX_WIDTH];
1366 GLint i;
1367 rb->GetRow(ctx, rb, n, x, y, temp);
1368 for (i = 0; i < n; i++) {
1369 depth[i] = temp[i] * scale;
1370 }
1371 }
1372 else if (rb->DataType == GL_UNSIGNED_SHORT) {
1373 GLushort temp[MAX_WIDTH];
1374 GLint i;
1375 rb->GetRow(ctx, rb, n, x, y, temp);
1376 for (i = 0; i < n; i++) {
1377 depth[i] = temp[i] * scale;
1378 }
1379 }
1380 else {
1381 _mesa_problem(ctx, "Invalid depth renderbuffer data type");
1382 }
1383 }
1384
1385
1386 /**
1387 * Clear the given z/depth renderbuffer. If the buffer is a combined
1388 * depth+stencil buffer, only the Z bits will be touched.
1389 */
1390 void
1391 _swrast_clear_depth_buffer(struct gl_context *ctx)
1392 {
1393 struct gl_renderbuffer *rb =
1394 ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
1395 GLuint clearValue;
1396 GLint x, y, width, height;
1397 GLubyte *map;
1398 GLint rowStride, i, j;
1399 GLbitfield mapMode;
1400
1401 if (!rb || !ctx->Depth.Mask) {
1402 /* no depth buffer, or writing to it is disabled */
1403 return;
1404 }
1405
1406 /* compute integer clearing value */
1407 if (ctx->Depth.Clear == 1.0) {
1408 clearValue = ctx->DrawBuffer->_DepthMax;
1409 }
1410 else {
1411 clearValue = (GLuint) (ctx->Depth.Clear * ctx->DrawBuffer->_DepthMaxF);
1412 }
1413
1414 /* compute region to clear */
1415 x = ctx->DrawBuffer->_Xmin;
1416 y = ctx->DrawBuffer->_Ymin;
1417 width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
1418 height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
1419
1420 mapMode = GL_MAP_WRITE_BIT;
1421 if (rb->Format == MESA_FORMAT_S8_Z24 ||
1422 rb->Format == MESA_FORMAT_X8_Z24 ||
1423 rb->Format == MESA_FORMAT_Z24_S8 ||
1424 rb->Format == MESA_FORMAT_Z24_X8) {
1425 mapMode |= GL_MAP_READ_BIT;
1426 }
1427
1428 ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height,
1429 mapMode, &map, &rowStride);
1430 if (!map) {
1431 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glClear(depth)");
1432 return;
1433 }
1434
1435 switch (rb->Format) {
1436 case MESA_FORMAT_Z16:
1437 {
1438 GLfloat clear = (GLfloat) ctx->Depth.Clear;
1439 GLushort clearVal = 0;
1440 _mesa_pack_float_z_row(rb->Format, 1, &clear, &clearVal);
1441 if (clearVal == 0xffff && width * 2 == rowStride) {
1442 /* common case */
1443 memset(map, 0xff, width * height * 2);
1444 }
1445 else {
1446 for (i = 0; i < height; i++) {
1447 GLushort *row = (GLushort *) map;
1448 for (j = 0; j < width; j++) {
1449 row[j] = clearVal;
1450 }
1451 map += rowStride;
1452 }
1453 }
1454 }
1455 break;
1456 case MESA_FORMAT_Z32:
1457 case MESA_FORMAT_Z32_FLOAT:
1458 {
1459 GLfloat clear = (GLfloat) ctx->Depth.Clear;
1460 GLuint clearVal = 0;
1461 _mesa_pack_float_z_row(rb->Format, 1, &clear, &clearVal);
1462 for (i = 0; i < height; i++) {
1463 GLuint *row = (GLuint *) map;
1464 for (j = 0; j < width; j++) {
1465 row[j] = clearVal;
1466 }
1467 map += rowStride;
1468 }
1469 }
1470 break;
1471 case MESA_FORMAT_S8_Z24:
1472 case MESA_FORMAT_X8_Z24:
1473 case MESA_FORMAT_Z24_S8:
1474 case MESA_FORMAT_Z24_X8:
1475 {
1476 GLfloat clear = (GLfloat) ctx->Depth.Clear;
1477 GLuint clearVal = 0;
1478 GLuint mask;
1479
1480 if (rb->Format == MESA_FORMAT_S8_Z24 ||
1481 rb->Format == MESA_FORMAT_X8_Z24)
1482 mask = 0xff000000;
1483 else
1484 mask = 0xff;
1485
1486 _mesa_pack_float_z_row(rb->Format, 1, &clear, &clearVal);
1487 for (i = 0; i < height; i++) {
1488 GLuint *row = (GLuint *) map;
1489 for (j = 0; j < width; j++) {
1490 row[j] = (row[j] & mask) | clearVal;
1491 }
1492 map += rowStride;
1493 }
1494
1495 }
1496 break;
1497 case MESA_FORMAT_Z32_FLOAT_X24S8:
1498 /* XXX untested */
1499 {
1500 GLfloat clearVal = (GLfloat) ctx->Depth.Clear;
1501 for (i = 0; i < height; i++) {
1502 GLfloat *row = (GLfloat *) map;
1503 for (j = 0; j < width; j++) {
1504 row[j * 2] = clearVal;
1505 }
1506 map += rowStride;
1507 }
1508 }
1509 break;
1510 default:
1511 _mesa_problem(ctx, "Unexpected depth buffer format %s"
1512 " in _swrast_clear_depth_buffer()",
1513 _mesa_get_format_name(rb->Format));
1514 }
1515
1516 ctx->Driver.UnmapRenderbuffer(ctx, rb);
1517 }
1518
1519
1520
1521
1522 /**
1523 * Clear both depth and stencil values in a combined depth+stencil buffer.
1524 */
1525 void
1526 _swrast_clear_depth_stencil_buffer(struct gl_context *ctx)
1527 {
1528 const GLubyte stencilBits = ctx->DrawBuffer->Visual.stencilBits;
1529 const GLuint writeMask = ctx->Stencil.WriteMask[0];
1530 const GLuint stencilMax = (1 << stencilBits) - 1;
1531 struct gl_renderbuffer *rb =
1532 ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
1533 GLint x, y, width, height;
1534 GLbitfield mapMode;
1535 GLubyte *map;
1536 GLint rowStride, i, j;
1537
1538 /* check that we really have a combined depth+stencil buffer */
1539 assert(rb == ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer);
1540
1541 /* compute region to clear */
1542 x = ctx->DrawBuffer->_Xmin;
1543 y = ctx->DrawBuffer->_Ymin;
1544 width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
1545 height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
1546
1547 mapMode = GL_MAP_WRITE_BIT;
1548 if ((writeMask & stencilMax) != stencilMax) {
1549 /* need to mask stencil values */
1550 mapMode |= GL_MAP_READ_BIT;
1551 }
1552
1553 ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height,
1554 mapMode, &map, &rowStride);
1555 if (!map) {
1556 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glClear(depth+stencil)");
1557 return;
1558 }
1559
1560 switch (rb->Format) {
1561 case MESA_FORMAT_S8_Z24:
1562 case MESA_FORMAT_Z24_S8:
1563 {
1564 GLfloat zClear = (GLfloat) ctx->Depth.Clear;
1565 GLuint clear = 0, mask;
1566
1567 _mesa_pack_float_z_row(rb->Format, 1, &zClear, &clear);
1568
1569 if (rb->Format == MESA_FORMAT_S8_Z24) {
1570 mask = ((~writeMask) & 0xff) << 24;
1571 clear |= (ctx->Stencil.Clear & writeMask & 0xff) << 24;
1572 }
1573 else {
1574 mask = ((~writeMask) & 0xff);
1575 clear |= (ctx->Stencil.Clear & writeMask & 0xff);
1576 }
1577
1578 for (i = 0; i < height; i++) {
1579 GLuint *row = (GLuint *) map;
1580 if (mask != 0x0) {
1581 for (j = 0; j < width; j++) {
1582 row[j] = (row[j] & mask) | clear;
1583 }
1584 }
1585 else {
1586 for (j = 0; j < width; j++) {
1587 row[j] = clear;
1588 }
1589 }
1590 map += rowStride;
1591 }
1592 }
1593 break;
1594 case MESA_FORMAT_Z32_FLOAT_X24S8:
1595 /* XXX untested */
1596 {
1597 const GLfloat zClear = (GLfloat) ctx->Depth.Clear;
1598 const GLuint sClear = ctx->Stencil.Clear & writeMask;
1599 const GLuint sMask = (~writeMask) & 0xff;
1600 for (i = 0; i < height; i++) {
1601 GLfloat *zRow = (GLfloat *) map;
1602 GLuint *sRow = (GLuint *) map;
1603 for (j = 0; j < width; j++) {
1604 zRow[j * 2 + 0] = zClear;
1605 }
1606 if (sMask != 0) {
1607 for (j = 0; j < width; j++) {
1608 sRow[j * 2 + 1] = (sRow[j * 2 + 1] & sMask) | sClear;
1609 }
1610 }
1611 else {
1612 for (j = 0; j < width; j++) {
1613 sRow[j * 2 + 1] = sClear;
1614 }
1615 }
1616 map += rowStride;
1617 }
1618 }
1619 break;
1620 default:
1621 _mesa_problem(ctx, "Unexpected depth buffer format %s"
1622 " in _swrast_clear_depth_buffer()",
1623 _mesa_get_format_name(rb->Format));
1624 }
1625
1626 ctx->Driver.UnmapRenderbuffer(ctx, rb);
1627
1628 }