diff options
author | Timothy Arceri <[email protected]> | 2017-06-28 15:21:51 +1000 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2017-06-29 08:54:11 +1000 |
commit | f21a764092b9f031c459f1b4f22b08a33da5111f (patch) | |
tree | bedd8c833df0596e996ee700951a6f88dc9bbe16 /src | |
parent | 87bc32166afc00dedd1e95b1e11ceef26a994fe0 (diff) |
mesa: create some glBlendFunc*() helper functions
Reviewed-by: Samuel Pitoiset <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/main/blend.c | 131 |
1 files changed, 81 insertions, 50 deletions
diff --git a/src/mesa/main/blend.c b/src/mesa/main/blend.c index 3fa9678730d..b06ec334062 100644 --- a/src/mesa/main/blend.c +++ b/src/mesa/main/blend.c @@ -157,20 +157,6 @@ validate_blend_factors(struct gl_context *ctx, const char *func, } -/** - * Specify the blending operation. - * - * \param sfactor source factor operator. - * \param dfactor destination factor operator. - * - * \sa glBlendFunc, glBlendFuncSeparateEXT - */ -void GLAPIENTRY -_mesa_BlendFunc( GLenum sfactor, GLenum dfactor ) -{ - _mesa_BlendFuncSeparate(sfactor, dfactor, sfactor, dfactor); -} - static GLboolean blend_factor_is_dual_src(GLenum factor) { @@ -203,40 +189,23 @@ num_buffers(const struct gl_context *ctx) } -/** - * Set the separate blend source/dest factors for all draw buffers. - * - * \param sfactorRGB RGB source factor operator. - * \param dfactorRGB RGB destination factor operator. - * \param sfactorA alpha source factor operator. - * \param dfactorA alpha destination factor operator. - */ -void GLAPIENTRY -_mesa_BlendFuncSeparate( GLenum sfactorRGB, GLenum dfactorRGB, - GLenum sfactorA, GLenum dfactorA ) +/* Returns true if there was no change */ +static bool +skip_blend_state_update(const struct gl_context *ctx, + GLenum sfactorRGB, GLenum dfactorRGB, + GLenum sfactorA, GLenum dfactorA) { - GET_CURRENT_CONTEXT(ctx); - const unsigned numBuffers = num_buffers(ctx); - unsigned buf; - bool changed = false; - - if (MESA_VERBOSE & VERBOSE_API) - _mesa_debug(ctx, "glBlendFuncSeparate %s %s %s %s\n", - _mesa_enum_to_string(sfactorRGB), - _mesa_enum_to_string(dfactorRGB), - _mesa_enum_to_string(sfactorA), - _mesa_enum_to_string(dfactorA)); - /* Check if we're really changing any state. If not, return early. */ if (ctx->Color._BlendFuncPerBuffer) { + const unsigned numBuffers = num_buffers(ctx); + /* Check all per-buffer states */ - for (buf = 0; buf < numBuffers; buf++) { + for (unsigned buf = 0; buf < numBuffers; buf++) { if (ctx->Color.Blend[buf].SrcRGB != sfactorRGB || ctx->Color.Blend[buf].DstRGB != dfactorRGB || ctx->Color.Blend[buf].SrcA != sfactorA || ctx->Color.Blend[buf].DstA != dfactorA) { - changed = true; - break; + return false; } } } @@ -246,23 +215,24 @@ _mesa_BlendFuncSeparate( GLenum sfactorRGB, GLenum dfactorRGB, ctx->Color.Blend[0].DstRGB != dfactorRGB || ctx->Color.Blend[0].SrcA != sfactorA || ctx->Color.Blend[0].DstA != dfactorA) { - changed = true; + return false; } } - if (!changed) - return; + return true; +} - if (!validate_blend_factors(ctx, "glBlendFuncSeparate", - sfactorRGB, dfactorRGB, - sfactorA, dfactorA)) { - return; - } +static void +blend_func_separate(struct gl_context *ctx, + GLenum sfactorRGB, GLenum dfactorRGB, + GLenum sfactorA, GLenum dfactorA) +{ FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR); ctx->NewDriverState |= ctx->DriverFlags.NewBlend; - for (buf = 0; buf < numBuffers; buf++) { + const unsigned numBuffers = num_buffers(ctx); + for (unsigned buf = 0; buf < numBuffers; buf++) { ctx->Color.Blend[buf].SrcRGB = sfactorRGB; ctx->Color.Blend[buf].DstRGB = dfactorRGB; ctx->Color.Blend[buf].SrcA = sfactorA; @@ -270,7 +240,7 @@ _mesa_BlendFuncSeparate( GLenum sfactorRGB, GLenum dfactorRGB, } update_uses_dual_src(ctx, 0); - for (buf = 1; buf < numBuffers; buf++) { + for (unsigned buf = 1; buf < numBuffers; buf++) { ctx->Color.Blend[buf]._UsesDualSrc = ctx->Color.Blend[0]._UsesDualSrc; } @@ -283,6 +253,67 @@ _mesa_BlendFuncSeparate( GLenum sfactorRGB, GLenum dfactorRGB, } +/** + * Specify the blending operation. + * + * \param sfactor source factor operator. + * \param dfactor destination factor operator. + * + * \sa glBlendFunc, glBlendFuncSeparateEXT + */ +void GLAPIENTRY +_mesa_BlendFunc( GLenum sfactor, GLenum dfactor ) +{ + GET_CURRENT_CONTEXT(ctx); + + if (skip_blend_state_update(ctx, sfactor, dfactor, sfactor, dfactor)) + return; + + if (!validate_blend_factors(ctx, "glBlendFunc", + sfactor, dfactor, sfactor, dfactor)) { + return; + } + + blend_func_separate(ctx, sfactor, dfactor, sfactor, dfactor); +} + + +/** + * Set the separate blend source/dest factors for all draw buffers. + * + * \param sfactorRGB RGB source factor operator. + * \param dfactorRGB RGB destination factor operator. + * \param sfactorA alpha source factor operator. + * \param dfactorA alpha destination factor operator. + */ +void GLAPIENTRY +_mesa_BlendFuncSeparate( GLenum sfactorRGB, GLenum dfactorRGB, + GLenum sfactorA, GLenum dfactorA ) +{ + GET_CURRENT_CONTEXT(ctx); + + if (MESA_VERBOSE & VERBOSE_API) + _mesa_debug(ctx, "glBlendFuncSeparate %s %s %s %s\n", + _mesa_enum_to_string(sfactorRGB), + _mesa_enum_to_string(dfactorRGB), + _mesa_enum_to_string(sfactorA), + _mesa_enum_to_string(dfactorA)); + + + + if (skip_blend_state_update(ctx, sfactorRGB, dfactorRGB, sfactorA, dfactorA)) + return; + + if (!validate_blend_factors(ctx, "glBlendFuncSeparate", + sfactorRGB, dfactorRGB, + sfactorA, dfactorA)) { + return; + } + + blend_func_separate(ctx, sfactorRGB, dfactorRGB, sfactorA, dfactorA); +} + + void GLAPIENTRY _mesa_BlendFunciARB_no_error(GLuint buf, GLenum sfactor, GLenum dfactor) { |