Add a quad 'bufloop' stage to handle glDrawBuffer(GL_FRONT_AND_BACK).
authorBrian <brian.paul@tungstengraphics.com>
Thu, 12 Jul 2007 20:13:48 +0000 (14:13 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Thu, 12 Jul 2007 20:13:48 +0000 (14:13 -0600)
This removes the notion of multiple color buffers from all other stages.
Will need a bit more work when shaders with multiple render targets arrive.

src/mesa/pipe/softpipe/sp_context.c
src/mesa/pipe/softpipe/sp_context.h
src/mesa/pipe/softpipe/sp_quad.c
src/mesa/pipe/softpipe/sp_quad.h
src/mesa/pipe/softpipe/sp_quad_blend.c
src/mesa/pipe/softpipe/sp_quad_bufloop.c [new file with mode: 0644]
src/mesa/pipe/softpipe/sp_quad_colormask.c
src/mesa/pipe/softpipe/sp_quad_output.c
src/mesa/sources

index 9511254a96c6f006b644e7c89b8ef5c3cc6445dd..cc4b8d5914101a635de595c27174cf7a6abdb6d5 100644 (file)
@@ -88,6 +88,7 @@ struct pipe_context *softpipe_create( void )
    softpipe->quad.alpha_test = sp_quad_alpha_test_stage(softpipe);
    softpipe->quad.depth_test = sp_quad_depth_test_stage(softpipe);
    softpipe->quad.stencil_test = sp_quad_stencil_test_stage(softpipe);
+   softpipe->quad.bufloop = sp_quad_bufloop_stage(softpipe);
    softpipe->quad.blend = sp_quad_blend_stage(softpipe);
    softpipe->quad.colormask = sp_quad_colormask_stage(softpipe);
    softpipe->quad.output = sp_quad_output_stage(softpipe);
index 3ae1de71cf74f9b5b5bee3beb5813c0d0672ee2b..81d2b58cf93bbcd0c4938cac0d23e85ea4c44b85 100644 (file)
@@ -122,6 +122,7 @@ struct softpipe_context {
       struct quad_stage *alpha_test;
       struct quad_stage *stencil_test;
       struct quad_stage *depth_test;
+      struct quad_stage *bufloop;
       struct quad_stage *blend;
       struct quad_stage *colormask;
       struct quad_stage *output;
@@ -131,6 +132,8 @@ struct softpipe_context {
 
    /** The primitive drawing context */
    struct draw_context *draw;
+
+   struct pipe_surface *cbuf;      /**< current color buffer (one of cbufs) */
 };
 
 
index 419a720de9a3aca2b2a2aa7ee0cb885773254e2c..5f34f5f1b34f8d0c3a4c54d3fe18f5cd65c40c07 100644 (file)
@@ -21,6 +21,16 @@ sp_build_quad_pipeline(struct softpipe_context *sp)
       sp->quad.first = sp->quad.blend;
    }
 
+   if (sp->framebuffer.num_cbufs == 1) {
+      /* the usual case: write to exactly one colorbuf */
+      sp->cbuf = sp->framebuffer.cbufs[0];
+   }
+   else {
+      /* insert bufloop stage */
+      sp->quad.bufloop->next = sp->quad.first;
+      sp->quad.first = sp->quad.bufloop;
+   }
+
    if (   sp->stencil.front_enabled
        || sp->stencil.front_enabled) {
       sp->quad.stencil_test->next = sp->quad.first;
index 966f72d3b5b1685c73d0bde1b7b6b4a35acf6c80..719d4774ccae89328f3930c74e989e5d95bb1559 100644 (file)
@@ -51,6 +51,7 @@ struct quad_stage *sp_quad_shade_stage( struct softpipe_context *softpipe );
 struct quad_stage *sp_quad_alpha_test_stage( struct softpipe_context *softpipe );
 struct quad_stage *sp_quad_stencil_test_stage( struct softpipe_context *softpipe );
 struct quad_stage *sp_quad_depth_test_stage( struct softpipe_context *softpipe );
+struct quad_stage *sp_quad_bufloop_stage( struct softpipe_context *softpipe );
 struct quad_stage *sp_quad_blend_stage( struct softpipe_context *softpipe );
 struct quad_stage *sp_quad_colormask_stage( struct softpipe_context *softpipe );
 struct quad_stage *sp_quad_output_stage( struct softpipe_context *softpipe );
index 2599e7a2f98b893dfc5783879d3469193ee5559c..3d097aea65e155fdeba0ebe64a8f86e9e3fe69ed 100644 (file)
@@ -104,287 +104,281 @@ blend_quad(struct quad_stage *qs, struct quad_header *quad)
    static const GLfloat zero[4] = { 0, 0, 0, 0 };
    static const GLfloat one[4] = { 1, 1, 1, 1 };
    struct softpipe_context *softpipe = qs->softpipe;
+   struct softpipe_surface *sps = softpipe_surface(softpipe->cbuf);
    GLfloat source[4][QUAD_SIZE], dest[4][QUAD_SIZE];
-   GLuint i;
-
-   /* XXX we're also looping in output_quad() !?! */
-
-   for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) {
-      struct softpipe_surface *sps
-         = softpipe_surface(softpipe->framebuffer.cbufs[i]);
    
-      sps->read_quad_f_swz(sps, quad->x0, quad->y0, dest);
+   /* get colors from framebuffer */
+   sps->read_quad_f_swz(sps, quad->x0, quad->y0, dest);
 
-      /*
-       * Compute src/first term RGB
-       */
-      switch (softpipe->blend.rgb_src_factor) {
-      case PIPE_BLENDFACTOR_ONE:
-         VEC4_COPY(source[0], quad->outputs.color[0]); /* R */
-         VEC4_COPY(source[1], quad->outputs.color[1]); /* G */
-         VEC4_COPY(source[2], quad->outputs.color[2]); /* B */
-         break;
-      case PIPE_BLENDFACTOR_SRC_COLOR:
-         VEC4_MUL(source[0], quad->outputs.color[0], quad->outputs.color[0]); /* R */
-         VEC4_MUL(source[1], quad->outputs.color[1], quad->outputs.color[1]); /* G */
-         VEC4_MUL(source[2], quad->outputs.color[2], quad->outputs.color[2]); /* B */
-         break;
-      case PIPE_BLENDFACTOR_SRC_ALPHA:
-         {
-            const GLfloat *alpha = quad->outputs.color[3];
-            VEC4_MUL(source[0], quad->outputs.color[0], alpha); /* R */
-            VEC4_MUL(source[1], quad->outputs.color[1], alpha); /* G */
-            VEC4_MUL(source[2], quad->outputs.color[2], alpha); /* B */
-         }
-         break;
-      case PIPE_BLENDFACTOR_DST_COLOR:
-         VEC4_MUL(source[0], quad->outputs.color[0], dest[0]); /* R */
-         VEC4_MUL(source[1], quad->outputs.color[1], dest[1]); /* G */
-         VEC4_MUL(source[2], quad->outputs.color[2], dest[2]); /* B */
-         break;
-      case PIPE_BLENDFACTOR_DST_ALPHA:
-         {
-            const GLfloat *alpha = dest[3];
-            VEC4_MUL(source[0], quad->outputs.color[0], alpha); /* R */
-            VEC4_MUL(source[1], quad->outputs.color[1], alpha); /* G */
-            VEC4_MUL(source[2], quad->outputs.color[2], alpha); /* B */
-         }
-         break;
-      case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
-         assert(0); /* to do */
-         break;
-      case PIPE_BLENDFACTOR_CONST_COLOR:
-         {
-            GLfloat comp[4];
-            VEC4_SCALAR(comp, softpipe->blend_color.color[0]); /* R */
-            VEC4_MUL(source[0], quad->outputs.color[0], comp); /* R */
-            VEC4_SCALAR(comp, softpipe->blend_color.color[1]); /* G */
-            VEC4_MUL(source[1], quad->outputs.color[1], comp); /* G */
-            VEC4_SCALAR(comp, softpipe->blend_color.color[2]); /* B */
-            VEC4_MUL(source[2], quad->outputs.color[2], comp); /* B */
-         }
-         break;
-      case PIPE_BLENDFACTOR_CONST_ALPHA:
-         {
-            GLfloat alpha[4];
-            VEC4_SCALAR(alpha, softpipe->blend_color.color[3]);
-            VEC4_MUL(source[0], quad->outputs.color[0], alpha); /* R */
-            VEC4_MUL(source[1], quad->outputs.color[1], alpha); /* G */
-            VEC4_MUL(source[2], quad->outputs.color[2], alpha); /* B */
-         }
-         break;
-      case PIPE_BLENDFACTOR_SRC1_COLOR:
-         assert(0); /* to do */
-         break;
-      case PIPE_BLENDFACTOR_SRC1_ALPHA:
-         assert(0); /* to do */
-         break;
-      case PIPE_BLENDFACTOR_ZERO:
-         VEC4_COPY(source[0], zero); /* R */
-         VEC4_COPY(source[1], zero); /* G */
-         VEC4_COPY(source[2], zero); /* B */
-         break;
-      case PIPE_BLENDFACTOR_INV_SRC_COLOR:
-         {
-            GLfloat inv_comp[4];
-            VEC4_SUB(inv_comp, one, quad->outputs.color[0]); /* R */
-            VEC4_MUL(source[0], quad->outputs.color[0], inv_comp); /* R */
-            VEC4_SUB(inv_comp, one, quad->outputs.color[1]); /* G */
-            VEC4_MUL(source[1], quad->outputs.color[1], inv_comp); /* G */
-            VEC4_SUB(inv_comp, one, quad->outputs.color[2]); /* B */
-            VEC4_MUL(source[2], quad->outputs.color[2], inv_comp); /* B */
-         }
-         break;
-      case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
-         {
-            GLfloat inv_alpha[4];
-            VEC4_SUB(inv_alpha, one, quad->outputs.color[3]);
-            VEC4_MUL(source[0], quad->outputs.color[0], inv_alpha); /* R */
-            VEC4_MUL(source[1], quad->outputs.color[1], inv_alpha); /* G */
-            VEC4_MUL(source[2], quad->outputs.color[2], inv_alpha); /* B */
-         }
-         break;
-      case PIPE_BLENDFACTOR_INV_DST_ALPHA:
-         {
-            GLfloat inv_alpha[4];
-            VEC4_SUB(inv_alpha, one, dest[3]);
-            VEC4_MUL(source[0], quad->outputs.color[0], inv_alpha); /* R */
-            VEC4_MUL(source[1], quad->outputs.color[1], inv_alpha); /* G */
-            VEC4_MUL(source[2], quad->outputs.color[2], inv_alpha); /* B */
-         }
-         break;
-      case PIPE_BLENDFACTOR_INV_DST_COLOR:
-         {
-            GLfloat inv_comp[4];
-            VEC4_SUB(inv_comp, one, dest[0]); /* R */
-            VEC4_MUL(source[0], quad->outputs.color[0], inv_comp); /* R */
-            VEC4_SUB(inv_comp, one, dest[1]); /* G */
-            VEC4_MUL(source[1], quad->outputs.color[1], inv_comp); /* G */
-            VEC4_SUB(inv_comp, one, dest[2]); /* B */
-            VEC4_MUL(source[2], quad->outputs.color[2], inv_comp); /* B */
-         }
-         break;
-      case PIPE_BLENDFACTOR_INV_CONST_COLOR:
-         {
-            GLfloat inv_comp[4];
-            /* R */
-            VEC4_SCALAR(inv_comp, 1.0 - softpipe->blend_color.color[0]);
-            VEC4_MUL(source[0], quad->outputs.color[0], inv_comp);
-            /* G */
-            VEC4_SCALAR(inv_comp, 1.0 - softpipe->blend_color.color[1]);
-            VEC4_MUL(source[1], quad->outputs.color[1], inv_comp);
-            /* B */
-            VEC4_SCALAR(inv_comp, 1.0 - softpipe->blend_color.color[2]);
-            VEC4_MUL(source[2], quad->outputs.color[2], inv_comp);
-         }
-         break;
-      case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
-         {
-            GLfloat alpha[4], inv_alpha[4];
-            VEC4_SCALAR(alpha, 1.0 - softpipe->blend_color.color[3]);
-            VEC4_MUL(source[0], quad->outputs.color[0], inv_alpha); /* R */
-            VEC4_MUL(source[1], quad->outputs.color[1], inv_alpha); /* G */
-            VEC4_MUL(source[2], quad->outputs.color[2], inv_alpha); /* B */
-         }
-         break;
-      case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
-         assert(0); /* to do */
-         break;
-      case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
-         assert(0); /* to do */
-         break;
-      default:
-         abort();
+   /*
+    * Compute src/first term RGB
+    */
+   switch (softpipe->blend.rgb_src_factor) {
+   case PIPE_BLENDFACTOR_ONE:
+      VEC4_COPY(source[0], quad->outputs.color[0]); /* R */
+      VEC4_COPY(source[1], quad->outputs.color[1]); /* G */
+      VEC4_COPY(source[2], quad->outputs.color[2]); /* B */
+      break;
+   case PIPE_BLENDFACTOR_SRC_COLOR:
+      VEC4_MUL(source[0], quad->outputs.color[0], quad->outputs.color[0]); /* R */
+      VEC4_MUL(source[1], quad->outputs.color[1], quad->outputs.color[1]); /* G */
+      VEC4_MUL(source[2], quad->outputs.color[2], quad->outputs.color[2]); /* B */
+      break;
+   case PIPE_BLENDFACTOR_SRC_ALPHA:
+      {
+         const GLfloat *alpha = quad->outputs.color[3];
+         VEC4_MUL(source[0], quad->outputs.color[0], alpha); /* R */
+         VEC4_MUL(source[1], quad->outputs.color[1], alpha); /* G */
+         VEC4_MUL(source[2], quad->outputs.color[2], alpha); /* B */
       }
-
-      /*
-       * Compute src/first term A
-       */
-      switch (softpipe->blend.alpha_src_factor) {
-      case PIPE_BLENDFACTOR_ONE:
-         VEC4_COPY(source[3], quad->outputs.color[3]); /* A */
-         break;
-      case PIPE_BLENDFACTOR_SRC_ALPHA:
-         {
-            const GLfloat *alpha = quad->outputs.color[3];
-            VEC4_MUL(source[3], quad->outputs.color[3], alpha); /* A */
-         }
-         break;
-      case PIPE_BLENDFACTOR_ZERO:
-         VEC4_COPY(source[3], zero); /* A */
-         break;
-         /* XXX fill in remaining terms */
-      default:
-         abort();
+      break;
+   case PIPE_BLENDFACTOR_DST_COLOR:
+      VEC4_MUL(source[0], quad->outputs.color[0], dest[0]); /* R */
+      VEC4_MUL(source[1], quad->outputs.color[1], dest[1]); /* G */
+      VEC4_MUL(source[2], quad->outputs.color[2], dest[2]); /* B */
+      break;
+   case PIPE_BLENDFACTOR_DST_ALPHA:
+      {
+         const GLfloat *alpha = dest[3];
+         VEC4_MUL(source[0], quad->outputs.color[0], alpha); /* R */
+         VEC4_MUL(source[1], quad->outputs.color[1], alpha); /* G */
+         VEC4_MUL(source[2], quad->outputs.color[2], alpha); /* B */
       }
-
-
-      /*
-       * Compute dest/second term RGB
-       */
-      switch (softpipe->blend.rgb_dst_factor) {
-      case PIPE_BLENDFACTOR_ONE:
-         /* dest = dest * 1   NO-OP, leave dest as-is */
-         break;
-      case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
-         {
-            GLfloat one_minus_alpha[QUAD_SIZE];
-            VEC4_SUB(one_minus_alpha, one, quad->outputs.color[3]);
-            VEC4_MUL(dest[0], dest[0], one_minus_alpha); /* R */
-            VEC4_MUL(dest[1], dest[1], one_minus_alpha); /* G */
-            VEC4_MUL(dest[2], dest[2], one_minus_alpha); /* B */
-         }
-         break;
-      case PIPE_BLENDFACTOR_ZERO:
-         VEC4_COPY(dest[0], zero); /* R */
-         VEC4_COPY(dest[1], zero); /* G */
-         VEC4_COPY(dest[2], zero); /* B */
-         break;
-         /* XXX fill in remaining terms */
-      default:
-         abort();
+      break;
+   case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
+      assert(0); /* to do */
+      break;
+   case PIPE_BLENDFACTOR_CONST_COLOR:
+      {
+         GLfloat comp[4];
+         VEC4_SCALAR(comp, softpipe->blend_color.color[0]); /* R */
+         VEC4_MUL(source[0], quad->outputs.color[0], comp); /* R */
+         VEC4_SCALAR(comp, softpipe->blend_color.color[1]); /* G */
+         VEC4_MUL(source[1], quad->outputs.color[1], comp); /* G */
+         VEC4_SCALAR(comp, softpipe->blend_color.color[2]); /* B */
+         VEC4_MUL(source[2], quad->outputs.color[2], comp); /* B */
       }
-
-      /*
-       * Compute dest/second term A
-       */
-      switch (softpipe->blend.alpha_dst_factor) {
-      case PIPE_BLENDFACTOR_ONE:
-         /* dest = dest * 1   NO-OP, leave dest as-is */
-         break;
-      case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
-         {
-            GLfloat one_minus_alpha[QUAD_SIZE];
-            VEC4_SUB(one_minus_alpha, one, quad->outputs.color[3]);
-            VEC4_MUL(dest[3], dest[3], one_minus_alpha); /* A */
-         }
-         break;
-      case PIPE_BLENDFACTOR_ZERO:
-         VEC4_COPY(dest[3], zero); /* A */
-         break;
-         /* XXX fill in remaining terms */
-      default:
-         abort();
+      break;
+   case PIPE_BLENDFACTOR_CONST_ALPHA:
+      {
+         GLfloat alpha[4];
+         VEC4_SCALAR(alpha, softpipe->blend_color.color[3]);
+         VEC4_MUL(source[0], quad->outputs.color[0], alpha); /* R */
+         VEC4_MUL(source[1], quad->outputs.color[1], alpha); /* G */
+         VEC4_MUL(source[2], quad->outputs.color[2], alpha); /* B */
       }
-
-      /*
-       * Combine RGB terms
-       */
-      switch (softpipe->blend.rgb_func) {
-      case PIPE_BLEND_ADD:
-         VEC4_ADD(quad->outputs.color[0], source[0], dest[0]); /* R */
-         VEC4_ADD(quad->outputs.color[1], source[1], dest[1]); /* G */
-         VEC4_ADD(quad->outputs.color[2], source[2], dest[2]); /* B */
-         break;
-      case PIPE_BLEND_SUBTRACT:
-         VEC4_SUB(quad->outputs.color[0], source[0], dest[0]); /* R */
-         VEC4_SUB(quad->outputs.color[1], source[1], dest[1]); /* G */
-         VEC4_SUB(quad->outputs.color[2], source[2], dest[2]); /* B */
-         break;
-      case PIPE_BLEND_REVERSE_SUBTRACT:
-         VEC4_SUB(quad->outputs.color[0], dest[0], source[0]); /* R */
-         VEC4_SUB(quad->outputs.color[1], dest[1], source[1]); /* G */
-         VEC4_SUB(quad->outputs.color[2], dest[2], source[2]); /* B */
-         break;
-      case PIPE_BLEND_MIN:
-         VEC4_MIN(quad->outputs.color[0], source[0], dest[0]); /* R */
-         VEC4_MIN(quad->outputs.color[1], source[1], dest[1]); /* G */
-         VEC4_MIN(quad->outputs.color[2], source[2], dest[2]); /* B */
-         break;
-      case PIPE_BLEND_MAX:
-         VEC4_MAX(quad->outputs.color[0], source[0], dest[0]); /* R */
-         VEC4_MAX(quad->outputs.color[1], source[1], dest[1]); /* G */
-         VEC4_MAX(quad->outputs.color[2], source[2], dest[2]); /* B */
-         break;
-      default:
-         abort();
+      break;
+   case PIPE_BLENDFACTOR_SRC1_COLOR:
+      assert(0); /* to do */
+      break;
+   case PIPE_BLENDFACTOR_SRC1_ALPHA:
+      assert(0); /* to do */
+      break;
+   case PIPE_BLENDFACTOR_ZERO:
+      VEC4_COPY(source[0], zero); /* R */
+      VEC4_COPY(source[1], zero); /* G */
+      VEC4_COPY(source[2], zero); /* B */
+      break;
+   case PIPE_BLENDFACTOR_INV_SRC_COLOR:
+      {
+         GLfloat inv_comp[4];
+         VEC4_SUB(inv_comp, one, quad->outputs.color[0]); /* R */
+         VEC4_MUL(source[0], quad->outputs.color[0], inv_comp); /* R */
+         VEC4_SUB(inv_comp, one, quad->outputs.color[1]); /* G */
+         VEC4_MUL(source[1], quad->outputs.color[1], inv_comp); /* G */
+         VEC4_SUB(inv_comp, one, quad->outputs.color[2]); /* B */
+         VEC4_MUL(source[2], quad->outputs.color[2], inv_comp); /* B */
       }
-
-      /*
-       * Combine A terms
-       */
-      switch (softpipe->blend.alpha_func) {
-      case PIPE_BLEND_ADD:
-         VEC4_ADD(quad->outputs.color[3], source[3], dest[3]); /* A */
-         break;
-      case PIPE_BLEND_SUBTRACT:
-         VEC4_SUB(quad->outputs.color[3], source[3], dest[3]); /* A */
-         break;
-      case PIPE_BLEND_REVERSE_SUBTRACT:
-         VEC4_SUB(quad->outputs.color[3], dest[3], source[3]); /* A */
-         break;
-      case PIPE_BLEND_MIN:
-         VEC4_MIN(quad->outputs.color[3], source[3], dest[3]); /* A */
-         break;
-      case PIPE_BLEND_MAX:
-         VEC4_MAX(quad->outputs.color[3], source[3], dest[3]); /* A */
-      default:
-         abort();
+      break;
+   case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
+      {
+         GLfloat inv_alpha[4];
+         VEC4_SUB(inv_alpha, one, quad->outputs.color[3]);
+         VEC4_MUL(source[0], quad->outputs.color[0], inv_alpha); /* R */
+         VEC4_MUL(source[1], quad->outputs.color[1], inv_alpha); /* G */
+         VEC4_MUL(source[2], quad->outputs.color[2], inv_alpha); /* B */
       }
-
-      /* pass blended quad to next stage */
-      qs->next->run(qs->next, quad);
+      break;
+   case PIPE_BLENDFACTOR_INV_DST_ALPHA:
+      {
+         GLfloat inv_alpha[4];
+         VEC4_SUB(inv_alpha, one, dest[3]);
+         VEC4_MUL(source[0], quad->outputs.color[0], inv_alpha); /* R */
+         VEC4_MUL(source[1], quad->outputs.color[1], inv_alpha); /* G */
+         VEC4_MUL(source[2], quad->outputs.color[2], inv_alpha); /* B */
+      }
+      break;
+   case PIPE_BLENDFACTOR_INV_DST_COLOR:
+      {
+         GLfloat inv_comp[4];
+         VEC4_SUB(inv_comp, one, dest[0]); /* R */
+         VEC4_MUL(source[0], quad->outputs.color[0], inv_comp); /* R */
+         VEC4_SUB(inv_comp, one, dest[1]); /* G */
+         VEC4_MUL(source[1], quad->outputs.color[1], inv_comp); /* G */
+         VEC4_SUB(inv_comp, one, dest[2]); /* B */
+         VEC4_MUL(source[2], quad->outputs.color[2], inv_comp); /* B */
+      }
+      break;
+   case PIPE_BLENDFACTOR_INV_CONST_COLOR:
+      {
+         GLfloat inv_comp[4];
+         /* R */
+         VEC4_SCALAR(inv_comp, 1.0 - softpipe->blend_color.color[0]);
+         VEC4_MUL(source[0], quad->outputs.color[0], inv_comp);
+         /* G */
+         VEC4_SCALAR(inv_comp, 1.0 - softpipe->blend_color.color[1]);
+         VEC4_MUL(source[1], quad->outputs.color[1], inv_comp);
+         /* B */
+         VEC4_SCALAR(inv_comp, 1.0 - softpipe->blend_color.color[2]);
+         VEC4_MUL(source[2], quad->outputs.color[2], inv_comp);
+      }
+      break;
+   case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
+      {
+         GLfloat alpha[4], inv_alpha[4];
+         VEC4_SCALAR(alpha, 1.0 - softpipe->blend_color.color[3]);
+         VEC4_MUL(source[0], quad->outputs.color[0], inv_alpha); /* R */
+         VEC4_MUL(source[1], quad->outputs.color[1], inv_alpha); /* G */
+         VEC4_MUL(source[2], quad->outputs.color[2], inv_alpha); /* B */
+      }
+      break;
+   case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
+      assert(0); /* to do */
+      break;
+   case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
+      assert(0); /* to do */
+      break;
+   default:
+      abort();
+   }
+   
+   /*
+    * Compute src/first term A
+    */
+   switch (softpipe->blend.alpha_src_factor) {
+   case PIPE_BLENDFACTOR_ONE:
+      VEC4_COPY(source[3], quad->outputs.color[3]); /* A */
+      break;
+   case PIPE_BLENDFACTOR_SRC_ALPHA:
+      {
+         const GLfloat *alpha = quad->outputs.color[3];
+         VEC4_MUL(source[3], quad->outputs.color[3], alpha); /* A */
+      }
+      break;
+   case PIPE_BLENDFACTOR_ZERO:
+      VEC4_COPY(source[3], zero); /* A */
+      break;
+      /* XXX fill in remaining terms */
+   default:
+      abort();
+   }
+   
+   
+   /*
+    * Compute dest/second term RGB
+    */
+   switch (softpipe->blend.rgb_dst_factor) {
+   case PIPE_BLENDFACTOR_ONE:
+      /* dest = dest * 1   NO-OP, leave dest as-is */
+      break;
+   case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
+      {
+         GLfloat one_minus_alpha[QUAD_SIZE];
+         VEC4_SUB(one_minus_alpha, one, quad->outputs.color[3]);
+         VEC4_MUL(dest[0], dest[0], one_minus_alpha); /* R */
+         VEC4_MUL(dest[1], dest[1], one_minus_alpha); /* G */
+         VEC4_MUL(dest[2], dest[2], one_minus_alpha); /* B */
+      }
+      break;
+   case PIPE_BLENDFACTOR_ZERO:
+      VEC4_COPY(dest[0], zero); /* R */
+      VEC4_COPY(dest[1], zero); /* G */
+      VEC4_COPY(dest[2], zero); /* B */
+      break;
+      /* XXX fill in remaining terms */
+   default:
+      abort();
+   }
+   
+   /*
+    * Compute dest/second term A
+    */
+   switch (softpipe->blend.alpha_dst_factor) {
+   case PIPE_BLENDFACTOR_ONE:
+      /* dest = dest * 1   NO-OP, leave dest as-is */
+      break;
+   case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
+      {
+         GLfloat one_minus_alpha[QUAD_SIZE];
+         VEC4_SUB(one_minus_alpha, one, quad->outputs.color[3]);
+         VEC4_MUL(dest[3], dest[3], one_minus_alpha); /* A */
+      }
+      break;
+   case PIPE_BLENDFACTOR_ZERO:
+      VEC4_COPY(dest[3], zero); /* A */
+      break;
+      /* XXX fill in remaining terms */
+   default:
+      abort();
+   }
+   
+   /*
+    * Combine RGB terms
+    */
+   switch (softpipe->blend.rgb_func) {
+   case PIPE_BLEND_ADD:
+      VEC4_ADD(quad->outputs.color[0], source[0], dest[0]); /* R */
+      VEC4_ADD(quad->outputs.color[1], source[1], dest[1]); /* G */
+      VEC4_ADD(quad->outputs.color[2], source[2], dest[2]); /* B */
+      break;
+   case PIPE_BLEND_SUBTRACT:
+      VEC4_SUB(quad->outputs.color[0], source[0], dest[0]); /* R */
+      VEC4_SUB(quad->outputs.color[1], source[1], dest[1]); /* G */
+      VEC4_SUB(quad->outputs.color[2], source[2], dest[2]); /* B */
+      break;
+   case PIPE_BLEND_REVERSE_SUBTRACT:
+      VEC4_SUB(quad->outputs.color[0], dest[0], source[0]); /* R */
+      VEC4_SUB(quad->outputs.color[1], dest[1], source[1]); /* G */
+      VEC4_SUB(quad->outputs.color[2], dest[2], source[2]); /* B */
+      break;
+   case PIPE_BLEND_MIN:
+      VEC4_MIN(quad->outputs.color[0], source[0], dest[0]); /* R */
+      VEC4_MIN(quad->outputs.color[1], source[1], dest[1]); /* G */
+      VEC4_MIN(quad->outputs.color[2], source[2], dest[2]); /* B */
+      break;
+   case PIPE_BLEND_MAX:
+      VEC4_MAX(quad->outputs.color[0], source[0], dest[0]); /* R */
+      VEC4_MAX(quad->outputs.color[1], source[1], dest[1]); /* G */
+      VEC4_MAX(quad->outputs.color[2], source[2], dest[2]); /* B */
+      break;
+   default:
+      abort();
    }
+   
+   /*
+    * Combine A terms
+    */
+   switch (softpipe->blend.alpha_func) {
+   case PIPE_BLEND_ADD:
+      VEC4_ADD(quad->outputs.color[3], source[3], dest[3]); /* A */
+      break;
+   case PIPE_BLEND_SUBTRACT:
+      VEC4_SUB(quad->outputs.color[3], source[3], dest[3]); /* A */
+      break;
+   case PIPE_BLEND_REVERSE_SUBTRACT:
+      VEC4_SUB(quad->outputs.color[3], dest[3], source[3]); /* A */
+      break;
+   case PIPE_BLEND_MIN:
+      VEC4_MIN(quad->outputs.color[3], source[3], dest[3]); /* A */
+      break;
+   case PIPE_BLEND_MAX:
+      VEC4_MAX(quad->outputs.color[3], source[3], dest[3]); /* A */
+   default:
+      abort();
+   }
+   
+   /* pass blended quad to next stage */
+   qs->next->run(qs->next, quad);
 }
 
 
diff --git a/src/mesa/pipe/softpipe/sp_quad_bufloop.c b/src/mesa/pipe/softpipe/sp_quad_bufloop.c
new file mode 100644 (file)
index 0000000..977cc74
--- /dev/null
@@ -0,0 +1,59 @@
+
+
+#include "main/glheader.h"
+#include "main/imports.h"
+#include "sp_context.h"
+#include "sp_headers.h"
+#include "sp_surface.h"
+#include "sp_quad.h"
+
+
+/**
+ * Loop over colorbuffers, passing quad to next stage each time.
+ */
+static void
+cbuf_loop_quad(struct quad_stage *qs, struct quad_header *quad)
+{
+   struct softpipe_context *softpipe = qs->softpipe;
+   const GLuint sz = sizeof(quad->outputs.color);
+   GLfloat tmp[4][QUAD_SIZE];
+   GLuint i;
+
+   assert(sz == sizeof(tmp));
+
+   /* make copy of original colors since they can get modified
+    * by blending and masking.
+    */
+   memcpy(tmp, quad->outputs.color, sz);
+
+   for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) {
+      /* set current cbuffer */
+      softpipe->cbuf = softpipe->framebuffer.cbufs[i];
+
+      /* pass blended quad to next stage */
+      qs->next->run(qs->next, quad);
+
+      if (i + 1 < softpipe->framebuffer.num_cbufs) {
+         /* restore quad's colors for next buffer */
+         memcpy(quad->outputs.color, tmp, sz);
+      }
+   }
+
+   softpipe->cbuf = NULL; /* prevent accidental use */
+}
+
+
+/**
+ * Create the colorbuffer loop stage.
+ * This is used to implement GL_FRONT_AND_BACK rendering.
+ */
+struct quad_stage *sp_quad_bufloop_stage( struct softpipe_context *softpipe )
+{
+   struct quad_stage *stage = CALLOC_STRUCT(quad_stage);
+
+   stage->softpipe = softpipe;
+   stage->run = cbuf_loop_quad;
+
+   return stage;
+}
+
index 6fb228fddaf1d5525c4ddfd078963c579fb75b6a..fff6efa8f6ab9b061f78661249c42c425dd76867 100644 (file)
@@ -45,12 +45,8 @@ static void
 colormask_quad(struct quad_stage *qs, struct quad_header *quad)
 {
    struct softpipe_context *softpipe = qs->softpipe;
+   struct softpipe_surface *sps = softpipe_surface(softpipe->cbuf);
    GLfloat dest[4][QUAD_SIZE];
-
-   /* XXX buffer looping */
-
-   struct softpipe_surface *sps
-      = softpipe_surface(softpipe->framebuffer.cbufs[0]);
    
    sps->read_quad_f_swz(sps, quad->x0, quad->y0, dest);
 
index e898757a065be99114379fb4ee8734a931b7dc89..12ab1eca1c749085c2fedd8c2ae24c328165f1eb 100644 (file)
@@ -65,28 +65,21 @@ static void
 output_quad(struct quad_stage *qs, struct quad_header *quad)
 {
    struct softpipe_context *softpipe = qs->softpipe;
-   GLuint i;
+   struct softpipe_surface *sps = softpipe_surface(softpipe->cbuf);
 
-   for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) {
-      struct softpipe_surface *sps
-         = softpipe_surface(softpipe->framebuffer.cbufs[i]);
+   if (quad->mask != MASK_ALL) {
+      GLfloat tmp[4][QUAD_SIZE];
 
-      if (quad->mask != MASK_ALL) {
-         GLfloat tmp[4][QUAD_SIZE];
+      /* XXX probably add a masked-write function someday */
 
-         /* Yes, we'll probably have a masked write as well, but this is
-          * how blend will be done at least.
-          */
+      sps->read_quad_f_swz(sps, quad->x0, quad->y0, tmp);
 
-         sps->read_quad_f_swz(sps, quad->x0, quad->y0, tmp);
+      mask_copy( tmp, quad->outputs.color, quad->mask );
 
-         mask_copy( tmp, quad->outputs.color, quad->mask );
-
-         sps->write_quad_f_swz(sps, quad->x0, quad->y0, tmp);
-      }
-      else {
-         sps->write_quad_f_swz(sps, quad->x0, quad->y0, quad->outputs.color);
-      }
+      sps->write_quad_f_swz(sps, quad->x0, quad->y0, tmp);
+   }
+   else if (quad->mask) {
+      sps->write_quad_f_swz(sps, quad->x0, quad->y0, quad->outputs.color);
    }
 }
 
@@ -100,4 +93,3 @@ struct quad_stage *sp_quad_output_stage( struct softpipe_context *softpipe )
 
    return stage;
 }
-
index 78a030b767d79bc1e6160d9cf59e4118476e7459..4856f7b023ce13318ce091b3720d514a13ffd9ea 100644 (file)
@@ -160,6 +160,7 @@ SOFTPIPE_SOURCES = \
        pipe/softpipe/sp_quad.c \
        pipe/softpipe/sp_quad_alpha_test.c \
        pipe/softpipe/sp_quad_blend.c \
+       pipe/softpipe/sp_quad_bufloop.c \
        pipe/softpipe/sp_quad_colormask.c \
        pipe/softpipe/sp_quad_depth_test.c \
        pipe/softpipe/sp_quad_fs.c \