1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
|
/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */
/*
* Mesa 3-D graphics library
* Version: 3.3
*
* Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*
* Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
* terms stated above.
*
* Thank you for your contribution, David!
*
* Please make note of the above copyright/license statement. If you
* contributed code or bug fixes to this code under the previous (GNU
* Library) license and object to the new license, your code will be
* removed at your request. Please see the Mesa docs/COPYRIGHT file
* for more information.
*
* Additional Mesa/3Dfx driver developers:
* Daryll Strauss <daryll@precisioninsight.com>
* Keith Whitwell <keith@precisioninsight.com>
*
* See fxapi.h for more revision/author details.
*/
/* fxcva.c - the CVA related code */
#ifdef HAVE_CONFIG_H
#include "conf.h"
#endif
#if defined(FX)
#include "fxdrv.h"
#include "mmath.h"
#include "vbindirect.h"
#include "pb.h"
#include "fxvsetup.h"
#include "pipeline.h"
#include "stages.h"
#define PRIM_POINTS 0
#define PRIM_LINES 1
#define PRIM_TRIS 2
#define PRIM_CULLED 3
static GLuint reduce_prim[GL_POLYGON+2] = {
PRIM_POINTS,
PRIM_LINES,
PRIM_LINES,
PRIM_LINES,
PRIM_TRIS,
PRIM_TRIS,
PRIM_TRIS,
PRIM_TRIS,
PRIM_TRIS,
PRIM_TRIS,
PRIM_CULLED
};
typedef void (*mergefunc)( struct vertex_buffer *cvaVB,
struct vertex_buffer *VB,
const struct gl_prim_state *state,
GLuint start,
GLuint count );
static void fxCvaRenderNoop( struct vertex_buffer *cvaVB,
struct vertex_buffer *VB,
const struct gl_prim_state *state,
GLuint start,
GLuint count )
{
}
static INLINE void fxRenderClippedTriangle2( struct vertex_buffer *VB,
GLuint v1, GLuint v2, GLuint v3 )
{
fxVertex *gWin = FX_DRIVER_DATA(VB)->verts;
GLubyte *clipmask = VB->ClipMask;
GLubyte mask = clipmask[v1] | clipmask[v2] | clipmask[v3];
if (!mask) {
FX_grDrawTriangle((GrVertex *)gWin[v1].f,
(GrVertex *)gWin[v2].f,
(GrVertex *)gWin[v3].f);
} else if (!(clipmask[v1]&clipmask[v2]&clipmask[v3]&CLIP_ALL_BITS)) {
GLuint n;
GLuint vlist[VB_MAX_CLIPPED_VERTS];
ASSIGN_3V(vlist, v1, v2, v3);
n = (VB->ctx->poly_clip_tab[VB->ClipPtr->size])( VB, 3, vlist, mask );
if (n >= 3) {
GLuint i, j0 = vlist[0];
for (i=2;i<n;i++) {
FX_grDrawTriangle((GrVertex *)gWin[j0].f,
(GrVertex *)gWin[vlist[i-1]].f,
(GrVertex *)gWin[vlist[i]].f);
}
}
}
}
static mergefunc merge_and_render_tab[2][MAX_MERGABLE][PRIM_CULLED+1];
/*
#define CVA_VARS_RGBA \
GLubyte (*color)[4] = VB->ColorPtr->data; \
GLubyte (*cva_color)[4] = (cvaVB->ColorPtr = cvaVB->LitColor[0])->data;
*/
#define CVA_VARS_RGBA \
GLubyte (*color)[4] = VB->ColorPtr->data; \
GLubyte (*cva_color)[4] = cvaVB->ColorPtr->data;
#undef DO_SETUP_RGBA
#if FX_USE_PARGB
#define DO_SETUP_RGBA \
{ \
GLubyte *col = color[i]; \
GET_PARGB(v)= ((col[3] << 24) | \
(col[0] << 16) | \
(col[1] << 8) | \
(col[2])); \
}
#else
#define DO_SETUP_RGBA \
{ \
GLubyte *col = color[i]; \
v[GR_VERTEX_R_OFFSET]=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[0]); \
v[GR_VERTEX_G_OFFSET]=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[1]); \
v[GR_VERTEX_B_OFFSET]=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[2]); \
v[GR_VERTEX_A_OFFSET]=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[3]); \
}
#endif /* FX_USE_PARGB */
#define CVA_VARS_TMU0 \
VARS_TMU0 \
GLfloat (*cva_tex0)[4] = (cvaVB->TexCoordPtr[tmu0_source] = cvaVB->store.TexCoord[tmu0_source])->data;
#define CVA_VARS_TMU1 \
VARS_TMU1 \
GLfloat (*cva_tex1)[4] = (cvaVB->TexCoordPtr[tmu1_source] = cvaVB->store.TexCoord[tmu1_source])->data;
#define INIT_RGBA (void) cva_color;
#define INIT_TMU0 (void) cva_tex0; (void) tmu0_stride; (void) tmu0_sz;
#define INIT_TMU1 (void) cva_tex1; (void) tmu1_stride; (void) tmu1_sz;
#define DRAW_POINT FX_grDrawPoint( (GrVertex *)v )
#define DRAW_LINE FX_grDrawLine( (GrVertex *)v, (GrVertex *)prev_v )
#define DRAW_TRI FX_grDrawTriangle( (GrVertex *)gWin[l[0]].f, (GrVertex *)gWin[l[1]].f, (GrVertex *)v )
#define DRAW_TRI2 FX_grDrawTriangle( vl[0], vl[1], vl[2] )
#define CLIP_LINE fxRenderClippedLine( cvaVB, e, prev )
#define CLIP_OR_DRAW_TRI fxRenderClippedTriangle2( cvaVB, l[0], l[1], e )
#define DIRECT 1
#define TAG(x) x
#define IDX 0
#define VARS
#define INIT
#define INCR
#define MERGE_RAST
#define MERGE_VB
#include "fxcvatmp.h"
#define TAG(x) x##RGBA
#define IDX SETUP_RGBA
#define VARS CVA_VARS_RGBA
#define INIT INIT_RGBA
#define INCR
#define MERGE_RAST DO_SETUP_RGBA
#define MERGE_VB COPY_4UBV(cva_color[e], color[i])
#include "fxcvatmp.h"
#define TAG(x) x##T0
#define IDX SETUP_TMU0
#define VARS CVA_VARS_TMU0
#define INIT INIT_TMU0
#define INCR , tmu0_data+=4
#define MERGE_RAST DO_SETUP_TMU0
#define MERGE_VB COPY_2FV(cva_tex0[e], tmu0_data)
#include "fxcvatmp.h"
#define TAG(x) x##T1
#define IDX SETUP_TMU1
#define VARS CVA_VARS_TMU1
#define INIT INIT_TMU1
#define INCR , tmu1_data+=4
#define MERGE_RAST DO_SETUP_TMU1
#define MERGE_VB COPY_2FV(cva_tex1[e], tmu1_data)
#include "fxcvatmp.h"
#define TAG(x) x##T0T1
#define IDX SETUP_TMU0|SETUP_TMU1
#define VARS CVA_VARS_TMU0 CVA_VARS_TMU1
#define INIT INIT_TMU0 INIT_TMU1
#define INCR , tmu0_data+=4 , tmu1_data+=4
#define MERGE_RAST DO_SETUP_TMU0 DO_SETUP_TMU1
#define MERGE_VB COPY_2FV(cva_tex0[e], tmu0_data); \
COPY_2FV(cva_tex1[e], tmu1_data);
#include "fxcvatmp.h"
#define TAG(x) x##RGBAT0
#define IDX SETUP_RGBA|SETUP_TMU0
#define VARS CVA_VARS_RGBA CVA_VARS_TMU0
#define INIT INIT_RGBA INIT_TMU0
#define INCR , tmu0_data+=4
#define MERGE_RAST DO_SETUP_RGBA; DO_SETUP_TMU0
#define MERGE_VB COPY_2FV(cva_tex0[e], tmu0_data); \
COPY_4UBV(cva_color[e], color[i]);
#include "fxcvatmp.h"
#define TAG(x) x##RGBAT1
#define IDX SETUP_RGBA|SETUP_TMU1
#define VARS CVA_VARS_RGBA CVA_VARS_TMU1
#define INIT INIT_RGBA INIT_TMU1
#define INCR , tmu1_data+=4
#define MERGE_RAST DO_SETUP_RGBA; DO_SETUP_TMU1
#define MERGE_VB COPY_2FV(cva_tex1[e], tmu1_data); \
COPY_4UBV(cva_color[e], color[i]);
#include "fxcvatmp.h"
#define TAG(x) x##RGBAT0T1
#define IDX SETUP_RGBA|SETUP_TMU0|SETUP_TMU1
#define VARS CVA_VARS_RGBA CVA_VARS_TMU0 CVA_VARS_TMU1
#define INIT INIT_RGBA INIT_TMU0 INIT_TMU1
#define INCR , tmu0_data+=4 , tmu1_data+=4
#define MERGE_RAST DO_SETUP_RGBA; DO_SETUP_TMU0 DO_SETUP_TMU1
#define MERGE_VB COPY_2FV(cva_tex0[e], tmu0_data); \
COPY_2FV(cva_tex1[e], tmu1_data); \
COPY_4UBV(cva_color[e], color[i]);
#include "fxcvatmp.h"
#undef DRAW_POINT
#undef DRAW_LINE
#undef DRAW_TRI
#undef CLIP_LINE
#undef CLIP_OR_DRAW_TRI
#undef DIRECT
#define DRAW_POINT ctx->Driver.PointsFunc( ctx, e, e )
#define DRAW_LINE ctx->Driver.LineFunc( ctx, e, prev, e )
#define DRAW_TRI ctx->TriangleFunc( ctx, l[0], l[1], e, e )
#define CLIP_LINE gl_render_clipped_line( ctx, e, prev )
#define CLIP_OR_DRAW_TRI \
do { \
if (clip[l[0]] | clip[l[1]] | clip[e]) { \
if (!(clip[l[0]] & clip[l[1]] & clip[e] & CLIP_ALL_BITS)) { \
COPY_3V(vlist, l); \
gl_render_clipped_triangle( ctx, 3, vlist, e ); \
} \
} \
else ctx->TriangleFunc( ctx, l[0], l[1], e, e ); \
} while (0)
#define DIRECT 0
#define TAG(x) x##_indirect
#define IDX 0
#define VARS
#define INIT
#define INCR
#define MERGE_RAST
#define MERGE_VB
#include "fxcvatmp.h"
#define TAG(x) x##RGBA_indirect
#define IDX SETUP_RGBA
#define VARS CVA_VARS_RGBA
#define INIT INIT_RGBA
#define INCR
#define MERGE_RAST DO_SETUP_RGBA
#define MERGE_VB COPY_4UBV(cva_color[e], color[i])
#include "fxcvatmp.h"
#define TAG(x) x##T0_indirect
#define IDX SETUP_TMU0
#define VARS CVA_VARS_TMU0
#define INIT INIT_TMU0
#define INCR , tmu0_data+=4
#define MERGE_RAST DO_SETUP_TMU0
#define MERGE_VB COPY_2FV(cva_tex0[e], tmu0_data)
#include "fxcvatmp.h"
#define TAG(x) x##T1_indirect
#define IDX SETUP_TMU1
#define VARS CVA_VARS_TMU1
#define INIT INIT_TMU1
#define INCR , tmu1_data+=4
#define MERGE_RAST DO_SETUP_TMU1
#define MERGE_VB COPY_2FV(cva_tex1[e], tmu1_data)
#include "fxcvatmp.h"
#define TAG(x) x##T0T1_indirect
#define IDX SETUP_TMU0|SETUP_TMU1
#define VARS CVA_VARS_TMU0 CVA_VARS_TMU1
#define INIT INIT_TMU0 INIT_TMU1
#define INCR , tmu0_data+=4 , tmu1_data+=4
#define MERGE_RAST DO_SETUP_TMU0 DO_SETUP_TMU1
#define MERGE_VB COPY_2FV(cva_tex0[e], tmu0_data); \
COPY_2FV(cva_tex1[e], tmu1_data);
#include "fxcvatmp.h"
#define TAG(x) x##RGBAT0_indirect
#define IDX SETUP_RGBA|SETUP_TMU0
#define VARS CVA_VARS_RGBA CVA_VARS_TMU0
#define INIT INIT_RGBA INIT_TMU0
#define INCR , tmu0_data+=4
#define MERGE_RAST DO_SETUP_RGBA; DO_SETUP_TMU0
#define MERGE_VB COPY_2FV(cva_tex0[e], tmu0_data); \
COPY_4UBV(cva_color[e], color[i]);
#include "fxcvatmp.h"
#define TAG(x) x##RGBAT1_indirect
#define IDX SETUP_RGBA|SETUP_TMU1
#define VARS CVA_VARS_RGBA CVA_VARS_TMU1
#define INIT INIT_RGBA INIT_TMU1
#define INCR , tmu1_data+=4
#define MERGE_RAST DO_SETUP_RGBA; DO_SETUP_TMU1
#define MERGE_VB COPY_2FV(cva_tex1[e], tmu1_data); \
COPY_4UBV(cva_color[e], color[i]);
#include "fxcvatmp.h"
#define TAG(x) x##RGBAT0T1_indirect
#define IDX SETUP_RGBA|SETUP_TMU0|SETUP_TMU1
#define VARS CVA_VARS_RGBA CVA_VARS_TMU0 CVA_VARS_TMU1
#define INIT INIT_RGBA INIT_TMU0 INIT_TMU1
#define INCR , tmu0_data+=4 , tmu1_data+=4
#define MERGE_RAST DO_SETUP_RGBA DO_SETUP_TMU0 DO_SETUP_TMU1
#define MERGE_VB COPY_2FV(cva_tex0[e], tmu0_data); \
COPY_2FV(cva_tex1[e], tmu1_data); \
COPY_4UBV(cva_color[e], color[i]);
#include "fxcvatmp.h"
void fxDDCvaInit()
{
/* Call grDrawTriangle et al */
init_cva();
init_cvaT0();
init_cvaT1();
init_cvaT0T1();
init_cvaRGBA();
init_cvaRGBAT0();
init_cvaRGBAT1();
init_cvaRGBAT0T1();
/* Call ctx->TriangleFunc and friends */
init_cva_indirect();
init_cvaT0_indirect();
init_cvaT1_indirect();
init_cvaT0T1_indirect();
init_cvaRGBA_indirect();
init_cvaRGBAT0_indirect();
init_cvaRGBAT1_indirect();
init_cvaRGBAT0T1_indirect();
}
void fxDDCheckMergeAndRender( GLcontext *ctx, struct gl_pipeline_stage *d )
{
GLuint inputs = ctx->RenderFlags & ~ctx->CVA.pre.outputs;
if (!(ctx->TriangleCaps & DD_TRI_UNFILLED) &&
(ctx->Array.Summary & VERT_OBJ_ANY))
{
d->inputs = (VERT_SETUP_PART | VERT_ELT | inputs);
d->outputs = 0;
d->type = PIPE_IMMEDIATE;
}
/* gl_print_vert_flags("merge&render inputs", d->inputs); */
}
extern void fxPointSmooth(GLcontext *ctx, GLuint first, GLuint last);
extern void fxLineSmooth(GLcontext *ctx, GLuint v1, GLuint v2, GLuint pv);
extern void fxTriangleSmooth(GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3,
GLuint pv);
extern const char *gl_prim_name[];
/* static GLboolean edge_flag[GL_POLYGON+2] = { 0,0,0,0,1,0,0,1,0,1,0 }; */
void fxDDMergeAndRender( struct vertex_buffer *VB )
{
GLcontext *ctx = VB->ctx;
struct vertex_buffer *cvaVB = ctx->CVA.VB;
fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx;
GLuint i, next, prim;
GLuint parity = VB->Parity;
GLuint count = VB->Count;
const struct gl_prim_state *state;
mergefunc func;
struct vertex_buffer *saved_vb = ctx->VB;
GLuint inputs = ctx->RenderFlags & ~ctx->CVA.pre.outputs;
GLuint flags = 0;
GLuint direct = (fxMesa->render_index == 0);
mergefunc (*tab)[PRIM_CULLED+1] = merge_and_render_tab[direct];
GLuint p = 0;
if (fxMesa->new_state)
fxSetupFXUnits(ctx);
/* May actually contain elements not present in fxMesa->setupindex,
* eg RGBA when flat shading. These need to be copied into the cva
* VB so that funcs like fxTriangleFlat will be able to reach them.
*
* This leads to some duplication of effort in the merge funcs.
*/
if (inputs & VERT_RGBA) {
cvaVB->ColorPtr = cvaVB->Color[0] = cvaVB->LitColor[0];
cvaVB->Color[1] = cvaVB->LitColor[1];
flags |= SETUP_RGBA;
}
if (inputs & VERT_TEX0_ANY) {
cvaVB->TexCoordPtr[0] = cvaVB->store.TexCoord[0];
flags |= fxMesa->tex_dest[0];
}
if (inputs & VERT_TEX1_ANY) {
cvaVB->TexCoordPtr[1] = cvaVB->store.TexCoord[1];
flags |= fxMesa->tex_dest[1];
}
#if 0
fxPrintSetupFlags("FX cva merge & render", flags);
#endif
if (cvaVB->ClipOrMask)
gl_import_client_data( cvaVB, ctx->RenderFlags,
VEC_WRITABLE|VEC_GOOD_STRIDE );
ctx->VB = cvaVB;
do {
for ( i= VB->CopyStart ; i < count ; parity = 0, i = next )
{
prim = VB->Primitive[i];
next = VB->NextPrimitive[i];
state = gl_prim_state_machine[prim][parity];
func = tab[flags][reduce_prim[prim]];
func( cvaVB, VB, state, i, next );
if ( ctx->TriangleCaps & DD_TRI_LIGHT_TWOSIDE )
{
cvaVB->Specular = cvaVB->Spec[0];
cvaVB->ColorPtr = cvaVB->Color[0];
cvaVB->IndexPtr = cvaVB->Index[0];
}
}
} while (ctx->Driver.MultipassFunc &&
ctx->Driver.MultipassFunc( VB, ++p ));
if (ctx->PB->count > 0)
gl_flush_pb(ctx);
ctx->VB = saved_vb;
}
#else
/*
* Need this to provide at least one external definition.
*/
int gl_fx_dummy_function_cva(void)
{
return 0;
}
#endif /* FX */
|