mesa: replace _mesa_update_stencil() with helper functions
[mesa.git] / src / mesa / main / stencil.c
index 746775d2db6a810e6621a27393e5be67764e34cd..612ad38dcc1472ea2862b008fffed0e919ad56df 100644 (file)
@@ -184,20 +184,11 @@ _mesa_StencilFuncSeparateATI( GLenum frontfunc, GLenum backfunc, GLint ref, GLui
  * __struct gl_contextRec::Stencil. On change flushes the vertices and notifies
  * the driver via the dd_function_table::StencilFunc callback.
  */
-void GLAPIENTRY
-_mesa_StencilFunc( GLenum func, GLint ref, GLuint mask )
+static void
+stencil_func(struct gl_context *ctx, GLenum func, GLint ref, GLuint mask)
 {
-   GET_CURRENT_CONTEXT(ctx);
    const GLint face = ctx->Stencil.ActiveFace;
 
-   if (MESA_VERBOSE & VERBOSE_API)
-      _mesa_debug(ctx, "glStencilFunc()\n");
-
-   if (!validate_stencil_func(ctx, func)) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFunc(func)");
-      return;
-   }
-
    if (face != 0) {
       if (ctx->Stencil.Function[face] == func &&
           ctx->Stencil.ValueMask[face] == mask &&
@@ -238,6 +229,31 @@ _mesa_StencilFunc( GLenum func, GLint ref, GLuint mask )
 }
 
 
+void GLAPIENTRY
+_mesa_StencilFunc_no_error(GLenum func, GLint ref, GLuint mask)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   stencil_func(ctx, func, ref, mask);
+}
+
+
+void GLAPIENTRY
+_mesa_StencilFunc(GLenum func, GLint ref, GLuint mask)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glStencilFunc()\n");
+
+   if (!validate_stencil_func(ctx, func)) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFunc(func)");
+      return;
+   }
+
+   stencil_func(ctx, func, ref, mask);
+}
+
+
 /**
  * Set the stencil writing mask.
  *
@@ -304,28 +320,11 @@ _mesa_StencilMask( GLuint mask )
  * __struct gl_contextRec::Stencil. On change flushes the vertices and notifies
  * the driver via the dd_function_table::StencilOp callback.
  */
-void GLAPIENTRY
-_mesa_StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
+static void
+stencil_op(struct gl_context *ctx, GLenum fail, GLenum zfail, GLenum zpass)
 {
-   GET_CURRENT_CONTEXT(ctx);
    const GLint face = ctx->Stencil.ActiveFace;
 
-   if (MESA_VERBOSE & VERBOSE_API)
-      _mesa_debug(ctx, "glStencilOp()\n");
-
-   if (!validate_stencil_op(ctx, fail)) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(sfail)");
-      return;
-   }
-   if (!validate_stencil_op(ctx, zfail)) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(zfail)");
-      return;
-   }
-   if (!validate_stencil_op(ctx, zpass)) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(zpass)");
-      return;
-   }
-
    if (face != 0) {
       /* only set active face state */
       if (ctx->Stencil.ZFailFunc[face] == zfail &&
@@ -367,6 +366,40 @@ _mesa_StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
 }
 
 
+void GLAPIENTRY
+_mesa_StencilOp_no_error(GLenum fail, GLenum zfail, GLenum zpass)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   stencil_op(ctx, fail, zfail, zpass);
+}
+
+
+void GLAPIENTRY
+_mesa_StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glStencilOp()\n");
+
+   if (!validate_stencil_op(ctx, fail)) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(sfail)");
+      return;
+   }
+
+   if (!validate_stencil_op(ctx, zfail)) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(zfail)");
+      return;
+   }
+
+   if (!validate_stencil_op(ctx, zpass)) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(zpass)");
+      return;
+   }
+
+   stencil_op(ctx, fail, zfail, zpass);
+}
+
 
 /* GL_EXT_stencil_two_side */
 void GLAPIENTRY
@@ -391,32 +424,11 @@ _mesa_ActiveStencilFaceEXT(GLenum face)
 }
 
 
