From: Brian Date: Wed, 11 Jul 2007 17:34:19 +0000 (-0600) Subject: Implement polygon stipple state tracking, application. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e89bd0fbc56ecfb96f3aff926c5891c45221dd37;p=mesa.git Implement polygon stipple state tracking, application. --- diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 50434600c3f..a5bd61b7842 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -83,6 +83,7 @@ struct pipe_context *softpipe_create( void ) softpipe->pipe.draw_vb = softpipe_draw_vb; softpipe->pipe.clear = softpipe_clear; + softpipe->quad.polygon_stipple = sp_quad_polygon_stipple_stage(softpipe); softpipe->quad.shade = sp_quad_shade_stage(softpipe); softpipe->quad.alpha_test = sp_quad_alpha_test_stage(softpipe); softpipe->quad.blend = sp_quad_blend_stage(softpipe); diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 2379a99b81f..21d6108ac6e 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -117,6 +117,7 @@ struct softpipe_context { /** Software quad rendering pipeline */ struct { + struct quad_stage *polygon_stipple; struct quad_stage *shade; struct quad_stage *alpha_test; struct quad_stage *stencil_test; diff --git a/src/mesa/pipe/softpipe/sp_prim_setup.c b/src/mesa/pipe/softpipe/sp_prim_setup.c index 332113979c0..0148a26259b 100644 --- a/src/mesa/pipe/softpipe/sp_prim_setup.c +++ b/src/mesa/pipe/softpipe/sp_prim_setup.c @@ -922,6 +922,9 @@ static void setup_end( struct prim_stage *stage ) } +/** + * Create a new primitive setup/render stage. + */ struct prim_stage *prim_setup( struct softpipe_context *softpipe ) { struct setup_stage *setup = CALLOC_STRUCT(setup_stage); diff --git a/src/mesa/pipe/softpipe/sp_quad.c b/src/mesa/pipe/softpipe/sp_quad.c index 31278f529d7..aba5ab280e6 100644 --- a/src/mesa/pipe/softpipe/sp_quad.c +++ b/src/mesa/pipe/softpipe/sp_quad.c @@ -37,4 +37,8 @@ sp_build_quad_pipeline(struct softpipe_context *sp) sp->quad.first = sp->quad.shade; } + if (sp->setup.poly_stipple_enable) { + sp->quad.polygon_stipple->next = sp->quad.first; + sp->quad.first = sp->quad.polygon_stipple; + } } diff --git a/src/mesa/pipe/softpipe/sp_quad.h b/src/mesa/pipe/softpipe/sp_quad.h index df416dfa7f2..8b8e12261b4 100644 --- a/src/mesa/pipe/softpipe/sp_quad.h +++ b/src/mesa/pipe/softpipe/sp_quad.h @@ -46,6 +46,7 @@ struct quad_stage { }; +struct quad_stage *sp_quad_polygon_stipple_stage( struct softpipe_context *softpipe ); 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 ); diff --git a/src/mesa/pipe/softpipe/sp_quad_stipple.c b/src/mesa/pipe/softpipe/sp_quad_stipple.c new file mode 100644 index 00000000000..f9a3c0ba265 --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_quad_stipple.c @@ -0,0 +1,56 @@ + +/** + * quad polygon stipple stage + */ + +#include "glheader.h" +#include "imports.h" +#include "sp_context.h" +#include "sp_headers.h" +#include "sp_quad.h" +#include "pipe/p_defines.h" + + +/** + * Apply polygon stipple to quads produced by triangle rasterization + */ +static void +stipple_quad(struct quad_stage *qs, struct quad_header *quad) +{ + struct softpipe_context *softpipe = qs->softpipe; + const GLint col0 = quad->x0 % 32; + const GLint row0 = quad->y0 % 32; + const GLuint stipple0 = softpipe->poly_stipple.stipple[row0]; + const GLuint stipple1 = softpipe->poly_stipple.stipple[row0 + 1]; + GLbitfield mask = 0x0; + + /* XXX this could be optimize a bit to use just two conditionals */ + if ((1 << col0) & stipple0) + mask |= MASK_BOTTOM_LEFT; + + if ((2 << col0) & stipple0) + mask |= MASK_BOTTOM_RIGHT; + + if ((1 << col0) & stipple1) + mask |= MASK_TOP_LEFT; + + if ((2 << col0) & stipple1) + mask |= MASK_TOP_RIGHT; + + quad->mask &= mask; + + if (quad->mask) + qs->next->run(qs->next, quad); +} + + +struct quad_stage * +sp_quad_polygon_stipple_stage( struct softpipe_context *softpipe ) +{ + struct quad_stage *stage = CALLOC_STRUCT(quad_stage); + + stage->softpipe = softpipe; + stage->run = stipple_quad; + + return stage; +} diff --git a/src/mesa/pipe/softpipe/sp_state_derived.c b/src/mesa/pipe/softpipe/sp_state_derived.c index 429ae55397e..34c893e396a 100644 --- a/src/mesa/pipe/softpipe/sp_state_derived.c +++ b/src/mesa/pipe/softpipe/sp_state_derived.c @@ -137,7 +137,12 @@ void softpipe_update_derived( struct softpipe_context *softpipe ) if (softpipe->dirty & (SP_NEW_SETUP | SP_NEW_FS)) calculate_vertex_layout( softpipe ); - if (softpipe->dirty & (SP_NEW_BLEND | SP_NEW_DEPTH_TEST | SP_NEW_ALPHA_TEST | SP_NEW_FS)) + if (softpipe->dirty & (SP_NEW_BLEND | + SP_NEW_DEPTH_TEST | + SP_NEW_ALPHA_TEST | + SP_NEW_STENCIL | + SP_NEW_SETUP | + SP_NEW_FS)) sp_build_quad_pipeline(softpipe); softpipe->dirty = 0; diff --git a/src/mesa/sources b/src/mesa/sources index 1ffac8df0ab..a7d132f4fdb 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -163,6 +163,7 @@ SOFTPIPE_SOURCES = \ pipe/softpipe/sp_quad_depth_test.c \ pipe/softpipe/sp_quad_fs.c \ pipe/softpipe/sp_quad_output.c \ + pipe/softpipe/sp_quad_stipple.c \ pipe/softpipe/sp_quad_stencil.c \ pipe/softpipe/sp_state_blend.c \ pipe/softpipe/sp_state_clip.c \ @@ -206,6 +207,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_atom_scissor.c \ state_tracker/st_atom_setup.c \ state_tracker/st_atom_stencil.c \ + state_tracker/st_atom_stipple.c \ state_tracker/st_atom_viewport.c \ state_tracker/st_cb_program.c \ state_tracker/st_draw.c \ diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index 88c6c776a3a..dfebfb4768c 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -48,6 +48,7 @@ static const struct st_tracked_state *atoms[] = &st_update_clip, &st_update_fs, &st_update_setup, + &st_update_polygon_stipple, &st_update_viewport, &st_update_scissor, &st_update_blend, diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h index 7ea3301ea57..a56483ac396 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -50,6 +50,7 @@ const struct st_tracked_state st_update_clear_color; const struct st_tracked_state st_update_depth; const struct st_tracked_state st_update_fs; const struct st_tracked_state st_update_setup; +const struct st_tracked_state st_update_polygon_stipple; const struct st_tracked_state st_update_viewport; const struct st_tracked_state st_update_constants; const struct st_tracked_state st_update_scissor; diff --git a/src/mesa/state_tracker/st_atom_stipple.c b/src/mesa/state_tracker/st_atom_stipple.c new file mode 100644 index 00000000000..dd04d2158c7 --- /dev/null +++ b/src/mesa/state_tracker/st_atom_stipple.c @@ -0,0 +1,62 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + /* + * \brief polygon stipple state + * + * Authors: + * Brian Paul + */ + + +#include "st_context.h" +#include "st_atom.h" +#include "pipe/p_context.h" +#include "pipe/p_defines.h" + + +static void +update_stipple( struct st_context *st ) +{ + const GLuint sz = sizeof(st->state.poly_stipple.stipple); + assert(sz == sizeof(st->ctx->PolygonStipple)); + + if (memcmp(&st->state.poly_stipple.stipple, st->ctx->PolygonStipple, sz)) { + /* state has changed */ + memcpy(st->state.poly_stipple.stipple, st->ctx->PolygonStipple, sz); + st->pipe->set_polygon_stipple(st->pipe, &st->state.poly_stipple); + } +} + + +const struct st_tracked_state st_update_polygon_stipple = { + .dirty = { + .mesa = (_NEW_POLYGONSTIPPLE), + .st = 0, + }, + .update = update_stipple +};