Merge remote branch 'origin/master' into pipe-video
[mesa.git] / src / mesa / state_tracker / st_atom_blend.c
index 809b10d4799a4671a2d3269c3ed060ba0cead256..a8ec4adce775b92a37e22f53af8e7532c79c8c5c 100644 (file)
@@ -152,17 +152,33 @@ translate_logicop(GLenum logicop)
    }
 }
 
-static boolean
-colormask_perrt(GLcontext *ctx)
+/**
+ * Figure out if colormasks are different per rt.
+ */
+static GLboolean
+colormask_per_rt(struct gl_context *ctx)
 {
-   /* XXX this is ugly beyond belief */
+   /* a bit suboptimal have to compare lots of values */
    unsigned i;
    for (i = 1; i < ctx->Const.MaxDrawBuffers; i++) {
-      if (!TEST_EQ_4V(ctx->Color.ColorMask[0], ctx->Color.ColorMask[i])) {
-         return true;
+      if (memcmp(ctx->Color.ColorMask[0], ctx->Color.ColorMask[i], 4)) {
+         return GL_TRUE;
       }
    }
-   return false;
+   return GL_FALSE;
+}
+
+/**
+ * Figure out if blend enables are different per rt.
+ */
+static GLboolean
+blend_per_rt(struct gl_context *ctx)
+{
+   if (ctx->Color.BlendEnabled &&
+      (ctx->Color.BlendEnabled != ((1 << ctx->Const.MaxDrawBuffers) - 1))) {
+      return GL_TRUE;
+   }
+   return GL_FALSE;
 }
 
 static void 
@@ -174,9 +190,7 @@ update_blend( struct st_context *st )
 
    memset(blend, 0, sizeof(*blend));
 
-   if ((st->ctx->Color.BlendEnabled &&
-      (st->ctx->Color.BlendEnabled != ((1 << st->ctx->Const.MaxDrawBuffers) - 1))) ||
-      colormask_perrt(st->ctx)) {
+   if (blend_per_rt(st->ctx) || colormask_per_rt(st->ctx)) {
       num_state = st->ctx->Const.MaxDrawBuffers;
       blend->independent_blend_enable = 1;
    }
@@ -243,6 +257,15 @@ update_blend( struct st_context *st )
    if (st->ctx->Color.DitherFlag)
       blend->dither = 1;
 
+   if (st->ctx->Multisample.Enabled) {
+      /* unlike in gallium/d3d10 these operations are only performed
+         if msaa is enabled */
+      if (st->ctx->Multisample.SampleAlphaToCoverage)
+         blend->alpha_to_coverage = 1;
+      if (st->ctx->Multisample.SampleAlphaToOne)
+         blend->alpha_to_one = 1;
+   }
+
    cso_set_blend(st->cso_context, blend);
 
    {
@@ -256,7 +279,7 @@ update_blend( struct st_context *st )
 const struct st_tracked_state st_update_blend = {
    "st_update_blend",                                  /* name */
    {                                                   /* dirty */
-      (_NEW_COLOR),  /* XXX _NEW_BLEND someday? */     /* mesa */
+      (_NEW_COLOR | _NEW_MULTISAMPLE),  /* XXX _NEW_BLEND someday? */  /* mesa */
       0,                                               /* st */
    },
    update_blend,                                       /* update */