r300: Some cleanups in depth and stencil state handling
authorNicolai Haehnle <nhaehnle@gmail.com>
Sat, 7 Jun 2008 19:07:28 +0000 (21:07 +0200)
committerNicolai Haehnle <nhaehnle@gmail.com>
Sat, 7 Jun 2008 19:08:43 +0000 (21:08 +0200)
This also fixes a bug with Zfunc set to GL_NEVER in glean/paths.

src/mesa/drivers/dri/r300/r300_context.h
src/mesa/drivers/dri/r300/r300_ioctl.c
src/mesa/drivers/dri/r300/r300_state.c

index b33dfeafdd6173c8f2d0f8930229a1241d5bbf69..3ac87d173b176ca681999433a1ddcdf31c0afda1 100644 (file)
@@ -574,9 +574,7 @@ struct r300_depthbuffer_state {
 };
 
 struct r300_stencilbuffer_state {
-       GLuint clear;
        GLboolean hw_stencil;
-
 };
 
 /* Vertex shader state */
index fbe69207454c96c1df1f0a77c89fbf585fc4af4c..6af23300f280a3cc16c4bdeca98fc35e9770672a 100644 (file)
@@ -148,7 +148,7 @@ static void r300ClearBuffer(r300ContextPtr r300, int flags, int buffer)
                e32(t1);
                e32(t2);
                e32(((ctx->Stencil.WriteMask[0] & R300_STENCILREF_MASK) << R300_STENCILWRITEMASK_SHIFT) |
-                   (r300->state.stencil.clear & R300_STENCILREF_MASK));
+                   (ctx->Stencil.Clear & R300_STENCILREF_MASK));
        }
 
        cmd2 = (drm_r300_cmd_header_t *) r300AllocCmdBuf(r300, 9, __FUNCTION__);
index 7602f12d814768c0aae0569694cf02ae10243c62..b36ca7aef85d84f0b4d0749f4d48b699b6fc7bc4 100644 (file)
@@ -525,24 +525,15 @@ static void r300SetDepthState(GLcontext * ctx)
        r300ContextPtr r300 = R300_CONTEXT(ctx);
 
        R300_STATECHANGE(r300, zs);
-       r300->hw.zs.cmd[R300_ZS_CNTL_0] &= R300_STENCIL_ENABLE; // XXX
-       r300->hw.zs.cmd[R300_ZS_CNTL_1] &=
-           ~(R300_ZS_MASK << R300_Z_FUNC_SHIFT);
+       r300->hw.zs.cmd[R300_ZS_CNTL_0] &= R300_STENCIL_ENABLE|R300_STENCIL_FRONT_BACK;
+       r300->hw.zs.cmd[R300_ZS_CNTL_1] &= ~(R300_ZS_MASK << R300_Z_FUNC_SHIFT);
 
-       if (ctx->Depth.Test && ctx->Depth.Func != GL_NEVER) {
+       if (ctx->Depth.Test) {
+               r300->hw.zs.cmd[R300_ZS_CNTL_0] |= R300_Z_ENABLE;
                if (ctx->Depth.Mask)
-                       r300->hw.zs.cmd[R300_ZS_CNTL_0] |=
-                           R300_Z_ENABLE | R300_Z_WRITE_ENABLE | R300_STENCIL_FRONT_BACK; // XXX
-               else
-                   r300->hw.zs.cmd[R300_ZS_CNTL_0] |= R300_Z_ENABLE | R300_STENCIL_FRONT_BACK; // XXX
-
+                       r300->hw.zs.cmd[R300_ZS_CNTL_0] |= R300_Z_WRITE_ENABLE;
                r300->hw.zs.cmd[R300_ZS_CNTL_1] |=
-                   translate_func(ctx->Depth.
-                                  Func) << R300_Z_FUNC_SHIFT;
-       } else {
-           r300->hw.zs.cmd[R300_ZS_CNTL_0] |= R300_STENCIL_FRONT_BACK; // XXX
-               r300->hw.zs.cmd[R300_ZS_CNTL_1] |=
-                   translate_func(GL_NEVER) << R300_Z_FUNC_SHIFT;
+                   translate_func(ctx->Depth.Func) << R300_Z_FUNC_SHIFT;
        }
 
        r300SetEarlyZState(ctx);
@@ -925,7 +916,7 @@ static void r300StencilFuncSeparate(GLcontext * ctx, GLenum face,
        GLuint flag;
 
        R300_STATECHANGE(rmesa, zs);
-
+       rmesa->hw.zs.cmd[R300_ZS_CNTL_0] |= R300_STENCIL_FRONT_BACK;
        rmesa->hw.zs.cmd[R300_ZS_CNTL_1] &= ~((R300_ZS_MASK <<
                                               R300_S_FRONT_FUNC_SHIFT)
                                              | (R300_ZS_MASK <<
@@ -1000,17 +991,6 @@ static void r300StencilOpSeparate(GLcontext * ctx, GLenum face,
        }
 }
 
-static void r300ClearStencil(GLcontext * ctx, GLint s)
-{
-       r300ContextPtr rmesa = R300_CONTEXT(ctx);
-
-       rmesa->state.stencil.clear =
-           ((GLuint) (ctx->Stencil.Clear & R300_STENCILREF_MASK) |
-            (R300_STENCILREF_MASK << R300_STENCILMASK_SHIFT) |
-            ((ctx->Stencil.WriteMask[0] & R300_STENCILREF_MASK) <<
-               R300_STENCILMASK_SHIFT));
-}
-
 /* =============================================================
  * Window position and viewport transformation
  */
@@ -2637,12 +2617,10 @@ void r300InitState(r300ContextPtr r300)
        case 16:
                r300->state.depth.scale = 1.0 / (GLfloat) 0xffff;
                depth_fmt = R300_DEPTHFORMAT_16BIT_INT_Z;
-               r300->state.stencil.clear = 0x00000000;
                break;
        case 24:
                r300->state.depth.scale = 1.0 / (GLfloat) 0xffffff;
                depth_fmt = R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL;
-               r300->state.stencil.clear = 0x00ff0000;
                break;
        default:
                fprintf(stderr, "Error: Unsupported depth %d... exiting\n",
@@ -2706,7 +2684,6 @@ void r300InitStateFuncs(struct dd_function_table *functions)
        functions->ShadeModel = r300ShadeModel;
 
        /* Stencil related */
-       functions->ClearStencil = r300ClearStencil;
        functions->StencilFuncSeparate = r300StencilFuncSeparate;
        functions->StencilMaskSeparate = r300StencilMaskSeparate;
        functions->StencilOpSeparate = r300StencilOpSeparate;