Merge branch 'mesa_7_5_branch' into mesa_7_6_branch
[mesa.git] / src / mesa / swrast / s_stencil.c
index d0cbdd6917d837bf3b1c0ff88f123f0a1b4ec1a9..e9e9d3a4f10eccb88e63d19008d4356b42eb8acb 100644 (file)
@@ -23,9 +23,9 @@
  */
 
 
-#include "glheader.h"
-#include "context.h"
-#include "imports.h"
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/imports.h"
 
 #include "s_context.h"
 #include "s_depth.h"
@@ -231,8 +231,9 @@ do_stencil_test( GLcontext *ctx, GLuint face, GLuint n, GLstencil stencil[],
    GLubyte fail[MAX_WIDTH];
    GLboolean allfail = GL_FALSE;
    GLuint i;
-   GLstencil r, s;
    const GLuint valueMask = ctx->Stencil.ValueMask[face];
+   const GLstencil r = (GLstencil) (ctx->Stencil.Ref[face] & valueMask);
+   GLstencil s;
 
    ASSERT(n <= MAX_WIDTH);
 
@@ -260,7 +261,6 @@ do_stencil_test( GLcontext *ctx, GLuint face, GLuint n, GLstencil stencil[],
         allfail = GL_TRUE;
         break;
       case GL_LESS:
-        r = (GLstencil) (ctx->Stencil.Ref[face] & valueMask);
         for (i=0;i<n;i++) {
            if (mask[i]) {
               s = (GLstencil) (stencil[i] & valueMask);
@@ -279,7 +279,6 @@ do_stencil_test( GLcontext *ctx, GLuint face, GLuint n, GLstencil stencil[],
         }
         break;
       case GL_LEQUAL:
-        r = (GLstencil) (ctx->Stencil.Ref[face] & valueMask);
         for (i=0;i<n;i++) {
            if (mask[i]) {
               s = (GLstencil) (stencil[i] & valueMask);
@@ -298,7 +297,6 @@ do_stencil_test( GLcontext *ctx, GLuint face, GLuint n, GLstencil stencil[],
         }
         break;
       case GL_GREATER:
-        r = (GLstencil) (ctx->Stencil.Ref[face] & valueMask);
         for (i=0;i<n;i++) {
            if (mask[i]) {
               s = (GLstencil) (stencil[i] & valueMask);
@@ -317,7 +315,6 @@ do_stencil_test( GLcontext *ctx, GLuint face, GLuint n, GLstencil stencil[],
         }
         break;
       case GL_GEQUAL:
-        r = (GLstencil) (ctx->Stencil.Ref[face] & valueMask);
         for (i=0;i<n;i++) {
            if (mask[i]) {
               s = (GLstencil) (stencil[i] & valueMask);
@@ -336,7 +333,6 @@ do_stencil_test( GLcontext *ctx, GLuint face, GLuint n, GLstencil stencil[],
         }
         break;
       case GL_EQUAL:
-        r = (GLstencil) (ctx->Stencil.Ref[face] & valueMask);
         for (i=0;i<n;i++) {
            if (mask[i]) {
               s = (GLstencil) (stencil[i] & valueMask);
@@ -355,7 +351,6 @@ do_stencil_test( GLcontext *ctx, GLuint face, GLuint n, GLstencil stencil[],
         }
         break;
       case GL_NOTEQUAL:
-        r = (GLstencil) (ctx->Stencil.Ref[face] & valueMask);
         for (i=0;i<n;i++) {
            if (mask[i]) {
               s = (GLstencil) (stencil[i] & valueMask);
@@ -923,6 +918,8 @@ stencil_and_ztest_pixels( GLcontext *ctx, SWspan *span, GLuint face )
       ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
       _swrast_get_values(ctx, rb, n, x, y, stencil, sizeof(GLubyte));
 
+      _mesa_memcpy(origMask, mask, n * sizeof(GLubyte));          
+
       (void) do_stencil_test(ctx, face, n, stencil, mask);
 
       if (ctx->Depth.Test == GL_FALSE) {
@@ -930,11 +927,12 @@ stencil_and_ztest_pixels( GLcontext *ctx, SWspan *span, GLuint face )
                           n, stencil, mask);
       }
       else {
-         _mesa_memcpy(origMask, mask, n * sizeof(GLubyte));
+         GLubyte tmpMask[MAX_WIDTH]; 
+         _mesa_memcpy(tmpMask, mask, n * sizeof(GLubyte));
 
          _swrast_depth_test_span(ctx, span);
 
-         compute_pass_fail_masks(n, origMask, mask, passMask, failMask);
+         compute_pass_fail_masks(n, tmpMask, mask, passMask, failMask);
 
          if (ctx->Stencil.ZFailFunc[face] != GL_KEEP) {
             apply_stencil_op(ctx, ctx->Stencil.ZFailFunc[face], face,
@@ -994,10 +992,12 @@ stencil_and_ztest_pixels( GLcontext *ctx, SWspan *span, GLuint face )
 GLboolean
 _swrast_stencil_and_ztest_span(GLcontext *ctx, SWspan *span)
 {
+   const GLuint face = (span->facing == 0) ? 0 : ctx->Stencil._BackFace;
+
    if (span->arrayMask & SPAN_XY)
-      return stencil_and_ztest_pixels(ctx, span, span->facing);
+      return stencil_and_ztest_pixels(ctx, span, face);
    else
-      return stencil_and_ztest_span(ctx, span, span->facing);
+      return stencil_and_ztest_span(ctx, span, face);
 }