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
|
/* $Id: fxvb.c,v 1.16 2002/11/04 20:29:04 brianp Exp $ */
/*
* Mesa 3-D graphics library
* Version: 4.0
*
* Copyright (C) 1999-2001 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
* KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS 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.
*/
/* Authors:
* Keith Whitwell
*/
#ifdef HAVE_CONFIG_H
#include "conf.h"
#endif
#ifdef FX
#include "glheader.h"
#include "mtypes.h"
#include "imports.h"
#include "macros.h"
#include "colormac.h"
#include "mmath.h"
#include "math/m_translate.h"
#include "swrast_setup/swrast_setup.h"
#include "tnl/tnl.h"
#include "tnl/t_context.h"
#include "fxdrv.h"
static void copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc )
{
fxMesaContext fxMesa = FX_CONTEXT( ctx );
GrVertex *dst = fxMesa->verts + edst;
GrVertex *src = fxMesa->verts + esrc;
dst->r = src->r;
dst->g = src->g;
dst->b = src->b;
dst->a = src->a;
}
typedef void (*emit_func)( GLcontext *, GLuint, GLuint, void * );
static struct {
emit_func emit;
interp_func interp;
GLboolean (*check_tex_sizes)( GLcontext *ctx );
GLuint vertex_format;
} setup_tab[MAX_SETUP];
static void import_float_colors( GLcontext *ctx )
{
struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
struct gl_client_array *from = VB->ColorPtr[0];
struct gl_client_array *to = &FX_CONTEXT(ctx)->UbyteColor;
GLuint count = VB->Count;
if (!to->Ptr) {
to->Ptr = ALIGN_MALLOC( VB->Size * 4 * sizeof(GLubyte), 32 );
to->Type = GL_UNSIGNED_BYTE;
}
/* No need to transform the same value 3000 times.
*/
if (!from->StrideB) {
to->StrideB = 0;
count = 1;
}
else
to->StrideB = 4 * sizeof(GLubyte);
_math_trans_4ub( (GLubyte (*)[4]) to->Ptr,
from->Ptr,
from->StrideB,
from->Type,
from->Size,
0,
count);
VB->ColorPtr[0] = to;
}
#define GET_COLOR(ptr, idx) (((GLfloat (*)[4])((ptr)->Ptr))[idx])
static void interp_extras( GLcontext *ctx,
GLfloat t,
GLuint dst, GLuint out, GLuint in,
GLboolean force_boundary )
{
struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
/*fprintf(stderr, "%s\n", __FUNCTION__);*/
if (VB->ColorPtr[1]) {
INTERP_4F( t,
GET_COLOR(VB->ColorPtr[1], dst),
GET_COLOR(VB->ColorPtr[1], out),
GET_COLOR(VB->ColorPtr[1], in) );
if (VB->SecondaryColorPtr[1]) {
INTERP_3F( t,
GET_COLOR(VB->SecondaryColorPtr[1], dst),
GET_COLOR(VB->SecondaryColorPtr[1], out),
GET_COLOR(VB->SecondaryColorPtr[1], in) );
}
}
if (VB->EdgeFlag) {
VB->EdgeFlag[dst] = VB->EdgeFlag[out] || force_boundary;
}
setup_tab[FX_CONTEXT(ctx)->SetupIndex].interp(ctx, t, dst, out, in,
force_boundary);
}
static void copy_pv_extras( GLcontext *ctx, GLuint dst, GLuint src )
{
struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
if (VB->ColorPtr[1]) {
COPY_4FV( GET_COLOR(VB->ColorPtr[1], dst),
GET_COLOR(VB->ColorPtr[1], src) );
if (VB->SecondaryColorPtr[1]) {
COPY_4FV( GET_COLOR(VB->SecondaryColorPtr[1], dst),
GET_COLOR(VB->SecondaryColorPtr[1], src) );
}
}
copy_pv(ctx, dst, src);
}
#define IND (SETUP_XYZW|SETUP_RGBA)
#define TAG(x) x##_wg
#include "fxvbtmp.h"
#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0)
#define TAG(x) x##_wgt0
#include "fxvbtmp.h"
#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_TMU1)
#define TAG(x) x##_wgt0t1
#include "fxvbtmp.h"
#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_PTEX)
#define TAG(x) x##_wgpt0
#include "fxvbtmp.h"
#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_TMU1|\
SETUP_PTEX)
#define TAG(x) x##_wgpt0t1
#include "fxvbtmp.h"
/* Snapping for voodoo-1
*/
#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA)
#define TAG(x) x##_wsg
#include "fxvbtmp.h"
#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0)
#define TAG(x) x##_wsgt0
#include "fxvbtmp.h"
#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
SETUP_TMU1)
#define TAG(x) x##_wsgt0t1
#include "fxvbtmp.h"
#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
SETUP_PTEX)
#define TAG(x) x##_wsgpt0
#include "fxvbtmp.h"
#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
SETUP_TMU1|SETUP_PTEX)
#define TAG(x) x##_wsgpt0t1
#include "fxvbtmp.h"
/* Vertex repair (multipass rendering)
*/
#define IND (SETUP_RGBA)
#define TAG(x) x##_g
#include "fxvbtmp.h"
#define IND (SETUP_TMU0)
#define TAG(x) x##_t0
#include "fxvbtmp.h"
#define IND (SETUP_TMU0|SETUP_TMU1)
#define TAG(x) x##_t0t1
#include "fxvbtmp.h"
#define IND (SETUP_RGBA|SETUP_TMU0)
#define TAG(x) x##_gt0
#include "fxvbtmp.h"
#define IND (SETUP_RGBA|SETUP_TMU0|SETUP_TMU1)
#define TAG(x) x##_gt0t1
#include "fxvbtmp.h"
static void init_setup_tab( void )
{
init_wg();
init_wgt0();
init_wgt0t1();
init_wgpt0();
init_wgpt0t1();
init_wsg();
init_wsgt0();
init_wsgt0t1();
init_wsgpt0();
init_wsgpt0t1();
init_g();
init_t0();
init_t0t1();
init_gt0();
init_gt0t1();
}
void fxPrintSetupFlags(char *msg, GLuint flags )
{
fprintf(stderr, "%s(%x): %s%s%s%s%s\n",
msg,
(int)flags,
(flags & SETUP_XYZW) ? " xyzw," : "",
(flags & SETUP_SNAP) ? " snap," : "",
(flags & SETUP_RGBA) ? " rgba," : "",
(flags & SETUP_TMU0) ? " tex-0," : "",
(flags & SETUP_TMU1) ? " tex-1," : "");
}
void fxCheckTexSizes( GLcontext *ctx )
{
TNLcontext *tnl = TNL_CONTEXT(ctx);
fxMesaContext fxMesa = FX_CONTEXT( ctx );
if (!setup_tab[fxMesa->SetupIndex].check_tex_sizes(ctx)) {
GLuint ind = fxMesa->SetupIndex |= (SETUP_PTEX|SETUP_RGBA);
/* Tdfx handles projective textures nicely; just have to change
* up to the new vertex format.
*/
if (setup_tab[ind].vertex_format != fxMesa->stw_hint_state) {
fxMesa->stw_hint_state = setup_tab[ind].vertex_format;
FX_grHints(GR_HINT_STWHINT, fxMesa->stw_hint_state);
/* This is required as we have just changed the vertex
* format, so the interp routines must also change.
* In the unfilled and twosided cases we are using the
* Extras ones anyway, so leave them in place.
*/
if (!(ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
tnl->Driver.Render.Interp = setup_tab[fxMesa->SetupIndex].interp;
}
}
}
}
void fxBuildVertices( GLcontext *ctx, GLuint start, GLuint count,
GLuint newinputs )
{
fxMesaContext fxMesa = FX_CONTEXT( ctx );
GrVertex *v = (fxMesa->verts + start);
if (!newinputs)
return;
if (newinputs & VERT_BIT_CLIP) {
setup_tab[fxMesa->SetupIndex].emit( ctx, start, count, v );
} else {
GLuint ind = 0;
if (newinputs & VERT_BIT_COLOR0)
ind |= SETUP_RGBA;
if (newinputs & VERT_BIT_TEX0)
ind |= SETUP_TMU0;
if (newinputs & VERT_BIT_TEX1)
ind |= SETUP_TMU0|SETUP_TMU1;
if (fxMesa->SetupIndex & SETUP_PTEX)
ind = ~0;
ind &= fxMesa->SetupIndex;
if (ind) {
setup_tab[ind].emit( ctx, start, count, v );
}
}
}
void fxChooseVertexState( GLcontext *ctx )
{
TNLcontext *tnl = TNL_CONTEXT(ctx);
fxMesaContext fxMesa = FX_CONTEXT( ctx );
GLuint ind = SETUP_XYZW|SETUP_RGBA;
if (fxMesa->snapVertices)
ind |= SETUP_SNAP;
fxMesa->tmu_source[0] = 0;
fxMesa->tmu_source[1] = 1;
if (ctx->Texture._EnabledUnits & 0x2) {
if (ctx->Texture._EnabledUnits & 0x1) {
ind |= SETUP_TMU1|SETUP_TMU0;
}
else {
fxMesa->tmu_source[0] = 1;
fxMesa->tmu_source[1] = 0;
ind |= SETUP_TMU0;
}
}
else if (ctx->Texture._EnabledUnits & 0x1) {
ind |= SETUP_TMU0;
}
fxMesa->SetupIndex = ind;
if (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED)) {
tnl->Driver.Render.Interp = interp_extras;
tnl->Driver.Render.CopyPV = copy_pv_extras;
} else {
tnl->Driver.Render.Interp = setup_tab[ind].interp;
tnl->Driver.Render.CopyPV = copy_pv;
}
if (setup_tab[ind].vertex_format != fxMesa->stw_hint_state) {
fxMesa->stw_hint_state = setup_tab[ind].vertex_format;
FX_grHints(GR_HINT_STWHINT, fxMesa->stw_hint_state);
}
}
void fxAllocVB( GLcontext *ctx )
{
fxMesaContext fxMesa = FX_CONTEXT(ctx);
GLuint size = TNL_CONTEXT(ctx)->vb.Size;
static int firsttime = 1;
if (firsttime) {
init_setup_tab();
firsttime = 0;
}
fxMesa->verts = (GrVertex *)ALIGN_MALLOC(size * sizeof(GrVertex), 32);
fxMesa->SetupIndex = SETUP_XYZW|SETUP_RGBA;
}
void fxFreeVB( GLcontext *ctx )
{
fxMesaContext fxMesa = FX_CONTEXT(ctx);
if (fxMesa->verts) {
ALIGN_FREE(fxMesa->verts);
fxMesa->verts = 0;
}
if (fxMesa->UbyteColor.Ptr) {
ALIGN_FREE(fxMesa->UbyteColor.Ptr);
fxMesa->UbyteColor.Ptr = 0;
}
}
#else
/*
* Need this to provide at least one external definition.
*/
extern int gl_fx_dummy_function_vb(void);
int
gl_fx_dummy_function_vb(void)
{
return 0;
}
#endif /* FX */
|