diff options
author | Brian <[email protected]> | 2007-06-20 15:14:47 -0600 |
---|---|---|
committer | Brian <[email protected]> | 2007-06-20 15:14:47 -0600 |
commit | 7658a0208aa31f1443be6eaa720a383b34e2bbb3 (patch) | |
tree | b0f7c914bb17a5aff40b5a195f10cec076db0337 /src/mesa/pipe | |
parent | fb5cdbd078d4d44fb43d417843debe41148f3714 (diff) |
quad blending works now, but many blend terms need to be added in blend_quad().
Diffstat (limited to 'src/mesa/pipe')
-rw-r--r-- | src/mesa/pipe/softpipe/sp_context.c | 1 | ||||
-rw-r--r-- | src/mesa/pipe/softpipe/sp_state.h | 3 | ||||
-rw-r--r-- | src/mesa/pipe/softpipe/sp_state_blend.c | 47 | ||||
-rw-r--r-- | src/mesa/pipe/softpipe/sp_tile_blend.c | 157 |
4 files changed, 184 insertions, 24 deletions
diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index d1023fb7822..593be0e1328 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 bc5a3512ae1..5a657c4a8f9 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 00000000000..1fd7a44105b --- /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 <[email protected]> + */ +#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 5681528d067..40af57149d0 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); } } |