return;
}
- _mesa_flush_vertices_for_blend_state(ctx);
+ _mesa_flush_vertices_for_blend_adv(ctx, ctx->Color.BlendEnabled,
+ advanced_mode);
for (buf = 0; buf < numBuffers; buf++) {
ctx->Color.Blend[buf].EquationRGB = mode;
ctx->Color.Blend[buf].EquationA == mode)
return; /* no change */
- _mesa_flush_vertices_for_blend_state(ctx);
+ _mesa_flush_vertices_for_blend_adv(ctx, ctx->Color.BlendEnabled,
+ advanced_mode);
ctx->Color.Blend[buf].EquationRGB = mode;
ctx->Color.Blend[buf].EquationA = mode;
ctx->Color._BlendEquationPerBuffer = GL_TRUE;
_mesa_init_color( struct gl_context * ctx );
+static inline enum gl_advanced_blend_mode
+_mesa_get_advanced_blend_sh_constant(GLbitfield blend_enabled,
+ enum gl_advanced_blend_mode mode)
+{
+ return blend_enabled ? mode : BLEND_NONE;
+}
+
+static inline bool
+_mesa_advanded_blend_sh_constant_changed(struct gl_context *ctx,
+ GLbitfield new_blend_enabled,
+ enum gl_advanced_blend_mode new_mode)
+{
+ return _mesa_get_advanced_blend_sh_constant(new_blend_enabled, new_mode) !=
+ _mesa_get_advanced_blend_sh_constant(ctx->Color.BlendEnabled,
+ ctx->Color._AdvancedBlendMode);
+}
+
static inline void
_mesa_flush_vertices_for_blend_state(struct gl_context *ctx)
{
- /* The advanced blend mode needs _NEW_COLOR to update the state constant,
- * so we have to set it. This is inefficient.
- * This should only be done for states that affect the state constant.
- * It shouldn't be done for other blend states.
- */
- if (_mesa_has_KHR_blend_equation_advanced(ctx) ||
- !ctx->DriverFlags.NewBlend) {
+ if (!ctx->DriverFlags.NewBlend) {
FLUSH_VERTICES(ctx, _NEW_COLOR);
} else {
FLUSH_VERTICES(ctx, 0);
+ ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
+ }
+}
+
+static inline void
+_mesa_flush_vertices_for_blend_adv(struct gl_context *ctx,
+ GLbitfield new_blend_enabled,
+ enum gl_advanced_blend_mode new_mode)
+{
+ /* The advanced blend mode needs _NEW_COLOR to update the state constant. */
+ if (_mesa_has_KHR_blend_equation_advanced(ctx) &&
+ _mesa_advanded_blend_sh_constant_changed(ctx, new_blend_enabled,
+ new_mode)) {
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+ ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
+ return;
}
- ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
+ _mesa_flush_vertices_for_blend_state(ctx);
}
#endif
GLbitfield newEnabled =
state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
if (newEnabled != ctx->Color.BlendEnabled) {
- _mesa_flush_vertices_for_blend_state(ctx);
+ _mesa_flush_vertices_for_blend_adv(ctx, newEnabled,
+ ctx->Color._AdvancedBlendMode);
ctx->Color.BlendEnabled = newEnabled;
}
}
return;
}
if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
- _mesa_flush_vertices_for_blend_state(ctx);
+ GLbitfield enabled = ctx->Color.BlendEnabled;
+
if (state)
- ctx->Color.BlendEnabled |= (1 << index);
+ enabled |= (1 << index);
else
- ctx->Color.BlendEnabled &= ~(1 << index);
+ enabled &= ~(1 << index);
+
+ _mesa_flush_vertices_for_blend_adv(ctx, enabled,
+ ctx->Color._AdvancedBlendMode);
+ ctx->Color.BlendEnabled = enabled;
}
break;
case GL_SCISSOR_TEST: