1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
33 #include "pipe/p_defines.h"
34 #include "util/u_debug.h"
40 static INLINE boolean
u_validate_pipe_prim( unsigned pipe_prim
, unsigned nr
)
45 case PIPE_PRIM_POINTS
:
51 case PIPE_PRIM_LINE_STRIP
:
52 case PIPE_PRIM_LINE_LOOP
:
55 case PIPE_PRIM_TRIANGLES
:
58 case PIPE_PRIM_TRIANGLE_STRIP
:
59 case PIPE_PRIM_TRIANGLE_FAN
:
60 case PIPE_PRIM_POLYGON
:
66 case PIPE_PRIM_QUAD_STRIP
:
78 static INLINE boolean
u_trim_pipe_prim( unsigned pipe_prim
, unsigned *nr
)
81 const static int values
[][2] = {
82 { 1, 0 }, /* PIPE_PRIM_POINTS */
83 { 2, 2 }, /* PIPE_PRIM_LINES */
84 { 2, 0 }, /* PIPE_PRIM_LINE_LOOP */
85 { 2, 0 }, /* PIPE_PRIM_LINE_STRIP */
86 { 3, 3 }, /* PIPE_PRIM_TRIANGLES */
87 { 3, 0 }, /* PIPE_PRIM_TRIANGLE_STRIP */
88 { 3, 0 }, /* PIPE_PRIM_TRIANGLE_FAN */
89 { 4, 4 }, /* PIPE_PRIM_TRIANGLE_QUADS */
90 { 4, 2 }, /* PIPE_PRIM_TRIANGLE_QUAD_STRIP */
91 { 3, 0 }, /* PIPE_PRIM_TRIANGLE_POLYGON */
92 { 4, 4 }, /* PIPE_PRIM_LINES_ADJACENCY */
93 { 4, 0 }, /* PIPE_PRIM_LINE_STRIP_ADJACENCY */
94 { 6, 5 }, /* PIPE_PRIM_TRIANGLES_ADJACENCY */
95 { 4, 0 }, /* PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY */
98 if (unlikely(pipe_prim
>= PIPE_PRIM_MAX
)) {
103 ok
= (*nr
>= values
[pipe_prim
][0]);
104 if (values
[pipe_prim
][1])
105 *nr
-= (*nr
% values
[pipe_prim
][1]);
114 static INLINE
unsigned u_reduced_prim( unsigned pipe_prim
)
117 case PIPE_PRIM_POINTS
:
118 return PIPE_PRIM_POINTS
;
120 case PIPE_PRIM_LINES
:
121 case PIPE_PRIM_LINE_STRIP
:
122 case PIPE_PRIM_LINE_LOOP
:
123 return PIPE_PRIM_LINES
;
126 return PIPE_PRIM_TRIANGLES
;
130 static INLINE
unsigned
131 u_vertices_per_prim(int primitive
)
134 case PIPE_PRIM_POINTS
:
136 case PIPE_PRIM_LINES
:
137 case PIPE_PRIM_LINE_LOOP
:
138 case PIPE_PRIM_LINE_STRIP
:
140 case PIPE_PRIM_TRIANGLES
:
141 case PIPE_PRIM_TRIANGLE_STRIP
:
142 case PIPE_PRIM_TRIANGLE_FAN
:
144 case PIPE_PRIM_LINES_ADJACENCY
:
145 case PIPE_PRIM_LINE_STRIP_ADJACENCY
:
147 case PIPE_PRIM_TRIANGLES_ADJACENCY
:
148 case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY
:
151 /* following primitives should never be used
152 * with geometry shaders abd their size is
154 case PIPE_PRIM_POLYGON
:
155 case PIPE_PRIM_QUADS
:
156 case PIPE_PRIM_QUAD_STRIP
:
158 debug_printf("Unrecognized geometry shader primitive");
164 * Returns the number of decomposed primitives for the given
166 * Geometry shader is invoked once for each triangle in
167 * triangle strip, triangle fans and triangles and once
168 * for each line in line strip, line loop, lines.
170 static INLINE
unsigned
171 u_gs_prims_for_vertices(int primitive
, int vertices
)
174 case PIPE_PRIM_POINTS
:
176 case PIPE_PRIM_LINES
:
178 case PIPE_PRIM_LINE_LOOP
:
180 case PIPE_PRIM_LINE_STRIP
:
182 case PIPE_PRIM_TRIANGLES
:
184 case PIPE_PRIM_TRIANGLE_STRIP
:
186 case PIPE_PRIM_TRIANGLE_FAN
:
188 case PIPE_PRIM_LINES_ADJACENCY
:
190 case PIPE_PRIM_LINE_STRIP_ADJACENCY
:
192 case PIPE_PRIM_TRIANGLES_ADJACENCY
:
194 case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY
:
197 /* following primitives should never be used
198 * with geometry shaders abd their size is
200 case PIPE_PRIM_POLYGON
:
201 case PIPE_PRIM_QUADS
:
202 case PIPE_PRIM_QUAD_STRIP
:
204 debug_printf("Unrecognized geometry shader primitive");
209 const char *u_prim_name( unsigned pipe_prim
);