Fix typo
[mesa.git] / src / mesa / swrast / s_stencil.c
index 80839451cba28a5bd70b8a14a0a61a522a78151e..a69bd3c96c4c5e05fc14b7e5db857a575d4a55fc 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: s_stencil.c,v 1.2 2000/11/05 18:24:40 keithw Exp $ */
+/* $Id: s_stencil.c,v 1.8 2001/03/03 20:33:30 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -219,7 +219,7 @@ static void apply_stencil_op( const GLcontext *ctx, GLenum oper,
         }
         break;
       default:
-         gl_problem(ctx, "Bad stencil op in apply_stencil_op");
+         _mesa_problem(ctx, "Bad stencil op in apply_stencil_op");
    }
 }
 
@@ -391,7 +391,7 @@ do_stencil_test( GLcontext *ctx, GLuint n, GLstencil stencil[],
         }
         break;
       default:
-         gl_problem(ctx, "Bad stencil func in gl_stencil_span");
+         _mesa_problem(ctx, "Bad stencil func in gl_stencil_span");
          return 0;
    }
 
@@ -697,7 +697,7 @@ apply_stencil_op_to_pixels( const GLcontext *ctx,
         }
         break;
       default:
-         gl_problem(ctx, "Bad stencilop in apply_stencil_op_to_pixels");
+         _mesa_problem(ctx, "Bad stencilop in apply_stencil_op_to_pixels");
    }
 }
 
@@ -875,7 +875,7 @@ stencil_test_pixels( GLcontext *ctx, GLuint n,
         }
         break;
       default:
-         gl_problem(ctx, "Bad stencil func in gl_stencil_pixels");
+         _mesa_problem(ctx, "Bad stencil func in gl_stencil_pixels");
          return 0;
    }
 
@@ -916,47 +916,47 @@ _mesa_stencil_and_ztest_pixels( GLcontext *ctx,
    if (ctx->Driver.WriteStencilPixels) {
       /*** Hardware stencil buffer ***/
       GLstencil stencil[PB_SIZE];
-      GLubyte mask[PB_SIZE];
+      GLubyte origMask[PB_SIZE];
 
       ASSERT(ctx->Driver.ReadStencilPixels);
       (*ctx->Driver.ReadStencilPixels)(ctx, n, x, y, stencil);
 
+      MEMCPY(origMask, mask, n * sizeof(GLubyte));
 
-      if (do_stencil_test( ctx, n, stencil, mask ) == GL_FALSE) {
-         /* all fragments failed the stencil test, we're done. */
-         return GL_FALSE;
-      }
+      (void) do_stencil_test(ctx, n, stencil, mask);
 
       if (ctx->Depth.Test == GL_FALSE) {
-         apply_stencil_op( ctx, ctx->Stencil.ZPassFunc, n, stencil, mask );
+         apply_stencil_op(ctx, ctx->Stencil.ZPassFunc, n, stencil, mask);
       }
       else {
-         GLubyte passmask[PB_SIZE], failmask[PB_SIZE], oldmask[PB_SIZE];
-         GLuint i;
-
-         MEMCPY(oldmask, mask, n * sizeof(GLubyte));
-
          _mesa_depth_test_pixels(ctx, n, x, y, z, mask);
 
-         for (i=0;i<n;i++) {
-            ASSERT(mask[i] == 0 || mask[i] == 1);
-            passmask[i] = oldmask[i] & mask[i];
-            failmask[i] = oldmask[i] & (mask[i] ^ 1);
-         }
-
          if (ctx->Stencil.ZFailFunc != GL_KEEP) {
-            apply_stencil_op( ctx, ctx->Stencil.ZFailFunc, n, stencil, failmask );
+            GLubyte failmask[PB_SIZE];
+            GLuint i;
+            for (i = 0; i < n; i++) {
+               ASSERT(mask[i] == 0 || mask[i] == 1);
+               failmask[i] = origMask[i] & (mask[i] ^ 1);
+            }
+            apply_stencil_op(ctx, ctx->Stencil.ZFailFunc,
+                             n, stencil, failmask);
          }
          if (ctx->Stencil.ZPassFunc != GL_KEEP) {
-            apply_stencil_op( ctx, ctx->Stencil.ZPassFunc, n, stencil, passmask );
+            GLubyte passmask[PB_SIZE];
+            GLuint i;
+            for (i = 0; i < n; i++) {
+               ASSERT(mask[i] == 0 || mask[i] == 1);
+               passmask[i] = origMask[i] & mask[i];
+            }
+            apply_stencil_op(ctx, ctx->Stencil.ZPassFunc,
+                             n, stencil, passmask);
          }
       }
 
       /* Write updated stencil values into hardware stencil buffer */
