st/mesa: use PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY
[mesa.git] / src / mesa / state_tracker / st_atom_blend.c
index f7327d6838c8493754d4c04d953925161c00ba6b..57400e2e791b4c5896489b3436f4daa6e48bc9e8 100644 (file)
@@ -112,23 +112,26 @@ translate_blend(GLenum blend)
  * Figure out if colormasks are different per rt.
  */
 static GLboolean
-colormask_per_rt(const struct gl_context *ctx)
+colormask_per_rt(const struct gl_context *ctx, unsigned num_cb)
 {
+   GLbitfield full_mask = _mesa_replicate_colormask(0xf, num_cb);
    GLbitfield repl_mask0 =
       _mesa_replicate_colormask(GET_COLORMASK(ctx->Color.ColorMask, 0),
-                                ctx->Const.MaxDrawBuffers);
+                                num_cb);
 
-   return ctx->Color.ColorMask != repl_mask0;
+   return (ctx->Color.ColorMask & full_mask) != repl_mask0;
 }
 
 /**
  * Figure out if blend enables/state are different per rt.
  */
 static GLboolean
-blend_per_rt(const struct gl_context *ctx)
+blend_per_rt(const struct gl_context *ctx, unsigned num_cb)
 {
-   if (ctx->Color.BlendEnabled &&
-      (ctx->Color.BlendEnabled != ((1U << ctx->Const.MaxDrawBuffers) - 1))) {
+   GLbitfield cb_mask = u_bit_consecutive(0, num_cb);
+   GLbitfield blend_enabled = ctx->Color.BlendEnabled & cb_mask;
+
+   if (blend_enabled && blend_enabled != cb_mask) {
       /* This can only happen if GL_EXT_draw_buffers2 is enabled */
       return GL_TRUE;
    }
@@ -144,15 +147,21 @@ st_update_blend( struct st_context *st )
 {
    struct pipe_blend_state *blend = &st->state.blend;
    const struct gl_context *ctx = st->ctx;
+   unsigned num_cb = st->state.fb_num_cb;
    unsigned num_state = 1;
    unsigned i, j;
 
    memset(blend, 0, sizeof(*blend));
 
-   if (blend_per_rt(ctx) || colormask_per_rt(ctx)) {
-      num_state = ctx->Const.MaxDrawBuffers;
+   if (num_cb > 1 &&
+       (blend_per_rt(ctx, num_cb) || colormask_per_rt(ctx, num_cb))) {
+      num_state = num_cb;
       blend->independent_blend_enable = 1;
    }
+
+   for (i = 0; i < num_state; i++)
+      blend->rt[i].colormask = GET_COLORMASK(ctx->Color.ColorMask, i);
+
    if (ctx->Color.ColorLogicOpEnabled) {
       /* logicop enabled */
       blend->logicop_enable = 1;
@@ -161,12 +170,14 @@ st_update_blend( struct st_context *st )
    else if (ctx->Color.BlendEnabled && !ctx->Color._AdvancedBlendMode) {
       /* blending enabled */
       for (i = 0, j = 0; i < num_state; i++) {
+         if (!(ctx->Color.BlendEnabled & (1 << i)) ||
+             !blend->rt[i].colormask)
+            continue;
 
-         blend->rt[i].blend_enable = (ctx->Color.BlendEnabled >> i) & 0x1;
-
-         if (ctx->Extensions.ARB_draw_buffers_blend)
+        if (ctx->Extensions.ARB_draw_buffers_blend)
             j = i;
 
+         blend->rt[i].blend_enable = 1;
          blend->rt[i].rgb_func =
             translate_blend(ctx->Color.Blend[j].EquationRGB);
 
@@ -204,9 +215,6 @@ st_update_blend( struct st_context *st )
       /* no blending / logicop */
    }
 
-   for (i = 0; i < num_state; i++)
-      blend->rt[i].colormask = GET_COLORMASK(ctx->Color.ColorMask, i);
-
    blend->dither = ctx->Color.DitherFlag;
 
    if (_mesa_is_multisample_enabled(ctx) &&