- /* deallocate current depth buffer if present */
- if (ctx->DrawBuffer->UseSoftwareDepthBuffer) {
- GLint bytesPerValue;
-
- if (ctx->DrawBuffer->Depth) {
- FREE(ctx->DrawBuffer->Depth);
- ctx->DrawBuffer->DepthBuffer = NULL;
- ctx->DrawBuffer->Depth = NULL;
- }
-
- /* allocate new depth buffer, but don't initialize it */
- if (ctx->Visual->DepthBits <= 16)
- bytesPerValue = sizeof(GLushort);
- else
- bytesPerValue = sizeof(GLuint);
-
- ctx->DrawBuffer->DepthBuffer = MALLOC( ctx->DrawBuffer->Width
- * ctx->DrawBuffer->Height
- * bytesPerValue );
- ctx->DrawBuffer->Depth = (GLdepth *) ctx->DrawBuffer->DepthBuffer;
-
- if (!ctx->DrawBuffer->Depth) {
- /* out of memory */
- ctx->Depth.Test = GL_FALSE;
- ctx->NewState |= NEW_RASTER_OPS;
- gl_error( ctx, GL_OUT_OF_MEMORY, "Couldn't allocate depth buffer" );
- }
- }
-}
-
-
-
-
-/*
- * Clear the depth buffer. If the depth buffer doesn't exist yet we'll
- * allocate it now.
- * This function is only called through Driver.clear_depth_buffer.
- */
-void
-_mesa_clear_depth_buffer( GLcontext *ctx )
-{
- if (ctx->Visual->DepthBits == 0
- || !ctx->DrawBuffer->DepthBuffer
- || !ctx->Depth.Mask) {
- /* no depth buffer, or writing to it is disabled */
- return;
- }
-
- /* The loops in this function have been written so the IRIX 5.3
- * C compiler can unroll them. Hopefully other compilers can too!
- */
-
- if (ctx->Scissor.Enabled) {
- /* only clear scissor region */
- if (ctx->Visual->DepthBits <= 16) {
- const GLushort clearValue = (GLushort) (ctx->Depth.Clear * ctx->Visual->DepthMax);
- const GLint rows = ctx->DrawBuffer->Ymax - ctx->DrawBuffer->Ymin + 1;
- const GLint width = ctx->DrawBuffer->Width;
- GLushort *dRow = (GLushort *) ctx->DrawBuffer->DepthBuffer
- + ctx->DrawBuffer->Ymin * width + ctx->DrawBuffer->Xmin;
- GLint i, j;
- for (i = 0; i < rows; i++) {
- for (j = 0; j < width; j++) {
- dRow[j] = clearValue;
- }
- dRow += width;
- }
- }
- else {
- const GLuint clearValue = (GLuint) (ctx->Depth.Clear * ctx->Visual->DepthMax);
- const GLint rows = ctx->DrawBuffer->Ymax - ctx->DrawBuffer->Ymin + 1;
- const GLint width = ctx->DrawBuffer->Width;
- GLuint *dRow = (GLuint *) ctx->DrawBuffer->DepthBuffer
- + ctx->DrawBuffer->Ymin * width + ctx->DrawBuffer->Xmin;
- GLint i, j;
- for (i = 0; i < rows; i++) {
- for (j = 0; j < width; j++) {
- dRow[j] = clearValue;
- }
- dRow += width;
- }
- }
- }
- else {
- /* clear whole buffer */
- if (ctx->Visual->DepthBits <= 16) {
- const GLushort clearValue = (GLushort) (ctx->Depth.Clear * ctx->Visual->DepthMax);
- if ((clearValue & 0xff) == (clearValue >> 8)) {
- /* lower and upper bytes of clear_value are same, use MEMSET */
- MEMSET( ctx->DrawBuffer->DepthBuffer, clearValue & 0xff,
- 2 * ctx->DrawBuffer->Width * ctx->DrawBuffer->Height);
- }
- else {
- GLushort *d = ctx->DrawBuffer->DepthBuffer;
- GLint n = ctx->DrawBuffer->Width * ctx->DrawBuffer->Height;
- while (n >= 16) {
- d[0] = clearValue; d[1] = clearValue;
- d[2] = clearValue; d[3] = clearValue;
- d[4] = clearValue; d[5] = clearValue;
- d[6] = clearValue; d[7] = clearValue;
- d[8] = clearValue; d[9] = clearValue;
- d[10] = clearValue; d[11] = clearValue;
- d[12] = clearValue; d[13] = clearValue;
- d[14] = clearValue; d[15] = clearValue;
- d += 16;
- n -= 16;
- }
- while (n > 0) {
- *d++ = clearValue;
- n--;
- }
- }
- }
- else {
- /* >16 bit depth buffer */
- GLuint *d = (GLuint *) ctx->DrawBuffer->DepthBuffer;
- const GLuint clearValue = (GLuint) (ctx->Depth.Clear * ctx->Visual->DepthMax);
- GLint n = ctx->DrawBuffer->Width * ctx->DrawBuffer->Height;
- while (n >= 16) {
- d[0] = clearValue; d[1] = clearValue;
- d[2] = clearValue; d[3] = clearValue;
- d[4] = clearValue; d[5] = clearValue;
- d[6] = clearValue; d[7] = clearValue;
- d[8] = clearValue; d[9] = clearValue;
- d[10] = clearValue; d[11] = clearValue;
- d[12] = clearValue; d[13] = clearValue;
- d[14] = clearValue; d[15] = clearValue;
- d += 16;
- n -= 16;
- }
- while (n > 0) {
- *d++ = clearValue;
- n--;
- }
- }
- }