8b731355b5172dfd5ecccd6ca802553bac7ea049
[mesa.git] / src / mesa / drivers / glide / fxvb.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 5.1
4 *
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
23 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 /* Authors:
27 * Keith Whitwell <keith@tungstengraphics.com>
28 * Daniel Borca <dborca@users.sourceforge.net>
29 */
30
31 #ifdef HAVE_CONFIG_H
32 #include "conf.h"
33 #endif
34
35 #ifdef FX
36
37 #include "glheader.h"
38 #include "mtypes.h"
39 #include "imports.h"
40 #include "macros.h"
41 #include "colormac.h"
42
43 #include "math/m_translate.h"
44 #include "swrast_setup/swrast_setup.h"
45
46 #include "tnl/tnl.h"
47 #include "tnl/t_context.h"
48
49 #include "fxdrv.h"
50
51
52 static void copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc )
53 {
54 fxMesaContext fxMesa = FX_CONTEXT( ctx );
55 GrVertex *dst = fxMesa->verts + edst;
56 GrVertex *src = fxMesa->verts + esrc;
57
58 #if FX_PACKEDCOLOR
59 *(GLuint *)&dst->pargb = *(GLuint *)&src->pargb;
60 #else /* !FX_PACKEDCOLOR */
61 COPY_FLOAT(dst->r, src->r);
62 COPY_FLOAT(dst->g, src->g);
63 COPY_FLOAT(dst->b, src->b);
64 COPY_FLOAT(dst->a, src->a);
65 #endif /* !FX_PACKEDCOLOR */
66 }
67
68 static void copy_pv2( GLcontext *ctx, GLuint edst, GLuint esrc )
69 {
70 fxMesaContext fxMesa = FX_CONTEXT( ctx );
71 GrVertex *dst = fxMesa->verts + edst;
72 GrVertex *src = fxMesa->verts + esrc;
73
74 #if FX_PACKEDCOLOR
75 *(GLuint *)&dst->pargb = *(GLuint *)&src->pargb;
76 *(GLuint *)&dst->pspec = *(GLuint *)&src->pspec;
77 #else /* !FX_PACKEDCOLOR */
78 COPY_FLOAT(dst->r, src->r);
79 COPY_FLOAT(dst->g, src->g);
80 COPY_FLOAT(dst->b, src->b);
81 COPY_FLOAT(dst->a, src->a);
82 COPY_FLOAT(dst->r1, src->r1);
83 COPY_FLOAT(dst->g1, src->g1);
84 COPY_FLOAT(dst->b1, src->b1);
85 #endif /* !FX_PACKEDCOLOR */
86 }
87
88 static struct {
89 void (*emit) (GLcontext *ctx, GLuint start, GLuint end, void *dest);
90 tnl_copy_pv_func copy_pv;
91 tnl_interp_func interp;
92 GLboolean (*check_tex_sizes) (GLcontext *ctx);
93 GLuint vertex_format;
94 } setup_tab[MAX_SETUP];
95
96
97 #define GET_COLOR(ptr, idx) ((ptr)->data[idx])
98
99
100 static void interp_extras( GLcontext *ctx,
101 GLfloat t,
102 GLuint dst, GLuint out, GLuint in,
103 GLboolean force_boundary )
104 {
105 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
106
107 /* If stride is zero, ColorPtr[1] is constant across the VB, so
108 * there is no point interpolating between two values as they will
109 * be identical.
110 */
111 if (VB->ColorPtr[1]) {
112 assert(VB->ColorPtr[1]->stride == 4 * sizeof(GLfloat));
113
114 INTERP_4F( t,
115 GET_COLOR(VB->ColorPtr[1], dst),
116 GET_COLOR(VB->ColorPtr[1], out),
117 GET_COLOR(VB->ColorPtr[1], in) );
118
119 if (VB->SecondaryColorPtr[1]) {
120 INTERP_3F( t,
121 GET_COLOR(VB->SecondaryColorPtr[1], dst),
122 GET_COLOR(VB->SecondaryColorPtr[1], out),
123 GET_COLOR(VB->SecondaryColorPtr[1], in) );
124 }
125 }
126
127 if (VB->EdgeFlag) {
128 VB->EdgeFlag[dst] = VB->EdgeFlag[out] || force_boundary;
129 }
130
131 setup_tab[FX_CONTEXT(ctx)->SetupIndex].interp(ctx, t, dst, out, in,
132 force_boundary);
133 }
134
135 static void copy_pv_extras( GLcontext *ctx, GLuint dst, GLuint src )
136 {
137 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
138
139 if (VB->ColorPtr[1]) {
140 COPY_4FV( GET_COLOR(VB->ColorPtr[1], dst),
141 GET_COLOR(VB->ColorPtr[1], src) );
142
143 if (VB->SecondaryColorPtr[1]) {
144 COPY_3FV( GET_COLOR(VB->SecondaryColorPtr[1], dst),
145 GET_COLOR(VB->SecondaryColorPtr[1], src) );
146 }
147 }
148
149 setup_tab[FX_CONTEXT(ctx)->SetupIndex].copy_pv(ctx, dst, src);
150 }
151
152
153 #define IND (SETUP_XYZW|SETUP_RGBA)
154 #define TAG(x) x##_wg
155 #include "fxvbtmp.h"
156
157 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0)
158 #define TAG(x) x##_wgt0
159 #include "fxvbtmp.h"
160
161 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_TMU1)
162 #define TAG(x) x##_wgt0t1
163 #include "fxvbtmp.h"
164
165 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_PTEX)
166 #define TAG(x) x##_wgpt0
167 #include "fxvbtmp.h"
168
169 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_TMU1|\
170 SETUP_PTEX)
171 #define TAG(x) x##_wgpt0t1
172 #include "fxvbtmp.h"
173
174 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_PSIZ)
175 #define TAG(x) x##_wga
176 #include "fxvbtmp.h"
177
178 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_PSIZ)
179 #define TAG(x) x##_wgt0a
180 #include "fxvbtmp.h"
181
182 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_TMU1|SETUP_PSIZ)
183 #define TAG(x) x##_wgt0t1a
184 #include "fxvbtmp.h"
185
186 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_PTEX|SETUP_PSIZ)
187 #define TAG(x) x##_wgpt0a
188 #include "fxvbtmp.h"
189
190 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_TMU1|\
191 SETUP_PTEX|SETUP_PSIZ)
192 #define TAG(x) x##_wgpt0t1a
193 #include "fxvbtmp.h"
194
195
196 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC)
197 #define TAG(x) x##_2wg
198 #include "fxvbtmp.h"
199
200 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0)
201 #define TAG(x) x##_2wgt0
202 #include "fxvbtmp.h"
203
204 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_TMU1)
205 #define TAG(x) x##_2wgt0t1
206 #include "fxvbtmp.h"
207
208 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_PTEX)
209 #define TAG(x) x##_2wgpt0
210 #include "fxvbtmp.h"
211
212 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_TMU1|\
213 SETUP_PTEX)
214 #define TAG(x) x##_2wgpt0t1
215 #include "fxvbtmp.h"
216
217 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_PSIZ)
218 #define TAG(x) x##_2wga
219 #include "fxvbtmp.h"
220
221 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_PSIZ)
222 #define TAG(x) x##_2wgt0a
223 #include "fxvbtmp.h"
224
225 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_TMU1|SETUP_PSIZ)
226 #define TAG(x) x##_2wgt0t1a
227 #include "fxvbtmp.h"
228
229 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_PTEX|SETUP_PSIZ)
230 #define TAG(x) x##_2wgpt0a
231 #include "fxvbtmp.h"
232
233 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_TMU1|\
234 SETUP_PTEX|SETUP_PSIZ)
235 #define TAG(x) x##_2wgpt0t1a
236 #include "fxvbtmp.h"
237
238 /* fog { */
239 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_FOGC)
240 #define TAG(x) x##_wgf
241 #include "fxvbtmp.h"
242
243 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_FOGC)
244 #define TAG(x) x##_wgt0f
245 #include "fxvbtmp.h"
246
247 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_TMU1|SETUP_FOGC)
248 #define TAG(x) x##_wgt0t1f
249 #include "fxvbtmp.h"
250
251 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_PTEX|SETUP_FOGC)
252 #define TAG(x) x##_wgpt0f
253 #include "fxvbtmp.h"
254
255 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_TMU1|\
256 SETUP_PTEX|SETUP_FOGC)
257 #define TAG(x) x##_wgpt0t1f
258 #include "fxvbtmp.h"
259
260 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_PSIZ|SETUP_FOGC)
261 #define TAG(x) x##_wgaf
262 #include "fxvbtmp.h"
263
264 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_PSIZ|SETUP_FOGC)
265 #define TAG(x) x##_wgt0af
266 #include "fxvbtmp.h"
267
268 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_TMU1|SETUP_PSIZ|SETUP_FOGC)
269 #define TAG(x) x##_wgt0t1af
270 #include "fxvbtmp.h"
271
272 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_PTEX|SETUP_PSIZ|SETUP_FOGC)
273 #define TAG(x) x##_wgpt0af
274 #include "fxvbtmp.h"
275
276 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_TMU1|\
277 SETUP_PTEX|SETUP_PSIZ|SETUP_FOGC)
278 #define TAG(x) x##_wgpt0t1af
279 #include "fxvbtmp.h"
280
281
282 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_FOGC)
283 #define TAG(x) x##_2wgf
284 #include "fxvbtmp.h"
285
286 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_FOGC)
287 #define TAG(x) x##_2wgt0f
288 #include "fxvbtmp.h"
289
290 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_TMU1|SETUP_FOGC)
291 #define TAG(x) x##_2wgt0t1f
292 #include "fxvbtmp.h"
293
294 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_PTEX|SETUP_FOGC)
295 #define TAG(x) x##_2wgpt0f
296 #include "fxvbtmp.h"
297
298 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_TMU1|\
299 SETUP_PTEX|SETUP_FOGC)
300 #define TAG(x) x##_2wgpt0t1f
301 #include "fxvbtmp.h"
302
303 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_PSIZ|SETUP_FOGC)
304 #define TAG(x) x##_2wgaf
305 #include "fxvbtmp.h"
306
307 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_PSIZ|SETUP_FOGC)
308 #define TAG(x) x##_2wgt0af
309 #include "fxvbtmp.h"
310
311 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_TMU1|SETUP_PSIZ|SETUP_FOGC)
312 #define TAG(x) x##_2wgt0t1af
313 #include "fxvbtmp.h"
314
315 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_PTEX|SETUP_PSIZ|SETUP_FOGC)
316 #define TAG(x) x##_2wgpt0af
317 #include "fxvbtmp.h"
318
319 #define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_TMU1|\
320 SETUP_PTEX|SETUP_PSIZ|SETUP_FOGC)
321 #define TAG(x) x##_2wgpt0t1af
322 #include "fxvbtmp.h"
323 /* fog } */
324
325
326 /* Snapping for voodoo-1
327 */
328 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA)
329 #define TAG(x) x##_wsg
330 #include "fxvbtmp.h"
331
332 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0)
333 #define TAG(x) x##_wsgt0
334 #include "fxvbtmp.h"
335
336 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
337 SETUP_TMU1)
338 #define TAG(x) x##_wsgt0t1
339 #include "fxvbtmp.h"
340
341 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
342 SETUP_PTEX)
343 #define TAG(x) x##_wsgpt0
344 #include "fxvbtmp.h"
345
346 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
347 SETUP_TMU1|SETUP_PTEX)
348 #define TAG(x) x##_wsgpt0t1
349 #include "fxvbtmp.h"
350
351 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_PSIZ)
352 #define TAG(x) x##_wsga
353 #include "fxvbtmp.h"
354
355 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|SETUP_PSIZ)
356 #define TAG(x) x##_wsgt0a
357 #include "fxvbtmp.h"
358
359 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
360 SETUP_TMU1|SETUP_PSIZ)
361 #define TAG(x) x##_wsgt0t1a
362 #include "fxvbtmp.h"
363
364 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
365 SETUP_PTEX|SETUP_PSIZ)
366 #define TAG(x) x##_wsgpt0a
367 #include "fxvbtmp.h"
368
369 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
370 SETUP_TMU1|SETUP_PTEX|SETUP_PSIZ)
371 #define TAG(x) x##_wsgpt0t1a
372 #include "fxvbtmp.h"
373
374
375 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC)
376 #define TAG(x) x##_2wsg
377 #include "fxvbtmp.h"
378
379 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0)
380 #define TAG(x) x##_2wsgt0
381 #include "fxvbtmp.h"
382
383 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
384 SETUP_TMU1)
385 #define TAG(x) x##_2wsgt0t1
386 #include "fxvbtmp.h"
387
388 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
389 SETUP_PTEX)
390 #define TAG(x) x##_2wsgpt0
391 #include "fxvbtmp.h"
392
393 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
394 SETUP_TMU1|SETUP_PTEX)
395 #define TAG(x) x##_2wsgpt0t1
396 #include "fxvbtmp.h"
397
398 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_PSIZ)
399 #define TAG(x) x##_2wsga
400 #include "fxvbtmp.h"
401
402 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_PSIZ)
403 #define TAG(x) x##_2wsgt0a
404 #include "fxvbtmp.h"
405
406 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
407 SETUP_TMU1|SETUP_PSIZ)
408 #define TAG(x) x##_2wsgt0t1a
409 #include "fxvbtmp.h"
410
411 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
412 SETUP_PTEX|SETUP_PSIZ)
413 #define TAG(x) x##_2wsgpt0a
414 #include "fxvbtmp.h"
415
416 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
417 SETUP_TMU1|SETUP_PTEX|SETUP_PSIZ)
418 #define TAG(x) x##_2wsgpt0t1a
419 #include "fxvbtmp.h"
420
421 /* fog { */
422 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_FOGC)
423 #define TAG(x) x##_wsgf
424 #include "fxvbtmp.h"
425
426 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|SETUP_FOGC)
427 #define TAG(x) x##_wsgt0f
428 #include "fxvbtmp.h"
429
430 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
431 SETUP_TMU1|SETUP_FOGC)
432 #define TAG(x) x##_wsgt0t1f
433 #include "fxvbtmp.h"
434
435 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
436 SETUP_PTEX|SETUP_FOGC)
437 #define TAG(x) x##_wsgpt0f
438 #include "fxvbtmp.h"
439
440 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
441 SETUP_TMU1|SETUP_PTEX|SETUP_FOGC)
442 #define TAG(x) x##_wsgpt0t1f
443 #include "fxvbtmp.h"
444
445 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_PSIZ|SETUP_FOGC)
446 #define TAG(x) x##_wsgaf
447 #include "fxvbtmp.h"
448
449 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|SETUP_PSIZ|SETUP_FOGC)
450 #define TAG(x) x##_wsgt0af
451 #include "fxvbtmp.h"
452
453 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
454 SETUP_TMU1|SETUP_PSIZ|SETUP_FOGC)
455 #define TAG(x) x##_wsgt0t1af
456 #include "fxvbtmp.h"
457
458 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
459 SETUP_PTEX|SETUP_PSIZ|SETUP_FOGC)
460 #define TAG(x) x##_wsgpt0af
461 #include "fxvbtmp.h"
462
463 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
464 SETUP_TMU1|SETUP_PTEX|SETUP_PSIZ|SETUP_FOGC)
465 #define TAG(x) x##_wsgpt0t1af
466 #include "fxvbtmp.h"
467
468
469 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_FOGC)
470 #define TAG(x) x##_2wsgf
471 #include "fxvbtmp.h"
472
473 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_FOGC)
474 #define TAG(x) x##_2wsgt0f
475 #include "fxvbtmp.h"
476
477 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
478 SETUP_TMU1|SETUP_FOGC)
479 #define TAG(x) x##_2wsgt0t1f
480 #include "fxvbtmp.h"
481
482 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
483 SETUP_PTEX|SETUP_FOGC)
484 #define TAG(x) x##_2wsgpt0f
485 #include "fxvbtmp.h"
486
487 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
488 SETUP_TMU1|SETUP_PTEX|SETUP_FOGC)
489 #define TAG(x) x##_2wsgpt0t1f
490 #include "fxvbtmp.h"
491
492 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_PSIZ|SETUP_FOGC)
493 #define TAG(x) x##_2wsgaf
494 #include "fxvbtmp.h"
495
496 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_PSIZ|SETUP_FOGC)
497 #define TAG(x) x##_2wsgt0af
498 #include "fxvbtmp.h"
499
500 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
501 SETUP_TMU1|SETUP_PSIZ|SETUP_FOGC)
502 #define TAG(x) x##_2wsgt0t1af
503 #include "fxvbtmp.h"
504
505 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
506 SETUP_PTEX|SETUP_PSIZ|SETUP_FOGC)
507 #define TAG(x) x##_2wsgpt0af
508 #include "fxvbtmp.h"
509
510 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
511 SETUP_TMU1|SETUP_PTEX|SETUP_PSIZ|SETUP_FOGC)
512 #define TAG(x) x##_2wsgpt0t1af
513 #include "fxvbtmp.h"
514 /* fog } */
515
516
517 /* Vertex repair (multipass rendering)
518 */
519 #define IND (SETUP_RGBA)
520 #define TAG(x) x##_g
521 #include "fxvbtmp.h"
522
523 #define IND (SETUP_TMU0)
524 #define TAG(x) x##_t0
525 #include "fxvbtmp.h"
526
527 #define IND (SETUP_TMU0|SETUP_TMU1)
528 #define TAG(x) x##_t0t1
529 #include "fxvbtmp.h"
530
531 #define IND (SETUP_RGBA|SETUP_TMU0)
532 #define TAG(x) x##_gt0
533 #include "fxvbtmp.h"
534
535 #define IND (SETUP_RGBA|SETUP_TMU0|SETUP_TMU1)
536 #define TAG(x) x##_gt0t1
537 #include "fxvbtmp.h"
538
539
540 #define IND (SETUP_RGBA|SETUP_SPEC)
541 #define TAG(x) x##_2g
542 #include "fxvbtmp.h"
543
544 #define IND (SETUP_TMU0|SETUP_SPEC)
545 #define TAG(x) x##_2t0
546 #include "fxvbtmp.h"
547
548 #define IND (SETUP_TMU0|SETUP_SPEC|SETUP_TMU1)
549 #define TAG(x) x##_2t0t1
550 #include "fxvbtmp.h"
551
552 #define IND (SETUP_RGBA|SETUP_SPEC|SETUP_TMU0)
553 #define TAG(x) x##_2gt0
554 #include "fxvbtmp.h"
555
556 #define IND (SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_TMU1)
557 #define TAG(x) x##_2gt0t1
558 #include "fxvbtmp.h"
559
560
561
562 static void init_setup_tab( void )
563 {
564 init_wg();
565 init_wgt0();
566 init_wgt0t1();
567 init_wgpt0();
568 init_wgpt0t1();
569 init_wga();
570 init_wgt0a();
571 init_wgt0t1a();
572 init_wgpt0a();
573 init_wgpt0t1a();
574 init_2wg();
575 init_2wgt0();
576 init_2wgt0t1();
577 init_2wgpt0();
578 init_2wgpt0t1();
579 init_2wga();
580 init_2wgt0a();
581 init_2wgt0t1a();
582 init_2wgpt0a();
583 init_2wgpt0t1a();
584 init_wgf();
585 init_wgt0f();
586 init_wgt0t1f();
587 init_wgpt0f();
588 init_wgpt0t1f();
589 init_wgaf();
590 init_wgt0af();
591 init_wgt0t1af();
592 init_wgpt0af();
593 init_wgpt0t1af();
594 init_2wgf();
595 init_2wgt0f();
596 init_2wgt0t1f();
597 init_2wgpt0f();
598 init_2wgpt0t1f();
599 init_2wgaf();
600 init_2wgt0af();
601 init_2wgt0t1af();
602 init_2wgpt0af();
603 init_2wgpt0t1af();
604
605 init_wsg();
606 init_wsgt0();
607 init_wsgt0t1();
608 init_wsgpt0();
609 init_wsgpt0t1();
610 init_wsga();
611 init_wsgt0a();
612 init_wsgt0t1a();
613 init_wsgpt0a();
614 init_wsgpt0t1a();
615 init_2wsg();
616 init_2wsgt0();
617 init_2wsgt0t1();
618 init_2wsgpt0();
619 init_2wsgpt0t1();
620 init_2wsga();
621 init_2wsgt0a();
622 init_2wsgt0t1a();
623 init_2wsgpt0a();
624 init_2wsgpt0t1a();
625 init_wsgf();
626 init_wsgt0f();
627 init_wsgt0t1f();
628 init_wsgpt0f();
629 init_wsgpt0t1f();
630 init_wsgaf();
631 init_wsgt0af();
632 init_wsgt0t1af();
633 init_wsgpt0af();
634 init_wsgpt0t1af();
635 init_2wsgf();
636 init_2wsgt0f();
637 init_2wsgt0t1f();
638 init_2wsgpt0f();
639 init_2wsgpt0t1f();
640 init_2wsgaf();
641 init_2wsgt0af();
642 init_2wsgt0t1af();
643 init_2wsgpt0af();
644 init_2wsgpt0t1af();
645
646 init_g();
647 init_t0();
648 init_t0t1();
649 init_gt0();
650 init_gt0t1();
651 init_2g();
652 init_2t0();
653 init_2t0t1();
654 init_2gt0();
655 init_2gt0t1();
656 }
657
658
659 void fxPrintSetupFlags(char *msg, GLuint flags )
660 {
661 fprintf(stderr, "%s(%x): %s%s%s%s%s%s%s%s\n",
662 msg,
663 (int)flags,
664 (flags & SETUP_XYZW) ? " xyzw," : "",
665 (flags & SETUP_SNAP) ? " snap," : "",
666 (flags & SETUP_RGBA) ? " rgba," : "",
667 (flags & SETUP_TMU0) ? " tex-0," : "",
668 (flags & SETUP_TMU1) ? " tex-1," : "",
669 (flags & SETUP_PSIZ) ? " psiz," : "",
670 (flags & SETUP_SPEC) ? " spec," : "",
671 (flags & SETUP_FOGC) ? " fog," : "");
672 }
673
674
675
676 void fxCheckTexSizes( GLcontext *ctx )
677 {
678 TNLcontext *tnl = TNL_CONTEXT(ctx);
679 fxMesaContext fxMesa = FX_CONTEXT( ctx );
680
681 if (!setup_tab[fxMesa->SetupIndex].check_tex_sizes(ctx)) {
682 GLuint ind = fxMesa->SetupIndex |= (SETUP_PTEX|SETUP_RGBA);
683
684 /* Tdfx handles projective textures nicely; just have to change
685 * up to the new vertex format.
686 */
687 if (setup_tab[ind].vertex_format != fxMesa->stw_hint_state) {
688
689 fxMesa->stw_hint_state = setup_tab[ind].vertex_format;
690 FX_grHints(GR_HINT_STWHINT, fxMesa->stw_hint_state);
691
692 /* This is required as we have just changed the vertex
693 * format, so the interp routines must also change.
694 * In the unfilled and twosided cases we are using the
695 * Extras ones anyway, so leave them in place.
696 */
697 if (!(ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
698 tnl->Driver.Render.Interp = setup_tab[fxMesa->SetupIndex].interp;
699 }
700 }
701 }
702 }
703
704
705 void fxBuildVertices( GLcontext *ctx, GLuint start, GLuint end,
706 GLuint newinputs )
707 {
708 fxMesaContext fxMesa = FX_CONTEXT( ctx );
709 GrVertex *v = (fxMesa->verts + start);
710
711 if (!newinputs)
712 return;
713
714 if (newinputs & VERT_BIT_POS) {
715 setup_tab[fxMesa->SetupIndex].emit( ctx, start, end, v );
716 } else {
717 GLuint ind = 0;
718
719 if (newinputs & VERT_BIT_COLOR0)
720 ind |= SETUP_RGBA;
721
722 if (newinputs & VERT_BIT_COLOR1)
723 ind |= SETUP_SPEC;
724
725 if (newinputs & VERT_BIT_FOG)
726 ind |= SETUP_FOGC;
727
728 if (newinputs & VERT_BIT_TEX0)
729 ind |= SETUP_TMU0;
730
731 if (newinputs & VERT_BIT_TEX1)
732 ind |= SETUP_TMU0|SETUP_TMU1;
733
734 if (fxMesa->SetupIndex & SETUP_PTEX)
735 ind = ~0;
736
737 ind &= fxMesa->SetupIndex;
738
739 if (ind) {
740 setup_tab[ind].emit( ctx, start, end, v );
741 }
742 }
743 }
744
745
746 void fxChooseVertexState( GLcontext *ctx )
747 {
748 TNLcontext *tnl = TNL_CONTEXT(ctx);
749 fxMesaContext fxMesa = FX_CONTEXT( ctx );
750 GLuint ind = SETUP_XYZW|SETUP_RGBA;
751
752 if (fxMesa->snapVertices)
753 ind |= SETUP_SNAP;
754
755 fxMesa->tmu_source[0] = 0;
756 fxMesa->tmu_source[1] = 1;
757
758 if (ctx->Texture._EnabledUnits & 0x2) {
759 if (ctx->Texture._EnabledUnits & 0x1) {
760 ind |= SETUP_TMU1;
761 }
762 ind |= SETUP_TMU0;
763 fxMesa->tmu_source[0] = 1;
764 fxMesa->tmu_source[1] = 0;
765 }
766 else if (ctx->Texture._EnabledUnits & 0x1) {
767 ind |= SETUP_TMU0;
768 }
769
770 if (ctx->_TriangleCaps & DD_POINT_ATTEN) {
771 ind |= SETUP_PSIZ;
772 }
773
774 if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) {
775 ind |= SETUP_SPEC;
776 }
777
778 if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) {
779 ind |= SETUP_FOGC;
780 }
781
782 fxMesa->SetupIndex = ind;
783
784 if (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED)) {
785 tnl->Driver.Render.Interp = interp_extras;
786 tnl->Driver.Render.CopyPV = copy_pv_extras;
787 } else {
788 tnl->Driver.Render.Interp = setup_tab[ind].interp;
789 tnl->Driver.Render.CopyPV = setup_tab[ind].copy_pv;
790 }
791
792 if (setup_tab[ind].vertex_format != fxMesa->stw_hint_state) {
793 fxMesa->stw_hint_state = setup_tab[ind].vertex_format;
794 FX_grHints(GR_HINT_STWHINT, fxMesa->stw_hint_state);
795 }
796 }
797
798
799
800 void fxAllocVB( GLcontext *ctx )
801 {
802 fxMesaContext fxMesa = FX_CONTEXT(ctx);
803 GLuint size = TNL_CONTEXT(ctx)->vb.Size;
804 static int firsttime = 1;
805 if (firsttime) {
806 init_setup_tab();
807 firsttime = 0;
808 }
809
810 fxMesa->verts = (GrVertex *)ALIGN_MALLOC(size * sizeof(GrVertex), 32);
811 fxMesa->SetupIndex = SETUP_XYZW|SETUP_RGBA;
812 }
813
814
815 void fxFreeVB( GLcontext *ctx )
816 {
817 fxMesaContext fxMesa = FX_CONTEXT(ctx);
818 if (fxMesa->verts) {
819 ALIGN_FREE(fxMesa->verts);
820 fxMesa->verts = 0;
821 }
822 }
823 #else
824
825
826 /*
827 * Need this to provide at least one external definition.
828 */
829
830 extern int gl_fx_dummy_function_vb(void);
831 int
832 gl_fx_dummy_function_vb(void)
833 {
834 return 0;
835 }
836
837 #endif /* FX */