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