add tdfx DRI driver
[mesa.git] / src / mesa / drivers / dri / tdfx / tdfx_tris.c
1 /* -*- mode: c; c-basic-offset: 3 -*-
2 *
3 * Copyright 2000 VA Linux Systems Inc., Fremont, California.
4 *
5 * 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 (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 */
26 /* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/tdfx_tris.c,v 1.4 2002/10/30 12:52:01 alanh Exp $ */
27
28 /* Authors:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32 #include "glheader.h"
33 #include "mtypes.h"
34 #include "macros.h"
35 #include "colormac.h"
36
37 #include "swrast/swrast.h"
38 #include "swrast_setup/swrast_setup.h"
39 #include "swrast_setup/ss_context.h"
40 #include "tnl/t_context.h"
41 #include "tnl/t_pipeline.h"
42
43 #include "tdfx_tris.h"
44 #include "tdfx_state.h"
45 #include "tdfx_vb.h"
46 #include "tdfx_lock.h"
47 #include "tdfx_render.h"
48
49
50 static void tdfxRasterPrimitive( GLcontext *ctx, GLenum prim );
51 static void tdfxRenderPrimitive( GLcontext *ctx, GLenum prim );
52
53 /***********************************************************************
54 * Macros for t_dd_tritmp.h to draw basic primitives *
55 ***********************************************************************/
56
57 #define TRI( a, b, c ) \
58 do { \
59 if (DO_FALLBACK) \
60 fxMesa->draw_triangle( fxMesa, a, b, c ); \
61 else \
62 fxMesa->Glide.grDrawTriangle( a, b, c ); \
63 } while (0) \
64
65 #define QUAD( a, b, c, d ) \
66 do { \
67 if (DO_FALLBACK) { \
68 fxMesa->draw_triangle( fxMesa, a, b, d ); \
69 fxMesa->draw_triangle( fxMesa, b, c, d ); \
70 } else { \
71 fxMesa->Glide.grDrawTriangle( a, b, d ); \
72 fxMesa->Glide.grDrawTriangle( b, c, d ); \
73 } \
74 } while (0)
75
76 #define LINE( v0, v1 ) \
77 do { \
78 if (DO_FALLBACK) \
79 fxMesa->draw_line( fxMesa, v0, v1 ); \
80 else { \
81 v0->v.x += LINE_X_OFFSET - TRI_X_OFFSET; \
82 v0->v.y += LINE_Y_OFFSET - TRI_Y_OFFSET; \
83 v1->v.x += LINE_X_OFFSET - TRI_X_OFFSET; \
84 v1->v.y += LINE_Y_OFFSET - TRI_Y_OFFSET; \
85 fxMesa->Glide.grDrawLine( v0, v1 ); \
86 v0->v.x -= LINE_X_OFFSET - TRI_X_OFFSET; \
87 v0->v.y -= LINE_Y_OFFSET - TRI_Y_OFFSET; \
88 v1->v.x -= LINE_X_OFFSET - TRI_X_OFFSET; \
89 v1->v.y -= LINE_Y_OFFSET - TRI_Y_OFFSET; \
90 } \
91 } while (0)
92
93 #define POINT( v0 ) \
94 do { \
95 if (DO_FALLBACK) \
96 fxMesa->draw_point( fxMesa, v0 ); \
97 else { \
98 v0->v.x += PNT_X_OFFSET - TRI_X_OFFSET; \
99 v0->v.y += PNT_Y_OFFSET - TRI_Y_OFFSET; \
100 fxMesa->Glide.grDrawPoint( v0 ); \
101 v0->v.x -= PNT_X_OFFSET - TRI_X_OFFSET; \
102 v0->v.y -= PNT_Y_OFFSET - TRI_Y_OFFSET; \
103 } \
104 } while (0)
105
106
107 /***********************************************************************
108 * Fallback to swrast for basic primitives *
109 ***********************************************************************/
110
111 /* Build an SWvertex from a hardware vertex.
112 *
113 * This code is hit only when a mix of accelerated and unaccelerated
114 * primitives are being drawn, and only for the unaccelerated
115 * primitives.
116 */
117 static void
118 tdfx_translate_vertex( GLcontext *ctx, const tdfxVertex *src, SWvertex *dst)
119 {
120 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
121
122 if (fxMesa->vertexFormat == TDFX_LAYOUT_TINY) {
123 dst->win[0] = src->tv.x - fxMesa->x_offset;
124 dst->win[1] = src->tv.y - (fxMesa->screen_height - fxMesa->height - fxMesa->y_offset);
125 dst->win[2] = src->tv.z;
126 dst->win[3] = 1.0;
127
128 dst->color[0] = src->tv.color.red;
129 dst->color[1] = src->tv.color.green;
130 dst->color[2] = src->tv.color.blue;
131 dst->color[3] = src->tv.color.alpha;
132 }
133 else {
134 GLfloat w = 1.0 / src->v.rhw;
135
136 dst->win[0] = src->v.x - fxMesa->x_offset;
137 dst->win[1] = fxMesa->screen_height - fxMesa->y_offset - src->v.y;
138 dst->win[2] = src->v.z;
139 dst->win[3] = src->v.rhw;
140
141 dst->color[0] = src->v.color.red;
142 dst->color[1] = src->v.color.green;
143 dst->color[2] = src->v.color.blue;
144 dst->color[3] = src->v.color.alpha;
145
146 if (fxMesa->vertexFormat == TDFX_LAYOUT_PROJECT) {
147 dst->texcoord[0][0] = fxMesa->sScale0 * w * src->pv.tu0;
148 dst->texcoord[0][1] = fxMesa->tScale0 * w * src->pv.tv0;
149 dst->texcoord[0][3] = w * src->pv.tq0;
150
151 if (fxMesa->SetupIndex & TDFX_TEX1_BIT) {
152 dst->texcoord[1][0] = fxMesa->sScale1 * w * src->pv.tu1;
153 dst->texcoord[1][1] = fxMesa->tScale1 * w * src->pv.tv1;
154 dst->texcoord[1][3] = w * src->pv.tq1;
155 }
156 } else if (fxMesa->SetupIndex & TDFX_TEX0_BIT) {
157 dst->texcoord[0][0] = fxMesa->sScale0 * w * src->v.tu0;
158 dst->texcoord[0][1] = fxMesa->tScale0 * w * src->v.tv0;
159 dst->texcoord[0][3] = 1.0;
160
161 if (fxMesa->SetupIndex & TDFX_TEX1_BIT) {
162 dst->texcoord[1][0] = fxMesa->sScale1 * w * src->v.tu1;
163 dst->texcoord[1][1] = fxMesa->tScale1 * w * src->v.tv1;
164 dst->texcoord[1][3] = 1.0;
165 }
166 }
167 }
168
169 dst->pointSize = ctx->Point._Size;
170 }
171
172
173 static void
174 tdfx_fallback_tri( tdfxContextPtr fxMesa,
175 tdfxVertex *v0,
176 tdfxVertex *v1,
177 tdfxVertex *v2 )
178 {
179 GLcontext *ctx = fxMesa->glCtx;
180 SWvertex v[3];
181 tdfx_translate_vertex( ctx, v0, &v[0] );
182 tdfx_translate_vertex( ctx, v1, &v[1] );
183 tdfx_translate_vertex( ctx, v2, &v[2] );
184 _swrast_Triangle( ctx, &v[0], &v[1], &v[2] );
185 }
186
187
188 static void
189 tdfx_fallback_line( tdfxContextPtr fxMesa,
190 tdfxVertex *v0,
191 tdfxVertex *v1 )
192 {
193 GLcontext *ctx = fxMesa->glCtx;
194 SWvertex v[2];
195 tdfx_translate_vertex( ctx, v0, &v[0] );
196 tdfx_translate_vertex( ctx, v1, &v[1] );
197 _swrast_Line( ctx, &v[0], &v[1] );
198 }
199
200
201 static void
202 tdfx_fallback_point( tdfxContextPtr fxMesa,
203 tdfxVertex *v0 )
204 {
205 GLcontext *ctx = fxMesa->glCtx;
206 SWvertex v[1];
207 tdfx_translate_vertex( ctx, v0, &v[0] );
208 _swrast_Point( ctx, &v[0] );
209 }
210
211 /***********************************************************************
212 * Functions to draw basic primitives *
213 ***********************************************************************/
214
215 static void tdfx_print_vertex( GLcontext *ctx, const tdfxVertex *v )
216 {
217 tdfxContextPtr imesa = TDFX_CONTEXT( ctx );
218
219 fprintf(stderr, "vertex at %p\n", v);
220
221 if (imesa->vertexFormat == TDFX_LAYOUT_TINY) {
222 fprintf(stderr, "x %f y %f z %f\n", v->v.x, v->v.y, v->v.z);
223 fprintf(stderr, "r %d g %d b %d a %d\n",
224 v->tv.color.red,
225 v->tv.color.green,
226 v->tv.color.blue,
227 v->tv.color.alpha);
228 }
229 else {
230 fprintf(stderr, "x %f y %f z %f oow %f\n",
231 v->v.x, v->v.y, v->v.z, v->v.rhw);
232 fprintf(stderr, "r %d g %d b %d a %d\n",
233 v->v.color.red,
234 v->v.color.green,
235 v->v.color.blue,
236 v->v.color.alpha);
237 }
238
239 fprintf(stderr, "\n");
240 }
241
242 #define DO_FALLBACK 0
243
244 /* Need to do clip loop at each triangle when mixing swrast and hw
245 * rendering. These functions are only used when mixed-mode rendering
246 * is occurring.
247 */
248 static void tdfx_draw_quad( tdfxContextPtr fxMesa,
249 tdfxVertexPtr v0,
250 tdfxVertexPtr v1,
251 tdfxVertexPtr v2,
252 tdfxVertexPtr v3 )
253 {
254 /* fprintf(stderr, "%s\n", __FUNCTION__); */
255 BEGIN_CLIP_LOOP_LOCKED(fxMesa) {
256 QUAD( v0, v1, v2, v3 );
257 } END_CLIP_LOOP_LOCKED(fxMesa);
258 }
259
260 static void tdfx_draw_triangle( tdfxContextPtr fxMesa,
261 tdfxVertexPtr v0,
262 tdfxVertexPtr v1,
263 tdfxVertexPtr v2 )
264 {
265 /* fprintf(stderr, "%s\n", __FUNCTION__); */
266 /* tdfx_print_vertex( fxMesa->glCtx, v0 ); */
267 /* tdfx_print_vertex( fxMesa->glCtx, v1 ); */
268 /* tdfx_print_vertex( fxMesa->glCtx, v2 ); */
269 BEGIN_CLIP_LOOP_LOCKED(fxMesa) {
270 TRI( v0, v1, v2 );
271 } END_CLIP_LOOP_LOCKED(fxMesa);
272 }
273
274 static void tdfx_draw_line( tdfxContextPtr fxMesa,
275 tdfxVertexPtr v0,
276 tdfxVertexPtr v1 )
277 {
278 /* No support for wide lines (avoid wide/aa line fallback).
279 */
280 BEGIN_CLIP_LOOP_LOCKED(fxMesa) {
281 LINE(v0, v1);
282 } END_CLIP_LOOP_LOCKED(fxMesa);
283 }
284
285 static void tdfx_draw_point( tdfxContextPtr fxMesa,
286 tdfxVertexPtr v0 )
287 {
288 /* No support for wide points.
289 */
290 BEGIN_CLIP_LOOP_LOCKED(fxMesa) {
291 POINT( v0 );
292 } END_CLIP_LOOP_LOCKED(fxMesa);
293 }
294
295 #undef DO_FALLBACK
296
297
298 #define TDFX_UNFILLED_BIT 0x1
299 #define TDFX_OFFSET_BIT 0x2
300 #define TDFX_TWOSIDE_BIT 0x4
301 #define TDFX_FLAT_BIT 0x8
302 #define TDFX_FALLBACK_BIT 0x10
303 #define TDFX_MAX_TRIFUNC 0x20
304
305 static struct {
306 points_func points;
307 line_func line;
308 triangle_func triangle;
309 quad_func quad;
310 } rast_tab[TDFX_MAX_TRIFUNC];
311
312 #define DO_FALLBACK (IND & TDFX_FALLBACK_BIT)
313 #define DO_OFFSET (IND & TDFX_OFFSET_BIT)
314 #define DO_UNFILLED (IND & TDFX_UNFILLED_BIT)
315 #define DO_TWOSIDE (IND & TDFX_TWOSIDE_BIT)
316 #define DO_FLAT (IND & TDFX_FLAT_BIT)
317 #define DO_TRI 1
318 #define DO_QUAD 1
319 #define DO_LINE 1
320 #define DO_POINTS 1
321 #define DO_FULL_QUAD 1
322
323 #define HAVE_RGBA 1
324 #define HAVE_SPEC 0
325 #define HAVE_HW_FLATSHADE 0
326 #define HAVE_BACK_COLORS 0
327 #define VERTEX tdfxVertex
328 #define TAB rast_tab
329
330 #define TDFX_COLOR( dst, src ) \
331 do { \
332 dst[0] = src[2]; \
333 dst[1] = src[1]; \
334 dst[2] = src[0]; \
335 dst[3] = src[3]; \
336 } while (0)
337
338 #define DEPTH_SCALE 1.0
339 #define UNFILLED_TRI unfilled_tri
340 #define UNFILLED_QUAD unfilled_quad
341 #define VERT_X(_v) _v->v.x
342 #define VERT_Y(_v) _v->v.y
343 #define VERT_Z(_v) _v->v.z
344 #define AREA_IS_CCW( a ) (a < 0)
345 #define GET_VERTEX(e) (fxMesa->verts + (e<<fxMesa->vertex_stride_shift))
346
347 #define VERT_SET_RGBA( v, c ) TDFX_COLOR( v->ub4[coloroffset], c )
348 #define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset]
349 #define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[coloroffset]
350 #define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]
351
352 #define LOCAL_VARS(n) \
353 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); \
354 GLuint coloroffset = (fxMesa->vertexFormat == \
355 TDFX_LAYOUT_TINY) ? 3 : 4; \
356 GLuint color[n]; \
357 (void) color; (void)coloroffset
358
359
360
361 /***********************************************************************
362 * Functions to draw basic unfilled primitives *
363 ***********************************************************************/
364
365 #define RASTERIZE(x) if (fxMesa->raster_primitive != x) \
366 tdfxRasterPrimitive( ctx, x )
367 #define RENDER_PRIMITIVE fxMesa->render_primitive
368 #define IND TDFX_FALLBACK_BIT
369 #define TAG(x) x
370 #include "tnl_dd/t_dd_unfilled.h"
371 #undef IND
372
373 /***********************************************************************
374 * Functions to draw GL primitives *
375 ***********************************************************************/
376
377 #define IND (0)
378 #define TAG(x) x
379 #include "tnl_dd/t_dd_tritmp.h"
380
381 #define IND (TDFX_OFFSET_BIT)
382 #define TAG(x) x##_offset
383 #include "tnl_dd/t_dd_tritmp.h"
384
385 #define IND (TDFX_TWOSIDE_BIT)
386 #define TAG(x) x##_twoside
387 #include "tnl_dd/t_dd_tritmp.h"
388
389 #define IND (TDFX_TWOSIDE_BIT|TDFX_OFFSET_BIT)
390 #define TAG(x) x##_twoside_offset
391 #include "tnl_dd/t_dd_tritmp.h"
392
393 #define IND (TDFX_UNFILLED_BIT)
394 #define TAG(x) x##_unfilled
395 #include "tnl_dd/t_dd_tritmp.h"
396
397 #define IND (TDFX_OFFSET_BIT|TDFX_UNFILLED_BIT)
398 #define TAG(x) x##_offset_unfilled
399 #include "tnl_dd/t_dd_tritmp.h"
400
401 #define IND (TDFX_TWOSIDE_BIT|TDFX_UNFILLED_BIT)
402 #define TAG(x) x##_twoside_unfilled
403 #include "tnl_dd/t_dd_tritmp.h"
404
405 #define IND (TDFX_TWOSIDE_BIT|TDFX_OFFSET_BIT|TDFX_UNFILLED_BIT)
406 #define TAG(x) x##_twoside_offset_unfilled
407 #include "tnl_dd/t_dd_tritmp.h"
408
409 #define IND (TDFX_FALLBACK_BIT)
410 #define TAG(x) x##_fallback
411 #include "tnl_dd/t_dd_tritmp.h"
412
413 #define IND (TDFX_OFFSET_BIT|TDFX_FALLBACK_BIT)
414 #define TAG(x) x##_offset_fallback
415 #include "tnl_dd/t_dd_tritmp.h"
416
417 #define IND (TDFX_TWOSIDE_BIT|TDFX_FALLBACK_BIT)
418 #define TAG(x) x##_twoside_fallback
419 #include "tnl_dd/t_dd_tritmp.h"
420
421 #define IND (TDFX_TWOSIDE_BIT|TDFX_OFFSET_BIT|TDFX_FALLBACK_BIT)
422 #define TAG(x) x##_twoside_offset_fallback
423 #include "tnl_dd/t_dd_tritmp.h"
424
425 #define IND (TDFX_UNFILLED_BIT|TDFX_FALLBACK_BIT)
426 #define TAG(x) x##_unfilled_fallback
427 #include "tnl_dd/t_dd_tritmp.h"
428
429 #define IND (TDFX_OFFSET_BIT|TDFX_UNFILLED_BIT|TDFX_FALLBACK_BIT)
430 #define TAG(x) x##_offset_unfilled_fallback
431 #include "tnl_dd/t_dd_tritmp.h"
432
433 #define IND (TDFX_TWOSIDE_BIT|TDFX_UNFILLED_BIT|TDFX_FALLBACK_BIT)
434 #define TAG(x) x##_twoside_unfilled_fallback
435 #include "tnl_dd/t_dd_tritmp.h"
436
437 #define IND (TDFX_TWOSIDE_BIT|TDFX_OFFSET_BIT|TDFX_UNFILLED_BIT| \
438 TDFX_FALLBACK_BIT)
439 #define TAG(x) x##_twoside_offset_unfilled_fallback
440 #include "tnl_dd/t_dd_tritmp.h"
441
442
443 /* Tdfx doesn't support provoking-vertex flat-shading?
444 */
445 #define IND (TDFX_FLAT_BIT)
446 #define TAG(x) x##_flat
447 #include "tnl_dd/t_dd_tritmp.h"
448
449 #define IND (TDFX_OFFSET_BIT|TDFX_FLAT_BIT)
450 #define TAG(x) x##_offset_flat
451 #include "tnl_dd/t_dd_tritmp.h"
452
453 #define IND (TDFX_TWOSIDE_BIT|TDFX_FLAT_BIT)
454 #define TAG(x) x##_twoside_flat
455 #include "tnl_dd/t_dd_tritmp.h"
456
457 #define IND (TDFX_TWOSIDE_BIT|TDFX_OFFSET_BIT|TDFX_FLAT_BIT)
458 #define TAG(x) x##_twoside_offset_flat
459 #include "tnl_dd/t_dd_tritmp.h"
460
461 #define IND (TDFX_UNFILLED_BIT|TDFX_FLAT_BIT)
462 #define TAG(x) x##_unfilled_flat
463 #include "tnl_dd/t_dd_tritmp.h"
464
465 #define IND (TDFX_OFFSET_BIT|TDFX_UNFILLED_BIT|TDFX_FLAT_BIT)
466 #define TAG(x) x##_offset_unfilled_flat
467 #include "tnl_dd/t_dd_tritmp.h"
468
469 #define IND (TDFX_TWOSIDE_BIT|TDFX_UNFILLED_BIT|TDFX_FLAT_BIT)
470 #define TAG(x) x##_twoside_unfilled_flat
471 #include "tnl_dd/t_dd_tritmp.h"
472
473 #define IND (TDFX_TWOSIDE_BIT|TDFX_OFFSET_BIT|TDFX_UNFILLED_BIT|TDFX_FLAT_BIT)
474 #define TAG(x) x##_twoside_offset_unfilled_flat
475 #include "tnl_dd/t_dd_tritmp.h"
476
477 #define IND (TDFX_FALLBACK_BIT|TDFX_FLAT_BIT)
478 #define TAG(x) x##_fallback_flat
479 #include "tnl_dd/t_dd_tritmp.h"
480
481 #define IND (TDFX_OFFSET_BIT|TDFX_FALLBACK_BIT|TDFX_FLAT_BIT)
482 #define TAG(x) x##_offset_fallback_flat
483 #include "tnl_dd/t_dd_tritmp.h"
484
485 #define IND (TDFX_TWOSIDE_BIT|TDFX_FALLBACK_BIT|TDFX_FLAT_BIT)
486 #define TAG(x) x##_twoside_fallback_flat
487 #include "tnl_dd/t_dd_tritmp.h"
488
489 #define IND (TDFX_TWOSIDE_BIT|TDFX_OFFSET_BIT|TDFX_FALLBACK_BIT|TDFX_FLAT_BIT)
490 #define TAG(x) x##_twoside_offset_fallback_flat
491 #include "tnl_dd/t_dd_tritmp.h"
492
493 #define IND (TDFX_UNFILLED_BIT|TDFX_FALLBACK_BIT|TDFX_FLAT_BIT)
494 #define TAG(x) x##_unfilled_fallback_flat
495 #include "tnl_dd/t_dd_tritmp.h"
496
497 #define IND (TDFX_OFFSET_BIT|TDFX_UNFILLED_BIT|TDFX_FALLBACK_BIT|TDFX_FLAT_BIT)
498 #define TAG(x) x##_offset_unfilled_fallback_flat
499 #include "tnl_dd/t_dd_tritmp.h"
500
501 #define IND (TDFX_TWOSIDE_BIT|TDFX_UNFILLED_BIT|TDFX_FALLBACK_BIT|TDFX_FLAT_BIT)
502 #define TAG(x) x##_twoside_unfilled_fallback_flat
503 #include "tnl_dd/t_dd_tritmp.h"
504
505 #define IND (TDFX_TWOSIDE_BIT|TDFX_OFFSET_BIT|TDFX_UNFILLED_BIT| \
506 TDFX_FALLBACK_BIT|TDFX_FLAT_BIT)
507 #define TAG(x) x##_twoside_offset_unfilled_fallback_flat
508 #include "tnl_dd/t_dd_tritmp.h"
509
510
511 static void init_rast_tab( void )
512 {
513 init();
514 init_offset();
515 init_twoside();
516 init_twoside_offset();
517 init_unfilled();
518 init_offset_unfilled();
519 init_twoside_unfilled();
520 init_twoside_offset_unfilled();
521 init_fallback();
522 init_offset_fallback();
523 init_twoside_fallback();
524 init_twoside_offset_fallback();
525 init_unfilled_fallback();
526 init_offset_unfilled_fallback();
527 init_twoside_unfilled_fallback();
528 init_twoside_offset_unfilled_fallback();
529
530 init_flat();
531 init_offset_flat();
532 init_twoside_flat();
533 init_twoside_offset_flat();
534 init_unfilled_flat();
535 init_offset_unfilled_flat();
536 init_twoside_unfilled_flat();
537 init_twoside_offset_unfilled_flat();
538 init_fallback_flat();
539 init_offset_fallback_flat();
540 init_twoside_fallback_flat();
541 init_twoside_offset_fallback_flat();
542 init_unfilled_fallback_flat();
543 init_offset_unfilled_fallback_flat();
544 init_twoside_unfilled_fallback_flat();
545 init_twoside_offset_unfilled_fallback_flat();
546 }
547
548
549 /**********************************************************************/
550 /* Render whole begin/end objects */
551 /**********************************************************************/
552
553
554 /* Accelerate vertex buffer rendering when renderindex == 0 and
555 * there is no clipping.
556 */
557
558 static void tdfx_render_vb_points( GLcontext *ctx,
559 GLuint start,
560 GLuint count,
561 GLuint flags )
562 {
563 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
564 GLuint shift = fxMesa->vertex_stride_shift;
565 GLubyte *fxVB = fxMesa->verts + (start << shift);
566 int stride = 1<<shift;
567 GLubyte *tmp;
568 GLint i;
569 (void) flags;
570
571 /* Adjust point coords */
572 for (i = start, tmp = fxVB; i < count; i++, tmp += stride) {
573 ((tdfxVertexPtr)tmp)->v.x += PNT_X_OFFSET - TRI_X_OFFSET;
574 ((tdfxVertexPtr)tmp)->v.y += PNT_Y_OFFSET - TRI_Y_OFFSET;
575 }
576
577 fxMesa->Glide.grDrawVertexArrayContiguous( GR_POINTS, count-start,
578 fxVB, stride);
579 /* restore point coords */
580 for (i = start, tmp = fxVB; i < count; i++, tmp += stride) {
581 ((tdfxVertexPtr)tmp)->v.x -= PNT_X_OFFSET - TRI_X_OFFSET;
582 ((tdfxVertexPtr)tmp)->v.y -= PNT_Y_OFFSET - TRI_Y_OFFSET;
583 }
584 }
585
586 static void tdfx_render_vb_line_strip( GLcontext *ctx,
587 GLuint start,
588 GLuint count,
589 GLuint flags )
590 {
591 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
592 GLuint shift = fxMesa->vertex_stride_shift;
593 GLubyte *fxVB = fxMesa->verts + (start << shift);
594 int stride = 1<<shift;
595 GLubyte *tmp;
596 GLint i;
597 (void) flags;
598
599 /* adjust line coords */
600 for (i = start, tmp = fxVB; i < count; i++, tmp += stride) {
601 ((tdfxVertexPtr)tmp)->v.x += LINE_X_OFFSET - TRI_X_OFFSET;
602 ((tdfxVertexPtr)tmp)->v.y += LINE_Y_OFFSET - TRI_Y_OFFSET;
603 }
604
605 fxMesa->Glide.grDrawVertexArrayContiguous( GR_LINE_STRIP, count-start,
606 fxVB, 1<<shift);
607
608 /* restore line coords */
609 for (i = start, tmp = fxVB; i < count; i++, tmp += stride) {
610 ((tdfxVertexPtr)tmp)->v.x -= LINE_X_OFFSET - TRI_X_OFFSET;
611 ((tdfxVertexPtr)tmp)->v.y -= LINE_Y_OFFSET - TRI_Y_OFFSET;
612 }
613 }
614
615 static void tdfx_render_vb_line_loop( GLcontext *ctx,
616 GLuint start,
617 GLuint count,
618 GLuint flags )
619 {
620 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
621 GLuint shift = fxMesa->vertex_stride_shift;
622 GLubyte *fxVB = fxMesa->verts + (start << shift);
623 int stride = 1<<shift;
624 GLubyte *tmp, *tmp2 = fxVB;
625 GLint i;
626 GLint j = start;
627 (void) flags;
628
629 if (!(flags & PRIM_BEGIN)) {
630 fxVB += (1 << shift);
631 j++;
632 }
633
634 /* adjust line coords */
635 for (i = start, tmp = tmp2; i < count; i++, tmp += stride) {
636 ((tdfxVertexPtr)tmp)->v.x += LINE_X_OFFSET - TRI_X_OFFSET;
637 ((tdfxVertexPtr)tmp)->v.y += LINE_Y_OFFSET - TRI_Y_OFFSET;
638 }
639
640 fxMesa->Glide.grDrawVertexArrayContiguous( GR_LINE_STRIP, count-j,
641 fxVB, 1<<shift);
642
643 if (flags & PRIM_END)
644 fxMesa->Glide.grDrawLine( fxMesa->verts + ((count - 1)<<shift),
645 fxMesa->verts + (start<<shift) );
646
647 /* restore line coords */
648 for (i = start, tmp = tmp2; i < count; i++, tmp += stride) {
649 ((tdfxVertexPtr)tmp)->v.x -= LINE_X_OFFSET - TRI_X_OFFSET;
650 ((tdfxVertexPtr)tmp)->v.y -= LINE_Y_OFFSET - TRI_Y_OFFSET;
651 }
652 }
653
654 static void tdfx_render_vb_lines( GLcontext *ctx,
655 GLuint start,
656 GLuint count,
657 GLuint flags )
658 {
659 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
660 GLuint shift = fxMesa->vertex_stride_shift;
661 GLubyte *fxVB = fxMesa->verts + (start << shift);
662 int stride = 1<<shift;
663 GLubyte *tmp;
664 GLint i;
665 (void) flags;
666
667 /* adjust line coords */
668 for (i = start, tmp = fxVB; i < count; i++, tmp += stride) {
669 ((tdfxVertexPtr)tmp)->v.x += LINE_X_OFFSET - TRI_X_OFFSET;
670 ((tdfxVertexPtr)tmp)->v.y += LINE_Y_OFFSET - TRI_Y_OFFSET;
671 }
672
673 fxMesa->Glide.grDrawVertexArrayContiguous( GR_LINES, count-start,
674 fxVB, 1<<shift);
675
676 /* restore line coords */
677 for (i = start, tmp = fxVB; i < count; i++, tmp += stride) {
678 ((tdfxVertexPtr)tmp)->v.x -= LINE_X_OFFSET - TRI_X_OFFSET;
679 ((tdfxVertexPtr)tmp)->v.y -= LINE_Y_OFFSET - TRI_Y_OFFSET;
680 }
681 }
682
683 static void tdfx_render_vb_triangles( GLcontext *ctx,
684 GLuint start,
685 GLuint count,
686 GLuint flags )
687 {
688 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
689 GLuint shift = fxMesa->vertex_stride_shift;
690 GLubyte *fxVB = fxMesa->verts + (start << shift);
691 (void) flags;
692
693 fxMesa->Glide.grDrawVertexArrayContiguous( GR_TRIANGLES, count-start,
694 fxVB, 1<<shift);
695 }
696
697
698 static void tdfx_render_vb_tri_strip( GLcontext *ctx,
699 GLuint start,
700 GLuint count,
701 GLuint flags )
702 {
703 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
704 GLuint shift = fxMesa->vertex_stride_shift;
705 GLubyte *fxVB = fxMesa->verts + (start << shift);
706 int mode;
707 (void) flags;
708
709 /* fprintf(stderr, "%s/%d\n", __FUNCTION__, 1<<shift); */
710 /* if(!prevLockLine) abort(); */
711
712 if (flags & PRIM_PARITY)
713 mode = GR_TRIANGLE_STRIP_CONTINUE;
714 else
715 mode = GR_TRIANGLE_STRIP;
716
717 fxMesa->Glide.grDrawVertexArrayContiguous( mode, count-start,
718 fxVB, 1<<shift);
719 }
720
721
722 static void tdfx_render_vb_tri_fan( GLcontext *ctx,
723 GLuint start,
724 GLuint count,
725 GLuint flags )
726 {
727 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
728 GLuint shift = fxMesa->vertex_stride_shift;
729 GLubyte *fxVB = fxMesa->verts + (start << shift);
730 (void) flags;
731
732 fxMesa->Glide.grDrawVertexArrayContiguous( GR_TRIANGLE_FAN, count-start,
733 fxVB, 1<<shift );
734 }
735
736 static void tdfx_render_vb_quads( GLcontext *ctx,
737 GLuint start,
738 GLuint count,
739 GLuint flags )
740 {
741 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
742 GLuint shift = fxMesa->vertex_stride_shift;
743 GLubyte *fxVB = fxMesa->verts;
744 GLuint i;
745 (void) flags;
746
747 for (i = start ; i < count-3 ; i += 4 ) {
748 #define VERT(x) (fxVB + ((x)<<shift))
749 fxMesa->Glide.grDrawTriangle( VERT(i), VERT(i+1), VERT(i+3) );
750 fxMesa->Glide.grDrawTriangle( VERT(i+1), VERT(i+2), VERT(i+3) );
751 #undef VERT
752 }
753 }
754
755 static void tdfx_render_vb_quad_strip( GLcontext *ctx,
756 GLuint start,
757 GLuint count,
758 GLuint flags )
759 {
760 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
761 GLuint shift = fxMesa->vertex_stride_shift;
762 GLubyte *fxVB = fxMesa->verts + (start << shift);
763 (void) flags;
764
765 count -= (count-start)&1;
766
767 fxMesa->Glide.grDrawVertexArrayContiguous( GR_TRIANGLE_STRIP,
768 count-start, fxVB, 1<<shift);
769 }
770
771 static void tdfx_render_vb_poly( GLcontext *ctx,
772 GLuint start,
773 GLuint count,
774 GLuint flags )
775 {
776 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
777 GLuint shift = fxMesa->vertex_stride_shift;
778 GLubyte *fxVB = fxMesa->verts + (start << shift);
779 (void) flags;
780
781 fxMesa->Glide.grDrawVertexArrayContiguous( GR_POLYGON, count-start,
782 fxVB, 1<<shift);
783 }
784
785 static void tdfx_render_vb_noop( GLcontext *ctx,
786 GLuint start,
787 GLuint count,
788 GLuint flags )
789 {
790 (void) (ctx && start && count && flags);
791 }
792
793 static void (*tdfx_render_tab_verts[GL_POLYGON+2])(GLcontext *,
794 GLuint,
795 GLuint,
796 GLuint) =
797 {
798 tdfx_render_vb_points,
799 tdfx_render_vb_lines,
800 tdfx_render_vb_line_loop,
801 tdfx_render_vb_line_strip,
802 tdfx_render_vb_triangles,
803 tdfx_render_vb_tri_strip,
804 tdfx_render_vb_tri_fan,
805 tdfx_render_vb_quads,
806 tdfx_render_vb_quad_strip,
807 tdfx_render_vb_poly,
808 tdfx_render_vb_noop,
809 };
810
811
812 /**********************************************************************/
813 /* Render whole (indexed) begin/end objects */
814 /**********************************************************************/
815
816
817 #define VERT(x) (tdfxVertex *)(vertptr + ((x)<<vertshift))
818
819 #define RENDER_POINTS( start, count ) \
820 for ( ; start < count ; start++) \
821 fxMesa->Glide.grDrawPoint( VERT(ELT(start)) );
822
823 #define RENDER_LINE( v0, v1 ) \
824 fxMesa->Glide.grDrawLine( VERT(v0), VERT(v1) )
825
826 #define RENDER_TRI( v0, v1, v2 ) \
827 fxMesa->Glide.grDrawTriangle( VERT(v0), VERT(v1), VERT(v2) )
828
829 #define RENDER_QUAD( v0, v1, v2, v3 ) \
830 tdfx_draw_quad( fxMesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
831
832 #define INIT(x) tdfxRenderPrimitive( ctx, x )
833
834 #undef LOCAL_VARS
835 #define LOCAL_VARS \
836 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); \
837 GLubyte *vertptr = (GLubyte *)fxMesa->verts; \
838 const GLuint vertshift = fxMesa->vertex_stride_shift; \
839 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
840 (void) elt;
841
842 #define RESET_STIPPLE
843 #define RESET_OCCLUSION
844 #define PRESERVE_VB_DEFS
845
846 /* Elts, no clipping.
847 */
848 #undef ELT
849 #undef TAG
850 #define TAG(x) tdfx_##x##_elts
851 #define ELT(x) elt[x]
852 #include "tnl_dd/t_dd_rendertmp.h"
853
854
855
856 /**********************************************************************/
857 /* Render clipped primitives */
858 /**********************************************************************/
859
860
861
862 static void tdfxRenderClippedPoly( GLcontext *ctx, const GLuint *elts,
863 GLuint n )
864 {
865 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
866 TNLcontext *tnl = TNL_CONTEXT(ctx);
867 struct vertex_buffer *VB = &tnl->vb;
868 GLuint prim = fxMesa->render_primitive;
869
870 /* Render the new vertices as an unclipped polygon.
871 */
872 {
873 GLuint *tmp = VB->Elts;
874 VB->Elts = (GLuint *)elts;
875 tnl->Driver.Render.PrimTabElts[GL_POLYGON]( ctx, 0, n, PRIM_BEGIN|PRIM_END );
876 VB->Elts = tmp;
877 }
878
879 /* Restore the render primitive
880 */
881 if (prim != GL_POLYGON)
882 tnl->Driver.Render.PrimitiveNotify( ctx, prim );
883 }
884
885 static void tdfxRenderClippedLine( GLcontext *ctx, GLuint ii, GLuint jj )
886 {
887 TNLcontext *tnl = TNL_CONTEXT(ctx);
888 tnl->Driver.Render.Line( ctx, ii, jj );
889 }
890
891 static void tdfxFastRenderClippedPoly( GLcontext *ctx, const GLuint *elts,
892 GLuint n )
893 {
894 tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx );
895 GLubyte *vertptr = (GLubyte *)fxMesa->verts;
896 const GLuint vertshift = fxMesa->vertex_stride_shift;
897 const GLuint *start = (const GLuint *)VERT(elts[0]);
898 int i;
899
900 for (i = 2 ; i < n ; i++) {
901 fxMesa->Glide.grDrawTriangle( VERT(elts[i-1]), VERT(elts[i]), start );
902 }
903 }
904
905 /**********************************************************************/
906 /* Choose render functions */
907 /**********************************************************************/
908
909
910 #define POINT_FALLBACK (DD_POINT_SMOOTH)
911 #define LINE_FALLBACK (DD_LINE_STIPPLE)
912 #define TRI_FALLBACK (DD_TRI_SMOOTH)
913 #define ANY_FALLBACK_FLAGS (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK|DD_TRI_STIPPLE)
914 #define ANY_RASTER_FLAGS (DD_FLATSHADE|DD_TRI_LIGHT_TWOSIDE|DD_TRI_OFFSET| \
915 DD_TRI_UNFILLED)
916
917
918 /* All state referenced below:
919 */
920 #define _TDFX_NEW_RENDERSTATE (_DD_NEW_POINT_SMOOTH | \
921 _DD_NEW_LINE_STIPPLE | \
922 _DD_NEW_TRI_SMOOTH | \
923 _DD_NEW_FLATSHADE | \
924 _DD_NEW_TRI_UNFILLED | \
925 _DD_NEW_TRI_LIGHT_TWOSIDE | \
926 _DD_NEW_TRI_OFFSET | \
927 _DD_NEW_TRI_STIPPLE | \
928 _NEW_POLYGONSTIPPLE)
929
930
931 static void tdfxChooseRenderState(GLcontext *ctx)
932 {
933 TNLcontext *tnl = TNL_CONTEXT(ctx);
934 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
935 GLuint flags = ctx->_TriangleCaps;
936 GLuint index = 0;
937
938 if (0) {
939 fxMesa->draw_point = tdfx_draw_point;
940 fxMesa->draw_line = tdfx_draw_line;
941 fxMesa->draw_triangle = tdfx_draw_triangle;
942 index |= TDFX_FALLBACK_BIT;
943 }
944
945 if (flags & (ANY_FALLBACK_FLAGS|ANY_RASTER_FLAGS)) {
946 if (flags & ANY_RASTER_FLAGS) {
947 if (flags & DD_TRI_LIGHT_TWOSIDE) index |= TDFX_TWOSIDE_BIT;
948 if (flags & DD_TRI_OFFSET) index |= TDFX_OFFSET_BIT;
949 if (flags & DD_TRI_UNFILLED) index |= TDFX_UNFILLED_BIT;
950 if (flags & DD_FLATSHADE) index |= TDFX_FLAT_BIT;
951 }
952
953 fxMesa->draw_point = tdfx_draw_point;
954 fxMesa->draw_line = tdfx_draw_line;
955 fxMesa->draw_triangle = tdfx_draw_triangle;
956
957 /* Hook in fallbacks for specific primitives.
958 *
959 * DD_TRI_UNFILLED is here because the unfilled_tri functions use
960 * fxMesa->draw_tri *always*, and thus can't use the multipass
961 * approach to cliprects.
962 *
963 */
964 if (flags & (POINT_FALLBACK|
965 LINE_FALLBACK|
966 TRI_FALLBACK|
967 DD_TRI_STIPPLE|
968 DD_TRI_UNFILLED))
969 {
970 if (flags & POINT_FALLBACK)
971 fxMesa->draw_point = tdfx_fallback_point;
972
973 if (flags & LINE_FALLBACK)
974 fxMesa->draw_line = tdfx_fallback_line;
975
976 if (flags & TRI_FALLBACK)
977 fxMesa->draw_triangle = tdfx_fallback_tri;
978
979 if ((flags & DD_TRI_STIPPLE) && !fxMesa->haveHwStipple)
980 fxMesa->draw_triangle = tdfx_fallback_tri;
981
982 index |= TDFX_FALLBACK_BIT;
983 }
984 }
985
986 if (fxMesa->RenderIndex != index) {
987 fxMesa->RenderIndex = index;
988
989 tnl->Driver.Render.Points = rast_tab[index].points;
990 tnl->Driver.Render.Line = rast_tab[index].line;
991 tnl->Driver.Render.Triangle = rast_tab[index].triangle;
992 tnl->Driver.Render.Quad = rast_tab[index].quad;
993
994 if (index == 0) {
995 tnl->Driver.Render.PrimTabVerts = tdfx_render_tab_verts;
996 tnl->Driver.Render.PrimTabElts = tdfx_render_tab_elts;
997 tnl->Driver.Render.ClippedLine = line; /* from tritmp.h */
998 tnl->Driver.Render.ClippedPolygon = tdfxFastRenderClippedPoly;
999 } else {
1000 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
1001 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
1002 tnl->Driver.Render.ClippedLine = tdfxRenderClippedLine;
1003 tnl->Driver.Render.ClippedPolygon = tdfxRenderClippedPoly;
1004 }
1005 }
1006 }
1007
1008 /**********************************************************************/
1009 /* Use multipass rendering for cliprects */
1010 /**********************************************************************/
1011
1012
1013
1014 /* TODO: Benchmark this.
1015 * TODO: Use single back-buffer cliprect where possible.
1016 * NOTE: <pass> starts at 1, not zero!
1017 */
1018 static GLboolean multipass_cliprect( GLcontext *ctx, GLuint pass )
1019 {
1020 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1021 if (pass >= fxMesa->numClipRects)
1022 return GL_FALSE;
1023 else {
1024 fxMesa->Glide.grClipWindow(fxMesa->pClipRects[pass].x1,
1025 fxMesa->screen_height - fxMesa->pClipRects[pass].y2,
1026 fxMesa->pClipRects[pass].x2,
1027 fxMesa->screen_height - fxMesa->pClipRects[pass].y1);
1028
1029 return GL_TRUE;
1030 }
1031 }
1032
1033
1034 /**********************************************************************/
1035 /* Runtime render state and callbacks */
1036 /**********************************************************************/
1037
1038 static void tdfxRunPipeline( GLcontext *ctx )
1039 {
1040 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1041
1042 if (fxMesa->new_state) {
1043 tdfxDDUpdateHwState( ctx );
1044 }
1045
1046 if (!fxMesa->Fallback && fxMesa->new_gl_state) {
1047 if (fxMesa->new_gl_state & _TDFX_NEW_RASTERSETUP)
1048 tdfxChooseVertexState( ctx );
1049
1050 if (fxMesa->new_gl_state & _TDFX_NEW_RENDERSTATE)
1051 tdfxChooseRenderState( ctx );
1052
1053 fxMesa->new_gl_state = 0;
1054 }
1055
1056 _tnl_run_pipeline( ctx );
1057 }
1058
1059
1060 static void tdfxRenderStart( GLcontext *ctx )
1061 {
1062 TNLcontext *tnl = TNL_CONTEXT(ctx);
1063 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1064
1065 tdfxCheckTexSizes( ctx );
1066
1067 LOCK_HARDWARE(fxMesa);
1068
1069 /* Make sure vertex format changes get uploaded before we start
1070 * sending triangles.
1071 */
1072 if (fxMesa->dirty) {
1073 tdfxEmitHwStateLocked( fxMesa );
1074 }
1075
1076 if (fxMesa->numClipRects && !(fxMesa->RenderIndex & TDFX_FALLBACK_BIT)) {
1077 fxMesa->Glide.grClipWindow(fxMesa->pClipRects[0].x1,
1078 fxMesa->screen_height - fxMesa->pClipRects[0].y2,
1079 fxMesa->pClipRects[0].x2,
1080 fxMesa->screen_height - fxMesa->pClipRects[0].y1);
1081 if (fxMesa->numClipRects > 1)
1082 tnl->Driver.Render.Multipass = multipass_cliprect;
1083 else
1084 tnl->Driver.Render.Multipass = NULL;
1085 }
1086 else
1087 tnl->Driver.Render.Multipass = NULL;
1088 }
1089
1090
1091 static GLenum reduced_prim[GL_POLYGON+1] = {
1092 GL_POINTS,
1093 GL_LINES,
1094 GL_LINES,
1095 GL_LINES,
1096 GL_TRIANGLES,
1097 GL_TRIANGLES,
1098 GL_TRIANGLES,
1099 GL_TRIANGLES,
1100 GL_TRIANGLES,
1101 GL_TRIANGLES
1102 };
1103
1104
1105
1106 /* Always called between RenderStart and RenderFinish --> We already
1107 * hold the lock.
1108 */
1109 static void tdfxRasterPrimitive( GLcontext *ctx, GLenum prim )
1110 {
1111 tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx );
1112
1113 FLUSH_BATCH( fxMesa );
1114
1115 fxMesa->raster_primitive = prim;
1116
1117 tdfxUpdateCull(ctx);
1118 if ( fxMesa->dirty & TDFX_UPLOAD_CULL ) {
1119 fxMesa->Glide.grCullMode( fxMesa->CullMode );
1120 fxMesa->dirty &= ~TDFX_UPLOAD_CULL;
1121 }
1122
1123 tdfxUpdateStipple(ctx);
1124 if ( fxMesa->dirty & TDFX_UPLOAD_STIPPLE ) {
1125 fxMesa->Glide.grStipplePattern ( fxMesa->Stipple.Pattern );
1126 fxMesa->Glide.grStippleMode ( fxMesa->Stipple.Mode );
1127 fxMesa->dirty &= ~TDFX_UPLOAD_STIPPLE;
1128 }
1129 }
1130
1131
1132
1133 /* Determine the rasterized primitive when not drawing unfilled
1134 * polygons.
1135 *
1136 * Used only for the default render stage which always decomposes
1137 * primitives to trianges/lines/points. For the accelerated stage,
1138 * which renders strips as strips, the equivalent calculations are
1139 * performed in tdfx_render.c.
1140 */
1141 static void tdfxRenderPrimitive( GLcontext *ctx, GLenum prim )
1142 {
1143 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1144 GLuint rprim = reduced_prim[prim];
1145
1146 fxMesa->render_primitive = prim;
1147
1148 if (rprim == GL_TRIANGLES && (ctx->_TriangleCaps & DD_TRI_UNFILLED))
1149 return;
1150
1151 if (fxMesa->raster_primitive != rprim) {
1152 tdfxRasterPrimitive( ctx, rprim );
1153 }
1154 }
1155
1156 static void tdfxRenderFinish( GLcontext *ctx )
1157 {
1158 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1159
1160 if (fxMesa->RenderIndex & TDFX_FALLBACK_BIT)
1161 _swrast_flush( ctx );
1162
1163 UNLOCK_HARDWARE(fxMesa);
1164 }
1165
1166
1167 /**********************************************************************/
1168 /* Manage total rasterization fallbacks */
1169 /**********************************************************************/
1170
1171 static char *fallbackStrings[] = {
1172 "1D/3D Texture map",
1173 "glDrawBuffer(GL_FRONT_AND_BACK)",
1174 "Separate specular color",
1175 "glEnable/Disable(GL_STENCIL_TEST)",
1176 "glRenderMode(selection or feedback)",
1177 "glLogicOp()",
1178 "Texture env mode",
1179 "Texture border",
1180 "glColorMask",
1181 "blend mode",
1182 "line stipple"
1183 };
1184
1185
1186 static char *getFallbackString(GLuint bit)
1187 {
1188 int i = 0;
1189 while (bit > 1) {
1190 i++;
1191 bit >>= 1;
1192 }
1193 return fallbackStrings[i];
1194 }
1195
1196
1197 void tdfxFallback( GLcontext *ctx, GLuint bit, GLboolean mode )
1198 {
1199 TNLcontext *tnl = TNL_CONTEXT(ctx);
1200 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1201 GLuint oldfallback = fxMesa->Fallback;
1202
1203 if (mode) {
1204 fxMesa->Fallback |= bit;
1205 if (oldfallback == 0) {
1206 /*printf("Go to software rendering, bit = 0x%x\n", bit);*/
1207 FLUSH_BATCH(fxMesa);
1208 _swsetup_Wakeup( ctx );
1209 fxMesa->RenderIndex = ~0;
1210 if (fxMesa->debugFallbacks) {
1211 fprintf(stderr, "Tdfx begin software fallback: 0x%x %s\n",
1212 bit, getFallbackString(bit));
1213 }
1214 }
1215 }
1216 else {
1217 fxMesa->Fallback &= ~bit;
1218 if (oldfallback == bit) {
1219 /*printf("Go to hardware rendering, bit = 0x%x\n", bit);*/
1220 _swrast_flush( ctx );
1221 tnl->Driver.Render.Start = tdfxRenderStart;
1222 tnl->Driver.Render.PrimitiveNotify = tdfxRenderPrimitive;
1223 tnl->Driver.Render.Finish = tdfxRenderFinish;
1224 tnl->Driver.Render.BuildVertices = tdfxBuildVertices;
1225 fxMesa->new_gl_state |= (_TDFX_NEW_RENDERSTATE|
1226 _TDFX_NEW_RASTERSETUP);
1227 if (fxMesa->debugFallbacks) {
1228 fprintf(stderr, "Tdfx end software fallback: 0x%x %s\n",
1229 bit, getFallbackString(bit));
1230 }
1231 }
1232 }
1233 }
1234
1235
1236 void tdfxDDInitTriFuncs( GLcontext *ctx )
1237 {
1238 TNLcontext *tnl = TNL_CONTEXT(ctx);
1239 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1240 static int firsttime = 1;
1241
1242 if (firsttime) {
1243 init_rast_tab();
1244 firsttime = 0;
1245 }
1246
1247 fxMesa->RenderIndex = ~0;
1248
1249 tnl->Driver.RunPipeline = tdfxRunPipeline;
1250 tnl->Driver.Render.Start = tdfxRenderStart;
1251 tnl->Driver.Render.Finish = tdfxRenderFinish;
1252 tnl->Driver.Render.PrimitiveNotify = tdfxRenderPrimitive;
1253 tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple;
1254 tnl->Driver.Render.BuildVertices = tdfxBuildVertices;
1255 tnl->Driver.Render.Multipass = NULL;
1256
1257 (void) tdfx_print_vertex;
1258 }