10ac08ea3002e5e9506f1c513a8cab31b2a51a73
[mesa.git] / src / gallium / auxiliary / draw / draw_pt_varray_tmp.h
1
2 static void FUNC(struct draw_pt_front_end *frontend,
3 pt_elt_func get_elt,
4 const void *elts,
5 unsigned count)
6 {
7 struct varray_frontend *varray = (struct varray_frontend *)frontend;
8 struct draw_context *draw = varray->draw;
9 unsigned start = (unsigned)elts;
10
11 boolean flatfirst = (draw->rasterizer->flatshade &&
12 draw->rasterizer->flatshade_first);
13 unsigned i, j, flags;
14 unsigned first, incr;
15
16 varray->fetch_start = start;
17
18 split_prim_inplace(varray->input_prim, &first, &incr);
19
20 #if 0
21 debug_printf("%s (%d) %d/%d\n", __FUNCTION__,
22 varray->input_prim,
23 start, count);
24 #endif
25
26 switch (varray->input_prim) {
27 case PIPE_PRIM_POINTS:
28 for (j = 0; j + first <= count; j += i) {
29 unsigned end = MIN2(FETCH_MAX, count - j);
30 end -= (end % incr);
31 for (i = 0; i < count; i++) {
32 POINT(varray, i + 0);
33 }
34 i = end;
35 fetch_init(varray, end);
36 varray_flush(varray);
37 }
38 break;
39
40 case PIPE_PRIM_LINES:
41 for (j = 0; j + first <= count; j += i) {
42 unsigned end = MIN2(FETCH_MAX, count - j);
43 end -= (end % incr);
44 for (i = 0; i+1 < end; i += 2) {
45 LINE(varray, DRAW_PIPE_RESET_STIPPLE,
46 i + 0, i + 1);
47 }
48 i = end;
49 fetch_init(varray, end);
50 varray_flush(varray);
51 }
52 break;
53
54 case PIPE_PRIM_LINE_LOOP:
55 if (count >= 2) {
56 flags = DRAW_PIPE_RESET_STIPPLE;
57
58 for (j = 0; j + first <= count; j += i) {
59 unsigned end = MIN2(FETCH_MAX, count - j);
60 end -= (end % incr);
61 for (i = 1; i < end; i++, flags = 0) {
62 LINE(varray, flags, i - 1, i);
63 }
64 LINE(varray, flags, i - 1, 0);
65 i = end;
66 fetch_init(varray, end);
67 varray_flush(varray);
68 }
69 }
70 break;
71
72 case PIPE_PRIM_LINE_STRIP:
73 flags = DRAW_PIPE_RESET_STIPPLE;
74 for (j = 0; j + first <= count; j += i) {
75 unsigned end = MIN2(FETCH_MAX, count - j);
76 end -= (end % incr);
77 for (i = 1; i < end; i++, flags = 0) {
78 LINE(varray, flags, i - 1, i);
79 }
80 i = end;
81 fetch_init(varray, end);
82 varray_flush(varray);
83 }
84 break;
85
86 case PIPE_PRIM_TRIANGLES:
87 for (j = 0; j + first <= count; j += i) {
88 unsigned end = MIN2(FETCH_MAX, count - j);
89 end -= (end % incr);
90 for (i = 0; i+2 < end; i += 3) {
91 TRIANGLE(varray, DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
92 i + 0, i + 1, i + 2);
93 }
94 i = end;
95 varray->fetch_count = end;
96 varray_flush_linear(varray);
97 varray->fetch_start += end;
98 }
99 break;
100
101 case PIPE_PRIM_TRIANGLE_STRIP:
102 if (flatfirst) {
103 for (j = 0; j + first <= count; j += i) {
104 unsigned end = MIN2(FETCH_MAX, count - j);
105 end -= (end % incr);
106 for (i = 0; i+2 < end; i++) {
107 TRIANGLE(varray, DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
108 i + 0, i + 1 + (i&1), i + 2 - (i&1));
109 }
110 i = end;
111 fetch_init(varray, end);
112 varray_flush(varray);
113 }
114 }
115 else {
116 for (j = 0; j + first <= count; j += i) {
117 unsigned end = MIN2(FETCH_MAX, count - j);
118 end -= (end % incr);
119 for (i = 0; i+2 < end; i++) {
120 TRIANGLE(varray, DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
121 i + 0 + (i&1), i + 1 - (i&1), i + 2);
122 }
123 i = end;
124 fetch_init(varray, end);
125 varray_flush(varray);
126 }
127 }
128 break;
129
130 case PIPE_PRIM_TRIANGLE_FAN:
131 if (count >= 3) {
132 if (flatfirst) {
133 flags = DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL;
134 for (j = 0; j + first <= count; j += i) {
135 unsigned end = MIN2(FETCH_MAX, count - j);
136 end -= (end % incr);
137 for (i = 0; i+2 < end; i++) {
138 TRIANGLE(varray, flags, i + 1, i + 2, 0);
139 }
140 i = end;
141 fetch_init(varray, end);
142 varray_flush(varray);
143 }
144 }
145 else {
146 flags = DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL;
147 for (j = 0; j + first <= count; j += i) {
148 unsigned end = MIN2(FETCH_MAX, count - j);
149 end -= (end % incr);
150 for (i = 0; i+2 < end; i++) {
151 TRIANGLE(varray, flags, 0, i + 1, i + 2);
152 }
153 i = end;
154 fetch_init(varray, end);
155 varray_flush(varray);
156 }
157 }
158 }
159 break;
160
161 case PIPE_PRIM_QUADS:
162 for (j = 0; j + first <= count; j += i) {
163 unsigned end = MIN2(FETCH_MAX, count - j);
164 end -= (end % incr);
165 for (i = 0; i+3 < end; i += 4) {
166 QUAD(varray, i + 0, i + 1, i + 2, i + 3);
167 }
168 i = end;
169 fetch_init(varray, end);
170 varray_flush(varray);
171 }
172 break;
173
174 case PIPE_PRIM_QUAD_STRIP:
175 for (j = 0; j + first <= count; j += i) {
176 unsigned end = MIN2(FETCH_MAX, count - j);
177 end -= (end % incr);
178 for (i = 0; i+3 < end; i += 2) {
179 QUAD(varray, i + 2, i + 0, i + 1, i + 3);
180 }
181 i = end;
182 fetch_init(varray, end);
183 varray_flush(varray);
184 }
185 break;
186
187 case PIPE_PRIM_POLYGON:
188 {
189 /* These bitflags look a little odd because we submit the
190 * vertices as (1,2,0) to satisfy flatshade requirements.
191 */
192 const unsigned edge_first = DRAW_PIPE_EDGE_FLAG_2;
193 const unsigned edge_middle = DRAW_PIPE_EDGE_FLAG_0;
194 const unsigned edge_last = DRAW_PIPE_EDGE_FLAG_1;
195
196 flags = DRAW_PIPE_RESET_STIPPLE | edge_first | edge_middle;
197 for (j = 0; j + first <= count; j += i) {
198 unsigned end = MIN2(FETCH_MAX, count - j);
199 end -= (end % incr);
200 for (i = 0; i+2 < end; i++, flags = edge_middle) {
201
202 if (i + 3 == count)
203 flags |= edge_last;
204
205 TRIANGLE(varray, flags, i + 1, i + 2, 0);
206 }
207 i = end;
208 fetch_init(varray, end);
209 varray_flush(varray);
210 }
211 }
212 break;
213
214 default:
215 assert(0);
216 break;
217 }
218
219 varray_flush(varray);
220 }
221
222 #undef TRIANGLE
223 #undef QUAD
224 #undef POINT
225 #undef LINE
226 #undef FUNC