-      (ctx->Driver.WriteStencilPixels)(ctx, n, x, y, stencil, mask );
+      (ctx->Driver.WriteStencilPixels)(ctx, n, x, y, stencil, origMask);
 
       return GL_TRUE;
-
    }
    else {
       /*** Software stencil buffer ***/
@@ -966,9 +966,9 @@ _mesa_stencil_and_ztest_pixels( GLcontext *ctx,
          return GL_FALSE;
       }
 
-
       if (ctx->Depth.Test==GL_FALSE) {
-         apply_stencil_op_to_pixels( ctx, n, x, y, ctx->Stencil.ZPassFunc, mask );
+         apply_stencil_op_to_pixels(ctx, n, x, y,
+                                    ctx->Stencil.ZPassFunc, mask);
       }
       else {
          GLubyte passmask[PB_SIZE], failmask[PB_SIZE], oldmask[PB_SIZE];
@@ -985,12 +985,12 @@ _mesa_stencil_and_ztest_pixels( GLcontext *ctx,
          }
 
          if (ctx->Stencil.ZFailFunc != GL_KEEP) {
-            apply_stencil_op_to_pixels( ctx, n, x, y,
-                                        ctx->Stencil.ZFailFunc, failmask );
+            apply_stencil_op_to_pixels(ctx, n, x, y,
+                                       ctx->Stencil.ZFailFunc, failmask);
          }
          if (ctx->Stencil.ZPassFunc != GL_KEEP) {
-            apply_stencil_op_to_pixels( ctx, n, x, y,
-                                        ctx->Stencil.ZPassFunc, passmask );
+            apply_stencil_op_to_pixels(ctx, n, x, y,
+                                       ctx->Stencil.ZPassFunc, passmask);
          }
       }
 
@@ -1118,7 +1118,7 @@ _mesa_alloc_stencil_buffer( GLcontext *ctx )
    if (!ctx->DrawBuffer->Stencil) {
       /* out of memory */
 /*        _mesa_set_enable( ctx, GL_STENCIL_TEST, GL_FALSE ); */
-      gl_error( ctx, GL_OUT_OF_MEMORY, "_mesa_alloc_stencil_buffer" );
+      _mesa_error( ctx, GL_OUT_OF_MEMORY, "_mesa_alloc_stencil_buffer" );
    }
 }
 
