added missing \'s
[mesa.git] / src / mesa / swrast / s_depth.c
index 3186f8ea27c217475eaecd18da644d422f09a73f..5001081ae049fa59c84393f4a85398869529066f 100644 (file)
@@ -1,21 +1,21 @@
-/* $Id: s_depth.c,v 1.2 2000/11/05 18:24:40 keithw Exp $ */
+/* $Id: s_depth.c,v 1.9 2001/03/19 02:25:36 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  3.3
- * 
- * Copyright (C) 1999-2000  Brian Paul   All Rights Reserved.
- * 
+ * Version:  3.5
+ *
+ * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  * to deal in the Software without restriction, including without limitation
  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  * and/or sell copies of the Software, and to permit persons to whom the
  * Software is furnished to do so, subject to the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be included
  * in all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
@@ -43,7 +43,7 @@
 GLvoid *
 _mesa_zbuffer_address(GLcontext *ctx, GLint x, GLint y)
 {
-   if (ctx->Visual.DepthBits <= 16)
+   if (ctx->Visual.depthBits <= 16)
       return (GLushort *) ctx->DrawBuffer->DepthBuffer + ctx->DrawBuffer->Width * y + x;
    else
       return (GLuint *) ctx->DrawBuffer->DepthBuffer + ctx->DrawBuffer->Width * y + x;
@@ -294,7 +294,7 @@ depth_test_span16( GLcontext *ctx, GLuint n, GLint x, GLint y,
          BZERO(mask, n * sizeof(GLubyte));
         break;
       default:
-         gl_problem(ctx, "Bad depth func in depth_test_span16");
+         _mesa_problem(ctx, "Bad depth func in depth_test_span16");
    }
 
    return passed;
@@ -523,7 +523,7 @@ depth_test_span32( GLcontext *ctx, GLuint n, GLint x, GLint y,
          BZERO(mask, n * sizeof(GLubyte));
         break;
       default:
-         gl_problem(ctx, "Bad depth func in depth_test_span32");
+         _mesa_problem(ctx, "Bad depth func in depth_test_span32");
    }
 
    return passed;
@@ -538,19 +538,20 @@ GLuint
 _mesa_depth_test_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
                        const GLdepth z[], GLubyte mask[] )
 {
-   if (ctx->Driver.ReadDepthSpan) {
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
+   if (swrast->Driver.ReadDepthSpan) {
       /* hardware-based depth buffer */
       GLdepth zbuffer[MAX_WIDTH];
       GLuint passed;
-      (*ctx->Driver.ReadDepthSpan)(ctx, n, x, y, zbuffer);
+      (*swrast->Driver.ReadDepthSpan)(ctx, n, x, y, zbuffer);
       passed = depth_test_span32(ctx, n, x, y, zbuffer, z, mask);
-      assert(ctx->Driver.WriteDepthSpan);
-      (*ctx->Driver.WriteDepthSpan)(ctx, n, x, y, zbuffer, mask);
+      assert(swrast->Driver.WriteDepthSpan);
+      (*swrast->Driver.WriteDepthSpan)(ctx, n, x, y, zbuffer, mask);
       return passed;
    }
    else {
       /* software depth buffer */
-      if (ctx->Visual.DepthBits <= 16) {
+      if (ctx->Visual.depthBits <= 16) {
          GLushort *zptr = (GLushort *) Z_ADDRESS16(ctx, x, y);
          GLuint passed = depth_test_span16(ctx, n, x, y, zptr, z, mask);
          return passed;
@@ -806,7 +807,7 @@ software_depth_test_pixels16( GLcontext *ctx, GLuint n,
          BZERO(mask, n * sizeof(GLubyte));
         break;
       default:
-         gl_problem(ctx, "Bad depth func in software_depth_test_pixels");
+         _mesa_problem(ctx, "Bad depth func in software_depth_test_pixels");
    }
 }
 
@@ -1052,7 +1053,7 @@ software_depth_test_pixels32( GLcontext *ctx, GLuint n,
          BZERO(mask, n * sizeof(GLubyte));
         break;
       default:
-         gl_problem(ctx, "Bad depth func in software_depth_test_pixels");
+         _mesa_problem(ctx, "Bad depth func in software_depth_test_pixels");
    }
 }
 
@@ -1286,7 +1287,7 @@ hardware_depth_test_pixels( GLcontext *ctx, GLuint n, GLdepth zbuffer[],
          BZERO(mask, n * sizeof(GLubyte));
         break;
       default:
-         gl_problem(ctx, "Bad depth func in hardware_depth_test_pixels");
+         _mesa_problem(ctx, "Bad depth func in hardware_depth_test_pixels");
    }
 }
 