-
-void GLAPIENTRY
-_mesa_StencilOpSeparate(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass)
+static void
+stencil_op_separate(struct gl_context *ctx, GLenum face, GLenum sfail,
+                    GLenum zfail, GLenum zpass)
 {
    GLboolean set = GL_FALSE;
-   GET_CURRENT_CONTEXT(ctx);
-
-   if (MESA_VERBOSE & VERBOSE_API)
-      _mesa_debug(ctx, "glStencilOpSeparate()\n");
-
-   if (!validate_stencil_op(ctx, sfail)) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(sfail)");
-      return;
-   }
-   if (!validate_stencil_op(ctx, zfail)) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(zfail)");
-      return;
-   }
-   if (!validate_stencil_op(ctx, zpass)) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(zpass)");
-      return;
-   }
-   if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(face)");
-      return;
-   }
 
    if (face != GL_BACK) {
       /* set front */
@@ -430,6 +442,7 @@ _mesa_StencilOpSeparate(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass)
          set = GL_TRUE;
       }
    }
+
    if (face != GL_FRONT) {
       /* set back */
       if (ctx->Stencil.ZFailFunc[1] != zfail ||
@@ -442,12 +455,54 @@ _mesa_StencilOpSeparate(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass)
          set = GL_TRUE;
       }
    }
+
    if (set && ctx->Driver.StencilOpSeparate) {
       ctx->Driver.StencilOpSeparate(ctx, face, sfail, zfail, zpass);
    }
 }
 
 
+void GLAPIENTRY
+_mesa_StencilOpSeparate_no_error(GLenum face, GLenum sfail, GLenum zfail,
+                                 GLenum zpass)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   stencil_op_separate(ctx, face, sfail, zfail, zpass);
+}
+
+
+void GLAPIENTRY
+_mesa_StencilOpSeparate(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glStencilOpSeparate()\n");
+
+   if (!validate_stencil_op(ctx, sfail)) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(sfail)");
+      return;
+   }
+
+   if (!validate_stencil_op(ctx, zfail)) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(zfail)");
+      return;
+   }
+
+   if (!validate_stencil_op(ctx, zpass)) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(zpass)");
+      return;
+   }
+
+   if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(face)");
+      return;
+   }
+
+   stencil_op_separate(ctx, face, sfail, zfail, zpass);
+}
+
+
 static void
 stencil_func_separate(struct gl_context *ctx, GLenum face, GLenum func,
                       GLint ref, GLuint mask)
@@ -551,34 +606,6 @@ _mesa_StencilMaskSeparate(GLenum face, GLuint mask)
 }
 
 
-/**
- * Update derived stencil state.
- */
-void
-_mesa_update_stencil(struct gl_context *ctx)
-{
-   const GLint face = ctx->Stencil._BackFace;
-
-   ctx->Stencil._Enabled = (ctx->Stencil.Enabled &&
-                            ctx->DrawBuffer->Visual.stencilBits > 0);
-
-    ctx->Stencil._TestTwoSide =
-       ctx->Stencil._Enabled &&
-       (ctx->Stencil.Function[0] != ctx->Stencil.Function[face] ||
-       ctx->Stencil.FailFunc[0] != ctx->Stencil.FailFunc[face] ||
-       ctx->Stencil.ZPassFunc[0] != ctx->Stencil.ZPassFunc[face] ||
-       ctx->Stencil.ZFailFunc[0] != ctx->Stencil.ZFailFunc[face] ||
-       ctx->Stencil.Ref[0] != ctx->Stencil.Ref[face] ||
-       ctx->Stencil.ValueMask[0] != ctx->Stencil.ValueMask[face] ||
-       ctx->Stencil.WriteMask[0] != ctx->Stencil.WriteMask[face]);
-
-   ctx->Stencil._WriteEnabled =
-      ctx->Stencil._Enabled &&
-      (ctx->Stencil.WriteMask[0] != 0 ||
-       (ctx->Stencil._TestTwoSide && ctx->Stencil.WriteMask[face] != 0));
-}
-
-
 /**
  * Initialize the context stipple state.
  *