Esempio n. 1
0
static void
i915UpdateBlendState(struct gl_context * ctx)
{
   struct i915_context *i915 = I915_CONTEXT(ctx);
   GLuint iab = (i915->state.Blend[I915_BLENDREG_IAB] &
                 ~(IAB_SRC_FACTOR_MASK |
                   IAB_DST_FACTOR_MASK |
                   (BLENDFUNC_MASK << IAB_FUNC_SHIFT) | IAB_ENABLE));

   GLuint lis6 = (i915->state.Ctx[I915_CTXREG_LIS6] &
                  ~(S6_CBUF_SRC_BLEND_FACT_MASK |
                    S6_CBUF_DST_BLEND_FACT_MASK | S6_CBUF_BLEND_FUNC_MASK));

   GLuint eqRGB = ctx->Color.Blend[0].EquationRGB;
   GLuint eqA = ctx->Color.Blend[0].EquationA;
   GLuint srcRGB = ctx->Color.Blend[0].SrcRGB;
   GLuint dstRGB = ctx->Color.Blend[0].DstRGB;
   GLuint srcA = ctx->Color.Blend[0].SrcA;
   GLuint dstA = ctx->Color.Blend[0].DstA;

   if (eqRGB == GL_MIN || eqRGB == GL_MAX) {
      srcRGB = dstRGB = GL_ONE;
   }

   if (eqA == GL_MIN || eqA == GL_MAX) {
      srcA = dstA = GL_ONE;
   }

   lis6 |= SRC_BLND_FACT(intel_translate_blend_factor(srcRGB));
   lis6 |= DST_BLND_FACT(intel_translate_blend_factor(dstRGB));
   lis6 |= translate_blend_equation(eqRGB) << S6_CBUF_BLEND_FUNC_SHIFT;

   iab |= SRC_ABLND_FACT(intel_translate_blend_factor(srcA));
   iab |= DST_ABLND_FACT(intel_translate_blend_factor(dstA));
   iab |= translate_blend_equation(eqA) << IAB_FUNC_SHIFT;

   if (srcA != srcRGB || dstA != dstRGB || eqA != eqRGB)
      iab |= IAB_ENABLE;

   if (iab != i915->state.Blend[I915_BLENDREG_IAB]) {
      i915->state.Blend[I915_BLENDREG_IAB] = iab;
      I915_STATECHANGE(i915, I915_UPLOAD_BLEND);
   }
   if (lis6 != i915->state.Ctx[I915_CTXREG_LIS6]) {
      i915->state.Ctx[I915_CTXREG_LIS6] = lis6;
      I915_STATECHANGE(i915, I915_UPLOAD_CTX);
   }

   /* This will catch a logicop blend equation */
   i915EvalLogicOpBlendState(ctx);
}
static void *brw_create_blend_state( struct pipe_context *pipe,
				     const struct pipe_blend_state *templ )
{
   struct brw_blend_state *blend = CALLOC_STRUCT(brw_blend_state);
   if (blend == NULL)
      return NULL;

   if (templ->logicop_enable) {
      blend->cc2.logicop_enable = 1;
      blend->cc5.logicop_func = translate_logicop(templ->logicop_func);
   } 
   else if (templ->rt[0].blend_enable) {
      blend->cc6.dest_blend_factor = translate_blend_factor(templ->rt[0].rgb_dst_factor);
      blend->cc6.src_blend_factor = translate_blend_factor(templ->rt[0].rgb_src_factor);
      blend->cc6.blend_function = translate_blend_equation(templ->rt[0].rgb_func);

      blend->cc5.ia_dest_blend_factor = translate_blend_factor(templ->rt[0].alpha_dst_factor);
      blend->cc5.ia_src_blend_factor = translate_blend_factor(templ->rt[0].alpha_src_factor);
      blend->cc5.ia_blend_function = translate_blend_equation(templ->rt[0].alpha_func);

      blend->cc3.blend_enable = 1;
      blend->cc3.ia_blend_enable = 
	 (blend->cc6.dest_blend_factor != blend->cc5.ia_dest_blend_factor ||
	  blend->cc6.src_blend_factor != blend->cc5.ia_src_blend_factor ||
	  blend->cc6.blend_function != blend->cc5.ia_blend_function);

      /* Per-surface blend enables, currently just follow global
       * state:
       */
      blend->ss0.color_blend = 1;
   }

   blend->cc5.dither_enable = templ->dither;

   if (BRW_DEBUG & DEBUG_STATS)
      blend->cc5.statistics_enable = 1;

   /* Per-surface color mask -- just follow global state:
    */
   blend->ss0.writedisable_red   = (templ->rt[0].colormask & PIPE_MASK_R) ? 0 : 1;
   blend->ss0.writedisable_green = (templ->rt[0].colormask & PIPE_MASK_G) ? 0 : 1;
   blend->ss0.writedisable_blue  = (templ->rt[0].colormask & PIPE_MASK_B) ? 0 : 1;
   blend->ss0.writedisable_alpha = (templ->rt[0].colormask & PIPE_MASK_A) ? 0 : 1;

   return (void *)blend;
}