@@ -1130,22 +1130,22 @@ _mesa_alloc_stencil_buffer( GLcontext *ctx )
 static void
 clear_software_stencil_buffer( GLcontext *ctx )
 {
-   if (ctx->Visual.StencilBits==0 || !ctx->DrawBuffer->Stencil) {
+   if (ctx->Visual.stencilBits==0 || !ctx->DrawBuffer->Stencil) {
       /* no stencil buffer */
       return;
    }
 
    if (ctx->Scissor.Enabled) {
       /* clear scissor region only */
-      const GLint width = ctx->DrawBuffer->Xmax - ctx->DrawBuffer->Xmin;
+      const GLint width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
       if (ctx->Stencil.WriteMask != STENCIL_MAX) {
          /* must apply mask to the clear */
          GLint y;
-         for (y = ctx->DrawBuffer->Ymin; y < ctx->DrawBuffer->Ymax; y++) {
+         for (y = ctx->DrawBuffer->_Ymin; y < ctx->DrawBuffer->_Ymax; y++) {
             const GLstencil mask = ctx->Stencil.WriteMask;
             const GLstencil invMask = ~mask;
             const GLstencil clearVal = (ctx->Stencil.Clear & mask);
-            GLstencil *stencil = STENCIL_ADDRESS( ctx->DrawBuffer->Xmin, y );
+            GLstencil *stencil = STENCIL_ADDRESS( ctx->DrawBuffer->_Xmin, y );
             GLint i;
             for (i = 0; i < width; i++) {
                stencil[i] = (stencil[i] & invMask) | clearVal;
@@ -1155,8 +1155,8 @@ clear_software_stencil_buffer( GLcontext *ctx )
       else {
          /* no masking */
          GLint y;
-         for (y = ctx->DrawBuffer->Ymin; y < ctx->DrawBuffer->Ymax; y++) {
-            GLstencil *stencil = STENCIL_ADDRESS( ctx->DrawBuffer->Xmin, y );
+         for (y = ctx->DrawBuffer->_Ymin; y < ctx->DrawBuffer->_Ymax; y++) {
+            GLstencil *stencil = STENCIL_ADDRESS( ctx->DrawBuffer->_Xmin, y );
 #if STENCIL_BITS==8
             MEMSET( stencil, ctx->Stencil.Clear, width * sizeof(GLstencil) );
 #else
@@ -1217,22 +1217,22 @@ clear_hardware_stencil_buffer( GLcontext *ctx )
 
    if (ctx->Scissor.Enabled) {
       /* clear scissor region only */
-      const GLint x = ctx->DrawBuffer->Xmin;
-      const GLint width = ctx->DrawBuffer->Xmax - ctx->DrawBuffer->Xmin;
+      const GLint x = ctx->DrawBuffer->_Xmin;
+      const GLint width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
       if (ctx->Stencil.WriteMask != STENCIL_MAX) {
          /* must apply mask to the clear */
          GLint y;
-         for (y = ctx->DrawBuffer->Ymin; y < ctx->DrawBuffer->Ymax; y++) {
+         for (y = ctx->DrawBuffer->_Ymin; y < ctx->DrawBuffer->_Ymax; y++) {
             const GLstencil mask = ctx->Stencil.WriteMask;
             const GLstencil invMask = ~mask;
             const GLstencil clearVal = (ctx->Stencil.Clear & mask);
             GLstencil stencil[MAX_WIDTH];
             GLint i;
-            (*ctx->Driver.ReadStencilSpan)(ctx, x, y, width, stencil);
+            (*ctx->Driver.ReadStencilSpan)(ctx, width, x, y, stencil);
             for (i = 0; i < width; i++) {
                stencil[i] = (stencil[i] & invMask) | clearVal;
             }
-            (*ctx->Driver.WriteStencilSpan)(ctx, x, y, width, stencil, NULL);
+            (*ctx->Driver.WriteStencilSpan)(ctx, width, x, y, stencil, NULL);
          }
       }
       else {
@@ -1242,8 +1242,8 @@ clear_hardware_stencil_buffer( GLcontext *ctx )
          for (i = 0; i < width; i++) {
             stencil[i] = ctx->Stencil.Clear;
          }
-         for (y = ctx->DrawBuffer->Ymin; y < ctx->DrawBuffer->Ymax; y++) {
-            (*ctx->Driver.WriteStencilSpan)(ctx, x, y, width, stencil, NULL);
+         for (y = ctx->DrawBuffer->_Ymin; y < ctx->DrawBuffer->_Ymax; y++) {
+            (*ctx->Driver.WriteStencilSpan)(ctx, width, x, y, stencil, NULL);
          }
       }
    }
@@ -1256,30 +1256,30 @@ clear_hardware_stencil_buffer( GLcontext *ctx )
          const GLstencil clearVal = (ctx->Stencil.Clear & mask);
          const GLint width = ctx->DrawBuffer->Width;
          const GLint height = ctx->DrawBuffer->Height;
-         const GLint x = ctx->DrawBuffer->Xmin;
+         const GLint x = ctx->DrawBuffer->_Xmin;
          GLint y;
          for (y = 0; y < height; y++) {
             GLstencil stencil[MAX_WIDTH];
             GLuint i;
-            (*ctx->Driver.ReadStencilSpan)(ctx, x, y, width, stencil);
+            (*ctx->Driver.ReadStencilSpan)(ctx, width, x, y, stencil);
             for (i = 0; i < width; i++) {
                stencil[i] = (stencil[i] & invMask) | clearVal;
             }
-            (*ctx->Driver.WriteStencilSpan)(ctx, x, y, width, stencil, NULL);
+            (*ctx->Driver.WriteStencilSpan)(ctx, width, x, y, stencil, NULL);
          }
       }
       else {
          /* clear whole buffer without masking */
          const GLint width = ctx->DrawBuffer->Width;
          const GLint height = ctx->DrawBuffer->Width;
-         const GLint x = ctx->DrawBuffer->Xmin;
+         const GLint x = ctx->DrawBuffer->_Xmin;
          GLstencil stencil[MAX_WIDTH];
          GLint y, i;
          for (i = 0; i < width; i++) {
             stencil[i] = ctx->Stencil.Clear;
          }
          for (y = 0; y < height; y++) {
-            (*ctx->Driver.WriteStencilSpan)(ctx, x, y, width, stencil, NULL);
+            (*ctx->Driver.WriteStencilSpan)(ctx, width, x, y, stencil, NULL);
          }
       }
    }