1 /* $Id: s_depth.c,v 1.6 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.
34 #include "s_context.h"
41 * Return address of depth buffer value for given window coord.
44 _mesa_zbuffer_address(GLcontext
*ctx
, GLint x
, GLint y
)
46 if (ctx
->Visual
.depthBits
<= 16)
47 return (GLushort
*) ctx
->DrawBuffer
->DepthBuffer
+ ctx
->DrawBuffer
->Width
* y
+ x
;
49 return (GLuint
*) ctx
->DrawBuffer
->DepthBuffer
+ ctx
->DrawBuffer
->Width
* y
+ x
;
53 #define Z_ADDRESS16( CTX, X, Y ) \
54 ( ((GLushort *) (CTX)->DrawBuffer->DepthBuffer) \
55 + (CTX)->DrawBuffer->Width * (Y) + (X) )
57 #define Z_ADDRESS32( CTX, X, Y ) \
58 ( ((GLuint *) (CTX)->DrawBuffer->DepthBuffer) \
59 + (CTX)->DrawBuffer->Width * (Y) + (X) )
63 /**********************************************************************/
64 /***** Depth Testing Functions *****/
65 /**********************************************************************/
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.
76 depth_test_span16( GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
77 GLushort zbuffer
[], const GLdepth z
[], GLubyte mask
[] )
81 /* switch cases ordered from most frequent to less frequent */
82 switch (ctx
->Depth
.Func
) {
84 if (ctx
->Depth
.Mask
) {
89 if (z
[i
] < zbuffer
[i
]) {
102 /* Don't update Z buffer */
104 for (i
=0; i
<n
; i
++) {
106 if (z
[i
] < zbuffer
[i
]) {
118 if (ctx
->Depth
.Mask
) {
119 /* Update Z buffer */
123 if (z
[i
] <= zbuffer
[i
]) {
134 /* Don't update Z buffer */
138 if (z
[i
] <= zbuffer
[i
]) {
150 if (ctx
->Depth
.Mask
) {
151 /* Update Z buffer */
155 if (z
[i
] >= zbuffer
[i
]) {
166 /* Don't update Z buffer */
170 if (z
[i
] >= zbuffer
[i
]) {
182 if (ctx
->Depth
.Mask
) {
183 /* Update Z buffer */
187 if (z
[i
] > zbuffer
[i
]) {
198 /* Don't update Z buffer */
202 if (z
[i
] > zbuffer
[i
]) {
214 if (ctx
->Depth
.Mask
) {
215 /* Update Z buffer */
219 if (z
[i
] != zbuffer
[i
]) {
230 /* Don't update Z buffer */
234 if (z
[i
] != zbuffer
[i
]) {
246 if (ctx
->Depth
.Mask
) {
247 /* Update Z buffer */
251 if (z
[i
] == zbuffer
[i
]) {
262 /* Don't update Z buffer */
266 if (z
[i
] == zbuffer
[i
]) {
278 if (ctx
->Depth
.Mask
) {
279 /* Update Z buffer */
289 /* Don't update Z buffer or mask */
294 BZERO(mask
, n
* sizeof(GLubyte
));
297 _mesa_problem(ctx
, "Bad depth func in depth_test_span16");
305 depth_test_span32( GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
306 GLuint zbuffer
[], const GLdepth z
[], GLubyte mask
[] )
310 /* switch cases ordered from most frequent to less frequent */
311 switch (ctx
->Depth
.Func
) {
313 if (ctx
->Depth
.Mask
) {
314 /* Update Z buffer */
316 for (i
=0; i
<n
; i
++) {
318 if (z
[i
] < zbuffer
[i
]) {
331 /* Don't update Z buffer */
333 for (i
=0; i
<n
; i
++) {
335 if (z
[i
] < zbuffer
[i
]) {
347 if (ctx
->Depth
.Mask
) {
348 /* Update Z buffer */
352 if (z
[i
] <= zbuffer
[i
]) {
363 /* Don't update Z buffer */
367 if (z
[i
] <= zbuffer
[i
]) {
379 if (ctx
->Depth
.Mask
) {
380 /* Update Z buffer */
384 if (z
[i
] >= zbuffer
[i
]) {
395 /* Don't update Z buffer */
399 if (z
[i
] >= zbuffer
[i
]) {
411 if (ctx
->Depth
.Mask
) {
412 /* Update Z buffer */
416 if (z
[i
] > zbuffer
[i
]) {
427 /* Don't update Z buffer */
431 if (z
[i
] > zbuffer
[i
]) {
443 if (ctx
->Depth
.Mask
) {
444 /* Update Z buffer */
448 if (z
[i
] != zbuffer
[i
]) {
459 /* Don't update Z buffer */
463 if (z
[i
] != zbuffer
[i
]) {
475 if (ctx
->Depth
.Mask
) {
476 /* Update Z buffer */
480 if (z
[i
] == zbuffer
[i
]) {
491 /* Don't update Z buffer */
495 if (z
[i
] == zbuffer
[i
]) {
507 if (ctx
->Depth
.Mask
) {
508 /* Update Z buffer */
518 /* Don't update Z buffer or mask */
523 BZERO(mask
, n
* sizeof(GLubyte
));
526 _mesa_problem(ctx
, "Bad depth func in depth_test_span32");
535 * Apply depth test to span of fragments. Hardware or software z buffer.
538 _mesa_depth_test_span( GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
539 const GLdepth z
[], GLubyte mask
[] )
541 if (ctx
->Driver
.ReadDepthSpan
) {
542 /* hardware-based depth buffer */
543 GLdepth zbuffer
[MAX_WIDTH
];
545 (*ctx
->Driver
.ReadDepthSpan
)(ctx
, n
, x
, y
, zbuffer
);
546 passed
= depth_test_span32(ctx
, n
, x
, y
, zbuffer
, z
, mask
);
547 assert(ctx
->Driver
.WriteDepthSpan
);
548 (*ctx
->Driver
.WriteDepthSpan
)(ctx
, n
, x
, y
, zbuffer
, mask
);
552 /* software depth buffer */
553 if (ctx
->Visual
.depthBits
<= 16) {
554 GLushort
*zptr
= (GLushort
*) Z_ADDRESS16(ctx
, x
, y
);
555 GLuint passed
= depth_test_span16(ctx
, n
, x
, y
, zptr
, z
, mask
);
559 GLuint
*zptr
= (GLuint
*) Z_ADDRESS32(ctx
, x
, y
);
560 GLuint passed
= depth_test_span32(ctx
, n
, x
, y
, zptr
, z
, mask
);
570 * Do depth testing for an array of fragments using software Z buffer.
573 software_depth_test_pixels16( GLcontext
*ctx
, GLuint n
,
574 const GLint x
[], const GLint y
[],
575 const GLdepth z
[], GLubyte mask
[] )
577 /* switch cases ordered from most frequent to less frequent */
578 switch (ctx
->Depth
.Func
) {
580 if (ctx
->Depth
.Mask
) {
581 /* Update Z buffer */
583 for (i
=0; i
<n
; i
++) {
585 GLushort
*zptr
= Z_ADDRESS16(ctx
,x
[i
],y
[i
]);
598 /* Don't update Z buffer */
600 for (i
=0; i
<n
; i
++) {
602 GLushort
*zptr
= Z_ADDRESS16(ctx
,x
[i
],y
[i
]);
615 if (ctx
->Depth
.Mask
) {
616 /* Update Z buffer */
618 for (i
=0; i
<n
; i
++) {
620 GLushort
*zptr
= Z_ADDRESS16(ctx
,x
[i
],y
[i
]);
633 /* Don't update Z buffer */
635 for (i
=0; i
<n
; i
++) {
637 GLushort
*zptr
= Z_ADDRESS16(ctx
,x
[i
],y
[i
]);
650 if (ctx
->Depth
.Mask
) {
651 /* Update Z buffer */
653 for (i
=0; i
<n
; i
++) {
655 GLushort
*zptr
= Z_ADDRESS16(ctx
,x
[i
],y
[i
]);
668 /* Don't update Z buffer */
670 for (i
=0; i
<n
; i
++) {
672 GLushort
*zptr
= Z_ADDRESS16(ctx
,x
[i
],y
[i
]);
685 if (ctx
->Depth
.Mask
) {
686 /* Update Z buffer */
688 for (i
=0; i
<n
; i
++) {
690 GLushort
*zptr
= Z_ADDRESS16(ctx
,x
[i
],y
[i
]);
703 /* Don't update Z buffer */
705 for (i
=0; i
<n
; i
++) {
707 GLushort
*zptr
= Z_ADDRESS16(ctx
,x
[i
],y
[i
]);
720 if (ctx
->Depth
.Mask
) {
721 /* Update Z buffer */
723 for (i
=0; i
<n
; i
++) {
725 GLushort
*zptr
= Z_ADDRESS16(ctx
,x
[i
],y
[i
]);
738 /* Don't update Z buffer */
740 for (i
=0; i
<n
; i
++) {
742 GLushort
*zptr
= Z_ADDRESS16(ctx
,x
[i
],y
[i
]);
755 if (ctx
->Depth
.Mask
) {
756 /* Update Z buffer */
758 for (i
=0; i
<n
; i
++) {
760 GLushort
*zptr
= Z_ADDRESS16(ctx
,x
[i
],y
[i
]);
773 /* Don't update Z buffer */
775 for (i
=0; i
<n
; i
++) {
777 GLushort
*zptr
= Z_ADDRESS16(ctx
,x
[i
],y
[i
]);
790 if (ctx
->Depth
.Mask
) {
791 /* Update Z buffer */
793 for (i
=0; i
<n
; i
++) {
795 GLushort
*zptr
= Z_ADDRESS16(ctx
,x
[i
],y
[i
]);
801 /* Don't update Z buffer or mask */
805 /* depth test never passes */
806 BZERO(mask
, n
* sizeof(GLubyte
));
809 _mesa_problem(ctx
, "Bad depth func in software_depth_test_pixels");
816 * Do depth testing for an array of fragments using software Z buffer.
819 software_depth_test_pixels32( GLcontext
*ctx
, GLuint n
,
820 const GLint x
[], const GLint y
[],
821 const GLdepth z
[], GLubyte mask
[] )
823 /* switch cases ordered from most frequent to less frequent */
824 switch (ctx
->Depth
.Func
) {
826 if (ctx
->Depth
.Mask
) {
827 /* Update Z buffer */
829 for (i
=0; i
<n
; i
++) {
831 GLuint
*zptr
= Z_ADDRESS32(ctx
,x
[i
],y
[i
]);
844 /* Don't update Z buffer */
846 for (i
=0; i
<n
; i
++) {
848 GLuint
*zptr
= Z_ADDRESS32(ctx
,x
[i
],y
[i
]);
861 if (ctx
->Depth
.Mask
) {
862 /* Update Z buffer */
864 for (i
=0; i
<n
; i
++) {
866 GLuint
*zptr
= Z_ADDRESS32(ctx
,x
[i
],y
[i
]);
879 /* Don't update Z buffer */
881 for (i
=0; i
<n
; i
++) {
883 GLuint
*zptr
= Z_ADDRESS32(ctx
,x
[i
],y
[i
]);
896 if (ctx
->Depth
.Mask
) {
897 /* Update Z buffer */
899 for (i
=0; i
<n
; i
++) {
901 GLuint
*zptr
= Z_ADDRESS32(ctx
,x
[i
],y
[i
]);
914 /* Don't update Z buffer */
916 for (i
=0; i
<n
; i
++) {
918 GLuint
*zptr
= Z_ADDRESS32(ctx
,x
[i
],y
[i
]);
931 if (ctx
->Depth
.Mask
) {
932 /* Update Z buffer */
934 for (i
=0; i
<n
; i
++) {
936 GLuint
*zptr
= Z_ADDRESS32(ctx
,x
[i
],y
[i
]);
949 /* Don't update Z buffer */
951 for (i
=0; i
<n
; i
++) {
953 GLuint
*zptr
= Z_ADDRESS32(ctx
,x
[i
],y
[i
]);
966 if (ctx
->Depth
.Mask
) {
967 /* Update Z buffer */
969 for (i
=0; i
<n
; i
++) {
971 GLuint
*zptr
= Z_ADDRESS32(ctx
,x
[i
],y
[i
]);
984 /* Don't update Z buffer */
986 for (i
=0; i
<n
; i
++) {
988 GLuint
*zptr
= Z_ADDRESS32(ctx
,x
[i
],y
[i
]);
1001 if (ctx
->Depth
.Mask
) {
1002 /* Update Z buffer */
1004 for (i
=0; i
<n
; i
++) {
1006 GLuint
*zptr
= Z_ADDRESS32(ctx
,x
[i
],y
[i
]);
1007 if (z
[i
] == *zptr
) {
1019 /* Don't update Z buffer */
1021 for (i
=0; i
<n
; i
++) {
1023 GLuint
*zptr
= Z_ADDRESS32(ctx
,x
[i
],y
[i
]);
1024 if (z
[i
] == *zptr
) {
1036 if (ctx
->Depth
.Mask
) {
1037 /* Update Z buffer */
1039 for (i
=0; i
<n
; i
++) {
1041 GLuint
*zptr
= Z_ADDRESS32(ctx
,x
[i
],y
[i
]);
1047 /* Don't update Z buffer or mask */
1051 /* depth test never passes */
1052 BZERO(mask
, n
* sizeof(GLubyte
));
1055 _mesa_problem(ctx
, "Bad depth func in software_depth_test_pixels");
1062 * Do depth testing for an array of pixels using hardware Z buffer.
1063 * Input/output: zbuffer - array of depth values from Z buffer
1064 * Input: z - array of fragment z values.
1067 hardware_depth_test_pixels( GLcontext
*ctx
, GLuint n
, GLdepth zbuffer
[],
1068 const GLdepth z
[], GLubyte mask
[] )
1070 /* switch cases ordered from most frequent to less frequent */
1071 switch (ctx
->Depth
.Func
) {
1073 if (ctx
->Depth
.Mask
) {
1074 /* Update Z buffer */
1076 for (i
=0; i
<n
; i
++) {
1078 if (z
[i
] < zbuffer
[i
]) {
1090 /* Don't update Z buffer */
1092 for (i
=0; i
<n
; i
++) {
1094 if (z
[i
] < zbuffer
[i
]) {
1106 if (ctx
->Depth
.Mask
) {
1107 /* Update Z buffer */
1109 for (i
=0; i
<n
; i
++) {
1111 if (z
[i
] <= zbuffer
[i
]) {
1123 /* Don't update Z buffer */
1125 for (i
=0; i
<n
; i
++) {
1127 if (z
[i
] <= zbuffer
[i
]) {
1139 if (ctx
->Depth
.Mask
) {
1140 /* Update Z buffer */
1142 for (i
=0; i
<n
; i
++) {
1144 if (z
[i
] >= zbuffer
[i
]) {
1156 /* Don't update Z buffer */
1158 for (i
=0; i
<n
; i
++) {
1160 if (z
[i
] >= zbuffer
[i
]) {
1172 if (ctx
->Depth
.Mask
) {
1173 /* Update Z buffer */
1175 for (i
=0; i
<n
; i
++) {
1177 if (z
[i
] > zbuffer
[i
]) {
1189 /* Don't update Z buffer */
1191 for (i
=0; i
<n
; i
++) {
1193 if (z
[i
] > zbuffer
[i
]) {
1205 if (ctx
->Depth
.Mask
) {
1206 /* Update Z buffer */
1208 for (i
=0; i
<n
; i
++) {
1210 if (z
[i
] != zbuffer
[i
]) {
1222 /* Don't update Z buffer */
1224 for (i
=0; i
<n
; i
++) {
1226 if (z
[i
] != zbuffer
[i
]) {
1238 if (ctx
->Depth
.Mask
) {
1239 /* Update Z buffer */
1241 for (i
=0; i
<n
; i
++) {
1243 if (z
[i
] == zbuffer
[i
]) {
1255 /* Don't update Z buffer */
1257 for (i
=0; i
<n
; i
++) {
1259 if (z
[i
] == zbuffer
[i
]) {
1271 if (ctx
->Depth
.Mask
) {
1272 /* Update Z buffer */
1274 for (i
=0; i
<n
; i
++) {
1281 /* Don't update Z buffer or mask */
1285 /* depth test never passes */
1286 BZERO(mask
, n
* sizeof(GLubyte
));
1289 _mesa_problem(ctx
, "Bad depth func in hardware_depth_test_pixels");
1296 _mesa_depth_test_pixels( GLcontext
*ctx
,
1297 GLuint n
, const GLint x
[], const GLint y
[],
1298 const GLdepth z
[], GLubyte mask
[] )
1300 if (ctx
->Driver
.ReadDepthPixels
) {
1301 /* read depth values from hardware Z buffer */
1302 GLdepth zbuffer
[PB_SIZE
];
1303 (*ctx
->Driver
.ReadDepthPixels
)(ctx
, n
, x
, y
, zbuffer
);
1305 hardware_depth_test_pixels( ctx
, n
, zbuffer
, z
, mask
);
1307 /* update hardware Z buffer with new values */
1308 assert(ctx
->Driver
.WriteDepthPixels
);
1309 (*ctx
->Driver
.WriteDepthPixels
)(ctx
, n
, x
, y
, zbuffer
, mask
);
1312 /* software depth testing */
1313 if (ctx
->Visual
.depthBits
<= 16)
1314 software_depth_test_pixels16(ctx
, n
, x
, y
, z
, mask
);
1316 software_depth_test_pixels32(ctx
, n
, x
, y
, z
, mask
);
1324 /**********************************************************************/
1325 /***** Read Depth Buffer *****/
1326 /**********************************************************************/
1330 * Read a span of depth values from the depth buffer.
1331 * This function does clipping before calling the device driver function.
1334 _mesa_read_depth_span( GLcontext
*ctx
,
1335 GLint n
, GLint x
, GLint y
, GLdepth depth
[] )
1337 if (y
< 0 || y
>= ctx
->DrawBuffer
->Height
||
1338 x
+ (GLint
) n
<= 0 || x
>= ctx
->DrawBuffer
->Width
) {
1339 /* span is completely outside framebuffer */
1341 for (i
= 0; i
< n
; i
++)
1349 for (i
= 0; i
< dx
; i
++)
1355 if (x
+ n
> ctx
->DrawBuffer
->Width
) {
1356 GLint dx
= x
+ n
- ctx
->DrawBuffer
->Width
;
1358 for (i
= 0; i
< dx
; i
++)
1359 depth
[n
- i
- 1] = 0;
1366 if (ctx
->DrawBuffer
->DepthBuffer
) {
1367 /* read from software depth buffer */
1368 if (ctx
->Visual
.depthBits
<= 16) {
1369 const GLushort
*zptr
= Z_ADDRESS16( ctx
, x
, y
);
1371 for (i
= 0; i
< n
; i
++) {
1376 const GLuint
*zptr
= Z_ADDRESS32( ctx
, x
, y
);
1378 for (i
= 0; i
< n
; i
++) {
1383 else if (ctx
->Driver
.ReadDepthSpan
) {
1384 /* read from hardware depth buffer */
1385 (*ctx
->Driver
.ReadDepthSpan
)( ctx
, n
, x
, y
, depth
);
1388 /* no depth buffer */
1389 BZERO(depth
, n
* sizeof(GLfloat
));
1398 * Return a span of depth values from the depth buffer as floats in [0,1].
1399 * This is used for both hardware and software depth buffers.
1400 * Input: n - how many pixels
1401 * x,y - location of first pixel
1402 * Output: depth - the array of depth values
1405 _mesa_read_depth_span_float( GLcontext
*ctx
,
1406 GLint n
, GLint x
, GLint y
, GLfloat depth
[] )
1408 const GLfloat scale
= 1.0F
/ ctx
->DepthMaxF
;
1410 if (y
< 0 || y
>= ctx
->DrawBuffer
->Height
||
1411 x
+ (GLint
) n
<= 0 || x
>= ctx
->DrawBuffer
->Width
) {
1412 /* span is completely outside framebuffer */
1414 for (i
= 0; i
< n
; i
++)
1422 for (i
= 0; i
< dx
; i
++)
1427 if (x
+ n
> ctx
->DrawBuffer
->Width
) {
1428 GLint dx
= x
+ n
- ctx
->DrawBuffer
->Width
;
1430 for (i
= 0; i
< dx
; i
++)
1431 depth
[n
- i
- 1] = 0.0F
;
1438 if (ctx
->DrawBuffer
->DepthBuffer
) {
1439 /* read from software depth buffer */
1440 if (ctx
->Visual
.depthBits
<= 16) {
1441 const GLushort
*zptr
= Z_ADDRESS16( ctx
, x
, y
);
1443 for (i
= 0; i
< n
; i
++) {
1444 depth
[i
] = (GLfloat
) zptr
[i
] * scale
;
1448 const GLuint
*zptr
= Z_ADDRESS32( ctx
, x
, y
);
1450 for (i
= 0; i
< n
; i
++) {
1451 depth
[i
] = (GLfloat
) zptr
[i
] * scale
;
1455 else if (ctx
->Driver
.ReadDepthSpan
) {
1456 /* read from hardware depth buffer */
1457 GLdepth d
[MAX_WIDTH
];
1459 assert(n
<= MAX_WIDTH
);
1460 (*ctx
->Driver
.ReadDepthSpan
)( ctx
, n
, x
, y
, d
);
1461 for (i
= 0; i
< n
; i
++) {
1462 depth
[i
] = d
[i
] * scale
;
1466 /* no depth buffer */
1467 BZERO(depth
, n
* sizeof(GLfloat
));
1473 /**********************************************************************/
1474 /***** Allocate and Clear Depth Buffer *****/
1475 /**********************************************************************/
1480 * Allocate a new depth buffer. If there's already a depth buffer allocated
1481 * it will be free()'d. The new depth buffer will be uniniitalized.
1482 * This function is only called through Driver.alloc_depth_buffer.
1485 _mesa_alloc_depth_buffer( GLcontext
*ctx
)
1487 /* deallocate current depth buffer if present */
1488 if (ctx
->DrawBuffer
->UseSoftwareDepthBuffer
) {
1489 GLint bytesPerValue
;
1491 if (ctx
->DrawBuffer
->DepthBuffer
) {
1492 FREE(ctx
->DrawBuffer
->DepthBuffer
);
1493 ctx
->DrawBuffer
->DepthBuffer
= NULL
;
1496 /* allocate new depth buffer, but don't initialize it */
1497 if (ctx
->Visual
.depthBits
<= 16)
1498 bytesPerValue
= sizeof(GLushort
);
1500 bytesPerValue
= sizeof(GLuint
);
1502 ctx
->DrawBuffer
->DepthBuffer
= MALLOC( ctx
->DrawBuffer
->Width
1503 * ctx
->DrawBuffer
->Height
1506 if (!ctx
->DrawBuffer
->DepthBuffer
) {
1508 ctx
->Depth
.Test
= GL_FALSE
;
1509 ctx
->NewState
|= _NEW_DEPTH
;
1510 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "Couldn't allocate depth buffer" );
1519 * Clear the depth buffer. If the depth buffer doesn't exist yet we'll
1521 * This function is only called through Driver.clear_depth_buffer.
1524 _mesa_clear_depth_buffer( GLcontext
*ctx
)
1526 if (ctx
->Visual
.depthBits
== 0
1527 || !ctx
->DrawBuffer
->DepthBuffer
1528 || !ctx
->Depth
.Mask
) {
1529 /* no depth buffer, or writing to it is disabled */
1533 /* The loops in this function have been written so the IRIX 5.3
1534 * C compiler can unroll them. Hopefully other compilers can too!
1537 if (ctx
->Scissor
.Enabled
) {
1538 /* only clear scissor region */
1539 if (ctx
->Visual
.depthBits
<= 16) {
1540 const GLushort clearValue
= (GLushort
) (ctx
->Depth
.Clear
* ctx
->DepthMax
);
1541 const GLint rows
= ctx
->DrawBuffer
->_Ymax
- ctx
->DrawBuffer
->_Ymin
;
1542 const GLint cols
= ctx
->DrawBuffer
->_Xmax
- ctx
->DrawBuffer
->_Xmin
;
1543 const GLint rowStride
= ctx
->DrawBuffer
->Width
;
1544 GLushort
*dRow
= (GLushort
*) ctx
->DrawBuffer
->DepthBuffer
1545 + ctx
->DrawBuffer
->_Ymin
* rowStride
+ ctx
->DrawBuffer
->_Xmin
;
1547 for (i
= 0; i
< rows
; i
++) {
1548 for (j
= 0; j
< cols
; j
++) {
1549 dRow
[j
] = clearValue
;
1555 const GLuint clearValue
= (GLuint
) (ctx
->Depth
.Clear
* ctx
->DepthMax
);
1556 const GLint rows
= ctx
->DrawBuffer
->_Ymax
- ctx
->DrawBuffer
->_Ymin
;
1557 const GLint cols
= ctx
->DrawBuffer
->_Xmax
- ctx
->DrawBuffer
->_Xmin
;
1558 const GLint rowStride
= ctx
->DrawBuffer
->Width
;
1559 GLuint
*dRow
= (GLuint
*) ctx
->DrawBuffer
->DepthBuffer
1560 + ctx
->DrawBuffer
->_Ymin
* rowStride
+ ctx
->DrawBuffer
->_Xmin
;
1562 for (i
= 0; i
< rows
; i
++) {
1563 for (j
= 0; j
< cols
; j
++) {
1564 dRow
[j
] = clearValue
;
1571 /* clear whole buffer */
1572 if (ctx
->Visual
.depthBits
<= 16) {
1573 const GLushort clearValue
= (GLushort
) (ctx
->Depth
.Clear
* ctx
->DepthMax
);
1574 if ((clearValue
& 0xff) == (clearValue
>> 8)) {
1575 if (clearValue
== 0) {
1576 BZERO(ctx
->DrawBuffer
->DepthBuffer
,
1577 2*ctx
->DrawBuffer
->Width
*ctx
->DrawBuffer
->Height
);
1580 /* lower and upper bytes of clear_value are same, use MEMSET */
1581 MEMSET( ctx
->DrawBuffer
->DepthBuffer
, clearValue
& 0xff,
1582 2 * ctx
->DrawBuffer
->Width
* ctx
->DrawBuffer
->Height
);
1586 GLushort
*d
= (GLushort
*) ctx
->DrawBuffer
->DepthBuffer
;
1587 GLint n
= ctx
->DrawBuffer
->Width
* ctx
->DrawBuffer
->Height
;
1589 d
[0] = clearValue
; d
[1] = clearValue
;
1590 d
[2] = clearValue
; d
[3] = clearValue
;
1591 d
[4] = clearValue
; d
[5] = clearValue
;
1592 d
[6] = clearValue
; d
[7] = clearValue
;
1593 d
[8] = clearValue
; d
[9] = clearValue
;
1594 d
[10] = clearValue
; d
[11] = clearValue
;
1595 d
[12] = clearValue
; d
[13] = clearValue
;
1596 d
[14] = clearValue
; d
[15] = clearValue
;
1607 /* >16 bit depth buffer */
1608 const GLuint clearValue
= (GLuint
) (ctx
->Depth
.Clear
* ctx
->DepthMax
);
1609 if (clearValue
== 0) {
1610 BZERO(ctx
->DrawBuffer
->DepthBuffer
,
1611 ctx
->DrawBuffer
->Width
*ctx
->DrawBuffer
->Height
*sizeof(GLuint
));
1614 GLint n
= ctx
->DrawBuffer
->Width
* ctx
->DrawBuffer
->Height
;
1615 GLuint
*d
= (GLuint
*) ctx
->DrawBuffer
->DepthBuffer
;
1617 d
[0] = clearValue
; d
[1] = clearValue
;
1618 d
[2] = clearValue
; d
[3] = clearValue
;
1619 d
[4] = clearValue
; d
[5] = clearValue
;
1620 d
[6] = clearValue
; d
[7] = clearValue
;
1621 d
[8] = clearValue
; d
[9] = clearValue
;
1622 d
[10] = clearValue
; d
[11] = clearValue
;
1623 d
[12] = clearValue
; d
[13] = clearValue
;
1624 d
[14] = clearValue
; d
[15] = clearValue
;