llvmpipe: Fix lp_test_format on 32bit OSes.
[mesa.git] / src / gallium / drivers / i965 / brw_pipe_blend.c
index d3bb882b1aa6e7b841e405cd1a39cf88c8fa0397..21f786f871529402604145ef1bb5be211b9d5c69 100644 (file)
@@ -111,25 +111,32 @@ 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->blend_enable) {
-      blend->cc6.dest_blend_factor = translate_blend_factor(templ->rgb_dst_factor);
-      blend->cc6.src_blend_factor = translate_blend_factor(templ->rgb_src_factor);
-      blend->cc6.blend_function = translate_blend_equation(templ->rgb_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->alpha_dst_factor);
-      blend->cc5.ia_src_blend_factor = translate_blend_factor(templ->alpha_src_factor);
-      blend->cc5.ia_blend_function = translate_blend_equation(templ->alpha_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;
@@ -137,6 +144,13 @@ static void *brw_create_blend_state( struct pipe_context *pipe,
    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;
 }
 
@@ -163,9 +177,6 @@ static void brw_set_blend_color(struct pipe_context *pipe,
    struct brw_context *brw = brw_context(pipe);
    struct brw_blend_constant_color *bcc = &brw->curr.bcc;
 
-   memset(bcc, 0, sizeof(*bcc));      
-   bcc->header.opcode = CMD_BLEND_CONSTANT_COLOR;
-   bcc->header.length = sizeof(*bcc)/4-2;
    bcc->blend_constant_color[0] = blend_color->color[0];
    bcc->blend_constant_color[1] = blend_color->color[1];
    bcc->blend_constant_color[2] = blend_color->color[2];
@@ -181,6 +192,15 @@ void brw_pipe_blend_init( struct brw_context *brw )
    brw->base.create_blend_state = brw_create_blend_state;
    brw->base.bind_blend_state = brw_bind_blend_state;
    brw->base.delete_blend_state = brw_delete_blend_state;
+
+   {
+      struct brw_blend_constant_color *bcc = &brw->curr.bcc;
+
+      memset(bcc, 0, sizeof(*bcc));      
+      bcc->header.opcode = CMD_BLEND_CONSTANT_COLOR;
+      bcc->header.length = sizeof(*bcc)/4-2;
+   }
+
 }
 
 void brw_pipe_blend_cleanup( struct brw_context *brw )