f0aec5febabdb0b518cd626c5f28661c08a713d7
[mesa.git] / src / gallium / auxiliary / draw / draw_pt_varray_tmp_linear.h
1 static unsigned trim( unsigned count, unsigned first, unsigned incr )
2 {
3 return count - (count - first) % incr;
4 }
5
6 static void FUNC(struct draw_pt_front_end *frontend,
7 pt_elt_func get_elt,
8 const void *elts,
9 unsigned count)
10 {
11 struct varray_frontend *varray = (struct varray_frontend *)frontend;
12 unsigned start = (unsigned) ((char *) elts - (char *) NULL);
13
14 unsigned j;
15 unsigned first, incr;
16
17 draw_pt_split_prim(varray->input_prim, &first, &incr);
18
19 /* Sanitize primitive length:
20 */
21 count = trim(count, first, incr);
22 if (count < first)
23 return;
24
25 #if 0
26 debug_printf("%s (%d) %d/%d\n", __FUNCTION__,
27 varray->input_prim,
28 start, count);
29 #endif
30
31 switch (varray->input_prim) {
32 case PIPE_PRIM_POINTS:
33 case PIPE_PRIM_LINES:
34 case PIPE_PRIM_TRIANGLES:
35 case PIPE_PRIM_LINE_STRIP:
36 case PIPE_PRIM_TRIANGLE_STRIP:
37 case PIPE_PRIM_QUADS:
38 case PIPE_PRIM_QUAD_STRIP:
39 case PIPE_PRIM_LINES_ADJACENCY:
40 case PIPE_PRIM_LINE_STRIP_ADJACENCY:
41 case PIPE_PRIM_TRIANGLES_ADJACENCY:
42 case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
43 for (j = 0; j < count;) {
44 unsigned remaining = count - j;
45 unsigned nr = trim( MIN2(varray->driver_fetch_max, remaining), first, incr );
46 varray_flush_linear(varray, start + j, nr);
47 j += nr;
48 if (nr != remaining)
49 j -= (first - incr);
50 }
51 break;
52
53 case PIPE_PRIM_LINE_LOOP:
54 /* Always have to decompose as we've stated that this will be
55 * emitted as a line-strip.
56 */
57 for (j = 0; j < count;) {
58 unsigned remaining = count - j;
59 unsigned nr = trim( MIN2(varray->fetch_max-1, remaining), first, incr );
60 varray_line_loop_segment(varray, start, j, nr, nr == remaining);
61 j += nr;
62 if (nr != remaining)
63 j -= (first - incr);
64 }
65 break;
66
67
68 case PIPE_PRIM_POLYGON:
69 case PIPE_PRIM_TRIANGLE_FAN:
70 if (count < varray->driver_fetch_max) {
71 varray_flush_linear(varray, start, count);
72 }
73 else {
74 for ( j = 0; j < count;) {
75 unsigned remaining = count - j;
76 unsigned nr = trim( MIN2(varray->fetch_max-1, remaining), first, incr );
77 varray_fan_segment(varray, start, j, nr);
78 j += nr;
79 if (nr != remaining)
80 j -= (first - incr);
81 }
82 }
83 break;
84
85 default:
86 assert(0);
87 break;
88 }
89 }
90
91 #undef TRIANGLE
92 #undef QUAD
93 #undef POINT
94 #undef LINE
95 #undef FUNC