6e2b16d9be2af761dd6b8866df0406b26d135539
[mesa.git] / src / gallium / auxiliary / draw / draw_pt_varray_tmp_linear.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 case PIPE_PRIM_LINES:
29 case PIPE_PRIM_TRIANGLES:
30 j = 0;
31 while (j + first <= count) {
32 unsigned end = MIN2(FETCH_MAX, count - j);
33 end -= (end % incr);
34 varray_flush_linear(varray, start + j, end);
35 j += end;
36 }
37 break;
38
39 case PIPE_PRIM_LINE_LOOP:
40 if (count >= 2) {
41 flags = DRAW_PIPE_RESET_STIPPLE;
42
43 for (j = 0; j + first <= count; j += i) {
44 unsigned end = MIN2(FETCH_MAX, count - j);
45 end -= (end % incr);
46 for (i = 1; i < end; i++, flags = 0) {
47 LINE(varray, flags, i - 1, i);
48 }
49 LINE(varray, flags, i - 1, 0);
50 i = end;
51 fetch_init(varray, end);
52 varray_flush(varray);
53 }
54 }
55 break;
56
57 case PIPE_PRIM_LINE_STRIP:
58 flags = DRAW_PIPE_RESET_STIPPLE;
59 for (j = 0; j + first <= count; j += i) {
60 unsigned end = MIN2(FETCH_MAX, count - j);
61 end -= (end % incr);
62 for (i = 1; i < end; i++, flags = 0) {
63 LINE(varray, flags, i - 1, i);
64 }
65 i = end;
66 fetch_init(varray, end);
67 varray_flush(varray);
68 }
69 break;
70
71 case PIPE_PRIM_TRIANGLE_STRIP:
72 if (flatfirst) {
73 for (j = 0; j + first <= count; j += i) {
74 unsigned end = MIN2(FETCH_MAX, count - j);
75 end -= (end % incr);
76 for (i = 0; i+2 < end; i++) {
77 TRIANGLE(varray, DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
78 i + 0, i + 1 + (i&1), i + 2 - (i&1));
79 }
80 i = end;
81 fetch_init(varray, end);
82 varray_flush(varray);
83 if (j + first + i <= count) {
84 varray->fetch_start -= 2;
85 i -= 2;
86 }
87 }
88 }
89 else {
90 for (j = 0; j + first <= count; j += i) {
91 unsigned end = MIN2(FETCH_MAX, count - j);
92 end -= (end % incr);
93 for (i = 0; i+2 < end; i++) {
94 TRIANGLE(varray, DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
95 i + 0 + (i&1), i + 1 - (i&1), i + 2);
96 }
97 i = end;
98 fetch_init(varray, end);
99 varray_flush(varray);
100 if (j + first + i <= count) {
101 varray->fetch_start -= 2;
102 i -= 2;
103 }
104 }
105 }
106 break;
107
108 case PIPE_PRIM_TRIANGLE_FAN:
109 if (count >= 3) {
110 if (flatfirst) {
111 flags = DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL;
112 for (j = 0; j + first <= count; j += i) {
113 unsigned end = MIN2(FETCH_MAX, count - j);
114 end -= (end % incr);
115 for (i = 0; i+2 < end; i++) {
116 TRIANGLE(varray, flags, i + 1, i + 2, 0);
117 }
118 i = end;
119 fetch_init(varray, end);
120 varray_flush(varray);
121 }
122 }
123 else {
124 flags = DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL;
125 for (j = 0; j + first <= count; j += i) {
126 unsigned end = MIN2(FETCH_MAX, count - j);
127 end -= (end % incr);
128 for (i = 0; i+2 < end; i++) {
129 TRIANGLE(varray, flags, 0, i + 1, i + 2);
130 }
131 i = end;
132 fetch_init(varray, end);
133 varray_flush(varray);
134 }
135 }
136 }
137 break;
138
139 case PIPE_PRIM_QUADS:
140 for (j = 0; j + first <= count; j += i) {
141 unsigned end = MIN2(FETCH_MAX, count - j);
142 end -= (end % incr);
143 for (i = 0; i+3 < end; i += 4) {
144 QUAD(varray, i + 0, i + 1, i + 2, i + 3);
145 }
146 i = end;
147 fetch_init(varray, end);
148 varray_flush(varray);
149 }
150 break;
151
152 case PIPE_PRIM_QUAD_STRIP:
153 for (j = 0; j + first <= count; j += i) {
154 unsigned end = MIN2(FETCH_MAX, count - j);
155 end -= (end % incr);
156 for (i = 0; i+3 < end; i += 2) {
157 QUAD(varray, i + 2, i + 0, i + 1, i + 3);
158 }
159 i = end;
160 fetch_init(varray, end);
161 varray_flush(varray);
162 if (j + first + i <= count) {
163 varray->fetch_start -= 2;
164 i -= 2;
165 }
166 }
167 break;
168
169 case PIPE_PRIM_POLYGON:
170 {
171 /* These bitflags look a little odd because we submit the
172 * vertices as (1,2,0) to satisfy flatshade requirements.
173 */
174 const unsigned edge_first = DRAW_PIPE_EDGE_FLAG_2;
175 const unsigned edge_middle = DRAW_PIPE_EDGE_FLAG_0;
176 const unsigned edge_last = DRAW_PIPE_EDGE_FLAG_1;
177
178 flags = DRAW_PIPE_RESET_STIPPLE | edge_first | edge_middle;
179 for (j = 0; j + first <= count; j += i) {
180 unsigned end = MIN2(FETCH_MAX, count - j);
181 end -= (end % incr);
182 for (i = 0; i+2 < end; i++, flags = edge_middle) {
183
184 if (i + 3 == count)
185 flags |= edge_last;
186
187 TRIANGLE(varray, flags, i + 1, i + 2, 0);
188 }
189 i = end;
190 fetch_init(varray, end);
191 varray_flush(varray);
192 }
193 }
194 break;
195
196 default:
197 assert(0);
198 break;
199 }
200
201 varray_flush(varray);
202 }
203
204 #undef TRIANGLE
205 #undef QUAD
206 #undef POINT
207 #undef LINE
208 #undef FUNC