Fix typo
[mesa.git] / src / mesa / swrast / s_stencil.c
index aed107ca003bba31fcabf05cf61ed701c7691008..a69bd3c96c4c5e05fc14b7e5db857a575d4a55fc 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: s_stencil.c,v 1.3 2000/11/13 20:02:57 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,7 +1130,7 @@ _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;
    }
@@ -1228,11 +1228,11 @@ clear_hardware_stencil_buffer( GLcontext *ctx )
             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 {
@@ -1243,7 +1243,7 @@ clear_hardware_stencil_buffer( GLcontext *ctx )
             stencil[i] = ctx->Stencil.Clear;
          }
          for (y = ctx->DrawBuffer->_Ymin; y < ctx->DrawBuffer->_Ymax; y++) {
-            (*ctx->Driver.WriteStencilSpan)(ctx, x, y, width, stencil, NULL);
+            (*ctx->Driver.WriteStencilSpan)(ctx, width, x, y, stencil, NULL);
          }
       }
    }
@@ -1261,11 +1261,11 @@ clear_hardware_stencil_buffer( GLcontext *ctx )
          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 {
@@ -1279,7 +1279,7 @@ clear_hardware_stencil_buffer( GLcontext *ctx )
             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);
          }
       }
    }