support as much of GL_EXT_stencil_two_side as we can. untested.
authorAapo Tahkola <aet@rasterburn.org>
Thu, 18 Jan 2007 03:56:13 +0000 (05:56 +0200)
committerAapo Tahkola <aet@rasterburn.org>
Thu, 18 Jan 2007 03:56:13 +0000 (05:56 +0200)
src/mesa/drivers/dri/r300/r300_context.c
src/mesa/drivers/dri/r300/r300_render.c
src/mesa/drivers/dri/r300/r300_state.c
src/mesa/drivers/dri/radeon/radeon_screen.c

index 54eb081d055ed5239f27a1c6334e8e5d3ce1b02d..71402761ae50f0e713881c43c68f49e91a7577bf 100644 (file)
@@ -73,6 +73,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 int future_hw_tcl_on=1;
 int hw_tcl_on=1;
 
+#define need_GL_EXT_stencil_two_side
 #define need_GL_ARB_multisample
 #define need_GL_ARB_texture_compression
 #define need_GL_ARB_vertex_buffer_object
@@ -126,6 +127,10 @@ const struct dri_extension card_extensions[] = {
   {NULL,                               NULL}
 };
 
+const struct dri_extension stencil_two_side[] = {
+  {"GL_EXT_stencil_two_side",          GL_EXT_stencil_two_side_functions},
+};
+
 extern struct tnl_pipeline_stage _r300_render_stage;
 extern const struct tnl_pipeline_stage _r300_tcl_stage;
 extern const struct tnl_pipeline_stage _r300_texrect_stage;
@@ -331,6 +336,9 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
 
        driInitExtensions(ctx, card_extensions, GL_TRUE);
        
