util/prim: add u_reduced_prims_for_vertices()
authorChia-I Wu <olvaffe@gmail.com>
Thu, 2 May 2013 06:28:12 +0000 (14:28 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Fri, 3 May 2013 03:59:10 +0000 (11:59 +0800)
The function returns the number of reduced/tessellated primitives for the
given vertex count.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Acked-by: Zack Rusin <zackr@vmware.com>
src/gallium/auxiliary/util/u_prim.h

index 624a508c42cca0ac6d6874132f1721bff3724e21..8f444a30529b4f09a4a28402c6ebed7d30efdf1d 100644 (file)
@@ -243,6 +243,26 @@ u_decomposed_prims_for_vertices(int primitive, int vertices)
    }
 }
 
+/**
+ * Returns the number of reduced/tessellated primitives for the given vertex
+ * count.  Each quad is treated as two triangles.  Polygons are treated as
+ * triangle fans.
+ */
+static INLINE unsigned
+u_reduced_prims_for_vertices(int primitive, int vertices)
+{
+   switch (primitive) {
+   case PIPE_PRIM_QUADS:
+   case PIPE_PRIM_QUAD_STRIP:
+      return u_decomposed_prims_for_vertices(primitive, vertices) * 2;
+   case PIPE_PRIM_POLYGON:
+      primitive = PIPE_PRIM_TRIANGLE_FAN;
+      /* fall through */
+   default:
+      return u_decomposed_prims_for_vertices(primitive, vertices);
+   }
+}
+
 const char *u_prim_name( unsigned pipe_prim );
 
 #endif