[Mesa-dev] [PATCH 09/16] mesa: Track an _AdvancedBlendEnabled bitfield.

Kenneth Graunke kenneth at whitecape.org
Sat Aug 13 03:13:01 UTC 2016


Drivers emulating advanced blending will want to disable hardware
blending.  This makes it easy to check whether hardware blending
should be enabled for buffer "i" by doing:

   (BlendEnabled & ~_AdvancedBlendEnabled) & (1 << i)

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/mesa/main/blend.c  | 18 ++++++++++++++----
 src/mesa/main/mtypes.h |  2 ++
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/mesa/main/blend.c b/src/mesa/main/blend.c
index fe83e59..e23b9cb 100644
--- a/src/mesa/main/blend.c
+++ b/src/mesa/main/blend.c
@@ -274,6 +274,7 @@ _mesa_BlendFuncSeparate( GLenum sfactorRGB, GLenum dfactorRGB,
    }
 
    ctx->Color._BlendFuncPerBuffer = GL_FALSE;
+   ctx->Color._AdvancedBlendEnabled = 0;
 
    if (ctx->Driver.BlendFuncSeparate) {
       ctx->Driver.BlendFuncSeparate(ctx, sfactorRGB, dfactorRGB,
@@ -332,6 +333,7 @@ _mesa_BlendFuncSeparateiARB(GLuint buf, GLenum sfactorRGB, GLenum dfactorRGB,
    ctx->Color.Blend[buf].DstA = dfactorA;
    update_uses_dual_src(ctx, buf);
    ctx->Color._BlendFuncPerBuffer = GL_TRUE;
+   ctx->Color._AdvancedBlendEnabled = 0;
 }
 
 
@@ -394,6 +396,7 @@ _mesa_BlendEquation( GLenum mode )
    const unsigned numBuffers = num_buffers(ctx);
    unsigned buf;
    bool changed = false;
+   bool is_advanced = legal_advanced_blend_equation(ctx, mode);
 
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glBlendEquation(%s)\n",
@@ -420,8 +423,8 @@ _mesa_BlendEquation( GLenum mode )
    if (!changed)
       return;
 
-   if (!legal_simple_blend_equation(ctx, mode) &&
-       !legal_advanced_blend_equation(ctx, mode)) {
+
+   if (!legal_simple_blend_equation(ctx, mode) && !is_advanced) {
       _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquation");
       return;
    }
@@ -433,6 +436,8 @@ _mesa_BlendEquation( GLenum mode )
       ctx->Color.Blend[buf].EquationA = mode;
    }
    ctx->Color._BlendEquationPerBuffer = GL_FALSE;
+   ctx->Color._AdvancedBlendEnabled =
+      is_advanced * ((1 << ctx->Const.MaxDrawBuffers) - 1);
 
    if (ctx->Driver.BlendEquationSeparate)
       ctx->Driver.BlendEquationSeparate(ctx, mode, mode);
@@ -446,6 +451,7 @@ void GLAPIENTRY
 _mesa_BlendEquationiARB(GLuint buf, GLenum mode)
 {
    GET_CURRENT_CONTEXT(ctx);
+   bool is_advanced = legal_advanced_blend_equation(ctx, mode);
 
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glBlendEquationi(%u, %s)\n",
@@ -457,8 +463,7 @@ _mesa_BlendEquationiARB(GLuint buf, GLenum mode)
       return;
    }
 
-   if (!legal_simple_blend_equation(ctx, mode) &&
-       !legal_advanced_blend_equation(ctx, mode)) {
+   if (!legal_simple_blend_equation(ctx, mode) && !is_advanced) {
       _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationi");
       return;
    }
@@ -471,6 +476,11 @@ _mesa_BlendEquationiARB(GLuint buf, GLenum mode)
    ctx->Color.Blend[buf].EquationRGB = mode;
    ctx->Color.Blend[buf].EquationA = mode;
    ctx->Color._BlendEquationPerBuffer = GL_TRUE;
+
+   if (is_advanced)
+      ctx->Color._AdvancedBlendEnabled |= (1 << buf);
+   else
+      ctx->Color._AdvancedBlendEnabled &= ~(1 << buf);
 }
 
 
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 6a9e729..9e0b831 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -452,6 +452,8 @@ struct gl_colorbuffer_attrib
    GLboolean _BlendFuncPerBuffer;
    /** Are the blend equations currently different for each buffer/target? */
    GLboolean _BlendEquationPerBuffer;
+   /** Per-buffer "is an advanced blending equation set?" flags. */
+   GLbitfield _AdvancedBlendEnabled;
    /*@}*/
 
    /** 
-- 
2.9.0



More information about the mesa-dev mailing list