quad blending works now, but many blend terms need to be added in blend_quad().
authorBrian <brian.paul@tungstengraphics.com>
Wed, 20 Jun 2007 21:14:47 +0000 (15:14 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Wed, 20 Jun 2007 21:14:47 +0000 (15:14 -0600)
src/mesa/pipe/softpipe/sp_context.c
src/mesa/pipe/softpipe/sp_state.h
src/mesa/pipe/softpipe/sp_state_blend.c [new file with mode: 0644]
src/mesa/pipe/softpipe/sp_tile_blend.c
src/mesa/sources

index d1023fb78225acb2c8bdfb37a5c7ff86cf1d5865..593be0e13287cda082cd272d5185db9f1d3f9b55 100644 (file)
@@ -65,6 +65,7 @@ struct pipe_context *softpipe_create( void )
 
    softpipe->pipe.destroy = softpipe_destroy;
    softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state;
+   softpipe->pipe.set_blend_state = softpipe_set_blend_state;
    softpipe->pipe.set_clip_state = softpipe_set_clip_state;
    softpipe->pipe.set_clear_color_state = softpipe_set_clear_color_state;
    softpipe->pipe.set_point_state = softpipe_set_point_state;
index bc5a3512ae173e37044670765db74b7af20e91d2..5a657c4a8f9351a44236a9d4bd25823a4f8ba080 100644 (file)
@@ -38,6 +38,9 @@
 void softpipe_set_framebuffer_state( struct pipe_context *,
                             const struct pipe_framebuffer_state * );
 
+void softpipe_set_blend_state( struct pipe_context *,
+                               const struct pipe_blend_state * );
+
 void softpipe_set_clear_color_state( struct pipe_context *,
                                      const struct pipe_clear_color_state * );
 
diff --git a/src/mesa/pipe/softpipe/sp_state_blend.c b/src/mesa/pipe/softpipe/sp_state_blend.c
new file mode 100644 (file)
index 0000000..1fd7a44
--- /dev/null
@@ -0,0 +1,47 @@
+/**************************************************************************
+ * 
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * 
+ **************************************************************************/
+
+/* Authors:  Keith Whitwell <keith@tungstengraphics.com>
+ */
+#include "imports.h"
+
+#include "sp_context.h"
+#include "sp_state.h"
+#include "sp_draw.h"
+
+
+
+void softpipe_set_blend_state( struct pipe_context *pipe,
+                            const struct pipe_blend_state *blend )
+{
+   struct softpipe_context *softpipe = softpipe_context(pipe);
+
+   softpipe->blend = *blend;
+
+   softpipe->dirty |= G_NEW_BLEND;
+}
+
index 5681528d0675f8a6442ef54849ad1f3b72a16ff8..40af57149d0cdbf57fda310c2344651860a0af75 100644 (file)
@@ -1,33 +1,39 @@
-/*
- * Mesa 3-D graphics library
- * Version:  6.5
- *
- * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
- *
+/**************************************************************************
+ * 
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ * 
  * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * 
+ **************************************************************************/
 
 /**
  * quad blending
+ * \author Brian Paul
  */
 
 #include "glheader.h"
 #include "imports.h"
+#include "macros.h"
+#include "pipe/p_defines.h"
 #include "sp_context.h"
 #include "sp_headers.h"
 #include "sp_surface.h"
@@ -39,19 +45,122 @@ static void
 blend_quad(struct quad_stage *qs, struct quad_header *quad)
 {
    struct softpipe_context *softpipe = qs->softpipe;
-   GLfloat dest[4][QUAD_SIZE], result[4][QUAD_SIZE];
-   GLuint i;
+   GLfloat source[4][QUAD_SIZE], dest[4][QUAD_SIZE];
+   GLuint i, j;
 
    /* XXX we're also looping in output_quad() !?! */
 
+   /* copy quad's colors since we'll modify them in the loop */
+   memcpy(source, quad->outputs.color, 4 * 4 * sizeof(GLfloat));
+
    for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) {
+      GLfloat srcTerm[4], dstTerm[4];
       struct softpipe_surface *sps
          = softpipe_surface(softpipe->framebuffer.cbufs[i]);
    
       sps->read_quad_f_swz(sps, quad->x0, quad->y0, dest);
 
-      /* XXX do blend here */
+      /* XXX this loop could be factored out - we'd compute the src/dstTerm
+       * for all four pixels in the quad at once.
+       */
+      for (j = 0; j < QUAD_SIZE; j++) {
+         switch (softpipe->blend.rgb_src_factor) {
+         case PIPE_BLENDFACTOR_ONE:
+            srcTerm[0] = srcTerm[1] = srcTerm[2] = 1.0;
+            break;
+         case PIPE_BLENDFACTOR_SRC_ALPHA:
+            srcTerm[0] = srcTerm[1] = srcTerm[2] = quad->outputs.color[3][j];
+            break;
+         case PIPE_BLENDFACTOR_ZERO:
+            srcTerm[0] = srcTerm[1] = srcTerm[2] = 0.0;
+            break;
+            /* XXX fill in remaining terms */
+         default:
+            abort();
+         }
+
+         switch (softpipe->blend.alpha_src_factor) {
+         case PIPE_BLENDFACTOR_ONE:
+            srcTerm[3] = 1.0;
+            break;
+         case PIPE_BLENDFACTOR_SRC_ALPHA:
+            srcTerm[3] = quad->outputs.color[3][j];
+            break;
+         case PIPE_BLENDFACTOR_ZERO:
+            srcTerm[3] = 0.0;
+            break;
+            /* XXX fill in remaining terms */
+         default:
+            abort();
+         }
+
+         switch (softpipe->blend.rgb_dst_factor) {
+         case PIPE_BLENDFACTOR_ONE:
+            dstTerm[0] = dstTerm[1] = dstTerm[2] = 1.0;
+            break;
+         case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
+            dstTerm[0] = dstTerm[1] = dstTerm[2] = 1.0 - quad->outputs.color[3][j];
+            break;
+         case PIPE_BLENDFACTOR_ZERO:
+            dstTerm[0] = dstTerm[1] = dstTerm[2] = 0.0;
+            break;
+            /* XXX fill in remaining terms */
+         default:
+            abort();
+         }
+
+         switch (softpipe->blend.alpha_dst_factor) {
+         case PIPE_BLENDFACTOR_ONE:
+            dstTerm[3] = 1.0;
+            break;
+         case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
+            dstTerm[3] = 1.0 - quad->outputs.color[3][j];
+            break;
+         case PIPE_BLENDFACTOR_ZERO:
+            dstTerm[3] = 0.0;
+            break;
+            /* XXX fill in remaining terms */
+         default:
+            abort();
+         }
+
+         switch (softpipe->blend.rgb_func) {
+         case PIPE_BLEND_ADD:
+            quad->outputs.color[0][j] = source[0][j] * srcTerm[0] + dest[0][j] * dstTerm[0];
+            quad->outputs.color[1][j] = source[1][j] * srcTerm[1] + dest[1][j] * dstTerm[1];
+            quad->outputs.color[2][j] = source[2][j] * srcTerm[2] + dest[2][j] * dstTerm[2];
+            quad->outputs.color[3][j] = source[3][j] * srcTerm[3] + dest[3][j] * dstTerm[3];
+            break;
+         case PIPE_BLEND_SUBTRACT:
+            quad->outputs.color[0][j] = source[0][j] * srcTerm[0] - dest[0][j] * dstTerm[0];
+            quad->outputs.color[1][j] = source[1][j] * srcTerm[1] - dest[1][j] * dstTerm[1];
+            quad->outputs.color[2][j] = source[2][j] * srcTerm[2] - dest[2][j] * dstTerm[2];
+            quad->outputs.color[3][j] = source[3][j] * srcTerm[3] - dest[3][j] * dstTerm[3];
+            break;
+         case PIPE_BLEND_REVERSE_SUBTRACT:
+            quad->outputs.color[0][j] = dest[0][j] * dstTerm[0] - source[0][j] * srcTerm[0];
+            quad->outputs.color[1][j] = dest[1][j] * dstTerm[1] - source[1][j] * srcTerm[1];
+            quad->outputs.color[2][j] = dest[2][j] * dstTerm[2] - source[2][j] * srcTerm[2];
+            quad->outputs.color[3][j] = dest[3][j] * dstTerm[3] - source[3][j] * srcTerm[3];
+            break;
+         case PIPE_BLEND_MIN:
+            quad->outputs.color[0][j] = MIN2(dest[0][j], source[0][j]);
+            quad->outputs.color[1][j] = MIN2(dest[1][j], source[1][j]);
+            quad->outputs.color[2][j] = MIN2(dest[2][j], source[2][j]);
+            quad->outputs.color[3][j] = MIN2(dest[3][j], source[3][j]);
+            break;
+         case PIPE_BLEND_MAX:
+            quad->outputs.color[0][j] = MAX2(dest[0][j], source[0][j]);
+            quad->outputs.color[1][j] = MAX2(dest[1][j], source[1][j]);
+            quad->outputs.color[2][j] = MAX2(dest[2][j], source[2][j]);
+            quad->outputs.color[3][j] = MAX2(dest[3][j], source[3][j]);
+            break;
+         default:
+            abort();
+         }
+      } /* loop over quads */
 
+      /* pass blended quad to next stage */
       qs->next->run(qs->next, quad);
    }
 }
index d07bd3fbe08398b41b0983559277db4a4f956788..cc675eab39dd4d137d0be75c0639e7a60e0174e5 100644 (file)
@@ -165,6 +165,7 @@ SOFTPIPE_SOURCES = \
        pipe/softpipe/sp_prim_setup.c \
        pipe/softpipe/sp_prim_twoside.c \
        pipe/softpipe/sp_prim_unfilled.c \
+       pipe/softpipe/sp_state_blend.c \
        pipe/softpipe/sp_state_clip.c \
        pipe/softpipe/sp_state_derived.c \
        pipe/softpipe/sp_state_fs.c \