Merge branch 'master' of git+ssh://keithw@git.freedesktop.org/git/mesa/mesa into...
[mesa.git] / src / mesa / main / stencil.c
index 6b4d7e81eb8b8e25f642c40eb8e8608df98c922a..e61eb0030c0619d66b491b69df699e061dbac5f4 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5
+ * Version:  6.5.2
  *
- * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2006  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"),
  *
  * So either we advertise the GL_EXT_stencil_two_side extension, or OpenGL
  * 2.0, but not both.
+ *
+ * Also, note that GL_ATI_separate_stencil is different as well:
+ * glStencilFuncSeparateATI(GLenum frontfunc, GLenum backfunc, ...)  vs.
+ * glStencilFuncSeparate(GLenum face, GLenum func, ...).
  */
 
 
@@ -109,29 +113,13 @@ _mesa_StencilFunc( GLenum func, GLint ref, GLuint mask )
       case GL_ALWAYS:
          break;
       default:
-         _mesa_error( ctx, GL_INVALID_ENUM, "glStencilFunc" );
+         _mesa_error( ctx, GL_INVALID_ENUM, "glStencilFunc (0x%04x)", func );
          return;
    }
 
    ref = CLAMP( ref, 0, stencilMax );
 
-   if (ctx->Extensions.EXT_stencil_two_side) {
-      /* only set active face state */
-      const GLint face = ctx->Stencil.ActiveFace;
-      if (ctx->Stencil.Function[face] == func &&
-          ctx->Stencil.ValueMask[face] == mask &&
-          ctx->Stencil.Ref[face] == ref)
-         return;
-      FLUSH_VERTICES(ctx, _NEW_STENCIL);
-      ctx->Stencil.Function[face] = func;
-      ctx->Stencil.Ref[face] = ref;
-      ctx->Stencil.ValueMask[face] = mask;
-      if (ctx->Driver.StencilFuncSeparate) {
-         ctx->Driver.StencilFuncSeparate(ctx, face ? GL_BACK : GL_FRONT,
-                                         func, ref, mask);
-      }
-   }
-   else {
+   if (ctx->Extensions.ATI_separate_stencil) {
       /* set both front and back state */
       if (ctx->Stencil.Function[0] == func &&
           ctx->Stencil.Function[1] == func &&
@@ -149,6 +137,22 @@ _mesa_StencilFunc( GLenum func, GLint ref, GLuint mask )
                                          func, ref, mask);
       }
    }
+   else {
+      /* only set active face state */
+      const GLint face = ctx->Stencil.ActiveFace;
+      if (ctx->Stencil.Function[face] == func &&
+          ctx->Stencil.ValueMask[face] == mask &&
+          ctx->Stencil.Ref[face] == ref)
+         return;
+      FLUSH_VERTICES(ctx, _NEW_STENCIL);
+      ctx->Stencil.Function[face] = func;
+      ctx->Stencil.Ref[face] = ref;
+      ctx->Stencil.ValueMask[face] = mask;
+      if (ctx->Driver.StencilFuncSeparate) {
+         ctx->Driver.StencilFuncSeparate(ctx, face ? GL_BACK : GL_FRONT,
+                                         func, ref, mask);
+      }
+   }
 }
 
 
@@ -169,26 +173,26 @@ _mesa_StencilMask( GLuint mask )
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (ctx->Extensions.EXT_stencil_two_side) {
-      /* only set active face state */
-      const GLint face = ctx->Stencil.ActiveFace;
-      if (ctx->Stencil.WriteMask[face] == mask)
+   if (ctx->Extensions.ATI_separate_stencil) {
+      /* set both front and back state */
+      if (ctx->Stencil.WriteMask[0] == mask &&
+          ctx->Stencil.WriteMask[1] == mask)
          return;
       FLUSH_VERTICES(ctx, _NEW_STENCIL);
-      ctx->Stencil.WriteMask[face] = mask;
+      ctx->Stencil.WriteMask[0] = ctx->Stencil.WriteMask[1] = mask;
       if (ctx->Driver.StencilMaskSeparate) {
-         ctx->Driver.StencilMaskSeparate(ctx, face ? GL_BACK : GL_FRONT, mask);
+         ctx->Driver.StencilMaskSeparate(ctx, GL_FRONT_AND_BACK, mask);
       }
    }
    else {
-      /* set both front and back state */
-      if (ctx->Stencil.WriteMask[0] == mask &&
-          ctx->Stencil.WriteMask[1] == mask)
+      /* only set active face state */
+      const GLint face = ctx->Stencil.ActiveFace;
+      if (ctx->Stencil.WriteMask[face] == mask)
          return;
       FLUSH_VERTICES(ctx, _NEW_STENCIL);
-      ctx->Stencil.WriteMask[0] = ctx->Stencil.WriteMask[1] = mask;
+      ctx->Stencil.WriteMask[face] = mask;
       if (ctx->Driver.StencilMaskSeparate) {
-         ctx->Driver.StencilMaskSeparate(ctx, GL_FRONT_AND_BACK, mask);
+         ctx->Driver.StencilMaskSeparate(ctx, face ? GL_BACK : GL_FRONT, mask);
       }
    }
 }
