1395275897629fe909eea9c21d19330670073d0d
[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 < end; 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 fetch_init(varray, end);
96 varray_flush(varray);
97 }
98 break;
99
100 case PIPE_PRIM_TRIANGLE_STRIP:
101 if (flatfirst) {
102 for (j = 0; j + first <= count; j += i) {
103 unsigned end = MIN2(FETCH_MAX, count - j);
104 end -= (end % incr);
105 for (i = 0; i+2 < end; i++) {
106 TRIANGLE(varray, DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
107 i + 0, i + 1 + (i&1), i + 2 - (i&1));
108 }
109 i = end;
110 fetch_init(varray, end);
111 varray_flush(varray);
112 if (j + first + i <= count) {
113 varray->fetch_start -= 2;
114 i -= 2;
115 }
116 }
117 }
118 else {
119 for (j = 0; j + first <= count; j += i) {
120 unsigned end = MIN2(FETCH_MAX, count - j);
121 end -= (end % incr);
122 for (i = 0; i + 2 < end; i++) {
123 TRIANGLE(varray, DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
124 i + 0 + (i&1), i + 1 - (i&1), i + 2);
125 }
126 i = end;
127 fetch_init(varray, end);
128 varray_flush(varray);
129 if (j + first + i <= count) {
130 varray->fetch_start -= 2;
131 i -= 2;
132 }
133 }
134 }
135 break;
136
137 case PIPE_PRIM_TRIANGLE_FAN:
138 if (count >= 3) {
139 if (flatfirst) {
140 flags = DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL;
141 for (j = 0; j + first <= count; j += i) {
142 unsigned end = MIN2(FETCH_MAX, count - j);
143 end -= (end % incr);
144 for (i = 0; i+2 < end; i++) {
145 TRIANGLE(varray, flags, i + 1, i + 2, 0);
146 }
147 i = end;
148 fetch_init(varray, end);
149 varray_flush(varray);
150 }
151 }
152 else {
153 flags = DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL;
154 for (j = 0; j + first <= count; j += i) {
155 unsigned end = MIN2(FETCH_MAX, count - j);
156 end -= (end % incr);
157 for (i = 0; i+2 < end; i++) {
158 TRIANGLE(varray, flags, 0, i + 1, i + 2);
159 }
160 i = end;
161 fetch_init(varray, end);
162 varray_flush(varray);
163 }
164 }
165 }
166 break;
167
168 case PIPE_PRIM_QUADS:
169 for (j = 0; j + first <= count; j += i) {
170 unsigned end = MIN2(FETCH_MAX, count - j);
171 end -= (end % incr);
172 for (i = 0; i+3 < end; i += 4) {
173 QUAD(varray, i + 0, i + 1, i + 2, i + 3);
174 }
175 i = end;
176 fetch_init(varray, end);
177 varray_flush(varray);
178 }
179 break;
180
181 case PIPE_PRIM_QUAD_STRIP:
182 for (j = 0; j + first <= count; j += i) {
183 unsigned end = MIN2(FETCH_MAX, count - j);
184 end -= (end % incr);
185 for (i = 0; i+3 < end; i += 2) {
186 QUAD(varray, i + 2, i + 0, i + 1, i + 3);
187 }
188 i = end;
189 fetch_init(varray, end);
190 varray_flush(varray);
191 if (j + first + i <= count) {
192 varray->fetch_start -= 2;
193 i -= 2;
194 }
195 }
196 break;
197
198 case PIPE_PRIM_POLYGON:
199 {
200 /* These bitflags look a little odd because we submit the
201 * vertices as (1,2,0) to satisfy flatshade requirements.
202 */
203 const unsigned edge_first = DRAW_PIPE_EDGE_FLAG_2;
204 const unsigned edge_middle = DRAW_PIPE_EDGE_FLAG_0;
205 const unsigned edge_last = DRAW_PIPE_EDGE_FLAG_1;
206
207 flags = DRAW_PIPE_RESET_STIPPLE | edge_first | edge_middle;
208 for (j = 0; j + first <= count; j += i) {
209 unsigned end = MIN2(FETCH_MAX, count - j);
210 end -= (end % incr);
211 for (i = 0; i+2 < end; i++, flags = edge_middle) {
212
213 if (i + 3 == count)
214 flags |= edge_last;
215
216 TRIANGLE(varray, flags, i + 1, i + 2, 0);
217 }
218 i = end;
219 fetch_init(varray, end);
220 varray_flush(varray);
221 }
222 }
223 break;
224
225 default:
226 assert(0);
227 break;
228 }
229
230 varray_flush(varray);
231 }
232
233 #undef TRIANGLE
234 #undef QUAD
235 #undef POINT
236 #undef LINE
237 #undef FUNC