+       if (driQueryOptionb(&r300->radeon.optionCache, "disable_stencil_two_side") == 0)
+               driInitSingleExtension(ctx, stencil_two_side);
+       
        if (r300->radeon.glCtx->Mesa_DXTn && !driQueryOptionb (&r300->radeon.optionCache, "disable_s3tc")) {
          _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
          _mesa_enable_extension( ctx, "GL_S3_s3tc" );
index 03f168365dc7b7f94c972802239d7d11a49ac550..91305cb5a22352137e8ddf0fd93c364eaa219af9 100644 (file)
@@ -406,6 +406,10 @@ int r300Fallback(GLcontext *ctx)
         */
        FALLBACK_IF(ctx->Fog.Enabled);
 #endif
+       FALLBACK_IF(ctx->Stencil._TestTwoSide &&
+                   (ctx->Stencil.Ref[0] != ctx->Stencil.Ref[1] ||
+                    ctx->Stencil.ValueMask[0] != ctx->Stencil.ValueMask[1] ||
+                    ctx->Stencil.WriteMask[0] != ctx->Stencil.WriteMask[1]));
 
        if(!r300->disable_lowimpact_fallback){
                /* GL_POLYGON_OFFSET_POINT */
index 72255066d5977d6ec64c22c36c747050354aedd3..6a22ccad2fd788da6e99a1722ce0bb90460e3815 100644 (file)
@@ -509,7 +509,6 @@ static void r300Enable(GLcontext* ctx, GLenum cap, GLboolean state)
                if (r300->state.stencil.hw_stencil) {
                        R300_STATECHANGE(r300, zs);
                        if (state) {
-                               WARN_ONCE("TODO - double side stencil !\n");
                                r300->hw.zs.cmd[R300_ZS_CNTL_0] |=
                                    R300_RB3D_STENCIL_ENABLE;
                        } else {
@@ -863,9 +862,12 @@ static void r300StencilFuncSeparate(GLcontext * ctx, GLenum face,
                                                (R300_RB3D_ZS2_STENCIL_MASK << R300_RB3D_ZS2_STENCIL_MASK_SHIFT));
        
        flag = translate_func(ctx->Stencil.Function[0]);
-
-       rmesa->hw.zs.cmd[R300_ZS_CNTL_1] |= (flag << R300_RB3D_ZS1_FRONT_FUNC_SHIFT)
-                                         | (flag << R300_RB3D_ZS1_BACK_FUNC_SHIFT);
+       rmesa->hw.zs.cmd[R300_ZS_CNTL_1] |= (flag << R300_RB3D_ZS1_FRONT_FUNC_SHIFT);
+       
+       if (ctx->Stencil._TestTwoSide)
+               flag = translate_func(ctx->Stencil.Function[1]);
+       
+       rmesa->hw.zs.cmd[R300_ZS_CNTL_1] |= (flag << R300_RB3D_ZS1_BACK_FUNC_SHIFT);
        rmesa->hw.zs.cmd[R300_ZS_CNTL_2] |= refmask;
 }
 
@@ -894,10 +896,19 @@ static void r300StencilOpSeparate(GLcontext * ctx, GLenum face, GLenum fail,
        rmesa->hw.zs.cmd[R300_ZS_CNTL_1] |=
                 (translate_stencil_op(ctx->Stencil.FailFunc[0]) << R300_RB3D_ZS1_FRONT_FAIL_OP_SHIFT)
                |(translate_stencil_op(ctx->Stencil.ZFailFunc[0]) << R300_RB3D_ZS1_FRONT_ZFAIL_OP_SHIFT)
-               |(translate_stencil_op(ctx->Stencil.ZPassFunc[0]) << R300_RB3D_ZS1_FRONT_ZPASS_OP_SHIFT)
-               |(translate_stencil_op(ctx->Stencil.FailFunc[0]) << R300_RB3D_ZS1_BACK_FAIL_OP_SHIFT)
-               |(translate_stencil_op(ctx->Stencil.ZFailFunc[0]) << R300_RB3D_ZS1_BACK_ZFAIL_OP_SHIFT)
-               |(translate_stencil_op(ctx->Stencil.ZPassFunc[0]) << R300_RB3D_ZS1_BACK_ZPASS_OP_SHIFT);
+               |(translate_stencil_op(ctx->Stencil.ZPassFunc[0]) << R300_RB3D_ZS1_FRONT_ZPASS_OP_SHIFT);
+       
+       if (ctx->Stencil._TestTwoSide) {
+               rmesa->hw.zs.cmd[R300_ZS_CNTL_1] |=
+                        (translate_stencil_op(ctx->Stencil.FailFunc[1]) << R300_RB3D_ZS1_BACK_FAIL_OP_SHIFT)
+                       |(translate_stencil_op(ctx->Stencil.ZFailFunc[1]) << R300_RB3D_ZS1_BACK_ZFAIL_OP_SHIFT)
+                       |(translate_stencil_op(ctx->Stencil.ZPassFunc[1]) << R300_RB3D_ZS1_BACK_ZPASS_OP_SHIFT);
+       } else {
+               rmesa->hw.zs.cmd[R300_ZS_CNTL_1] |=
+                        (translate_stencil_op(ctx->Stencil.FailFunc[0]) << R300_RB3D_ZS1_BACK_FAIL_OP_SHIFT)
+                       |(translate_stencil_op(ctx->Stencil.ZFailFunc[0]) << R300_RB3D_ZS1_BACK_ZFAIL_OP_SHIFT)
+                       |(translate_stencil_op(ctx->Stencil.ZPassFunc[0]) << R300_RB3D_ZS1_BACK_ZPASS_OP_SHIFT);
+       }
 }
 
 static void r300ClearStencil(GLcontext * ctx, GLint s)
index 279357ab5902a882769d00fa8bdec50b6dd0a125..cee1f7e2f9365bf19f52611c936f8f0ca0fc1b6e 100644 (file)
@@ -163,6 +163,11 @@ DRI_CONF_OPT_BEGIN(disable_lowimpact_fallback,bool,def) \
         DRI_CONF_DESC(en,"Disable Low-impact fallback") \
 DRI_CONF_OPT_END
 
+#define DRI_CONF_DISABLE_DOUBLE_SIDE_STENCIL(def) \
+DRI_CONF_OPT_BEGIN(disable_stencil_two_side,bool,def) \
+        DRI_CONF_DESC(en,"Disable GL_EXT_stencil_two_side") \
+DRI_CONF_OPT_END
+
 
 const char __driConfigOptions[] =
 DRI_CONF_BEGIN
@@ -174,6 +179,7 @@ DRI_CONF_BEGIN
                DRI_CONF_MAX_TEXTURE_COORD_UNITS(8, 2, 8)
                DRI_CONF_COMMAND_BUFFER_SIZE(8, 8, 32)
                DRI_CONF_DISABLE_FALLBACK(false)
+               DRI_CONF_DISABLE_DOUBLE_SIDE_STENCIL(false)
        DRI_CONF_SECTION_END
        DRI_CONF_SECTION_QUALITY
                DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB)
@@ -189,7 +195,7 @@ DRI_CONF_BEGIN
                DRI_CONF_NO_RAST(false)
        DRI_CONF_SECTION_END
 DRI_CONF_END;
-static const GLuint __driNConfigOptions = 16;
+static const GLuint __driNConfigOptions = 17;
 
 #ifndef RADEON_DEBUG
 int RADEON_DEBUG = 0;