Merge remote branch 'origin/master' into pipe-video
[mesa.git] / src / mesa / swrast / s_stencil.c
index d0cbdd6917d837bf3b1c0ff88f123f0a1b4ec1a9..5bec71c057ba02384f2f53275e7db3805b66b431 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"
@@ -61,7 +61,7 @@ ENDIF
  * Output:  stencil - modified values
  */
 static void
-apply_stencil_op( const GLcontext *ctx, GLenum oper, GLuint face,
+apply_stencil_op( const struct gl_context *ctx, GLenum oper, GLuint face,
                   GLuint n, GLstencil stencil[], const GLubyte mask[] )
 {
    const GLstencil ref = ctx->Stencil.Ref[face];
@@ -225,14 +225,15 @@ apply_stencil_op( const GLcontext *ctx, GLenum oper, GLuint face,
  * Return:  GL_FALSE = all pixels failed, GL_TRUE = zero or more pixels passed.
  */
 static GLboolean
-do_stencil_test( GLcontext *ctx, GLuint face, GLuint n, GLstencil stencil[],
+do_stencil_test( struct gl_context *ctx, GLuint face, GLuint n, GLstencil stencil[],
                  GLubyte mask[] )
 {
    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);
@@ -423,7 +418,7 @@ compute_pass_fail_masks(GLuint n, const GLubyte origMask[],
  *
  */
 static GLboolean
-stencil_and_ztest_span(GLcontext *ctx, SWspan *span, GLuint face)
+stencil_and_ztest_span(struct gl_context *ctx, SWspan *span, GLuint face)
 {
    struct gl_framebuffer *fb = ctx->DrawBuffer;
    struct gl_renderbuffer *rb = fb->_StencilBuffer;
@@ -480,7 +475,7 @@ stencil_and_ztest_span(GLcontext *ctx, SWspan *span, GLuint face)
       GLubyte passMask[MAX_WIDTH], failMask[MAX_WIDTH], origMask[MAX_WIDTH];
 
       /* save the current mask bits */
-      _mesa_memcpy(origMask, mask, n * sizeof(GLubyte));
+      memcpy(origMask, mask, n * sizeof(GLubyte));
 
       /* apply the depth test */
       _swrast_depth_test_span(ctx, span);
@@ -529,7 +524,7 @@ stencil_and_ztest_span(GLcontext *ctx, SWspan *span, GLuint face)
  *         mask - array [n] of flag:  1=apply operator, 0=don't apply operator
  */
 static void
-apply_stencil_op_to_pixels( GLcontext *ctx,
+apply_stencil_op_to_pixels( struct gl_context *ctx,
                             GLuint n, const GLint x[], const GLint y[],
                             GLenum oper, GLuint face, const GLubyte mask[] )
 {
@@ -703,7 +698,7 @@ apply_stencil_op_to_pixels( GLcontext *ctx,
  * \return  GL_FALSE = all pixels failed, GL_TRUE = zero or more pixels passed.
  */
 static GLboolean
-stencil_test_pixels( GLcontext *ctx, GLuint face, GLuint n,
+stencil_test_pixels( struct gl_context *ctx, GLuint face, GLuint n,
                      const GLint x[], const GLint y[], GLubyte mask[] )
 {
    const struct gl_framebuffer *fb = ctx->DrawBuffer;
@@ -902,7 +897,7 @@ stencil_test_pixels( GLcontext *ctx, GLuint face, GLuint n,
  *         GL_TRUE - one or more fragments passed the testing
  */
 static GLboolean
-stencil_and_ztest_pixels( GLcontext *ctx, SWspan *span, GLuint face )
+stencil_and_ztest_pixels( struct gl_context *ctx, SWspan *span, GLuint face )
 {
    GLubyte passMask[MAX_WIDTH], failMask[MAX_WIDTH], origMask[MAX_WIDTH];
    struct gl_framebuffer *fb = ctx->DrawBuffer;
@@ -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));
 
+      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]; 
+         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,
@@ -964,7 +962,7 @@ stencil_and_ztest_pixels( GLcontext *ctx, SWspan *span, GLuint face )
                                     ctx->Stencil.ZPassFunc[face], face, mask);
       }
       else {
-         _mesa_memcpy(origMask, mask, n * sizeof(GLubyte));
+         memcpy(origMask, mask, n * sizeof(GLubyte));
 
          _swrast_depth_test_span(ctx, span);
 
@@ -992,12 +990,14 @@ stencil_and_ztest_pixels( GLcontext *ctx, SWspan *span, GLuint face )
  * GL_FALSE = all fragments failed.
  */
 GLboolean
-_swrast_stencil_and_ztest_span(GLcontext *ctx, SWspan *span)
+_swrast_stencil_and_ztest_span(struct gl_context *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);
 }
 
 
@@ -1042,7 +1042,7 @@ clip_span(GLuint bufferWidth, GLuint bufferHeight,
  * Output:  stencil - the array of stencil values
  */
 void
-_swrast_read_stencil_span(GLcontext *ctx, struct gl_renderbuffer *rb,
+_swrast_read_stencil_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
                           GLint n, GLint x, GLint y, GLstencil stencil[])
 {
    if (y < 0 || y >= (GLint) rb->Height ||
@@ -1079,7 +1079,7 @@ _swrast_read_stencil_span(GLcontext *ctx, struct gl_renderbuffer *rb,
  *         stencil - the array of stencil values
  */
 void
-_swrast_write_stencil_span(GLcontext *ctx, GLint n, GLint x, GLint y,
+_swrast_write_stencil_span(struct gl_context *ctx, GLint n, GLint x, GLint y,
                            const GLstencil stencil[] )
 {
    struct gl_framebuffer *fb = ctx->DrawBuffer;
@@ -1128,7 +1128,7 @@ _swrast_write_stencil_span(GLcontext *ctx, GLint n, GLint x, GLint y,
  * Clear the stencil buffer.
  */
 void
-_swrast_clear_stencil_buffer( GLcontext *ctx, struct gl_renderbuffer *rb )
+_swrast_clear_stencil_buffer( struct gl_context *ctx, struct gl_renderbuffer *rb )
 {
    const GLubyte stencilBits = ctx->DrawBuffer->Visual.stencilBits;
    const GLuint mask = ctx->Stencil.WriteMask[0];
@@ -1181,7 +1181,7 @@ _swrast_clear_stencil_buffer( GLcontext *ctx, struct gl_renderbuffer *rb )
             /* Note: bottom-to-top raster assumed! */
             GLubyte *stencil = (GLubyte *) rb->GetPointer(ctx, rb, x, y);
             GLuint len = width * height * sizeof(GLubyte);
-            _mesa_memset(stencil, clearVal, len);
+            memset(stencil, clearVal, len);
          }
          else {
             /* general case */
@@ -1189,7 +1189,7 @@ _swrast_clear_stencil_buffer( GLcontext *ctx, struct gl_renderbuffer *rb )
             for (i = 0; i < height; i++) {
                GLvoid *stencil = rb->GetPointer(ctx, rb, x, y + i);
                if (rb->DataType == GL_UNSIGNED_BYTE) {
-                  _mesa_memset(stencil, clearVal, width);
+                  memset(stencil, clearVal, width);
                }
                else {
                   _mesa_memset16((short unsigned int*) stencil, clearVal, width);