88249888952a9e339eed40e1c0d9b4c620d14c47
[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
27 /* New fixes:
28 * Daniel Borca <dborca@users.sourceforge.net>, 19 Jul 2004
29 *
30 * Authors:
31 * Keith Whitwell <keith@tungstengraphics.com>
32 */
33
34 #include "main/glheader.h"
35 #include "main/mtypes.h"
36 #include "main/macros.h"
37 #include "main/colormac.h"
38
39 #include "swrast/swrast.h"
40 #include "swrast_setup/swrast_setup.h"
41 #include "swrast_setup/ss_context.h"
42 #include "tnl/t_context.h"
43 #include "tnl/t_pipeline.h"
44
45 #include "tdfx_tris.h"
46 #include "tdfx_state.h"
47 #include "tdfx_vb.h"
48 #include "tdfx_lock.h"
49 #include "tdfx_render.h"
50
51
52 static void tdfxRasterPrimitive( GLcontext *ctx, GLenum prim );
53 static void tdfxRenderPrimitive( GLcontext *ctx, GLenum prim );
54
55 static GLenum reduced_prim[GL_POLYGON+1] = {
56 GL_POINTS,
57 GL_LINES,
58 GL_LINES,
59 GL_LINES,
60 GL_TRIANGLES,
61 GL_TRIANGLES,
62 GL_TRIANGLES,
63 GL_TRIANGLES,
64 GL_TRIANGLES,
65 GL_TRIANGLES
66 };
67
68 /***********************************************************************
69 * Macros for t_dd_tritmp.h to draw basic primitives *
70 ***********************************************************************/
71
72 #define TRI( a, b, c ) \
73 do { \
74 if (DO_FALLBACK) \
75 fxMesa->draw_triangle( fxMesa, a, b, c ); \
76 else \
77 fxMesa->Glide.grDrawTriangle( a, b, c ); \
78 } while (0) \
79
80 #define QUAD( a, b, c, d ) \
81 do { \
82 if (DO_FALLBACK) { \
83 fxMesa->draw_triangle( fxMesa, a, b, d ); \
84 fxMesa->draw_triangle( fxMesa, b, c, d ); \
85 } else { \
86 tdfxVertex *_v_[4]; \
87 _v_[0] = d; \
88 _v_[1] = a; \
89 _v_[2] = b; \
90 _v_[3] = c; \
91 fxMesa->Glide.grDrawVertexArray(GR_TRIANGLE_FAN, 4, _v_);\
92 /*fxMesa->Glide.grDrawTriangle( a, b, d );*/\
93 /*fxMesa->Glide.grDrawTriangle( b, c, d );*/\
94 } \
95 } while (0)
96
97 #define LINE( v0, v1 ) \
98 do { \
99 if (DO_FALLBACK) \
100 fxMesa->draw_line( fxMesa, v0, v1 ); \
101 else { \
102 v0->x += LINE_X_OFFSET - TRI_X_OFFSET; \
103 v0->y += LINE_Y_OFFSET - TRI_Y_OFFSET; \
104 v1->x += LINE_X_OFFSET - TRI_X_OFFSET; \
105 v1->y += LINE_Y_OFFSET - TRI_Y_OFFSET; \
106 fxMesa->Glide.grDrawLine( v0, v1 ); \
107 v0->x -= LINE_X_OFFSET - TRI_X_OFFSET; \
108 v0->y -= LINE_Y_OFFSET - TRI_Y_OFFSET; \
109 v1->x -= LINE_X_OFFSET - TRI_X_OFFSET; \
110 v1->y -= LINE_Y_OFFSET - TRI_Y_OFFSET; \
111 } \
112 } while (0)
113
114 #define POINT( v0 ) \
115 do { \
116 if (DO_FALLBACK) \
117 fxMesa->draw_point( fxMesa, v0 ); \
118 else { \
119 v0->x += PNT_X_OFFSET - TRI_X_OFFSET; \
120 v0->y += PNT_Y_OFFSET - TRI_Y_OFFSET; \
121 fxMesa->Glide.grDrawPoint( v0 ); \
122 v0->x -= PNT_X_OFFSET - TRI_X_OFFSET; \
123 v0->y -= PNT_Y_OFFSET - TRI_Y_OFFSET; \
124 } \
125 } while (0)
126
127
128 /***********************************************************************
129 * Fallback to swrast for basic primitives *
130 ***********************************************************************/
131
132 /* Build an SWvertex from a hardware vertex.
133 *
134 * This code is hit only when a mix of accelerated and unaccelerated
135 * primitives are being drawn, and only for the unaccelerated
136 * primitives.
137 */
138 static void
139 tdfx_translate_vertex( GLcontext *ctx, const tdfxVertex *src, SWvertex *dst)
140 {
141 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
142
143 if (fxMesa->vertexFormat == TDFX_LAYOUT_TINY) {
144 dst->attrib[FRAG_ATTRIB_WPOS][0] = src->x - fxMesa->x_offset;
145 dst->attrib[FRAG_ATTRIB_WPOS][1] = src->y - (fxMesa->screen_height - fxMesa->height - fxMesa->y_offset);
146 dst->attrib[FRAG_ATTRIB_WPOS][2] = src->z;
147 dst->attrib[FRAG_ATTRIB_WPOS][3] = 1.0;
148
149 dst->color[0] = src->color[2];
150 dst->color[1] = src->color[1];
151 dst->color[2] = src->color[0];
152 dst->color[3] = src->color[3];
153 }
154 else {
155 GLfloat w = 1.0 / src->rhw;
156
157 dst->attrib[FRAG_ATTRIB_WPOS][0] = src->x - fxMesa->x_offset;
158 dst->attrib[FRAG_ATTRIB_WPOS][1] = src->y - (fxMesa->screen_height - fxMesa->height - fxMesa->y_offset);
159 dst->attrib[FRAG_ATTRIB_WPOS][2] = src->z;
160 dst->attrib[FRAG_ATTRIB_WPOS][3] = src->rhw;
161
162 dst->color[0] = src->color[2];
163 dst->color[1] = src->color[1];
164 dst->color[2] = src->color[0];
165 dst->color[3] = src->color[3];
166
167 dst->attrib[FRAG_ATTRIB_TEX0][0] = 1.0 / fxMesa->sScale0 * w * src->tu0;
168 dst->attrib[FRAG_ATTRIB_TEX0][1] = 1.0 / fxMesa->tScale0 * w * src->tv0;
169 if (fxMesa->vertexFormat == TDFX_LAYOUT_PROJ1 || fxMesa->vertexFormat == TDFX_LAYOUT_PROJ2) {
170 dst->attrib[FRAG_ATTRIB_TEX0][3] = w * src->tq0;
171 } else {
172 dst->attrib[FRAG_ATTRIB_TEX0][3] = 1.0;
173 }
174
175 if (fxMesa->SetupIndex & TDFX_TEX1_BIT) {
176 dst->attrib[FRAG_ATTRIB_TEX1][0] = 1.0 / fxMesa->sScale1 * w * src->tu1;
177 dst->attrib[FRAG_ATTRIB_TEX1][1] = 1.0 / fxMesa->tScale1 * w * src->tv1;
178 if (fxMesa->vertexFormat == TDFX_LAYOUT_PROJ2) {
179 dst->attrib[FRAG_ATTRIB_TEX1][3] = w * src->tq1;
180 } else {
181 dst->attrib[FRAG_ATTRIB_TEX1][3] = 1.0;
182 }
183 }
184 }
185
186 dst->pointSize = ctx->Point.Size;
187 }
188
189
190 static void
191 tdfx_fallback_tri( tdfxContextPtr fxMesa,
192 tdfxVertex *v0,
193 tdfxVertex *v1,
194 tdfxVertex *v2 )
195 {
196 GLcontext *ctx = fxMesa->glCtx;
197 SWvertex v[3];
198 tdfx_translate_vertex( ctx, v0, &v[0] );
199 tdfx_translate_vertex( ctx, v1, &v[1] );
200 tdfx_translate_vertex( ctx, v2, &v[2] );
201 _swrast_Triangle( ctx, &v[0], &v[1], &v[2] );
202 }
203
204
205 static void
206 tdfx_fallback_line( tdfxContextPtr fxMesa,
207 tdfxVertex *v0,
208 tdfxVertex *v1 )
209 {
210 GLcontext *ctx = fxMesa->glCtx;
211 SWvertex v[2];
212 tdfx_translate_vertex( ctx, v0, &v[0] );
213 tdfx_translate_vertex( ctx, v1, &v[1] );
214 _swrast_Line( ctx, &v[0], &v[1] );
215 }
216
217
218 static void
219 tdfx_fallback_point( tdfxContextPtr fxMesa,
220 tdfxVertex *v0 )
221 {
222 GLcontext *ctx = fxMesa->glCtx;
223 SWvertex v[1];
224 tdfx_translate_vertex( ctx, v0, &v[0] );
225 _swrast_Point( ctx, &v[0] );
226 }
227
228 /***********************************************************************
229 * Functions to draw basic primitives *
230 ***********************************************************************/
231
232 static void tdfx_print_vertex( GLcontext *ctx, const tdfxVertex *v )
233 {
234 tdfxContextPtr tmesa = TDFX_CONTEXT( ctx );
235
236 fprintf(stderr, "vertex at %p\n", (void *)v);
237
238 if (tmesa->vertexFormat == TDFX_LAYOUT_TINY) {
239 fprintf(stderr, "x %f y %f z %f\n", v->x, v->y, v->z);
240 }
241 else {
242 fprintf(stderr, "x %f y %f z %f oow %f\n",
243 v->x, v->y, v->z, v->rhw);
244 }
245 fprintf(stderr, "r %d g %d b %d a %d\n",
246 v->color[0],
247 v->color[1],
248 v->color[2],
249 v->color[3]);
250
251 fprintf(stderr, "\n");
252 }
253
254 #define DO_FALLBACK 0
255
256 /* Need to do clip loop at each triangle when mixing swrast and hw
257 * rendering. These functions are only used when mixed-mode rendering
258 * is occurring.
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 != reduced_prim[x]) \
368 tdfxRasterPrimitive( ctx, reduced_prim[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
1139 /* Always called between RenderStart and RenderFinish --> We already
1140 * hold the lock.
1141 */
1142 static void tdfxRasterPrimitive( GLcontext *ctx, GLenum prim )
1143 {
1144 tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx );
1145
1146 FLUSH_BATCH( fxMesa );
1147
1148 fxMesa->raster_primitive = prim;
1149
1150 tdfxUpdateCull(ctx);
1151 if ( fxMesa->dirty & TDFX_UPLOAD_CULL ) {
1152 fxMesa->Glide.grCullMode( fxMesa->CullMode );
1153 fxMesa->dirty &= ~TDFX_UPLOAD_CULL;
1154 }
1155
1156 tdfxUpdateStipple(ctx);
1157 if ( fxMesa->dirty & TDFX_UPLOAD_STIPPLE ) {
1158 fxMesa->Glide.grStipplePattern ( fxMesa->Stipple.Pattern );
1159 fxMesa->Glide.grStippleMode ( fxMesa->Stipple.Mode );
1160 fxMesa->dirty &= ~TDFX_UPLOAD_STIPPLE;
1161 }
1162 }
1163
1164
1165
1166 /* Determine the rasterized primitive when not drawing unfilled
1167 * polygons.
1168 *
1169 * Used only for the default render stage which always decomposes
1170 * primitives to trianges/lines/points. For the accelerated stage,
1171 * which renders strips as strips, the equivalent calculations are
1172 * performed in tdfx_render.c.
1173 */
1174 static void tdfxRenderPrimitive( GLcontext *ctx, GLenum prim )
1175 {
1176 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1177 GLuint rprim = reduced_prim[prim];
1178
1179 fxMesa->render_primitive = prim;
1180
1181 if (rprim == GL_TRIANGLES && (ctx->_TriangleCaps & DD_TRI_UNFILLED))
1182 return;
1183
1184 if (fxMesa->raster_primitive != rprim) {
1185 tdfxRasterPrimitive( ctx, rprim );
1186 }
1187 }
1188
1189 static void tdfxRenderFinish( GLcontext *ctx )
1190 {
1191 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1192
1193 if (fxMesa->RenderIndex & TDFX_FALLBACK_BIT)
1194 _swrast_flush( ctx );
1195
1196 UNLOCK_HARDWARE(fxMesa);
1197 }
1198
1199
1200 /**********************************************************************/
1201 /* Manage total rasterization fallbacks */
1202 /**********************************************************************/
1203
1204 static char *fallbackStrings[] = {
1205 "3D/Rect/Cube Texture map",
1206 "glDrawBuffer(GL_FRONT_AND_BACK)",
1207 "Separate specular color",
1208 "glEnable/Disable(GL_STENCIL_TEST)",
1209 "glRenderMode(selection or feedback)",
1210 "glLogicOp()",
1211 "Texture env mode",
1212 "Texture border",
1213 "glColorMask",
1214 "blend mode",
1215 "line stipple",
1216 "Rasterization disable"
1217 };
1218
1219
1220 static char *getFallbackString(GLuint bit)
1221 {
1222 int i = 0;
1223 while (bit > 1) {
1224 i++;
1225 bit >>= 1;
1226 }
1227 return fallbackStrings[i];
1228 }
1229
1230
1231 void tdfxFallback( GLcontext *ctx, GLuint bit, GLboolean mode )
1232 {
1233 TNLcontext *tnl = TNL_CONTEXT(ctx);
1234 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1235 GLuint oldfallback = fxMesa->Fallback;
1236
1237 if (mode) {
1238 fxMesa->Fallback |= bit;
1239 if (oldfallback == 0) {
1240 /*printf("Go to software rendering, bit = 0x%x\n", bit);*/
1241 FLUSH_BATCH(fxMesa);
1242 _swsetup_Wakeup( ctx );
1243 fxMesa->RenderIndex = ~0;
1244 if (TDFX_DEBUG & DEBUG_VERBOSE_FALL) {
1245 fprintf(stderr, "Tdfx begin software fallback: 0x%x %s\n",
1246 bit, getFallbackString(bit));
1247 }
1248 }
1249 }
1250 else {
1251 fxMesa->Fallback &= ~bit;
1252 if (oldfallback == bit) {
1253 /*printf("Go to hardware rendering, bit = 0x%x\n", bit);*/
1254 _swrast_flush( ctx );
1255 tnl->Driver.Render.Start = tdfxRenderStart;
1256 tnl->Driver.Render.PrimitiveNotify = tdfxRenderPrimitive;
1257 tnl->Driver.Render.Finish = tdfxRenderFinish;
1258 tnl->Driver.Render.BuildVertices = tdfxBuildVertices;
1259 fxMesa->new_gl_state |= (_TDFX_NEW_RENDERSTATE|
1260 _TDFX_NEW_RASTERSETUP);
1261 if (TDFX_DEBUG & DEBUG_VERBOSE_FALL) {
1262 fprintf(stderr, "Tdfx end software fallback: 0x%x %s\n",
1263 bit, getFallbackString(bit));
1264 }
1265 }
1266 }
1267 }
1268
1269
1270 void tdfxDDInitTriFuncs( GLcontext *ctx )
1271 {
1272 TNLcontext *tnl = TNL_CONTEXT(ctx);
1273 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1274 static int firsttime = 1;
1275
1276 if (firsttime) {
1277 init_rast_tab();
1278 firsttime = 0;
1279 }
1280
1281 fxMesa->RenderIndex = ~0;
1282
1283 tnl->Driver.RunPipeline = tdfxRunPipeline;
1284 tnl->Driver.Render.Start = tdfxRenderStart;
1285 tnl->Driver.Render.Finish = tdfxRenderFinish;
1286 tnl->Driver.Render.PrimitiveNotify = tdfxRenderPrimitive;
1287 tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple;
1288 tnl->Driver.Render.BuildVertices = tdfxBuildVertices;
1289 tnl->Driver.Render.Multipass = NULL;
1290
1291 (void) tdfx_print_vertex;
1292 }