Mesa (master): tnl: Add a utility to emit indexed vertices to a DMA buffer.

Thomas Hellstrom thomash at kemper.freedesktop.org
Tue Jan 20 10:30:04 UTC 2009


Module: Mesa
Branch: master
Commit: b00477acf3546242cd183630bd55a49085bbb3ed
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b00477acf3546242cd183630bd55a49085bbb3ed

Author: Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
Date:   Tue Jan 20 11:15:57 2009 +0100

tnl: Add a utility to emit indexed vertices to a DMA buffer.

This utility is useful for hardware that doesn't support HW index buffers.
It's a bit inefficient but appears to give a substantial performance gain,
as we can emit tri strips that would otherwise be split into triangles.

---

 src/mesa/tnl/t_vertex.c |   45 ++++++++++++++++++++++++++++++++++++++++++++-
 src/mesa/tnl/t_vertex.h |    6 ++++++
 2 files changed, 50 insertions(+), 1 deletions(-)

diff --git a/src/mesa/tnl/t_vertex.c b/src/mesa/tnl/t_vertex.c
index b661524..10b78f8 100644
--- a/src/mesa/tnl/t_vertex.c
+++ b/src/mesa/tnl/t_vertex.c
@@ -376,6 +376,22 @@ void _tnl_notify_pipeline_output_change( GLcontext *ctx )
    invalidate_funcs(vtx);
 }
 
+
+static void adjust_input_ptrs( GLcontext *ctx, GLint diff)
+{
+   struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
+   struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
+   struct tnl_clipspace_attr *a = vtx->attr;
+   const GLuint count = vtx->attr_count;
+   int j;
+
+   diff -= 1;
+   for (j=0; j<count; ++j) {
+           register GLvector4f *vptr = VB->AttribPtr[a->attrib];
+	   (a++)->inputptr += diff*vptr->stride;
+   }
+}
+
 static void update_input_ptrs( GLcontext *ctx, GLuint start )
 {
    struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
@@ -431,13 +447,40 @@ void *_tnl_emit_vertices_to_buffer( GLcontext *ctx,
    struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
 
    update_input_ptrs(ctx, start);
-
    /* Note: dest should not be adjusted for non-zero 'start' values:
     */
    vtx->emit( ctx, end - start, (GLubyte*) dest );	
    return (void *)((GLubyte *)dest + vtx->vertex_size * (end - start));
 }
 
+/* Emit indexed VB vertices start..end to dest.  Note that VB vertex at
+ * postion start will be emitted to dest at position zero.
+ */
+
+void *_tnl_emit_indexed_vertices_to_buffer( GLcontext *ctx,
+					    const GLuint *elts,
+					    GLuint start,
+					    GLuint end,
+					    void *dest )
+{
+   struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
+   GLuint oldIndex;
+   GLubyte *cdest = dest;
+
+   update_input_ptrs(ctx, oldIndex = elts[start++]);
+   vtx->emit( ctx, 1, cdest );
+   cdest += vtx->vertex_size;
+
+   for (; start < end; ++start) {
+      adjust_input_ptrs(ctx, elts[start] - oldIndex);
+      oldIndex = elts[start];
+      vtx->emit( ctx, 1, cdest);
+      cdest += vtx->vertex_size;
+   }
+
+   return (void *) cdest;
+}
+
 
 void _tnl_init_vertices( GLcontext *ctx, 
 			GLuint vb_size,
diff --git a/src/mesa/tnl/t_vertex.h b/src/mesa/tnl/t_vertex.h
index 712311a..16071fb 100644
--- a/src/mesa/tnl/t_vertex.h
+++ b/src/mesa/tnl/t_vertex.h
@@ -118,6 +118,12 @@ extern void *_tnl_emit_vertices_to_buffer( GLcontext *ctx,
 					   GLuint start,
 					   GLuint end,
 					   void *dest );
+extern void *_tnl_emit_indexed_vertices_to_buffer( GLcontext *ctx,
+						   const GLuint *elts,
+						   GLuint start,
+						   GLuint end,
+						   void *dest );
+
 
 extern void _tnl_build_vertices( GLcontext *ctx,
 				 GLuint start,




More information about the mesa-commit mailing list