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
|
/* -*- 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.
*/
static void TAG(fx_tri)(GLcontext *ctx, GLuint e1, GLuint e2, GLuint e3, GLuint pv)
{
fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
struct vertex_buffer *VB=ctx->VB;
fxVertex *gWin = FX_DRIVER_DATA(VB)->verts;
GrVertex *v1 = (GrVertex *)gWin[e1].f;
GrVertex *v2 = (GrVertex *)gWin[e2].f;
GrVertex *v3 = (GrVertex *)gWin[e3].f;
(void) fxMesa;
if (IND & (FX_TWOSIDE|FX_OFFSET))
{
GLfloat ex = v1->x - v3->x;
GLfloat ey = v1->y - v3->y;
GLfloat fx = v2->x - v3->x;
GLfloat fy = v2->y - v3->y;
GLfloat c = ex*fy-ey*fx;
if (IND & FX_TWOSIDE) {
GLuint facing = (c<0.0) ^ ctx->Polygon.FrontBit;
GLubyte (*color)[4] = VB->Color[facing]->data;
if (IND & FX_FLAT) {
GOURAUD2(v1,color[pv]);
GOURAUD2(v2,color[pv]);
GOURAUD2(v3,color[pv]);
} else {
GOURAUD2(v1,color[e1]);
GOURAUD2(v2,color[e2]);
GOURAUD2(v3,color[e3]);
}
}
/* Should apply a factor to ac to compensate for different x/y
* scaling introduced in the Viewport matrix.
*
* The driver should supply scaling factors for 'factor' and 'units'.
*/
if (IND & FX_OFFSET) {
GLfloat offset = ctx->Polygon.OffsetUnits;
if (c * c > 1e-16) {
GLfloat factor = ctx->Polygon.OffsetFactor;
GLfloat ez = v1->ooz - v3->ooz;
GLfloat fz = v2->ooz - v3->ooz;
GLfloat a = ey*fz-ez*fy;
GLfloat b = ez*fx-ex*fz;
GLfloat ic = 1.0 / c;
GLfloat ac = a * ic;
GLfloat bc = b * ic;
if (ac<0.0F) ac = -ac;
if (bc<0.0F) bc = -bc;
offset += MAX2( ac, bc ) * factor;
}
/* Probably a lot quicker just to nudge the z values and put
* them back afterwards.
*/
FX_grDepthBiasLevel((int)offset);
}
}
else if (IND & FX_FLAT) {
GLubyte (*color)[4] = VB->Color[0]->data;
GOURAUD2(v1,color[pv]);
GOURAUD2(v2,color[pv]);
GOURAUD2(v3,color[pv]);
}
if (IND & FX_FRONT_BACK) {
FX_grColorMask(ctx->Color.ColorMask[RCOMP] ||
ctx->Color.ColorMask[GCOMP] ||
ctx->Color.ColorMask[BCOMP],
FXFALSE);
FX_grDepthMask(FXFALSE);
FX_grRenderBuffer(GR_BUFFER_BACKBUFFER);
}
if (IND & FX_ANTIALIAS)
FX_grAADrawTriangle(v1, v2, v3, FXTRUE, FXTRUE, FXTRUE);
else
FX_grDrawTriangle(v1, v2, v3);
/* Might be quicker to do two passes, one for each buffer?
*/
if (IND & FX_FRONT_BACK) {
FX_grColorMask(ctx->Color.ColorMask[RCOMP] ||
ctx->Color.ColorMask[GCOMP] ||
ctx->Color.ColorMask[BCOMP],
ctx->Color.ColorMask[ACOMP] && fxMesa->haveAlphaBuffer);
if(ctx->Depth.Mask) FX_grDepthMask(FXTRUE);
FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER);
if (IND & FX_ANTIALIAS)
FX_grAADrawTriangle(v1,v2,v3, FXTRUE,FXTRUE,FXTRUE);
else
FX_grDrawTriangle(v1, v2, v3);
}
}
/* Not worth the space?
*/
static void TAG(fx_quad)(GLcontext *ctx, GLuint e1, GLuint e2, GLuint e3,
GLuint e4, GLuint pv)
{
fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
struct vertex_buffer *VB=ctx->VB;
fxVertex *gWin = FX_DRIVER_DATA(VB)->verts;
GrVertex *v1 = (GrVertex *)gWin[e1].f;
GrVertex *v2 = (GrVertex *)gWin[e2].f;
GrVertex *v3 = (GrVertex *)gWin[e3].f;
GrVertex *v4 = (GrVertex *)gWin[e4].f;
(void) fxMesa;
if (IND & (FX_TWOSIDE|FX_OFFSET))
{
GLfloat ex = v3->x - v1->x;
GLfloat ey = v3->y - v1->y;
GLfloat fx = v4->x - v2->x;
GLfloat fy = v4->y - v2->y;
GLfloat c = ex*fy-ey*fx;
if (IND & FX_TWOSIDE) {
GLuint facing = (c<0.0) ^ ctx->Polygon.FrontBit;
GLubyte (*color)[4] = VB->Color[facing]->data;
if (IND & FX_FLAT) {
GOURAUD2(v1,color[pv]);
GOURAUD2(v2,color[pv]);
GOURAUD2(v3,color[pv]);
GOURAUD2(v4,color[pv]);
} else {
GOURAUD2(v1,color[e1]);
GOURAUD2(v2,color[e2]);
GOURAUD2(v3,color[e3]);
GOURAUD2(v4,color[e4]);
}
}
/* Should apply a factor to ac to compensate for different x/y
* scaling introduced in the Viewport matrix.
*
* The driver should supply scaling factors for 'factor' and 'units'.
*/
if (IND & FX_OFFSET) {
GLfloat offset = ctx->Polygon.OffsetUnits;
if (c * c > 1e-16) {
GLfloat factor = ctx->Polygon.OffsetFactor;
GLfloat ez = v3->ooz - v1->ooz;
GLfloat fz = v4->ooz - v2->ooz;
GLfloat a = ey*fz-ez*fy;
GLfloat b = ez*fx-ex*fz;
GLfloat ic = 1.0 / c;
GLfloat ac = a * ic;
GLfloat bc = b * ic;
if (ac<0.0F) ac = -ac;
if (bc<0.0F) bc = -bc;
offset += MAX2( ac, bc ) * factor;
}
/* Probably a lot quicker just to nudge the z values and put
* them back afterwards.
*/
FX_grDepthBiasLevel((int)offset);
}
}
else if (IND & FX_FLAT) {
GLubyte (*color)[4] = VB->Color[0]->data;
GOURAUD2(v1,color[pv]);
GOURAUD2(v2,color[pv]);
GOURAUD2(v3,color[pv]);
GOURAUD2(v4,color[pv]);
}
if (IND & FX_FRONT_BACK) {
FX_grColorMask(ctx->Color.ColorMask[RCOMP] ||
ctx->Color.ColorMask[GCOMP] ||
ctx->Color.ColorMask[BCOMP],
FXFALSE);
FX_grDepthMask(FXFALSE);
FX_grRenderBuffer(GR_BUFFER_BACKBUFFER);
}
if (IND & FX_ANTIALIAS) {
FX_grAADrawTriangle(v1, v2, v4, FXTRUE, FXTRUE, FXTRUE);
FX_grAADrawTriangle(v2, v3, v4, FXTRUE, FXTRUE, FXTRUE);
} else {
FX_grDrawTriangle(v1, v2, v4);
FX_grDrawTriangle(v2, v3, v4);
}
/* Might be quicker to do two passes, one for each buffer?
*/
if (IND & FX_FRONT_BACK) {
FX_grColorMask(ctx->Color.ColorMask[RCOMP] ||
ctx->Color.ColorMask[GCOMP] ||
ctx->Color.ColorMask[BCOMP],
ctx->Color.ColorMask[ACOMP] && fxMesa->haveAlphaBuffer);
if(ctx->Depth.Mask) FX_grDepthMask(FXTRUE);
FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER);
if (IND & FX_ANTIALIAS) {
FX_grAADrawTriangle(v1, v2, v4, FXTRUE, FXTRUE, FXTRUE);
FX_grAADrawTriangle(v2, v3, v4, FXTRUE, FXTRUE, FXTRUE);
} else {
FX_grDrawTriangle(v1, v2, v4);
FX_grDrawTriangle(v2, v3, v4);
}
}
}
#define DRAW_LINE(tmp0, tmp1, width) \
do { \
const float xoff = 0.125, yoff = 0.125; \
GrVertex verts[4]; \
float dx, dy, wx, wy; \
\
dx = tmp0->x - tmp1->x; \
dy = tmp0->y - tmp1->y; \
\
if (dx * dx > dy * dy) { \
wx = 0; \
wy = width; \
} else { \
wx = width; \
wy = 0; \
} \
\
verts[0] = *tmp0; \
verts[1] = *tmp0; \
verts[2] = *tmp1; \
verts[3] = *tmp1; \
\
verts[0].x = tmp0->x - wx + xoff; \
verts[0].y = tmp0->y - wy + yoff; \
\
verts[1].x = tmp0->x + wx + xoff; \
verts[1].y = tmp0->y + wy + yoff; \
\
verts[2].x = tmp1->x + wx + xoff; \
verts[2].y = tmp1->y + wy + yoff; \
\
verts[3].x = tmp1->x - wx + xoff; \
verts[3].y = tmp1->y - wy + yoff; \
\
FX_grDrawPolygonVertexList(4, verts); \
} while (0)
#if (IND & FX_OFFSET) == 0
static void TAG(fx_line)(GLcontext *ctx, GLuint e1, GLuint e2, GLuint pv)
{
fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
struct vertex_buffer *VB=ctx->VB;
fxVertex *gWin = FX_DRIVER_DATA(VB)->verts;
GLubyte (* const color)[4] = VB->ColorPtr->data;
GrVertex *v1 = (GrVertex *)gWin[e1].f;
GrVertex *v2 = (GrVertex *)gWin[e2].f;
GLfloat w = ctx->Line.Width*.5;
if (IND & FX_FLAT) {
v1->r = v2->r = UBYTE_COLOR_TO_FLOAT_255_COLOR(color[pv][0]);
v1->g = v2->g = UBYTE_COLOR_TO_FLOAT_255_COLOR(color[pv][1]);
v1->b = v2->b = UBYTE_COLOR_TO_FLOAT_255_COLOR(color[pv][2]);
v1->a = v2->a = UBYTE_COLOR_TO_FLOAT_255_COLOR(color[pv][3]);
}
else if (IND & FX_TWOSIDE)
{
/* XXX use signed area of the polygon to determine front/back color choice */
GOURAUD2(v1,color[e1]);
GOURAUD2(v2,color[e2]);
}
if (IND & FX_FRONT_BACK) {
FX_grColorMask(ctx->Color.ColorMask[RCOMP] ||
ctx->Color.ColorMask[GCOMP] ||
ctx->Color.ColorMask[BCOMP],
FXFALSE);
FX_grDepthMask(FXFALSE);
FX_grRenderBuffer(GR_BUFFER_BACKBUFFER);
}
if (IND & FX_ANTIALIAS)
FX_grAADrawLine(v1,v2);
else
DRAW_LINE(v1,v2,w);
if (IND & FX_FRONT_BACK) {
FX_grColorMask(ctx->Color.ColorMask[RCOMP] ||
ctx->Color.ColorMask[GCOMP] ||
ctx->Color.ColorMask[BCOMP],
ctx->Color.ColorMask[ACOMP] && fxMesa->haveAlphaBuffer);
if(ctx->Depth.Mask)
FX_grDepthMask(FXTRUE);
FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER);
if (IND & FX_ANTIALIAS)
FX_grAADrawLine(v1,v2);
else
DRAW_LINE(v1,v2,w);
}
}
#endif
#if (IND & FX_OFFSET) == 0
#if IND & FX_FLAT
# if IND & FX_ANTIALIAS
#if FX_USE_PARGB
# define FLAT_COLOR(x,y) GET_PA(gWin[i].f) = y[3];
#else
# define FLAT_COLOR(x,y) gWin[i].f[ACOORD] = y[3]; \
FX_VB_COLOR(x, y)
#endif
# else
# define FLAT_COLOR(x,y) FX_VB_COLOR(x, y)
# endif
#else
#define FLAT_COLOR(x,y)
#endif
#define DRAW_POINT(i, sz) \
do { \
GrVertex verts[4], *tmp; \
\
tmp = (GrVertex*)gWin[i].f; \
verts[0] = *tmp; \
verts[1] = *tmp; \
verts[2] = *tmp; \
verts[3] = *tmp; \
verts[0].x = verts[3].x = tmp->x + sz; \
verts[0].y = verts[1].y = tmp->y + sz; \
verts[2].x = verts[1].x = tmp->x - sz; \
verts[2].y = verts[3].y = tmp->y - sz; \
\
FX_grDrawPolygonVertexList(4, verts); \
} while (0)
static void TAG(fx_points)(GLcontext *ctx, GLuint first, GLuint last)
{
fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
struct vertex_buffer *VB = ctx->VB;
fxVertex *gWin = FX_DRIVER_DATA(VB)->verts;
GLubyte (*color)[4] = VB->ColorPtr->data;
GLuint i;
GLfloat sz = ctx->Point.Size * .5;
(void) color; (void) fxMesa;
if (IND & FX_FRONT_BACK) {
FX_grColorMask(ctx->Color.ColorMask[RCOMP] ||
ctx->Color.ColorMask[GCOMP] ||
ctx->Color.ColorMask[BCOMP],
FXFALSE);
FX_grDepthMask(FXFALSE);
FX_grRenderBuffer(GR_BUFFER_BACKBUFFER);
}
if(!VB->ClipOrMask) {
for(i=first;i<=last;i++) {
FLAT_COLOR(fxMesa, color[i]);
DRAW_POINT(i, sz);
}
} else {
for(i=first;i<=last;i++) {
if(VB->ClipMask[i]==0) {
FLAT_COLOR(fxMesa, color[i]);
DRAW_POINT(i, sz);
}
}
}
if (IND & FX_FRONT_BACK) {
FX_grColorMask(ctx->Color.ColorMask[RCOMP] ||
ctx->Color.ColorMask[GCOMP] ||
ctx->Color.ColorMask[BCOMP],
ctx->Color.ColorMask[ACOMP] && fxMesa->haveAlphaBuffer);
if(ctx->Depth.Mask)
FX_grDepthMask(FXTRUE);
FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER);
if(!VB->ClipOrMask) {
for(i=first;i<=last;i++) {
FLAT_COLOR(fxMesa, color[i]);
DRAW_POINT(i, sz);
}
} else {
for(i=first;i<=last;i++) {
if(VB->ClipMask[i]==0) {
FLAT_COLOR(fxMesa, color[i]);
DRAW_POINT(i, sz);
}
}
}
}
}
#endif
static void TAG(init)( void )
{
tri_tab[IND] = TAG(fx_tri);
quad_tab[IND] = TAG(fx_quad);
#if ((IND & FX_OFFSET) == 0)
line_tab[IND] = TAG(fx_line);
points_tab[IND] = TAG(fx_points);
#else
line_tab[IND] = line_tab[IND & ~FX_OFFSET];
points_tab[IND] = points_tab[IND & ~FX_OFFSET];
#endif
}
#undef IND
#undef TAG
#undef FLAT_COLOR
#undef DRAW_POINT
|