Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / drivers / dri / mach64 / mach64_vb.c
1 /* -*- mode: c; c-basic-offset: 3 -*- */
2 /*
3  * Copyright 2000 Gareth Hughes
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 "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * GARETH HUGHES BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 /*
26  * Authors:
27  *      Gareth Hughes <gareth@valinux.com>
28  *      Leif Delgass <ldelgass@retinalburn.net>
29  *      José Fonseca <j_r_fonseca@yahoo.co.uk>
30  */
31
32 #include "main/glheader.h"
33 #include "main/mtypes.h"
34 #include "main/imports.h"
35 #include "main/macros.h"
36 #include "main/colormac.h"
37
38 #include "swrast_setup/swrast_setup.h"
39 #include "tnl/t_context.h"
40
41 #include "mach64_context.h"
42 #include "mach64_vb.h"
43 #include "mach64_ioctl.h"
44 #include "mach64_tris.h"
45
46
47 #define MACH64_TEX1_BIT       0x1
48 #define MACH64_TEX0_BIT       0x2
49 #define MACH64_RGBA_BIT       0x4
50 #define MACH64_SPEC_BIT       0x8
51 #define MACH64_FOG_BIT        0x10
52 #define MACH64_XYZW_BIT       0x20
53 #define MACH64_PTEX_BIT       0x40
54 #define MACH64_MAX_SETUP      0x80
55
56 static struct {
57    void                (*emit)( struct gl_context *, GLuint, GLuint, void *, GLuint );
58    tnl_interp_func              interp;
59    tnl_copy_pv_func             copy_pv;
60    GLboolean           (*check_tex_sizes)( struct gl_context *ctx );
61    GLuint               vertex_size;
62    GLuint               vertex_format;
63 } setup_tab[MACH64_MAX_SETUP];
64
65 #define TINY_VERTEX_FORMAT      1
66 #define NOTEX_VERTEX_FORMAT     2
67 #define TEX0_VERTEX_FORMAT      3
68 #define TEX1_VERTEX_FORMAT      4
69 #define PROJ_TEX1_VERTEX_FORMAT 0
70 #define TEX2_VERTEX_FORMAT      0
71 #define TEX3_VERTEX_FORMAT      0
72 #define PROJ_TEX3_VERTEX_FORMAT 0
73
74 #define DO_XYZW (IND & MACH64_XYZW_BIT)
75 #define DO_RGBA (IND & MACH64_RGBA_BIT)
76 #define DO_SPEC (IND & MACH64_SPEC_BIT)
77 #define DO_FOG  (IND & MACH64_FOG_BIT)
78 #define DO_TEX0 (IND & MACH64_TEX0_BIT)
79 #define DO_TEX1 (IND & MACH64_TEX1_BIT)
80 #define DO_TEX2 0
81 #define DO_TEX3 0
82 #define DO_PTEX (IND & MACH64_PTEX_BIT)
83
84 #define VERTEX mach64Vertex
85 #define LOCALVARS mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
86 #define GET_VIEWPORT_MAT() mmesa->hw_viewport
87 #define GET_TEXSOURCE(n)  mmesa->tmu_source[n]
88 #define GET_VERTEX_FORMAT() mmesa->vertex_format
89 #define GET_VERTEX_STORE() mmesa->verts
90 #define GET_VERTEX_SIZE() mmesa->vertex_size * sizeof(GLuint)
91
92 #define HAVE_HW_VIEWPORT    0
93 #define HAVE_HW_DIVIDE      0
94 #define HAVE_RGBA_COLOR     0
95 #define HAVE_TINY_VERTICES  1
96 #define HAVE_NOTEX_VERTICES 1
97 #define HAVE_TEX0_VERTICES  1
98 #define HAVE_TEX1_VERTICES  1
99 #define HAVE_TEX2_VERTICES  0
100 #define HAVE_TEX3_VERTICES  0
101 #define HAVE_PTEX_VERTICES  0
102
103 #define UNVIEWPORT_VARS                                         \
104    const GLfloat dx = - (GLfloat)mmesa->drawX - SUBPIXEL_X;     \
105    const GLfloat dy = (mmesa->driDrawable->h +                  \
106                        (GLfloat)mmesa->drawY  + SUBPIXEL_Y);    \
107    const GLfloat sz = 1.0 / mmesa->depth_scale
108
109 #if MACH64_NATIVE_VTXFMT
110    
111 #define UNVIEWPORT_X(x)    ((GLfloat)(x) / 4.0)  +  dx
112 #define UNVIEWPORT_Y(y)  - ((GLfloat)(y) / 4.0)  +  dy
113 #define UNVIEWPORT_Z(z)    (GLfloat)((z) >> 15)  *  sz
114
115 #else
116
117 #define UNVIEWPORT_X(x)    x  +  dx;
118 #define UNVIEWPORT_Y(y)  - y  +  dy;
119 #define UNVIEWPORT_Z(z)    z  *  sz;
120
121 #endif
122
123 #define PTEX_FALLBACK() FALLBACK(MACH64_CONTEXT(ctx), MACH64_FALLBACK_TEXTURE, 1)
124
125 #define IMPORT_FLOAT_COLORS mach64_import_float_colors
126 #define IMPORT_FLOAT_SPEC_COLORS mach64_import_float_spec_colors
127
128 #define INTERP_VERTEX setup_tab[mmesa->SetupIndex].interp
129 #define COPY_PV_VERTEX setup_tab[mmesa->SetupIndex].copy_pv
130
131 /***********************************************************************
132  *         Generate  pv-copying and translation functions              *
133  ***********************************************************************/
134
135 #if MACH64_NATIVE_VTXFMT
136
137 #define TAG(x) mach64_##x
138 #include "mach64_native_vb.c"
139
140 #else
141
142 #define TAG(x) mach64_##x
143 #include "tnl_dd/t_dd_vb.c"
144
145 #endif
146
147 /***********************************************************************
148  *             Generate vertex emit and interp functions               *
149  ***********************************************************************/
150
151
152 #if MACH64_NATIVE_VTXFMT
153
154 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT)
155 #define TAG(x) x##_wg
156 #include "mach64_native_vbtmp.h"
157
158 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_SPEC_BIT)
159 #define TAG(x) x##_wgs
160 #include "mach64_native_vbtmp.h"
161
162 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_TEX0_BIT)
163 #define TAG(x) x##_wgt0
164 #include "mach64_native_vbtmp.h"
165
166 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_TEX0_BIT|MACH64_TEX1_BIT)
167 #define TAG(x) x##_wgt0t1
168 #include "mach64_native_vbtmp.h"
169
170 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_TEX0_BIT|MACH64_PTEX_BIT)
171 #define TAG(x) x##_wgpt0
172 #include "mach64_native_vbtmp.h"
173
174 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_SPEC_BIT|MACH64_TEX0_BIT)
175 #define TAG(x) x##_wgst0
176 #include "mach64_native_vbtmp.h"
177
178 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_SPEC_BIT|MACH64_TEX0_BIT|\
179              MACH64_TEX1_BIT)
180 #define TAG(x) x##_wgst0t1
181 #include "mach64_native_vbtmp.h"
182
183 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_SPEC_BIT|MACH64_TEX0_BIT|\
184              MACH64_PTEX_BIT)
185 #define TAG(x) x##_wgspt0
186 #include "mach64_native_vbtmp.h"
187
188 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_FOG_BIT)
189 #define TAG(x) x##_wgf
190 #include "mach64_native_vbtmp.h"
191
192 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_SPEC_BIT)
193 #define TAG(x) x##_wgfs
194 #include "mach64_native_vbtmp.h"
195
196 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_TEX0_BIT)
197 #define TAG(x) x##_wgft0
198 #include "mach64_native_vbtmp.h"
199
200 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_TEX0_BIT|\
201              MACH64_TEX1_BIT)
202 #define TAG(x) x##_wgft0t1
203 #include "mach64_native_vbtmp.h"
204
205 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_TEX0_BIT|\
206              MACH64_PTEX_BIT)
207 #define TAG(x) x##_wgfpt0
208 #include "mach64_native_vbtmp.h"
209
210 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_SPEC_BIT|\
211              MACH64_TEX0_BIT)
212 #define TAG(x) x##_wgfst0
213 #include "mach64_native_vbtmp.h"
214
215 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_SPEC_BIT|\
216              MACH64_TEX0_BIT|MACH64_TEX1_BIT)
217 #define TAG(x) x##_wgfst0t1
218 #include "mach64_native_vbtmp.h"
219
220 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_SPEC_BIT|\
221              MACH64_TEX0_BIT|MACH64_PTEX_BIT)
222 #define TAG(x) x##_wgfspt0
223 #include "mach64_native_vbtmp.h"
224
225 #define IND (MACH64_TEX0_BIT)
226 #define TAG(x) x##_t0
227 #include "mach64_native_vbtmp.h"
228
229 #define IND (MACH64_TEX0_BIT|MACH64_TEX1_BIT)
230 #define TAG(x) x##_t0t1
231 #include "mach64_native_vbtmp.h"
232
233 #define IND (MACH64_FOG_BIT)
234 #define TAG(x) x##_f
235 #include "mach64_native_vbtmp.h"
236
237 #define IND (MACH64_FOG_BIT|MACH64_TEX0_BIT)
238 #define TAG(x) x##_ft0
239 #include "mach64_native_vbtmp.h"
240
241 #define IND (MACH64_FOG_BIT|MACH64_TEX0_BIT|MACH64_TEX1_BIT)
242 #define TAG(x) x##_ft0t1
243 #include "mach64_native_vbtmp.h"
244
245 #define IND (MACH64_RGBA_BIT)
246 #define TAG(x) x##_g
247 #include "mach64_native_vbtmp.h"
248
249 #define IND (MACH64_RGBA_BIT|MACH64_SPEC_BIT)
250 #define TAG(x) x##_gs
251 #include "mach64_native_vbtmp.h"
252
253 #define IND (MACH64_RGBA_BIT|MACH64_TEX0_BIT)
254 #define TAG(x) x##_gt0
255 #include "mach64_native_vbtmp.h"
256
257 #define IND (MACH64_RGBA_BIT|MACH64_TEX0_BIT|MACH64_TEX1_BIT)
258 #define TAG(x) x##_gt0t1
259 #include "mach64_native_vbtmp.h"
260
261 #define IND (MACH64_RGBA_BIT|MACH64_SPEC_BIT|MACH64_TEX0_BIT)
262 #define TAG(x) x##_gst0
263 #include "mach64_native_vbtmp.h"
264
265 #define IND (MACH64_RGBA_BIT|MACH64_SPEC_BIT|MACH64_TEX0_BIT|MACH64_TEX1_BIT)
266 #define TAG(x) x##_gst0t1
267 #include "mach64_native_vbtmp.h"
268
269 #define IND (MACH64_RGBA_BIT|MACH64_FOG_BIT)
270 #define TAG(x) x##_gf
271 #include "mach64_native_vbtmp.h"
272
273 #define IND (MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_SPEC_BIT)
274 #define TAG(x) x##_gfs
275 #include "mach64_native_vbtmp.h"
276
277 #define IND (MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_TEX0_BIT)
278 #define TAG(x) x##_gft0
279 #include "mach64_native_vbtmp.h"
280
281 #define IND (MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_TEX0_BIT|MACH64_TEX1_BIT)
282 #define TAG(x) x##_gft0t1
283 #include "mach64_native_vbtmp.h"
284
285 #define IND (MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_SPEC_BIT|MACH64_TEX0_BIT)
286 #define TAG(x) x##_gfst0
287 #include "mach64_native_vbtmp.h"
288
289 #define IND (MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_SPEC_BIT|MACH64_TEX0_BIT|\
290              MACH64_TEX1_BIT)
291 #define TAG(x) x##_gfst0t1
292 #include "mach64_native_vbtmp.h"
293
294 #else
295
296 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT)
297 #define TAG(x) x##_wg
298 #include "mach64_vbtmp.h"
299
300 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_SPEC_BIT)
301 #define TAG(x) x##_wgs
302 #include "mach64_vbtmp.h"
303
304 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_TEX0_BIT)
305 #define TAG(x) x##_wgt0
306 #include "mach64_vbtmp.h"
307
308 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_TEX0_BIT|MACH64_TEX1_BIT)
309 #define TAG(x) x##_wgt0t1
310 #include "mach64_vbtmp.h"
311
312 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_TEX0_BIT|MACH64_PTEX_BIT)
313 #define TAG(x) x##_wgpt0
314 #include "mach64_vbtmp.h"
315
316 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_SPEC_BIT|MACH64_TEX0_BIT)
317 #define TAG(x) x##_wgst0
318 #include "mach64_vbtmp.h"
319
320 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_SPEC_BIT|MACH64_TEX0_BIT|\
321              MACH64_TEX1_BIT)
322 #define TAG(x) x##_wgst0t1
323 #include "mach64_vbtmp.h"
324
325 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_SPEC_BIT|MACH64_TEX0_BIT|\
326              MACH64_PTEX_BIT)
327 #define TAG(x) x##_wgspt0
328 #include "mach64_vbtmp.h"
329
330 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_FOG_BIT)
331 #define TAG(x) x##_wgf
332 #include "mach64_vbtmp.h"
333
334 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_SPEC_BIT)
335 #define TAG(x) x##_wgfs
336 #include "mach64_vbtmp.h"
337
338 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_TEX0_BIT)
339 #define TAG(x) x##_wgft0
340 #include "mach64_vbtmp.h"
341
342 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_TEX0_BIT|\
343              MACH64_TEX1_BIT)
344 #define TAG(x) x##_wgft0t1
345 #include "mach64_vbtmp.h"
346
347 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_TEX0_BIT|\
348              MACH64_PTEX_BIT)
349 #define TAG(x) x##_wgfpt0
350 #include "mach64_vbtmp.h"
351
352 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_SPEC_BIT|\
353              MACH64_TEX0_BIT)
354 #define TAG(x) x##_wgfst0
355 #include "mach64_vbtmp.h"
356
357 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_SPEC_BIT|\
358              MACH64_TEX0_BIT|MACH64_TEX1_BIT)
359 #define TAG(x) x##_wgfst0t1
360 #include "mach64_vbtmp.h"
361
362 #define IND (MACH64_XYZW_BIT|MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_SPEC_BIT|\
363              MACH64_TEX0_BIT|MACH64_PTEX_BIT)
364 #define TAG(x) x##_wgfspt0
365 #include "mach64_vbtmp.h"
366
367 #define IND (MACH64_TEX0_BIT)
368 #define TAG(x) x##_t0
369 #include "mach64_vbtmp.h"
370
371 #define IND (MACH64_TEX0_BIT|MACH64_TEX1_BIT)
372 #define TAG(x) x##_t0t1
373 #include "mach64_vbtmp.h"
374
375 #define IND (MACH64_FOG_BIT)
376 #define TAG(x) x##_f
377 #include "mach64_vbtmp.h"
378
379 #define IND (MACH64_FOG_BIT|MACH64_TEX0_BIT)
380 #define TAG(x) x##_ft0
381 #include "mach64_vbtmp.h"
382
383 #define IND (MACH64_FOG_BIT|MACH64_TEX0_BIT|MACH64_TEX1_BIT)
384 #define TAG(x) x##_ft0t1
385 #include "mach64_vbtmp.h"
386
387 #define IND (MACH64_RGBA_BIT)
388 #define TAG(x) x##_g
389 #include "mach64_vbtmp.h"
390
391 #define IND (MACH64_RGBA_BIT|MACH64_SPEC_BIT)
392 #define TAG(x) x##_gs
393 #include "mach64_vbtmp.h"
394
395 #define IND (MACH64_RGBA_BIT|MACH64_TEX0_BIT)
396 #define TAG(x) x##_gt0
397 #include "mach64_vbtmp.h"
398
399 #define IND (MACH64_RGBA_BIT|MACH64_TEX0_BIT|MACH64_TEX1_BIT)
400 #define TAG(x) x##_gt0t1
401 #include "mach64_vbtmp.h"
402
403 #define IND (MACH64_RGBA_BIT|MACH64_SPEC_BIT|MACH64_TEX0_BIT)
404 #define TAG(x) x##_gst0
405 #include "mach64_vbtmp.h"
406
407 #define IND (MACH64_RGBA_BIT|MACH64_SPEC_BIT|MACH64_TEX0_BIT|MACH64_TEX1_BIT)
408 #define TAG(x) x##_gst0t1
409 #include "mach64_vbtmp.h"
410
411 #define IND (MACH64_RGBA_BIT|MACH64_FOG_BIT)
412 #define TAG(x) x##_gf
413 #include "mach64_vbtmp.h"
414
415 #define IND (MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_SPEC_BIT)
416 #define TAG(x) x##_gfs
417 #include "mach64_vbtmp.h"
418
419 #define IND (MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_TEX0_BIT)
420 #define TAG(x) x##_gft0
421 #include "mach64_vbtmp.h"
422
423 #define IND (MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_TEX0_BIT|MACH64_TEX1_BIT)
424 #define TAG(x) x##_gft0t1
425 #include "mach64_vbtmp.h"
426
427 #define IND (MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_SPEC_BIT|MACH64_TEX0_BIT)
428 #define TAG(x) x##_gfst0
429 #include "mach64_vbtmp.h"
430
431 #define IND (MACH64_RGBA_BIT|MACH64_FOG_BIT|MACH64_SPEC_BIT|MACH64_TEX0_BIT|\
432              MACH64_TEX1_BIT)
433 #define TAG(x) x##_gfst0t1
434 #include "mach64_vbtmp.h"
435
436 #endif
437
438 static void init_setup_tab( void )
439 {
440    init_wg();
441    init_wgs();
442    init_wgt0();
443    init_wgt0t1();
444    init_wgpt0();
445    init_wgst0();
446    init_wgst0t1();
447    init_wgspt0();
448    init_wgf();
449    init_wgfs();
450    init_wgft0();
451    init_wgft0t1();
452    init_wgfpt0();
453    init_wgfst0();
454    init_wgfst0t1();
455    init_wgfspt0();
456    init_t0();
457    init_t0t1();
458    init_f();
459    init_ft0();
460    init_ft0t1();
461    init_g();
462    init_gs();
463    init_gt0();
464    init_gt0t1();
465    init_gst0();
466    init_gst0t1();
467    init_gf();
468    init_gfs();
469    init_gft0();
470    init_gft0t1();
471    init_gfst0();
472    init_gfst0t1();
473 }
474
475
476
477 void mach64PrintSetupFlags( char *msg, GLuint flags )
478 {
479    fprintf( stderr, "%s: %d %s%s%s%s%s%s%s\n",
480             msg,
481             (int)flags,
482             (flags & MACH64_XYZW_BIT)   ? " xyzw," : "",
483             (flags & MACH64_RGBA_BIT)   ? " rgba," : "",
484             (flags & MACH64_SPEC_BIT)   ? " spec," : "",
485             (flags & MACH64_FOG_BIT)    ? " fog," : "",
486             (flags & MACH64_TEX0_BIT)   ? " tex-0," : "",
487             (flags & MACH64_TEX1_BIT)   ? " tex-1," : "",
488             (flags & MACH64_PTEX_BIT)   ? " ptex," : "");
489 }
490
491
492
493
494 void mach64CheckTexSizes( struct gl_context *ctx )
495 {
496    mach64ContextPtr mmesa = MACH64_CONTEXT( ctx );
497
498    if (!setup_tab[mmesa->SetupIndex].check_tex_sizes(ctx)) {
499       TNLcontext *tnl = TNL_CONTEXT(ctx);
500
501       /* Invalidate stored verts
502        */
503       mmesa->SetupNewInputs = ~0;
504       mmesa->SetupIndex |= MACH64_PTEX_BIT;
505
506       if (!mmesa->Fallback &&
507           !(ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
508          tnl->Driver.Render.Interp = setup_tab[mmesa->SetupIndex].interp;
509          tnl->Driver.Render.CopyPV = setup_tab[mmesa->SetupIndex].copy_pv;
510       }
511    }
512 }
513
514 void mach64BuildVertices( struct gl_context *ctx,
515                         GLuint start,
516                         GLuint count,
517                         GLuint newinputs )
518 {
519    mach64ContextPtr mmesa = MACH64_CONTEXT( ctx );
520    GLuint stride = mmesa->vertex_size * sizeof(int);
521    GLubyte *v = ((GLubyte *)mmesa->verts + (start * stride));
522
523    newinputs |= mmesa->SetupNewInputs;
524    mmesa->SetupNewInputs = 0;
525
526    if (!newinputs)
527       return;
528
529    if (newinputs & VERT_BIT_POS) {
530       setup_tab[mmesa->SetupIndex].emit( ctx, start, count, v, stride );
531    } else {
532       GLuint ind = 0;
533
534       if (newinputs & VERT_BIT_COLOR0)
535          ind |= MACH64_RGBA_BIT;
536
537       if (newinputs & VERT_BIT_COLOR1)
538          ind |= MACH64_SPEC_BIT;
539
540       if (newinputs & VERT_BIT_TEX0)
541          ind |= MACH64_TEX0_BIT;
542
543       if (newinputs & VERT_BIT_TEX1)
544          ind |= MACH64_TEX1_BIT;
545
546       if (newinputs & VERT_BIT_FOG)
547          ind |= MACH64_FOG_BIT;
548
549       if (mmesa->SetupIndex & MACH64_PTEX_BIT)
550          ind = ~0;
551
552       ind &= mmesa->SetupIndex;
553
554       if (ind) {
555          setup_tab[ind].emit( ctx, start, count, v, stride );
556       }
557    }
558 }
559
560 void mach64ChooseVertexState( struct gl_context *ctx )
561 {
562    TNLcontext *tnl = TNL_CONTEXT(ctx);
563    mach64ContextPtr mmesa = MACH64_CONTEXT( ctx );
564    GLuint ind = MACH64_XYZW_BIT|MACH64_RGBA_BIT;
565    
566    if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)
567       ind |= MACH64_SPEC_BIT;
568
569    if (ctx->Fog.Enabled)
570       ind |= MACH64_FOG_BIT;
571
572    if (ctx->Texture._EnabledUnits) {
573       ind |= MACH64_TEX0_BIT;
574       if (ctx->Texture.Unit[0]._ReallyEnabled &&
575           ctx->Texture.Unit[1]._ReallyEnabled) {
576          ind |= MACH64_TEX1_BIT;
577       }
578    }
579
580    mmesa->SetupIndex = ind;
581
582    if (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED)) {
583       tnl->Driver.Render.Interp = mach64_interp_extras;
584       tnl->Driver.Render.CopyPV = mach64_copy_pv_extras;
585    } else {
586       tnl->Driver.Render.Interp = setup_tab[ind].interp;
587       tnl->Driver.Render.CopyPV = setup_tab[ind].copy_pv;
588    }
589
590 #if 0
591    if (MACH64_DEBUG & DEBUG_VERBOSE_MSG) {
592       mach64PrintSetupFlags( __FUNCTION__, ind );
593   }
594 #endif
595
596    if (setup_tab[ind].vertex_format != mmesa->vertex_format) {
597       FLUSH_BATCH(mmesa);
598       mmesa->vertex_format = setup_tab[ind].vertex_format;
599       mmesa->vertex_size = setup_tab[ind].vertex_size;
600    }
601 }
602
603
604 #if 0
605 void mach64_emit_contiguous_verts( struct gl_context *ctx,
606                                  GLuint start,
607                                  GLuint count )
608 {
609    mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
610    GLuint vertex_size = mmesa->vertex_size * 4;
611    GLuint *dest = mach64AllocDmaLow( mmesa, (count-start) * vertex_size);
612    setup_tab[mmesa->SetupIndex].emit( ctx, start, count, dest, vertex_size );
613 }
614 #endif
615
616
617 void mach64InitVB( struct gl_context *ctx )
618 {
619    mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
620    GLuint size = TNL_CONTEXT(ctx)->vb.Size;
621
622    mmesa->verts = (GLubyte *)_mesa_align_malloc(size * 4 * 16, 32);
623
624    {
625       static int firsttime = 1;
626       if (firsttime) {
627          init_setup_tab();
628          firsttime = 0;
629       }
630    }
631 }
632
633
634 void mach64FreeVB( struct gl_context *ctx )
635 {
636    mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
637    if (mmesa->verts) {
638       _mesa_align_free(mmesa->verts);
639       mmesa->verts = 0;
640    }
641 }