1 /* Originally written by Ben Skeggs for the nv50 driver*/
6 #include "pipe/p_defines.h"
7 #include "pipe/p_compiler.h"
9 #include "util/u_debug.h"
11 struct util_split_prim
{
13 void (*emit
)(void *priv
, unsigned start
, unsigned count
);
14 void (*edge
)(void *priv
, boolean enabled
);
27 util_split_prim_init(struct util_split_prim
*s
,
28 unsigned mode
, unsigned start
, unsigned count
)
30 if (mode
== PIPE_PRIM_LINE_LOOP
) {
31 s
->mode
= PIPE_PRIM_LINE_STRIP
;
39 s
->p_end
= start
+ count
;
45 util_split_prim_next(struct util_split_prim
*s
, unsigned max_verts
)
49 if (s
->repeat_first
) {
50 s
->emit(s
->priv
, s
->start
, 1);
52 if (s
->edgeflag_off
) {
53 s
->edge(s
->priv
, TRUE
);
54 s
->edgeflag_off
= FALSE
;
58 if ((s
->p_end
- s
->p_start
) + s
->close_first
<= max_verts
) {
59 s
->emit(s
->priv
, s
->p_start
, s
->p_end
- s
->p_start
);
61 s
->emit(s
->priv
, s
->start
, 1);
69 case PIPE_PRIM_LINE_STRIP
:
72 case PIPE_PRIM_POLYGON
:
74 s
->emit(s
->priv
, s
->p_start
, max_verts
);
75 s
->edge(s
->priv
, FALSE
);
76 s
->emit(s
->priv
, s
->p_start
+ max_verts
, 1);
77 s
->p_start
+= max_verts
;
78 s
->repeat_first
= TRUE
;
79 s
->edgeflag_off
= TRUE
;
81 case PIPE_PRIM_TRIANGLES
:
82 max_verts
= max_verts
- (max_verts
% 3);
84 case PIPE_PRIM_TRIANGLE_STRIP
:
85 /* to ensure winding stays correct, always split
86 * on an even number of generated triangles
88 max_verts
= max_verts
& ~1;
91 case PIPE_PRIM_TRIANGLE_FAN
:
92 s
->repeat_first
= TRUE
;
98 case PIPE_PRIM_QUAD_STRIP
:
102 case PIPE_PRIM_POINTS
:
105 /* TODO: implement adjacency primitives */
109 s
->emit (s
->priv
, s
->p_start
, max_verts
);
110 s
->p_start
+= (max_verts
- repeat
);
114 #endif /* U_SPLIT_PRIM_H */