summaryrefslogtreecommitdiffstats
path: root/src/mesa/pipe
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-07-10 10:53:29 -0600
committerBrian <[email protected]>2007-07-10 10:53:29 -0600
commit8c1fa904edf991159a53b0f4bba04e2f5e326437 (patch)
treea3ab97764baa02cc43df085013cca10eecd296bc /src/mesa/pipe
parentd68ea4e23fd0cf1fedabb667a8067bfdc3fb308c (diff)
Fix EMIT_ATTR() to populate the draw->vf_attr_to_slot[] array.
Note that attribute index has to be biased by two, since vertex->data[] starts after the header and clipcoord fields. See comments for details. Added a bunch of comments/docs.
Diffstat (limited to 'src/mesa/pipe')
-rw-r--r--src/mesa/pipe/draw/draw_vb.c47
1 files changed, 37 insertions, 10 deletions
diff --git a/src/mesa/pipe/draw/draw_vb.c b/src/mesa/pipe/draw/draw_vb.c
index 74e7d7f2438..905e4654475 100644
--- a/src/mesa/pipe/draw/draw_vb.c
+++ b/src/mesa/pipe/draw/draw_vb.c
@@ -616,32 +616,59 @@ void draw_vb(struct draw_context *draw,
}
-#define EMIT_ATTR( ATTR, STYLE ) \
-do { \
- draw->attrs[draw->nr_attrs].attrib = ATTR; \
- draw->attrs[draw->nr_attrs].format = STYLE; \
- draw->nr_attrs++; \
+/**
+ * Accumulate another attribute's info.
+ * Note the "- 2" factor here. We need this because the vertex->data[]
+ * array does not include the first two attributes we emit (VERTEX_HEADER
+ * and CLIP_POS). So, the 3rd attribute actually winds up in the 1st
+ * position of the data[] array.
+ */
+#define EMIT_ATTR( VF_ATTR, STYLE ) \
+do { \
+ if (draw->nr_attrs >= 2) \
+ draw->vf_attr_to_slot[VF_ATTR] = draw->nr_attrs - 2; \
+ draw->attrs[draw->nr_attrs].attrib = VF_ATTR; \
+ draw->attrs[draw->nr_attrs].format = STYLE; \
+ draw->nr_attrs++; \
} while (0)
+/**
+ * Tell the draw module about the layout of attributes in the vertex.
+ * We need this in order to know which vertex slot has color0, etc.
+ *
+ * \param slot_to_vf_attr an array which maps slot indexes to vertex
+ * format tokens (VF_*).
+ * \param nr_attrs the size of the slot_to_vf_attr array
+ * (and number of attributes)
+ */
void draw_set_vertex_attributes( struct draw_context *draw,
- const GLuint *attrs,
+ const GLuint *slot_to_vf_attr,
GLuint nr_attrs )
{
GLuint i;
+ memset(draw->vf_attr_to_slot, 0, sizeof(draw->vf_attr_to_slot));
draw->nr_attrs = 0;
+ /*
+ * First three attribs are always the same: header, clip pos, winpos
+ */
EMIT_ATTR(VF_ATTRIB_VERTEX_HEADER, EMIT_1F);
EMIT_ATTR(VF_ATTRIB_CLIP_POS, EMIT_4F);
- assert(attrs[0] == VF_ATTRIB_POS);
- EMIT_ATTR(attrs[0], EMIT_4F_VIEWPORT);
+ assert(slot_to_vf_attr[0] == VF_ATTRIB_POS);
+ EMIT_ATTR(slot_to_vf_attr[0], EMIT_4F_VIEWPORT);
+ /*
+ * Remaining attribs (color, texcoords, etc)
+ */
for (i = 1; i < nr_attrs; i++)
- EMIT_ATTR(attrs[i], EMIT_4F);
+ EMIT_ATTR(slot_to_vf_attr[i], EMIT_4F);
- draw->vertex_size = vf_set_vertex_attributes( draw->vf, draw->attrs, draw->nr_attrs, 0 );
+ /* tell the vertex format module how to construct vertices for us */
+ draw->vertex_size = vf_set_vertex_attributes( draw->vf, draw->attrs,
+ draw->nr_attrs, 0 );
}