nir: support lowering clipdist to arrays
[mesa.git] / src / mesa / main / blend.h
index 0f0bb624aeeda636437c390e1c66b8c323551c13..6e56f2fd1ea88792ef54ee204c9e45a9838d5e95 100644 (file)
@@ -75,10 +75,16 @@ extern void GLAPIENTRY
 _mesa_BlendEquation( GLenum mode );
 
 
+void GLAPIENTRY
+_mesa_BlendEquationiARB_no_error(GLuint buf, GLenum mode);
+
 extern void GLAPIENTRY
 _mesa_BlendEquationiARB(GLuint buf, GLenum mode);
 
 
+void GLAPIENTRY
+_mesa_BlendEquationSeparate_no_error(GLenum modeRGB, GLenum modeA);
+
 extern void GLAPIENTRY
 _mesa_BlendEquationSeparate( GLenum modeRGB, GLenum modeA );
 
@@ -148,21 +154,58 @@ extern void
 _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);
+}
+
+static inline GLbitfield
+_mesa_replicate_colormask(GLbitfield mask0, unsigned num_buffers)
+{
+   GLbitfield mask = mask0;
+
+   for (unsigned i = 1; i < num_buffers; i++)
+      mask |= mask0 << (i * 4);
+   return mask;
 }
 
 #endif