Implement polygon stipple state tracking, application.
authorBrian <brian.paul@tungstengraphics.com>
Wed, 11 Jul 2007 17:34:19 +0000 (11:34 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Wed, 11 Jul 2007 17:34:19 +0000 (11:34 -0600)
src/mesa/pipe/softpipe/sp_context.c
src/mesa/pipe/softpipe/sp_context.h
src/mesa/pipe/softpipe/sp_prim_setup.c
src/mesa/pipe/softpipe/sp_quad.c
src/mesa/pipe/softpipe/sp_quad.h
src/mesa/pipe/softpipe/sp_quad_stipple.c [new file with mode: 0644]
src/mesa/pipe/softpipe/sp_state_derived.c
src/mesa/sources
src/mesa/state_tracker/st_atom.c
src/mesa/state_tracker/st_atom.h
src/mesa/state_tracker/st_atom_stipple.c [new file with mode: 0644]

index 5043460..a5bd61b 100644 (file)
@@ -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);
index 2379a99..21d6108 100644 (file)
@@ -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;
index 3321139..0148a26 100644 (file)
@@ -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);
index 31278f5..aba5ab2 100644 (file)
@@ -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;
+   }
 }
index df416df..8b8e122 100644 (file)
@@ -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 (file)
index 0000000..f9a3c0b
--- /dev/null
@@ -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;
+}
index 429ae55..34c893e 100644 (file)
@@ -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;
index 1ffac8d..a7d132f 100644 (file)
@@ -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 \
index 88c6c77..dfebfb4 100644 (file)
@@ -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,
index 7ea3301..a56483a 100644 (file)
@@ -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 (file)
index 0000000..dd04d21
--- /dev/null
@@ -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
+};