@@ -269,23 +273,7 @@ _mesa_StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
          return;
    }
 
-   if (ctx->Extensions.EXT_stencil_two_side) {
-      /* only set active face state */
-      const GLint face = ctx->Stencil.ActiveFace;
-      if (ctx->Stencil.ZFailFunc[face] == zfail &&
-          ctx->Stencil.ZPassFunc[face] == zpass &&
-          ctx->Stencil.FailFunc[face] == fail)
-         return;
-      FLUSH_VERTICES(ctx, _NEW_STENCIL);
-      ctx->Stencil.ZFailFunc[face] = zfail;
-      ctx->Stencil.ZPassFunc[face] = zpass;
-      ctx->Stencil.FailFunc[face] = fail;
-      if (ctx->Driver.StencilOpSeparate) {
-         ctx->Driver.StencilOpSeparate(ctx, face ? GL_BACK : GL_FRONT,
-                                       fail, zfail, zpass);
-      }
-   }
-   else {
+   if (ctx->Extensions.ATI_separate_stencil) {
       /* set both front and back state */
       if (ctx->Stencil.ZFailFunc[0] == zfail &&
           ctx->Stencil.ZFailFunc[1] == zfail &&
@@ -303,6 +291,22 @@ _mesa_StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
                                        fail, zfail, zpass);
       }
    }
+   else {
+      /* only set active face state */
+      const GLint face = ctx->Stencil.ActiveFace;
+      if (ctx->Stencil.ZFailFunc[face] == zfail &&
+          ctx->Stencil.ZPassFunc[face] == zpass &&
+          ctx->Stencil.FailFunc[face] == fail)
+         return;
+      FLUSH_VERTICES(ctx, _NEW_STENCIL);
+      ctx->Stencil.ZFailFunc[face] = zfail;
+      ctx->Stencil.ZPassFunc[face] = zpass;
+      ctx->Stencil.FailFunc[face] = fail;
+      if (ctx->Driver.StencilOpSeparate) {
+         ctx->Driver.StencilOpSeparate(ctx, face ? GL_BACK : GL_FRONT,
+                                       fail, zfail, zpass);
+      }
+   }
 }
 
 
@@ -406,17 +410,16 @@ _mesa_StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
 
    FLUSH_VERTICES(ctx, _NEW_STENCIL);
 
-   if (face == GL_FRONT || face == GL_FRONT_AND_BACK) {
+   if (face != GL_BACK) {
       ctx->Stencil.FailFunc[0] = fail;
       ctx->Stencil.ZFailFunc[0] = zfail;
       ctx->Stencil.ZPassFunc[0] = zpass;
    }
-   if (face == GL_BACK || face == GL_FRONT_AND_BACK) {
+   if (face != GL_FRONT) {
       ctx->Stencil.FailFunc[1] = fail;
       ctx->Stencil.ZFailFunc[1] = zfail;
       ctx->Stencil.ZPassFunc[1] = zpass;
    }
-
    if (ctx->Driver.StencilOpSeparate) {
       ctx->Driver.StencilOpSeparate(ctx, face, fail, zfail, zpass);
    }
@@ -465,7 +468,6 @@ _mesa_StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
       ctx->Stencil.Ref[1] = ref;
       ctx->Stencil.ValueMask[1] = mask;
    }
-
    if (ctx->Driver.StencilFuncSeparate) {
       ctx->Driver.StencilFuncSeparate(ctx, face, func, ref, mask);
    }
@@ -486,13 +488,12 @@ _mesa_StencilMaskSeparate(GLenum face, GLuint mask)
 
    FLUSH_VERTICES(ctx, _NEW_STENCIL);
 
-   if (face == GL_FRONT || face == GL_FRONT_AND_BACK) {
+   if (face != GL_BACK) {
       ctx->Stencil.WriteMask[0] = mask;
    }
-   if (face == GL_BACK || face == GL_FRONT_AND_BACK) {
+   if (face != GL_FRONT) {
       ctx->Stencil.WriteMask[1] = mask;
    }
-
    if (ctx->Driver.StencilMaskSeparate) {
       ctx->Driver.StencilMaskSeparate(ctx, face, mask);
    }