Merge commit 'origin/master' into gallium-0.2
[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 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 for (j = 0; j < count;) {
40 unsigned remaining = count - j;
41 unsigned nr = trim( MIN2(varray->driver_fetch_max, remaining), first, incr );
42 varray_flush_linear(varray, start + j, nr);
43 j += nr;
44 if (nr != remaining)
45 j -= (first - incr);
46 }
47 break;
48
49 case PIPE_PRIM_LINE_LOOP:
50 /* Always have to decompose as we've stated that this will be
51 * emitted as a line-strip.
52 */
53 for (j = 0; j < count;) {
54 unsigned remaining = count - j;
55 unsigned nr = trim( MIN2(varray->fetch_max-1, remaining), first, incr );
56 varray_line_loop_segment(varray, start, j, nr, nr == remaining);
57 j += nr;
58 if (nr != remaining)
59 j -= (first - incr);
60 }
61 break;
62
63
64 case PIPE_PRIM_POLYGON:
65 case PIPE_PRIM_TRIANGLE_FAN:
66 if (count < varray->driver_fetch_max) {
67 varray_flush_linear(varray, start, count);
68 }
69 else {
70 for ( j = 0; j < count;) {
71 unsigned remaining = count - j;
72 unsigned nr = trim( MIN2(varray->fetch_max-1, remaining), first, incr );
73 varray_fan_segment(varray, start, j, nr);
74 j += nr;
75 if (nr != remaining)
76 j -= (first - incr);
77 }
78 }
79 break;
80
81 default:
82 assert(0);
83 break;
84 }
85 }
86
87 #undef TRIANGLE
88 #undef QUAD
89 #undef POINT
90 #undef LINE
91 #undef FUNC