f2334a84f633453db1c0daba6b51c293db2b65f0
[mesa.git] / src / gallium / auxiliary / draw / draw_pt_vcache_tmp.h
1
2
3 static void FUNC( struct draw_pt_front_end *frontend,
4 pt_elt_func get_elt,
5 const void *elts,
6 unsigned count )
7 {
8 struct vcache_frontend *vcache = (struct vcache_frontend *)frontend;
9 struct draw_context *draw = vcache->draw;
10 unsigned i;
11 ushort flags;
12
13 if (0) debug_printf("%s %d\n", __FUNCTION__, count);
14
15 /* Note that no adjustment is made here for flatshade provoking
16 * vertex. This was previously the case, but was incorrect as the
17 * same logic would be applied twice both here & in the pipeline
18 * code or driver. The rule is now that we just preserve the
19 * original order in this code, and leave identification of the PV
20 * to the pipeline and driver.
21 */
22 switch (vcache->input_prim) {
23 case PIPE_PRIM_POINTS:
24 for (i = 0; i < count; i ++) {
25 POINT( vcache,
26 get_elt(elts, i + 0) );
27 }
28 break;
29
30 case PIPE_PRIM_LINES:
31 for (i = 0; i+1 < count; i += 2) {
32 LINE( vcache,
33 DRAW_PIPE_RESET_STIPPLE,
34 get_elt(elts, i + 0),
35 get_elt(elts, i + 1));
36 }
37 break;
38
39 case PIPE_PRIM_LINE_LOOP:
40 if (count >= 2) {
41 flags = DRAW_PIPE_RESET_STIPPLE;
42
43 for (i = 1; i < count; i++, flags = 0) {
44 LINE( vcache,
45 flags,
46 get_elt(elts, i - 1),
47 get_elt(elts, i ));
48 }
49
50 LINE( vcache,
51 flags,
52 get_elt(elts, i - 1),
53 get_elt(elts, 0 ));
54 }
55 break;
56
57 case PIPE_PRIM_LINE_STRIP:
58 flags = DRAW_PIPE_RESET_STIPPLE;
59 for (i = 1; i < count; i++, flags = 0) {
60 LINE( vcache,
61 flags,
62 get_elt(elts, i - 1),
63 get_elt(elts, i ));
64 }
65 break;
66
67 case PIPE_PRIM_TRIANGLES:
68 for (i = 0; i+2 < count; i += 3) {
69 TRIANGLE( vcache,
70 DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
71 get_elt(elts, i + 0),
72 get_elt(elts, i + 1),
73 get_elt(elts, i + 2 ));
74 }
75 break;
76
77 case PIPE_PRIM_TRIANGLE_STRIP:
78 for (i = 0; i+2 < count; i++) {
79 TRIANGLE( vcache,
80 DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
81 get_elt(elts, i + 0 + (i&1)),
82 get_elt(elts, i + 1 - (i&1)),
83 get_elt(elts, i + 2 ));
84 }
85 break;
86
87 case PIPE_PRIM_TRIANGLE_FAN:
88 if (count >= 3) {
89 for (i = 0; i+2 < count; i++) {
90 TRIANGLE( vcache,
91 DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
92 get_elt(elts, i + 1),
93 get_elt(elts, i + 2),
94 get_elt(elts, 0 ));
95 }
96 }
97 break;
98
99
100 case PIPE_PRIM_QUADS:
101 for (i = 0; i+3 < count; i += 4) {
102 QUAD( vcache,
103 get_elt(elts, i + 0),
104 get_elt(elts, i + 1),
105 get_elt(elts, i + 2),
106 get_elt(elts, i + 3));
107 }
108 break;
109
110 case PIPE_PRIM_QUAD_STRIP:
111 for (i = 0; i+3 < count; i += 2) {
112 QUAD( vcache,
113 get_elt(elts, i + 2),
114 get_elt(elts, i + 0),
115 get_elt(elts, i + 1),
116 get_elt(elts, i + 3));
117 }
118 break;
119
120 case PIPE_PRIM_POLYGON:
121 {
122 boolean flatfirst = (draw->rasterizer->flatshade &&
123 draw->rasterizer->flatshade_first);
124
125 /* These bitflags look a little odd because we submit the
126 * vertices as (1,2,0) to satisfy flatshade requirements.
127 *
128 * Polygon is defined has having vertex 0 be the provoking
129 * flatshade vertex and all known API's match this usage.
130 * However, the PV's for the triangles we emit from this
131 * decomposition vary according to the API, and hence we have
132 * to choose between two ways of emitting the triangles.
133 */
134 if (flatfirst) {
135 const ushort edge_first = DRAW_PIPE_EDGE_FLAG_0;
136 const ushort edge_middle = DRAW_PIPE_EDGE_FLAG_1;
137 const ushort edge_last = DRAW_PIPE_EDGE_FLAG_2;
138
139 flags = DRAW_PIPE_RESET_STIPPLE | edge_first | edge_middle;
140
141 for (i = 0; i+2 < count; i++, flags = edge_middle) {
142
143 if (i + 3 == count)
144 flags |= edge_last;
145
146 /* PV is first vertex */
147 TRIANGLE( vcache,
148 flags,
149 get_elt(elts, 0),
150 get_elt(elts, i + 1),
151 get_elt(elts, i + 2));
152 }
153 }
154 else {
155 const ushort edge_first = DRAW_PIPE_EDGE_FLAG_2;
156 const ushort edge_middle = DRAW_PIPE_EDGE_FLAG_0;
157 const ushort edge_last = DRAW_PIPE_EDGE_FLAG_1;
158
159 flags = DRAW_PIPE_RESET_STIPPLE | edge_first | edge_middle;
160
161 for (i = 0; i+2 < count; i++, flags = edge_middle) {
162
163 if (i + 3 == count)
164 flags |= edge_last;
165
166 /* PV is third vertex */
167 TRIANGLE( vcache,
168 flags,
169 get_elt(elts, i + 1),
170 get_elt(elts, i + 2),
171 get_elt(elts, 0));
172 }
173 }
174 }
175 break;
176
177 default:
178 assert(0);
179 break;
180 }
181
182 vcache_flush( vcache );
183 }
184
185
186 #undef TRIANGLE
187 #undef QUAD
188 #undef POINT
189 #undef LINE
190 #undef FUNC