@@ -1297,20 +1298,21 @@ _mesa_depth_test_pixels( GLcontext *ctx,
                          GLuint n, const GLint x[], const GLint y[],
                          const GLdepth z[], GLubyte mask[] )
 {
-   if (ctx->Driver.ReadDepthPixels) {
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
+   if (swrast->Driver.ReadDepthPixels) {
       /* read depth values from hardware Z buffer */
       GLdepth zbuffer[PB_SIZE];
-      (*ctx->Driver.ReadDepthPixels)(ctx, n, x, y, zbuffer);
+      (*swrast->Driver.ReadDepthPixels)(ctx, n, x, y, zbuffer);
 
       hardware_depth_test_pixels( ctx, n, zbuffer, z, mask );
 
       /* update hardware Z buffer with new values */
-      assert(ctx->Driver.WriteDepthPixels);
-      (*ctx->Driver.WriteDepthPixels)(ctx, n, x, y, zbuffer, mask );
+      assert(swrast->Driver.WriteDepthPixels);
+      (*swrast->Driver.WriteDepthPixels)(ctx, n, x, y, zbuffer, mask );
    }
    else {
       /* software depth testing */
-      if (ctx->Visual.DepthBits <= 16)
+      if (ctx->Visual.depthBits <= 16)
          software_depth_test_pixels16(ctx, n, x, y, z, mask);
       else
          software_depth_test_pixels32(ctx, n, x, y, z, mask);
@@ -1334,6 +1336,8 @@ void
 _mesa_read_depth_span( GLcontext *ctx,
                        GLint n, GLint x, GLint y, GLdepth depth[] )
 {
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
+
    if (y < 0 || y >= ctx->DrawBuffer->Height ||
        x + (GLint) n <= 0 || x >= ctx->DrawBuffer->Width) {
       /* span is completely outside framebuffer */
@@ -1365,24 +1369,24 @@ _mesa_read_depth_span( GLcontext *ctx,
 
    if (ctx->DrawBuffer->DepthBuffer) {
       /* read from software depth buffer */
-      if (ctx->Visual.DepthBits <= 16) {
+      if (ctx->Visual.depthBits <= 16) {
          const GLushort *zptr = Z_ADDRESS16( ctx, x, y );
-         GLuint i;
+         GLint i;
          for (i = 0; i < n; i++) {
             depth[i] = zptr[i];
          }
       }
       else {
          const GLuint *zptr = Z_ADDRESS32( ctx, x, y );
-         GLuint i;
+         GLint i;
          for (i = 0; i < n; i++) {
             depth[i] = zptr[i];
          }
       }
    }
-   else if (ctx->Driver.ReadDepthSpan) {
+   else if (swrast->Driver.ReadDepthSpan) {
       /* read from hardware depth buffer */
-      (*ctx->Driver.ReadDepthSpan)( ctx, n, x, y, depth );
+      (*swrast->Driver.ReadDepthSpan)( ctx, n, x, y, depth );
    }
    else {
       /* no depth buffer */
@@ -1405,7 +1409,8 @@ void
 _mesa_read_depth_span_float( GLcontext *ctx,
                              GLint n, GLint x, GLint y, GLfloat depth[] )
 {
-   const GLfloat scale = 1.0F / ctx->Visual.DepthMaxF;
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
+   const GLfloat scale = 1.0F / ctx->DepthMaxF;
 
    if (y < 0 || y >= ctx->DrawBuffer->Height ||
        x + (GLint) n <= 0 || x >= ctx->DrawBuffer->Width) {
@@ -1437,27 +1442,27 @@ _mesa_read_depth_span_float( GLcontext *ctx,
 
    if (ctx->DrawBuffer->DepthBuffer) {
       /* read from software depth buffer */
-      if (ctx->Visual.DepthBits <= 16) {
+      if (ctx->Visual.depthBits <= 16) {
          const GLushort *zptr = Z_ADDRESS16( ctx, x, y );
-         GLuint i;
+         GLint i;
          for (i = 0; i < n; i++) {
             depth[i] = (GLfloat) zptr[i] * scale;
          }
       }
       else {
          const GLuint *zptr = Z_ADDRESS32( ctx, x, y );
-         GLuint i;
+         GLint i;
          for (i = 0; i < n; i++) {
             depth[i] = (GLfloat) zptr[i] * scale;
          }
       }
    }
-   else if (ctx->Driver.ReadDepthSpan) {
+   else if (swrast->Driver.ReadDepthSpan) {
       /* read from hardware depth buffer */
       GLdepth d[MAX_WIDTH];
-      GLuint i;
+      GLint i;
       assert(n <= MAX_WIDTH);
-      (*ctx->Driver.ReadDepthSpan)( ctx, n, x, y, d );
+      (*swrast->Driver.ReadDepthSpan)( ctx, n, x, y, d );
       for (i = 0; i < n; i++) {
         depth[i] = d[i] * scale;
       }
@@ -1494,7 +1499,7 @@ _mesa_alloc_depth_buffer( GLcontext *ctx )
       }
 
       /* allocate new depth buffer, but don't initialize it */
-      if (ctx->Visual.DepthBits <= 16)
+      if (ctx->Visual.depthBits <= 16)
          bytesPerValue = sizeof(GLushort);
       else
          bytesPerValue = sizeof(GLuint);
@@ -1507,7 +1512,7 @@ _mesa_alloc_depth_buffer( GLcontext *ctx )
          /* out of memory */
          ctx->Depth.Test = GL_FALSE;
          ctx->NewState |= _NEW_DEPTH;
-         gl_error( ctx, GL_OUT_OF_MEMORY, "Couldn't allocate depth buffer" );
+         _mesa_error( ctx, GL_OUT_OF_MEMORY, "Couldn't allocate depth buffer" );
       }
    }
 }
@@ -1523,7 +1528,7 @@ _mesa_alloc_depth_buffer( GLcontext *ctx )
 void
 _mesa_clear_depth_buffer( GLcontext *ctx )
 {
-   if (ctx->Visual.DepthBits == 0
+   if (ctx->Visual.depthBits == 0
        || !ctx->DrawBuffer->DepthBuffer
        || !ctx->Depth.Mask) {
       /* no depth buffer, or writing to it is disabled */
@@ -1536,39 +1541,41 @@ _mesa_clear_depth_buffer( GLcontext *ctx )
 
    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;
-         const GLint width = ctx->DrawBuffer->Width;
+      if (ctx->Visual.depthBits <= 16) {
+         const GLushort clearValue = (GLushort) (ctx->Depth.Clear * ctx->DepthMax);
+         const GLint rows = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
+         const GLint cols = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
+         const GLint rowStride = ctx->DrawBuffer->Width;
          GLushort *dRow = (GLushort *) ctx->DrawBuffer->DepthBuffer
-            + ctx->DrawBuffer->Ymin * width + ctx->DrawBuffer->Xmin;
+            + ctx->DrawBuffer->_Ymin * rowStride + ctx->DrawBuffer->_Xmin;
          GLint i, j;
          for (i = 0; i < rows; i++) {
-            for (j = 0; j < width; j++) {
+            for (j = 0; j < cols; j++) {
                dRow[j] = clearValue;
             }
-            dRow += width;
+            dRow += rowStride;
          }
       }
       else {
-         const GLuint clearValue = (GLuint) (ctx->Depth.Clear * ctx->Visual.DepthMax);
-         const GLint rows = ctx->DrawBuffer->Ymax - ctx->DrawBuffer->Ymin;
-         const GLint width = ctx->DrawBuffer->Width;
+         const GLuint clearValue = (GLuint) (ctx->Depth.Clear * ctx->DepthMax);
+         const GLint rows = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
+         const GLint cols = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
+         const GLint rowStride = ctx->DrawBuffer->Width;
          GLuint *dRow = (GLuint *) ctx->DrawBuffer->DepthBuffer
-            + ctx->DrawBuffer->Ymin * width + ctx->DrawBuffer->Xmin;
+            + ctx->DrawBuffer->_Ymin * rowStride + ctx->DrawBuffer->_Xmin;
          GLint i, j;
          for (i = 0; i < rows; i++) {
-            for (j = 0; j < width; j++) {
+            for (j = 0; j < cols; j++) {
                dRow[j] = clearValue;
             }
-            dRow += width;
+            dRow += rowStride;
          }
       }
    }
    else {
       /* clear whole buffer */
-      if (ctx->Visual.DepthBits <= 16) {
-         const GLushort clearValue = (GLushort) (ctx->Depth.Clear * ctx->Visual.DepthMax);
+      if (ctx->Visual.depthBits <= 16) {
+         const GLushort clearValue = (GLushort) (ctx->Depth.Clear * ctx->DepthMax);
          if ((clearValue & 0xff) == (clearValue >> 8)) {
             if (clearValue == 0) {
                BZERO(ctx->DrawBuffer->DepthBuffer,
@@ -1603,7 +1610,7 @@ _mesa_clear_depth_buffer( GLcontext *ctx )
       }
       else {
          /* >16 bit depth buffer */
-         const GLuint clearValue = (GLuint) (ctx->Depth.Clear * ctx->Visual.DepthMax);
+         const GLuint clearValue = (GLuint) (ctx->Depth.Clear * ctx->DepthMax);
          if (clearValue == 0) {
             BZERO(ctx->DrawBuffer->DepthBuffer,
                 ctx->DrawBuffer->Width*ctx->DrawBuffer->Height*sizeof(GLuint));