summaryrefslogtreecommitdiffstats
path: root/src/mesa/pipe/draw
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-08-30 16:37:56 -0600
committerBrian <[email protected]>2007-08-30 16:37:56 -0600
commit963b8a74493a474560447080b23407bfe4c707c5 (patch)
treec6543db1fc959a433ee7487f2dcc68d947193b2b /src/mesa/pipe/draw
parentc9e133eab450870c8804e1d3d1e7a44f509454a0 (diff)
Remove dependency on TGSI_ATTRIB_x tokens in draw_twoside.c
Added a new draw_set_twoside_attributes() function for specifying which vertex attributes are to be copied/replaced when a polygon is back-facing.
Diffstat (limited to 'src/mesa/pipe/draw')
-rw-r--r--src/mesa/pipe/draw/draw_context.c41
-rw-r--r--src/mesa/pipe/draw/draw_context.h4
-rw-r--r--src/mesa/pipe/draw/draw_private.h3
-rw-r--r--src/mesa/pipe/draw/draw_twoside.c26
4 files changed, 60 insertions, 14 deletions
diff --git a/src/mesa/pipe/draw/draw_context.c b/src/mesa/pipe/draw/draw_context.c
index b14de341410..c15f7652a6f 100644
--- a/src/mesa/pipe/draw/draw_context.c
+++ b/src/mesa/pipe/draw/draw_context.c
@@ -67,6 +67,11 @@ struct draw_context *draw_create( void )
draw->vcache.vertex[i] = (struct vertex_header *)(tmp + i * MAX_VERTEX_SIZE);
}
+ draw->attrib_front0 = -1;
+ draw->attrib_back0 = -1;
+ draw->attrib_front1 = -1;
+ draw->attrib_back1 = -1;
+
return draw;
}
@@ -210,3 +215,39 @@ draw_set_vertex_shader(struct draw_context *draw,
{
draw->vertex_shader = *shader;
}
+
+
+/**
+ * This function is used to tell the draw module about attributes
+ * (like colors) that need to be selected based on front/back face
+ * orientation.
+ *
+ * The logic is:
+ * if (polygon is back-facing) {
+ * vertex->attrib[front0] = vertex->attrib[back0];
+ * vertex->attrib[front1] = vertex->attrib[back1];
+ * }
+ *
+ * \param front0 first attrib to replace if the polygon is back-facing
+ * \param back0 first attrib to copy if the polygon is back-facing
+ * \param front1 second attrib to replace if the polygon is back-facing
+ * \param back1 second attrib to copy if the polygon is back-facing
+ *
+ * Pass -1 to disable two-sided attributes.
+ */
+void
+draw_set_twoside_attributes(struct draw_context *draw,
+ uint front0, uint back0,
+ uint front1, uint back1)
+{
+ /* XXX we could alternately pass an array of front/back attribs if there's
+ * ever need for more than two. One could imagine a shader extension
+ * that allows arbitrary attributes to be selected based on polygon
+ * orientation...
+ */
+ draw->attrib_front0 = front0;
+ draw->attrib_back0 = back0;
+ draw->attrib_front1 = front1;
+ draw->attrib_back1 = back1;
+}
+
diff --git a/src/mesa/pipe/draw/draw_context.h b/src/mesa/pipe/draw/draw_context.h
index 4c9e64a12d2..21ee18e7cf6 100644
--- a/src/mesa/pipe/draw/draw_context.h
+++ b/src/mesa/pipe/draw/draw_context.h
@@ -92,6 +92,10 @@ void draw_set_vertex_attributes( struct draw_context *draw,
const uint *attrs, const uint *interp_mode,
unsigned nr_attrs );
+void draw_set_twoside_attributes(struct draw_context *draw,
+ uint front0, uint back0,
+ uint front1, uint back1);
+
unsigned draw_prim_info( unsigned prim, unsigned *first, unsigned *incr );
unsigned draw_trim( unsigned count, unsigned first, unsigned incr );
diff --git a/src/mesa/pipe/draw/draw_private.h b/src/mesa/pipe/draw/draw_private.h
index e61f228d12c..80c97ada329 100644
--- a/src/mesa/pipe/draw/draw_private.h
+++ b/src/mesa/pipe/draw/draw_private.h
@@ -158,6 +158,9 @@ struct draw_context
/** Describes the layout of post-transformation vertices */
struct vertex_info vertex_info;
+ /** Two-sided attributes: */
+ uint attrib_front0, attrib_back0;
+ uint attrib_front1, attrib_back1;
unsigned nr_vertices;
diff --git a/src/mesa/pipe/draw/draw_twoside.c b/src/mesa/pipe/draw/draw_twoside.c
index a05eea41fc2..98eb088035a 100644
--- a/src/mesa/pipe/draw/draw_twoside.c
+++ b/src/mesa/pipe/draw/draw_twoside.c
@@ -61,15 +61,11 @@ static void twoside_begin( struct draw_stage *stage )
}
-static INLINE void copy_color( unsigned attr_dst,
+static INLINE void copy_attrib( unsigned attr_dst,
unsigned attr_src,
struct vertex_header *v )
{
- if (attr_dst && attr_src) {
- memcpy( v->data[attr_dst],
- v->data[attr_src],
- sizeof(v->data[0]) );
- }
+ COPY_4FV(v->data[attr_dst], v->data[attr_src]);
}
@@ -78,14 +74,16 @@ static struct vertex_header *copy_bfc( struct twoside_stage *twoside,
unsigned idx )
{
struct vertex_header *tmp = dup_vert( &twoside->stage, v, idx );
+ const struct draw_context *draw = twoside->stage.draw;
- copy_color( twoside->lookup[TGSI_ATTRIB_COLOR0],
- twoside->lookup[TGSI_ATTRIB_BFC0],
- tmp );
-
- copy_color( twoside->lookup[TGSI_ATTRIB_COLOR1],
- twoside->lookup[TGSI_ATTRIB_BFC1],
- tmp );
+ if (draw->attrib_front0) {
+ assert(draw->attrib_back0);
+ copy_attrib(draw->attrib_front0, draw->attrib_back0, tmp);
+ }
+ if (draw->attrib_front1) {
+ assert(draw->attrib_back1);
+ copy_attrib(draw->attrib_front1, draw->attrib_back1, tmp);
+ }
return tmp;
}
@@ -104,7 +102,7 @@ static void twoside_tri( struct draw_stage *stage,
tmp.det = header->det;
tmp.edgeflags = header->edgeflags;
- /* copy back colors to front color slots */
+ /* copy back attribs to front attribs */
tmp.v[0] = copy_bfc(twoside, header->v[0], 0);
tmp.v[1] = copy_bfc(twoside, header->v[1], 1);
tmp.v[2] = copy_bfc(twoside, header->v[2], 2);