draw: squash warnings
[mesa.git] / src / gallium / auxiliary / draw / draw_pt_varray.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "pipe/p_util.h"
29 #include "draw/draw_context.h"
30 #include "draw/draw_private.h"
31 #include "draw/draw_pt.h"
32
33 #define FETCH_MAX 256
34 #define DRAW_MAX (16*FETCH_MAX)
35
36 struct varray_frontend {
37 struct draw_pt_front_end base;
38 struct draw_context *draw;
39
40 ushort draw_elts[DRAW_MAX];
41 unsigned fetch_elts[FETCH_MAX];
42
43 unsigned draw_count;
44 unsigned fetch_count;
45
46 struct draw_pt_middle_end *middle;
47
48 unsigned input_prim;
49 unsigned output_prim;
50 };
51
52 static void varray_flush(struct varray_frontend *varray)
53 {
54 if (varray->draw_count) {
55 #if 0
56 debug_printf("FLUSH fc = %d, dc = %d\n",
57 varray->fetch_count,
58 varray->draw_count);
59 #endif
60 varray->middle->run(varray->middle,
61 varray->fetch_elts,
62 varray->fetch_count,
63 varray->draw_elts,
64 varray->draw_count);
65 }
66
67 varray->fetch_count = 0;
68 varray->draw_count = 0;
69 }
70
71 #if 0
72 static void varray_check_flush(struct varray_frontend *varray)
73 {
74 if (varray->draw_count + 6 >= DRAW_MAX/* ||
75 varray->fetch_count + 4 >= FETCH_MAX*/) {
76 varray_flush(varray);
77 }
78 }
79 #endif
80
81 static INLINE void add_draw_el(struct varray_frontend *varray,
82 int idx, ushort flags)
83 {
84 varray->draw_elts[varray->draw_count++] = idx | flags;
85 }
86
87
88 static INLINE void varray_triangle( struct varray_frontend *varray,
89 unsigned i0,
90 unsigned i1,
91 unsigned i2 )
92 {
93 add_draw_el(varray, i0, 0);
94 add_draw_el(varray, i1, 0);
95 add_draw_el(varray, i2, 0);
96 }
97
98 static INLINE void varray_triangle_flags( struct varray_frontend *varray,
99 ushort flags,
100 unsigned i0,
101 unsigned i1,
102 unsigned i2 )
103 {
104 add_draw_el(varray, i0, flags);
105 add_draw_el(varray, i1, 0);
106 add_draw_el(varray, i2, 0);
107 }
108
109 static INLINE void varray_line( struct varray_frontend *varray,
110 unsigned i0,
111 unsigned i1 )
112 {
113 add_draw_el(varray, i0, 0);
114 add_draw_el(varray, i1, 0);
115 }
116
117
118 static INLINE void varray_line_flags( struct varray_frontend *varray,
119 ushort flags,
120 unsigned i0,
121 unsigned i1 )
122 {
123 add_draw_el(varray, i0, flags);
124 add_draw_el(varray, i1, 0);
125 }
126
127
128 static INLINE void varray_point( struct varray_frontend *varray,
129 unsigned i0 )
130 {
131 add_draw_el(varray, i0, 0);
132 }
133
134 static INLINE void varray_quad( struct varray_frontend *varray,
135 unsigned i0,
136 unsigned i1,
137 unsigned i2,
138 unsigned i3 )
139 {
140 varray_triangle( varray, i0, i1, i3 );
141 varray_triangle( varray, i1, i2, i3 );
142 }
143
144 static INLINE void varray_ef_quad( struct varray_frontend *varray,
145 unsigned i0,
146 unsigned i1,
147 unsigned i2,
148 unsigned i3 )
149 {
150 const unsigned omitEdge1 = DRAW_PIPE_EDGE_FLAG_0 | DRAW_PIPE_EDGE_FLAG_2;
151 const unsigned omitEdge2 = DRAW_PIPE_EDGE_FLAG_0 | DRAW_PIPE_EDGE_FLAG_1;
152
153 varray_triangle_flags( varray,
154 DRAW_PIPE_RESET_STIPPLE | omitEdge1,
155 i0, i1, i3 );
156
157 varray_triangle_flags( varray,
158 omitEdge2,
159 i1, i2, i3 );
160 }
161
162 /* At least for now, we're back to using a template include file for
163 * this. The two paths aren't too different though - it may be
164 * possible to reunify them.
165 */
166 #define TRIANGLE(vc,flags,i0,i1,i2) varray_triangle_flags(vc,flags,i0,i1,i2)
167 #define QUAD(vc,i0,i1,i2,i3) varray_ef_quad(vc,i0,i1,i2,i3)
168 #define LINE(vc,flags,i0,i1) varray_line_flags(vc,flags,i0,i1)
169 #define POINT(vc,i0) varray_point(vc,i0)
170 #define FUNC varray_run_extras
171 #include "draw_pt_varray_tmp.h"
172
173 #define TRIANGLE(vc,flags,i0,i1,i2) varray_triangle(vc,i0,i1,i2)
174 #define QUAD(vc,i0,i1,i2,i3) varray_quad(vc,i0,i1,i2,i3)
175 #define LINE(vc,flags,i0,i1) varray_line(vc,i0,i1)
176 #define POINT(vc,i0) varray_point(vc,i0)
177 #define FUNC varray_run
178 #include "draw_pt_varray_tmp.h"
179
180
181
182 static unsigned reduced_prim[PIPE_PRIM_POLYGON + 1] = {
183 PIPE_PRIM_POINTS,
184 PIPE_PRIM_LINES,
185 PIPE_PRIM_LINES,
186 PIPE_PRIM_LINES,
187 PIPE_PRIM_TRIANGLES,
188 PIPE_PRIM_TRIANGLES,
189 PIPE_PRIM_TRIANGLES,
190 PIPE_PRIM_TRIANGLES,
191 PIPE_PRIM_TRIANGLES,
192 PIPE_PRIM_TRIANGLES
193 };
194
195
196
197 static void varray_prepare(struct draw_pt_front_end *frontend,
198 unsigned prim,
199 struct draw_pt_middle_end *middle,
200 unsigned opt)
201 {
202 struct varray_frontend *varray = (struct varray_frontend *)frontend;
203
204 if (opt & PT_PIPELINE)
205 {
206 varray->base.run = varray_run_extras;
207 }
208 else
209 {
210 varray->base.run = varray_run;
211 }
212
213 varray->input_prim = prim;
214 varray->output_prim = reduced_prim[prim];
215
216 varray->middle = middle;
217 middle->prepare(middle, varray->output_prim, opt);
218 }
219
220
221
222
223 static void varray_finish(struct draw_pt_front_end *frontend)
224 {
225 struct varray_frontend *varray = (struct varray_frontend *)frontend;
226 varray->middle->finish(varray->middle);
227 varray->middle = NULL;
228 }
229
230 static void varray_destroy(struct draw_pt_front_end *frontend)
231 {
232 FREE(frontend);
233 }
234
235
236 struct draw_pt_front_end *draw_pt_varray(struct draw_context *draw)
237 {
238 struct varray_frontend *varray = CALLOC_STRUCT(varray_frontend);
239 if (varray == NULL)
240 return NULL;
241
242 varray->base.prepare = varray_prepare;
243 varray->base.run = NULL;
244 varray->base.finish = varray_finish;
245 varray->base.destroy = varray_destroy;
246 varray->draw = draw;
247
248 return &varray->base;
249 }