aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/gallium/auxiliary/util/u_prim.h
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-06-03 08:22:14 +0200
committermarha <marha@users.sourceforge.net>2011-06-03 08:22:14 +0200
commit6aea3a7470dfb2c513378b82c27f0ad87afda7f3 (patch)
treecefb863bdf986b740d8f9475514df400a56ff003 /mesalib/src/gallium/auxiliary/util/u_prim.h
parent5e835037510a4ccf001fb8f0a9aed29a28072fec (diff)
parentcda19b1d226d565f1ca4327aeae827c621b3dfd6 (diff)
downloadvcxsrv-6aea3a7470dfb2c513378b82c27f0ad87afda7f3.tar.gz
vcxsrv-6aea3a7470dfb2c513378b82c27f0ad87afda7f3.tar.bz2
vcxsrv-6aea3a7470dfb2c513378b82c27f0ad87afda7f3.zip
Merge remote-tracking branch 'origin/released'
Conflicts: mesalib/configs/linux-dri mesalib/src/gallium/auxiliary/util/u_math.h mesalib/src/mapi/glapi/gen/Makefile mesalib/src/mapi/glapi/glapi_mapi_tmp.h mesalib/src/mapi/glapi/glapi_sparc.S mesalib/src/mapi/glapi/glapi_x86-64.S mesalib/src/mapi/glapi/glapi_x86.S mesalib/src/mapi/glapi/glapitable.h mesalib/src/mapi/glapi/glapitemp.h mesalib/src/mapi/glapi/glprocs.h mesalib/src/mesa/drivers/dri/Makefile.template mesalib/src/mesa/main/dd.h mesalib/src/mesa/main/fbobject.c mesalib/src/mesa/main/remap_helper.h mesalib/src/mesa/main/shaderapi.c mesalib/src/mesa/main/teximage.c mesalib/src/mesa/main/uniforms.c mesalib/src/mesa/state_tracker/st_format.c mesalib/src/mesa/vbo/vbo_exec_array.c xorg-server/configure.ac xorg-server/dix/main.c xorg-server/dix/window.c xorg-server/hw/xquartz/GL/indirect.c xorg-server/hw/xquartz/X11Application.m xorg-server/hw/xquartz/darwin.c xorg-server/hw/xquartz/darwin.h xorg-server/hw/xquartz/mach-startup/Makefile.am xorg-server/hw/xquartz/pbproxy/app-main.m xorg-server/hw/xquartz/pbproxy/pbproxy.h xorg-server/hw/xquartz/pbproxy/x-selection.m xorg-server/hw/xquartz/xpr/xpr.h xorg-server/hw/xquartz/xpr/xprEvent.c xorg-server/hw/xquartz/xpr/xprScreen.c xorg-server/include/privates.h xorg-server/include/protocol-versions.h xorg-server/test/Makefile.am xorg-server/xfixes/cursor.c xorg-server/xfixes/xfixes.c xorg-server/xkeyboard-config/configure.in xorg-server/xkeyboard-config/rules/base.extras.xml.in xorg-server/xkeyboard-config/rules/base.xml.in xorg-server/xkeyboard-config/symbols/de xorg-server/xkeyboard-config/symbols/lk xorg-server/xkeyboard-config/symbols/ru
Diffstat (limited to 'mesalib/src/gallium/auxiliary/util/u_prim.h')
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_prim.h445
1 files changed, 211 insertions, 234 deletions
diff --git a/mesalib/src/gallium/auxiliary/util/u_prim.h b/mesalib/src/gallium/auxiliary/util/u_prim.h
index 519820e1b..ca7c67d7c 100644
--- a/mesalib/src/gallium/auxiliary/util/u_prim.h
+++ b/mesalib/src/gallium/auxiliary/util/u_prim.h
@@ -1,234 +1,211 @@
-/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-
-#ifndef U_BLIT_H
-#define U_BLIT_H
-
-
-#include "pipe/p_defines.h"
-#include "util/u_debug.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-static INLINE boolean u_validate_pipe_prim( unsigned pipe_prim, unsigned nr )
-{
- boolean ok = TRUE;
-
- switch (pipe_prim) {
- case PIPE_PRIM_POINTS:
- ok = (nr >= 1);
- break;
- case PIPE_PRIM_LINES:
- ok = (nr >= 2);
- break;
- case PIPE_PRIM_LINE_STRIP:
- case PIPE_PRIM_LINE_LOOP:
- ok = (nr >= 2);
- break;
- case PIPE_PRIM_TRIANGLES:
- ok = (nr >= 3);
- break;
- case PIPE_PRIM_TRIANGLE_STRIP:
- case PIPE_PRIM_TRIANGLE_FAN:
- case PIPE_PRIM_POLYGON:
- ok = (nr >= 3);
- break;
- case PIPE_PRIM_QUADS:
- ok = (nr >= 4);
- break;
- case PIPE_PRIM_QUAD_STRIP:
- ok = (nr >= 4);
- break;
- default:
- ok = 0;
- break;
- }
-
- return ok;
-}
-
-
-static INLINE boolean u_trim_pipe_prim( unsigned pipe_prim, unsigned *nr )
-{
- boolean ok = TRUE;
-
- switch (pipe_prim) {
- case PIPE_PRIM_POINTS:
- ok = (*nr >= 1);
- break;
- case PIPE_PRIM_LINES:
- ok = (*nr >= 2);
- *nr -= (*nr % 2);
- break;
- case PIPE_PRIM_LINE_STRIP:
- case PIPE_PRIM_LINE_LOOP:
- ok = (*nr >= 2);
- break;
- case PIPE_PRIM_TRIANGLES:
- ok = (*nr >= 3);
- *nr -= (*nr % 3);
- break;
- case PIPE_PRIM_TRIANGLE_STRIP:
- case PIPE_PRIM_TRIANGLE_FAN:
- case PIPE_PRIM_POLYGON:
- ok = (*nr >= 3);
- break;
- case PIPE_PRIM_QUADS:
- ok = (*nr >= 4);
- *nr -= (*nr % 4);
- break;
- case PIPE_PRIM_QUAD_STRIP:
- ok = (*nr >= 4);
- *nr -= (*nr % 2);
- break;
- case PIPE_PRIM_LINES_ADJACENCY:
- ok = (*nr >= 4);
- *nr -= (*nr % 4);
- break;
- case PIPE_PRIM_LINE_STRIP_ADJACENCY:
- ok = (*nr >= 4);
- break;
- case PIPE_PRIM_TRIANGLES_ADJACENCY:
- ok = (*nr >= 6);
- *nr -= (*nr % 5);
- break;
- case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
- ok = (*nr >= 4);
- break;
- default:
- ok = 0;
- break;
- }
-
- if (!ok)
- *nr = 0;
-
- return ok;
-}
-
-
-static INLINE unsigned u_reduced_prim( unsigned pipe_prim )
-{
- switch (pipe_prim) {
- case PIPE_PRIM_POINTS:
- return PIPE_PRIM_POINTS;
-
- case PIPE_PRIM_LINES:
- case PIPE_PRIM_LINE_STRIP:
- case PIPE_PRIM_LINE_LOOP:
- return PIPE_PRIM_LINES;
-
- default:
- return PIPE_PRIM_TRIANGLES;
- }
-}
-
-static INLINE unsigned
-u_vertices_per_prim(int primitive)
-{
- switch(primitive) {
- case PIPE_PRIM_POINTS:
- return 1;
- case PIPE_PRIM_LINES:
- case PIPE_PRIM_LINE_LOOP:
- case PIPE_PRIM_LINE_STRIP:
- return 2;
- case PIPE_PRIM_TRIANGLES:
- case PIPE_PRIM_TRIANGLE_STRIP:
- case PIPE_PRIM_TRIANGLE_FAN:
- return 3;
- case PIPE_PRIM_LINES_ADJACENCY:
- case PIPE_PRIM_LINE_STRIP_ADJACENCY:
- return 4;
- case PIPE_PRIM_TRIANGLES_ADJACENCY:
- case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
- return 6;
-
- /* following primitives should never be used
- * with geometry shaders abd their size is
- * undefined */
- case PIPE_PRIM_POLYGON:
- case PIPE_PRIM_QUADS:
- case PIPE_PRIM_QUAD_STRIP:
- default:
- debug_printf("Unrecognized geometry shader primitive");
- return 3;
- }
-}
-
-/**
- * Returns the number of decomposed primitives for the given
- * vertex count.
- * Geometry shader is invoked once for each triangle in
- * triangle strip, triangle fans and triangles and once
- * for each line in line strip, line loop, lines.
- */
-static INLINE unsigned
-u_gs_prims_for_vertices(int primitive, int vertices)
-{
- switch(primitive) {
- case PIPE_PRIM_POINTS:
- return vertices;
- case PIPE_PRIM_LINES:
- return vertices / 2;
- case PIPE_PRIM_LINE_LOOP:
- return vertices;
- case PIPE_PRIM_LINE_STRIP:
- return vertices - 1;
- case PIPE_PRIM_TRIANGLES:
- return vertices / 3;
- case PIPE_PRIM_TRIANGLE_STRIP:
- return vertices - 2;
- case PIPE_PRIM_TRIANGLE_FAN:
- return vertices - 2;
- case PIPE_PRIM_LINES_ADJACENCY:
- return vertices / 2;
- case PIPE_PRIM_LINE_STRIP_ADJACENCY:
- return vertices - 1;
- case PIPE_PRIM_TRIANGLES_ADJACENCY:
- return vertices / 3;
- case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
- return vertices - 2;
-
- /* following primitives should never be used
- * with geometry shaders abd their size is
- * undefined */
- case PIPE_PRIM_POLYGON:
- case PIPE_PRIM_QUADS:
- case PIPE_PRIM_QUAD_STRIP:
- default:
- debug_printf("Unrecognized geometry shader primitive");
- return 3;
- }
-}
-
-const char *u_prim_name( unsigned pipe_prim );
-
-#endif
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#ifndef U_BLIT_H
+#define U_BLIT_H
+
+
+#include "pipe/p_defines.h"
+#include "util/u_debug.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static INLINE boolean u_validate_pipe_prim( unsigned pipe_prim, unsigned nr )
+{
+ boolean ok = TRUE;
+
+ switch (pipe_prim) {
+ case PIPE_PRIM_POINTS:
+ ok = (nr >= 1);
+ break;
+ case PIPE_PRIM_LINES:
+ ok = (nr >= 2);
+ break;
+ case PIPE_PRIM_LINE_STRIP:
+ case PIPE_PRIM_LINE_LOOP:
+ ok = (nr >= 2);
+ break;
+ case PIPE_PRIM_TRIANGLES:
+ ok = (nr >= 3);
+ break;
+ case PIPE_PRIM_TRIANGLE_STRIP:
+ case PIPE_PRIM_TRIANGLE_FAN:
+ case PIPE_PRIM_POLYGON:
+ ok = (nr >= 3);
+ break;
+ case PIPE_PRIM_QUADS:
+ ok = (nr >= 4);
+ break;
+ case PIPE_PRIM_QUAD_STRIP:
+ ok = (nr >= 4);
+ break;
+ default:
+ ok = 0;
+ break;
+ }
+
+ return ok;
+}
+
+
+static INLINE boolean u_trim_pipe_prim( unsigned pipe_prim, unsigned *nr )
+{
+ boolean ok = TRUE;
+ const static int values[][2] = {
+ { 1, 0 }, /* PIPE_PRIM_POINTS */
+ { 2, 2 }, /* PIPE_PRIM_LINES */
+ { 2, 0 }, /* PIPE_PRIM_LINE_LOOP */
+ { 2, 0 }, /* PIPE_PRIM_LINE_STRIP */
+ { 3, 3 }, /* PIPE_PRIM_TRIANGLES */
+ { 3, 0 }, /* PIPE_PRIM_TRIANGLE_STRIP */
+ { 3, 0 }, /* PIPE_PRIM_TRIANGLE_FAN */
+ { 4, 4 }, /* PIPE_PRIM_TRIANGLE_QUADS */
+ { 4, 2 }, /* PIPE_PRIM_TRIANGLE_QUAD_STRIP */
+ { 3, 0 }, /* PIPE_PRIM_TRIANGLE_POLYGON */
+ { 4, 4 }, /* PIPE_PRIM_LINES_ADJACENCY */
+ { 4, 0 }, /* PIPE_PRIM_LINE_STRIP_ADJACENCY */
+ { 6, 5 }, /* PIPE_PRIM_TRIANGLES_ADJACENCY */
+ { 4, 0 }, /* PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY */
+ };
+
+ if (unlikely(pipe_prim >= PIPE_PRIM_MAX)) {
+ *nr = 0;
+ return FALSE;
+ }
+
+ ok = (*nr >= values[pipe_prim][0]);
+ if (values[pipe_prim][1])
+ *nr -= (*nr % values[pipe_prim][1]);
+
+ if (!ok)
+ *nr = 0;
+
+ return ok;
+}
+
+
+static INLINE unsigned u_reduced_prim( unsigned pipe_prim )
+{
+ switch (pipe_prim) {
+ case PIPE_PRIM_POINTS:
+ return PIPE_PRIM_POINTS;
+
+ case PIPE_PRIM_LINES:
+ case PIPE_PRIM_LINE_STRIP:
+ case PIPE_PRIM_LINE_LOOP:
+ return PIPE_PRIM_LINES;
+
+ default:
+ return PIPE_PRIM_TRIANGLES;
+ }
+}
+
+static INLINE unsigned
+u_vertices_per_prim(int primitive)
+{
+ switch(primitive) {
+ case PIPE_PRIM_POINTS:
+ return 1;
+ case PIPE_PRIM_LINES:
+ case PIPE_PRIM_LINE_LOOP:
+ case PIPE_PRIM_LINE_STRIP:
+ return 2;
+ case PIPE_PRIM_TRIANGLES:
+ case PIPE_PRIM_TRIANGLE_STRIP:
+ case PIPE_PRIM_TRIANGLE_FAN:
+ return 3;
+ case PIPE_PRIM_LINES_ADJACENCY:
+ case PIPE_PRIM_LINE_STRIP_ADJACENCY:
+ return 4;
+ case PIPE_PRIM_TRIANGLES_ADJACENCY:
+ case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
+ return 6;
+
+ /* following primitives should never be used
+ * with geometry shaders abd their size is
+ * undefined */
+ case PIPE_PRIM_POLYGON:
+ case PIPE_PRIM_QUADS:
+ case PIPE_PRIM_QUAD_STRIP:
+ default:
+ debug_printf("Unrecognized geometry shader primitive");
+ return 3;
+ }
+}
+
+/**
+ * Returns the number of decomposed primitives for the given
+ * vertex count.
+ * Geometry shader is invoked once for each triangle in
+ * triangle strip, triangle fans and triangles and once
+ * for each line in line strip, line loop, lines.
+ */
+static INLINE unsigned
+u_gs_prims_for_vertices(int primitive, int vertices)
+{
+ switch(primitive) {
+ case PIPE_PRIM_POINTS:
+ return vertices;
+ case PIPE_PRIM_LINES:
+ return vertices / 2;
+ case PIPE_PRIM_LINE_LOOP:
+ return vertices;
+ case PIPE_PRIM_LINE_STRIP:
+ return vertices - 1;
+ case PIPE_PRIM_TRIANGLES:
+ return vertices / 3;
+ case PIPE_PRIM_TRIANGLE_STRIP:
+ return vertices - 2;
+ case PIPE_PRIM_TRIANGLE_FAN:
+ return vertices - 2;
+ case PIPE_PRIM_LINES_ADJACENCY:
+ return vertices / 2;
+ case PIPE_PRIM_LINE_STRIP_ADJACENCY:
+ return vertices - 1;
+ case PIPE_PRIM_TRIANGLES_ADJACENCY:
+ return vertices / 3;
+ case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
+ return vertices - 2;
+
+ /* following primitives should never be used
+ * with geometry shaders abd their size is
+ * undefined */
+ case PIPE_PRIM_POLYGON:
+ case PIPE_PRIM_QUADS:
+ case PIPE_PRIM_QUAD_STRIP:
+ default:
+ debug_printf("Unrecognized geometry shader primitive");
+ return 3;
+ }
+}
+
+const char *u_prim_name( unsigned pipe_prim );
+
+#endif