r600: add alpha test support
authorAlex Deucher <alexdeucher@gmail.com>
Tue, 21 Jul 2009 05:58:05 +0000 (01:58 -0400)
committerAlex Deucher <alexdeucher@gmail.com>
Tue, 21 Jul 2009 14:53:20 +0000 (10:53 -0400)
src/mesa/drivers/dri/r600/r700_chip.c
src/mesa/drivers/dri/r600/r700_chip.h
src/mesa/drivers/dri/r600/r700_state.c

index 91aa8fc8fc65b05aab80a46df7f60b38e93755e8..635dd58e72c9e8241447c84314a55dc52d395030 100644 (file)
@@ -139,6 +139,7 @@ GLboolean r700InitChipObject(context_t *context)
     // SX
     LINK_STATES(SX_MISC);
     LINK_STATES(SX_ALPHA_TEST_CONTROL);
+    LINK_STATES(SX_ALPHA_REF);
 
     // VGT
     LINK_STATES(VGT_MAX_VTX_INDX);
index 04af4bc3b98c908e7ffe4bf1712af4f689f1e76f..fa419aa49957d0081abfd866efdee255afccbd96 100644 (file)
@@ -372,6 +372,7 @@ typedef struct _R700_CHIP_CONTEXT
        // SX
        union UINT_FLOAT                SX_MISC                   ;  /* 0xA0D4 */
        union UINT_FLOAT                SX_ALPHA_TEST_CONTROL     ;  /* 0xA104 */
+       union UINT_FLOAT                SX_ALPHA_REF              ;  /* 0xA10E */
 
        // VGT
        union UINT_FLOAT                VGT_MAX_VTX_INDX          ;  /* 0xA100 */
@@ -422,7 +423,7 @@ typedef struct _R700_CHIP_CONTEXT
        union UINT_FLOAT                SPI_FOG_FUNC_SCALE        ;  /* 0xA1B8 */
        union UINT_FLOAT                SPI_FOG_FUNC_BIAS         ;  /* 0xA1B9 */
 
-    union UINT_FLOAT           SQ_VTX_SEMANTIC_0         ;  /* 0xA0E0 */
+       union UINT_FLOAT                SQ_VTX_SEMANTIC_0         ;  /* 0xA0E0 */
        union UINT_FLOAT                SQ_VTX_SEMANTIC_1         ;  /* 0xA0E1 */
        union UINT_FLOAT                SQ_VTX_SEMANTIC_2         ;  /* 0xA0E2 */
        union UINT_FLOAT                SQ_VTX_SEMANTIC_3         ;  /* 0xA0E3 */
index 44584430036283963f814ffc867ee13f1d522de9..5fe4b36b7107505ce1c2fd32f10f7b9d6881b7ae 100644 (file)
@@ -305,8 +305,57 @@ static void r700SetDepthState(GLcontext * ctx)
     }
 }
 
+static void r700SetAlphaState(GLcontext * ctx)
+{
+       context_t *context = R700_CONTEXT(ctx);
+       R700_CHIP_CONTEXT *r700 = (R700_CHIP_CONTEXT*)(&context->hw);
+       uint32_t alpha_func;
+       GLboolean really_enabled = ctx->Color.AlphaEnabled;
+
+       switch (ctx->Color.AlphaFunc) {
+       case GL_NEVER:
+               alpha_func = REF_NEVER;
+               break;
+       case GL_LESS:
+               alpha_func = REF_LESS;
+               break;
+       case GL_EQUAL:
+               alpha_func = REF_EQUAL;
+               break;
+       case GL_LEQUAL:
+               alpha_func = REF_LEQUAL;
+               break;
+       case GL_GREATER:
+               alpha_func = REF_GREATER;
+               break;
+       case GL_NOTEQUAL:
+               alpha_func = REF_NOTEQUAL;
+               break;
+       case GL_GEQUAL:
+               alpha_func = REF_GEQUAL;
+               break;
+       case GL_ALWAYS:
+               /*alpha_func = REF_ALWAYS; */
+               really_enabled = GL_FALSE;
+               break;
+       }
+
+       if (really_enabled) {
+               SETfield(r700->SX_ALPHA_TEST_CONTROL.u32All, alpha_func,
+                        ALPHA_FUNC_shift, ALPHA_FUNC_mask);
+               SETbit(r700->SX_ALPHA_TEST_CONTROL.u32All, ALPHA_TEST_ENABLE_bit);
+               r700->SX_ALPHA_REF.f32All = ctx->Color.AlphaRef;
+       } else {
+               CLEARbit(r700->SX_ALPHA_TEST_CONTROL.u32All, ALPHA_TEST_ENABLE_bit);
+       }
+
+}
+
 static void r700AlphaFunc(GLcontext * ctx, GLenum func, GLfloat ref) //---------------
 {
+       (void)func;
+       (void)ref;
+       r700SetAlphaState(ctx);
 }
 
 
@@ -628,7 +677,7 @@ static void r700Enable(GLcontext * ctx, GLenum cap, GLboolean state) //---------
                /* empty */
                break;
        case GL_ALPHA_TEST:
-               //r700SetAlphaState(ctx);
+               r700SetAlphaState(ctx);
                break;
        case GL_COLOR_LOGIC_OP:
                r700SetLogicOpState(ctx);
@@ -1327,9 +1376,7 @@ void r700InitState(GLcontext * ctx) //-------------------
     /* Specify the number of instances */
     r700->VGT_DMA_NUM_INSTANCES.u32All = 1;
 
-    /* not alpha blend */
-    CLEARfield(r700->SX_ALPHA_TEST_CONTROL.u32All, ALPHA_FUNC_mask);
-    CLEARbit(r700->SX_ALPHA_TEST_CONTROL.u32All, ALPHA_TEST_ENABLE_bit);
+    r700AlphaFunc(ctx, ctx->Color.AlphaFunc, ctx->Color.AlphaRef);
 
     /* default shader connections. */
     r700->SPI_VS_OUT_ID_0.u32All  = 0x03020100;