From 7658a0208aa31f1443be6eaa720a383b34e2bbb3 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 20 Jun 2007 15:14:47 -0600 Subject: quad blending works now, but many blend terms need to be added in blend_quad(). --- src/mesa/pipe/softpipe/sp_context.c | 1 + src/mesa/pipe/softpipe/sp_state.h | 3 + src/mesa/pipe/softpipe/sp_state_blend.c | 47 ++++++++++ src/mesa/pipe/softpipe/sp_tile_blend.c | 157 +++++++++++++++++++++++++++----- src/mesa/sources | 1 + 5 files changed, 185 insertions(+), 24 deletions(-) create mode 100644 src/mesa/pipe/softpipe/sp_state_blend.c diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index d1023fb782..593be0e132 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -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; diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index bc5a3512ae..5a657c4a8f 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -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 index 0000000000..1fd7a44105 --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_state_blend.c @@ -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 + */ +#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; +} + diff --git a/src/mesa/pipe/softpipe/sp_tile_blend.c b/src/mesa/pipe/softpipe/sp_tile_blend.c index 5681528d06..40af57149d 100644 --- a/src/mesa/pipe/softpipe/sp_tile_blend.c +++ b/src/mesa/pipe/softpipe/sp_tile_blend.c @@ -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); } } diff --git a/src/mesa/sources b/src/mesa/sources index d07bd3fbe0..cc675eab39 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -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 \ -- cgit v1.2.3