gallium/util: add a helper for calculating primitive count from vertex count
authorMarek Olšák <marek.olsak@amd.com>
Sat, 26 Jul 2014 00:54:23 +0000 (02:54 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 28 Jul 2014 21:57:08 +0000 (23:57 +0200)
This is needed by the following commit which is a candidate for stable too.

Cc: mesa-stable@lists.freedesktop.org
src/gallium/auxiliary/util/u_prim.h

index fd95c0ba0cc218179b500dad28aa6e99ec94c6dc..cf1a18f427951e3494b6f94f26e3ac294a2aef0b 100644 (file)
@@ -136,6 +136,21 @@ u_prim_vertex_count(unsigned prim)
    return (likely(prim < PIPE_PRIM_MAX)) ? &prim_table[prim] : NULL;
 }
 
+/**
+ * Given a vertex count, return the number of primitives.
+ * For polygons, return the number of triangles.
+ */
+static INLINE unsigned
+u_prims_for_vertices(unsigned prim, unsigned num)
+{
+   const struct u_prim_vertex_count *info = u_prim_vertex_count(prim);
+
+   if (num < info->min)
+      return 0;
+
+   return 1 + ((num - info->min) / info->incr);
+}
+
 static INLINE boolean u_validate_pipe_prim( unsigned pipe_prim, unsigned nr )
 {
    const struct u_prim_vertex_count *count = u_prim_vertex_count(pipe_prim);