mesa: Keep a computed value for dual source blend func with each buffer.
authorEric Anholt <eric@anholt.net>
Thu, 17 May 2012 22:31:40 +0000 (15:31 -0700)
committerEric Anholt <eric@anholt.net>
Wed, 23 May 2012 17:45:43 +0000 (10:45 -0700)
The i965 driver needed this as well for hardware setup, so instead of
duplicating the logic, just save it off.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Dave Airlie <airlied@redhat.com>
src/mesa/main/blend.c
src/mesa/main/context.c
src/mesa/main/mtypes.h

index bc446edcabb1038f177638be7d2c204cd20ecfcf..5bc40a028bd18901800548222451fa4ef019803d 100644 (file)
@@ -166,6 +166,24 @@ _mesa_BlendFunc( GLenum sfactor, GLenum dfactor )
    _mesa_BlendFuncSeparateEXT(sfactor, dfactor, sfactor, dfactor);
 }
 
+static GLboolean
+blend_factor_is_dual_src(GLenum factor)
+{
+   return (factor == GL_SRC1_COLOR ||
+          factor == GL_SRC1_ALPHA ||
+          factor == GL_ONE_MINUS_SRC1_COLOR ||
+          factor == GL_ONE_MINUS_SRC1_ALPHA);
+}
+
+static void
+update_uses_dual_src(struct gl_context *ctx, int buf)
+{
+   ctx->Color.Blend[buf]._UsesDualSrc =
+      (blend_factor_is_dual_src(ctx->Color.Blend[buf].SrcRGB) ||
+       blend_factor_is_dual_src(ctx->Color.Blend[buf].DstRGB) ||
+       blend_factor_is_dual_src(ctx->Color.Blend[buf].SrcA) ||
+       blend_factor_is_dual_src(ctx->Color.Blend[buf].DstA));
+}
 
 /**
  * Set the separate blend source/dest factors for all draw buffers.
@@ -220,6 +238,7 @@ _mesa_BlendFuncSeparateEXT( GLenum sfactorRGB, GLenum dfactorRGB,
       ctx->Color.Blend[buf].DstRGB = dfactorRGB;
       ctx->Color.Blend[buf].SrcA = sfactorA;
       ctx->Color.Blend[buf].DstA = dfactorA;
+      update_uses_dual_src(ctx, buf);
    }
    ctx->Color._BlendFuncPerBuffer = GL_FALSE;
 
@@ -282,6 +301,7 @@ _mesa_BlendFuncSeparatei(GLuint buf, GLenum sfactorRGB, GLenum dfactorRGB,
    ctx->Color.Blend[buf].DstRGB = dfactorRGB;
    ctx->Color.Blend[buf].SrcA = sfactorA;
    ctx->Color.Blend[buf].DstA = dfactorA;
+   update_uses_dual_src(ctx, buf);
    ctx->Color._BlendFuncPerBuffer = GL_TRUE;
 
    if (ctx->Driver.BlendFuncSeparatei) {
index df0452cd1145ae6b103efc246c3b52dd4a380aed..3bcedecd9baa1e13a100f1a91b8596eec2731011 100644 (file)
@@ -1703,13 +1703,6 @@ _mesa_set_mvp_with_dp4( struct gl_context *ctx,
    ctx->mvp_with_dp4 = flag;
 }
 
-static GLboolean
-blend_factor_is_dual_src(GLenum factor)
-{
-   return factor == GL_SRC1_COLOR || factor == GL_SRC1_ALPHA ||
-      factor == GL_ONE_MINUS_SRC1_COLOR || factor == GL_ONE_MINUS_SRC1_ALPHA;
-}
-
 /*
  * ARB_blend_func_extended - ERRORS section
  * "The error INVALID_OPERATION is generated by Begin or any procedure that
@@ -1722,16 +1715,13 @@ static GLboolean
 _mesa_check_blend_func_error(struct gl_context *ctx)
 {
    GLuint i;
-   for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
-      if (blend_factor_is_dual_src(ctx->Color.Blend[i].SrcRGB) ||
-          blend_factor_is_dual_src(ctx->Color.Blend[i].DstRGB) ||
-          blend_factor_is_dual_src(ctx->Color.Blend[i].SrcA) ||
-          blend_factor_is_dual_src(ctx->Color.Blend[i].DstA)) {
-         if (i >= ctx->Const.MaxDualSourceDrawBuffers) {
-            _mesa_error(ctx, GL_INVALID_OPERATION,
-                        "dual source blend on illegal attachment");
-            return GL_FALSE;
-         }
+   for (i = ctx->Const.MaxDualSourceDrawBuffers;
+       i < ctx->DrawBuffer->_NumColorDrawBuffers;
+       i++) {
+      if (ctx->Color.Blend[i]._UsesDualSrc) {
+        _mesa_error(ctx, GL_INVALID_OPERATION,
+                    "dual source blend on illegal attachment");
+        return GL_FALSE;
       }
    }
    return GL_TRUE;
index eefe5e7e97d6471ca03953b2aa374878e1e7b73d..3a8cac9c5a1aeb24d66e9d5cff44cfa69381178d 100644 (file)
@@ -755,6 +755,11 @@ struct gl_colorbuffer_attrib
       GLenum DstA;               /**< Alpha blend dest term */
       GLenum EquationRGB;        /**< GL_ADD, GL_SUBTRACT, etc. */
       GLenum EquationA;          /**< GL_ADD, GL_SUBTRACT, etc. */
+      /**
+       * Set if any blend factor uses SRC1.  Computed at the time blend factors
+       * get set.
+       */
+      GLboolean _UsesDualSrc;
    } Blend[MAX_DRAW_BUFFERS];
    /** Are the blend func terms currently different for each buffer/target? */
    GLboolean _BlendFuncPerBuffer;