114ed371a06597d3776eab0ee4d6684993fa471f
[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)elts;
13
14 unsigned i, j;
15 unsigned first, incr;
16
17 varray->fetch_start = start;
18
19 draw_pt_split_prim(varray->input_prim, &first, &incr);
20
21 /* Sanitize primitive length:
22 */
23 count = trim(count, first, incr);
24 if (count < first)
25 return;
26
27 #if 0
28 debug_printf("%s (%d) %d/%d\n", __FUNCTION__,
29 varray->input_prim,
30 start, count);
31 #endif
32
33 switch (varray->input_prim) {
34 case PIPE_PRIM_POINTS:
35 case PIPE_PRIM_LINES:
36 case PIPE_PRIM_TRIANGLES:
37 case PIPE_PRIM_LINE_STRIP:
38 case PIPE_PRIM_TRIANGLE_STRIP:
39 case PIPE_PRIM_QUADS:
40 case PIPE_PRIM_QUAD_STRIP:
41 for (j = 0; j < count;) {
42 unsigned remaining = count - j;
43 unsigned nr = trim( MIN2(FETCH_MAX, remaining), first, incr );
44 varray_flush_linear(varray, start + j, nr);
45 j += nr;
46 if (nr != remaining)
47 j -= (first - incr);
48 }
49 break;
50
51 case PIPE_PRIM_LINE_LOOP:
52 if (count >= 2) {
53 for (j = 0; j + first <= count; j += i) {
54 unsigned end = MIN2(FETCH_MAX, count - j);
55 end -= (end % incr);
56 for (i = 1; i < end; i++) {
57 LINE(varray, i - 1, i);
58 }
59 LINE(varray, i - 1, 0);
60 i = end;
61 fetch_init(varray, end);
62 varray_flush(varray);
63 }
64 }
65 break;
66
67
68 case PIPE_PRIM_POLYGON:
69 case PIPE_PRIM_TRIANGLE_FAN:
70 for (j = 0; j + first <= count; j += i) {
71 unsigned end = MIN2(FETCH_MAX, count - j);
72 end -= (end % incr);
73 for (i = 2; i < end; i++) {
74 TRIANGLE(varray, 0, i - 1, i);
75 }
76 i = end;
77 fetch_init(varray, end);
78 varray_flush(varray);
79 }
80 break;
81
82 default:
83 assert(0);
84 break;
85 }
86
87 varray_flush(varray);
88 }
89
90 #undef TRIANGLE
91 #undef QUAD
92 #undef POINT
93 #undef LINE
94 #undef FUNC