summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2014-07-26 02:54:23 +0200
committerMarek Olšák <[email protected]>2014-07-28 23:57:08 +0200
commitc7407b94a8eb329a45cdd0acb5255670d4c0e041 (patch)
tree35b5156f5b608da0d16f88d653d7dbfb60a08a70
parent9b046474c95f15338d4c748df9b62871bba6f36f (diff)
gallium/util: add a helper for calculating primitive count from vertex count
This is needed by the following commit which is a candidate for stable too. Cc: [email protected]
-rw-r--r--src/gallium/auxiliary/util/u_prim.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_prim.h b/src/gallium/auxiliary/util/u_prim.h
index fd95c0ba0cc..cf1a18f4279 100644
--- a/src/gallium/auxiliary/util/u_prim.h
+++ b/src/gallium/auxiliary/util/u_prim.h
@@ -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);