Rename the various function types in t_context.h to include a tnl_ prefix.
[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", (void *)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 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 TDFX_COLOR( dst, src ) \
331 do { \
332 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
333 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
334 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
335 UNCLAMPED_FLOAT_TO_UBYTE((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 mode = GR_TRIANGLE_STRIP;
713
714 fxMesa->Glide.grDrawVertexArrayContiguous( mode, count-start,
715 fxVB, 1<<shift);
716 }
717
718
719 static void tdfx_render_vb_tri_fan( GLcontext *ctx,
720 GLuint start,
721 GLuint count,
722 GLuint flags )
723 {
724 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
725 GLuint shift = fxMesa->vertex_stride_shift;
726 GLubyte *fxVB = fxMesa->verts + (start << shift);
727 (void) flags;
728
729 fxMesa->Glide.grDrawVertexArrayContiguous( GR_TRIANGLE_FAN, count-start,
730 fxVB, 1<<shift );
731 }
732
733 static void tdfx_render_vb_quads( GLcontext *ctx,
734 GLuint start,
735 GLuint count,
736 GLuint flags )
737 {
738 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
739 GLuint shift = fxMesa->vertex_stride_shift;
740 GLubyte *fxVB = fxMesa->verts;
741 GLuint i;
742 (void) flags;
743
744 for (i = start ; i < count-3 ; i += 4 ) {
745 #define VERT(x) (fxVB + ((x)<<shift))
746 fxMesa->Glide.grDrawTriangle( VERT(i), VERT(i+1), VERT(i+3) );
747 fxMesa->Glide.grDrawTriangle( VERT(i+1), VERT(i+2), VERT(i+3) );
748 #undef VERT
749 }
750 }
751
752 static void tdfx_render_vb_quad_strip( GLcontext *ctx,
753 GLuint start,
754 GLuint count,
755 GLuint flags )
756 {
757 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
758 GLuint shift = fxMesa->vertex_stride_shift;
759 GLubyte *fxVB = fxMesa->verts + (start << shift);
760 (void) flags;
761
762 count -= (count-start)&1;
763
764 fxMesa->Glide.grDrawVertexArrayContiguous( GR_TRIANGLE_STRIP,
765 count-start, fxVB, 1<<shift);
766 }
767
768 static void tdfx_render_vb_poly( GLcontext *ctx,
769 GLuint start,
770 GLuint count,
771 GLuint flags )
772 {
773 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
774 GLuint shift = fxMesa->vertex_stride_shift;
775 GLubyte *fxVB = fxMesa->verts + (start << shift);
776 (void) flags;
777
778 fxMesa->Glide.grDrawVertexArrayContiguous( GR_POLYGON, count-start,
779 fxVB, 1<<shift);
780 }
781
782 static void tdfx_render_vb_noop( GLcontext *ctx,
783 GLuint start,
784 GLuint count,
785 GLuint flags )
786 {
787 (void) (ctx && start && count && flags);
788 }
789
790 static void (*tdfx_render_tab_verts[GL_POLYGON+2])(GLcontext *,
791 GLuint,
792 GLuint,
793 GLuint) =
794 {
795 tdfx_render_vb_points,
796 tdfx_render_vb_lines,
797 tdfx_render_vb_line_loop,
798 tdfx_render_vb_line_strip,
799 tdfx_render_vb_triangles,
800 tdfx_render_vb_tri_strip,
801 tdfx_render_vb_tri_fan,
802 tdfx_render_vb_quads,
803 tdfx_render_vb_quad_strip,
804 tdfx_render_vb_poly,
805 tdfx_render_vb_noop,
806 };
807
808
809 /**********************************************************************/
810 /* Render whole (indexed) begin/end objects */
811 /**********************************************************************/
812
813
814 #define VERT(x) (tdfxVertex *)(vertptr + ((x)<<vertshift))
815
816 #define RENDER_POINTS( start, count ) \
817 for ( ; start < count ; start++) \
818 fxMesa->Glide.grDrawPoint( VERT(ELT(start)) );
819
820 #define RENDER_LINE( v0, v1 ) \
821 fxMesa->Glide.grDrawLine( VERT(v0), VERT(v1) )
822
823 #define RENDER_TRI( v0, v1, v2 ) \
824 fxMesa->Glide.grDrawTriangle( VERT(v0), VERT(v1), VERT(v2) )
825
826 #define RENDER_QUAD( v0, v1, v2, v3 ) \
827 tdfx_draw_quad( fxMesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
828
829 #define INIT(x) tdfxRenderPrimitive( ctx, x )
830
831 #undef LOCAL_VARS
832 #define LOCAL_VARS \
833 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); \
834 GLubyte *vertptr = (GLubyte *)fxMesa->verts; \
835 const GLuint vertshift = fxMesa->vertex_stride_shift; \
836 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
837 (void) elt;
838
839 #define RESET_STIPPLE
840 #define RESET_OCCLUSION
841 #define PRESERVE_VB_DEFS
842
843 /* Elts, no clipping.
844 */
845 #undef ELT
846 #undef TAG
847 #define TAG(x) tdfx_##x##_elts
848 #define ELT(x) elt[x]
849 #include "tnl_dd/t_dd_rendertmp.h"
850
851
852
853 /**********************************************************************/
854 /* Render clipped primitives */
855 /**********************************************************************/
856
857
858
859 static void tdfxRenderClippedPoly( GLcontext *ctx, const GLuint *elts,
860 GLuint n )
861 {
862 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
863 TNLcontext *tnl = TNL_CONTEXT(ctx);
864 struct vertex_buffer *VB = &tnl->vb;
865 GLuint prim = fxMesa->render_primitive;
866
867 /* Render the new vertices as an unclipped polygon.
868 */
869 {
870 GLuint *tmp = VB->Elts;
871 VB->Elts = (GLuint *)elts;
872 tnl->Driver.Render.PrimTabElts[GL_POLYGON]( ctx, 0, n, PRIM_BEGIN|PRIM_END );
873 VB->Elts = tmp;
874 }
875
876 /* Restore the render primitive
877 */
878 if (prim != GL_POLYGON)
879 tnl->Driver.Render.PrimitiveNotify( ctx, prim );
880 }
881
882 static void tdfxRenderClippedLine( GLcontext *ctx, GLuint ii, GLuint jj )
883 {
884 TNLcontext *tnl = TNL_CONTEXT(ctx);
885 tnl->Driver.Render.Line( ctx, ii, jj );
886 }
887
888 static void tdfxFastRenderClippedPoly( GLcontext *ctx, const GLuint *elts,
889 GLuint n )
890 {
891 tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx );
892 GLubyte *vertptr = (GLubyte *)fxMesa->verts;
893 const GLuint vertshift = fxMesa->vertex_stride_shift;
894 const GLuint *start = (const GLuint *)VERT(elts[0]);
895 int i;
896
897 for (i = 2 ; i < n ; i++) {
898 fxMesa->Glide.grDrawTriangle( VERT(elts[i-1]), VERT(elts[i]), start );
899 }
900 }
901
902 /**********************************************************************/
903 /* Choose render functions */
904 /**********************************************************************/
905
906
907 #define POINT_FALLBACK (DD_POINT_SMOOTH)
908 #define LINE_FALLBACK (DD_LINE_STIPPLE)
909 #define TRI_FALLBACK (DD_TRI_SMOOTH)
910 #define ANY_FALLBACK_FLAGS (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK|DD_TRI_STIPPLE)
911 #define ANY_RASTER_FLAGS (DD_FLATSHADE|DD_TRI_LIGHT_TWOSIDE|DD_TRI_OFFSET| \
912 DD_TRI_UNFILLED)
913
914
915 /* All state referenced below:
916 */
917 #define _TDFX_NEW_RENDERSTATE (_DD_NEW_POINT_SMOOTH | \
918 _DD_NEW_LINE_STIPPLE | \
919 _DD_NEW_TRI_SMOOTH | \
920 _DD_NEW_FLATSHADE | \
921 _DD_NEW_TRI_UNFILLED | \
922 _DD_NEW_TRI_LIGHT_TWOSIDE | \
923 _DD_NEW_TRI_OFFSET | \
924 _DD_NEW_TRI_STIPPLE | \
925 _NEW_POLYGONSTIPPLE)
926
927
928 static void tdfxChooseRenderState(GLcontext *ctx)
929 {
930 TNLcontext *tnl = TNL_CONTEXT(ctx);
931 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
932 GLuint flags = ctx->_TriangleCaps;
933 GLuint index = 0;
934
935 if (0) {
936 fxMesa->draw_point = tdfx_draw_point;
937 fxMesa->draw_line = tdfx_draw_line;
938 fxMesa->draw_triangle = tdfx_draw_triangle;
939 index |= TDFX_FALLBACK_BIT;
940 }
941
942 if (flags & (ANY_FALLBACK_FLAGS|ANY_RASTER_FLAGS)) {
943 if (flags & ANY_RASTER_FLAGS) {
944 if (flags & DD_TRI_LIGHT_TWOSIDE) index |= TDFX_TWOSIDE_BIT;
945 if (flags & DD_TRI_OFFSET) index |= TDFX_OFFSET_BIT;
946 if (flags & DD_TRI_UNFILLED) index |= TDFX_UNFILLED_BIT;
947 if (flags & DD_FLATSHADE) index |= TDFX_FLAT_BIT;
948 }
949
950 fxMesa->draw_point = tdfx_draw_point;
951 fxMesa->draw_line = tdfx_draw_line;
952 fxMesa->draw_triangle = tdfx_draw_triangle;
953
954 /* Hook in fallbacks for specific primitives.
955 *
956 * DD_TRI_UNFILLED is here because the unfilled_tri functions use
957 * fxMesa->draw_tri *always*, and thus can't use the multipass
958 * approach to cliprects.
959 *
960 */
961 if (flags & (POINT_FALLBACK|
962 LINE_FALLBACK|
963 TRI_FALLBACK|
964 DD_TRI_STIPPLE|
965 DD_TRI_UNFILLED))
966 {
967 if (flags & POINT_FALLBACK)
968 fxMesa->draw_point = tdfx_fallback_point;
969
970 if (flags & LINE_FALLBACK)
971 fxMesa->draw_line = tdfx_fallback_line;
972
973 if (flags & TRI_FALLBACK)
974 fxMesa->draw_triangle = tdfx_fallback_tri;
975
976 if ((flags & DD_TRI_STIPPLE) && !fxMesa->haveHwStipple)
977 fxMesa->draw_triangle = tdfx_fallback_tri;
978
979 index |= TDFX_FALLBACK_BIT;
980 }
981 }
982
983 if (fxMesa->RenderIndex != index) {
984 fxMesa->RenderIndex = index;
985
986 tnl->Driver.Render.Points = rast_tab[index].points;
987 tnl->Driver.Render.Line = rast_tab[index].line;
988 tnl->Driver.Render.Triangle = rast_tab[index].triangle;
989 tnl->Driver.Render.Quad = rast_tab[index].quad;
990
991 if (index == 0) {
992 tnl->Driver.Render.PrimTabVerts = tdfx_render_tab_verts;
993 tnl->Driver.Render.PrimTabElts = tdfx_render_tab_elts;
994 tnl->Driver.Render.ClippedLine = line; /* from tritmp.h */
995 tnl->Driver.Render.ClippedPolygon = tdfxFastRenderClippedPoly;
996 } else {
997 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
998 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
999 tnl->Driver.Render.ClippedLine = tdfxRenderClippedLine;
1000 tnl->Driver.Render.ClippedPolygon = tdfxRenderClippedPoly;
1001 }
1002 }
1003 }
1004
1005 /**********************************************************************/
1006 /* Use multipass rendering for cliprects */
1007 /**********************************************************************/
1008
1009
1010
1011 /* TODO: Benchmark this.
1012 * TODO: Use single back-buffer cliprect where possible.
1013 * NOTE: <pass> starts at 1, not zero!
1014 */
1015 static GLboolean multipass_cliprect( GLcontext *ctx, GLuint pass )
1016 {
1017 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1018 if (pass >= fxMesa->numClipRects)
1019 return GL_FALSE;
1020 else {
1021 fxMesa->Glide.grClipWindow(fxMesa->pClipRects[pass].x1,
1022 fxMesa->screen_height - fxMesa->pClipRects[pass].y2,
1023 fxMesa->pClipRects[pass].x2,
1024 fxMesa->screen_height - fxMesa->pClipRects[pass].y1);
1025
1026 return GL_TRUE;
1027 }
1028 }
1029
1030
1031 /**********************************************************************/
1032 /* Runtime render state and callbacks */
1033 /**********************************************************************/
1034
1035 static void tdfxRunPipeline( GLcontext *ctx )
1036 {
1037 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1038
1039 if (fxMesa->new_state) {
1040 tdfxDDUpdateHwState( ctx );
1041 }
1042
1043 if (!fxMesa->Fallback && fxMesa->new_gl_state) {
1044 if (fxMesa->new_gl_state & _TDFX_NEW_RASTERSETUP)
1045 tdfxChooseVertexState( ctx );
1046
1047 if (fxMesa->new_gl_state & _TDFX_NEW_RENDERSTATE)
1048 tdfxChooseRenderState( ctx );
1049
1050 fxMesa->new_gl_state = 0;
1051 }
1052
1053 _tnl_run_pipeline( ctx );
1054 }
1055
1056
1057 static void tdfxRenderStart( GLcontext *ctx )
1058 {
1059 TNLcontext *tnl = TNL_CONTEXT(ctx);
1060 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1061
1062 tdfxCheckTexSizes( ctx );
1063
1064 LOCK_HARDWARE(fxMesa);
1065
1066 /* Make sure vertex format changes get uploaded before we start
1067 * sending triangles.
1068 */
1069 if (fxMesa->dirty) {
1070 tdfxEmitHwStateLocked( fxMesa );
1071 }
1072
1073 if (fxMesa->numClipRects && !(fxMesa->RenderIndex & TDFX_FALLBACK_BIT)) {
1074 fxMesa->Glide.grClipWindow(fxMesa->pClipRects[0].x1,
1075 fxMesa->screen_height - fxMesa->pClipRects[0].y2,
1076 fxMesa->pClipRects[0].x2,
1077 fxMesa->screen_height - fxMesa->pClipRects[0].y1);
1078 if (fxMesa->numClipRects > 1)
1079 tnl->Driver.Render.Multipass = multipass_cliprect;
1080 else
1081 tnl->Driver.Render.Multipass = NULL;
1082 }
1083 else
1084 tnl->Driver.Render.Multipass = NULL;
1085 }
1086
1087
1088 static GLenum reduced_prim[GL_POLYGON+1] = {
1089 GL_POINTS,
1090 GL_LINES,
1091 GL_LINES,
1092 GL_LINES,
1093 GL_TRIANGLES,
1094 GL_TRIANGLES,
1095 GL_TRIANGLES,
1096 GL_TRIANGLES,
1097 GL_TRIANGLES,
1098 GL_TRIANGLES
1099 };
1100
1101
1102
1103 /* Always called between RenderStart and RenderFinish --> We already
1104 * hold the lock.
1105 */
1106 static void tdfxRasterPrimitive( GLcontext *ctx, GLenum prim )
1107 {
1108 tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx );
1109
1110 FLUSH_BATCH( fxMesa );
1111
1112 fxMesa->raster_primitive = prim;
1113
1114 tdfxUpdateCull(ctx);
1115 if ( fxMesa->dirty & TDFX_UPLOAD_CULL ) {
1116 fxMesa->Glide.grCullMode( fxMesa->CullMode );
1117 fxMesa->dirty &= ~TDFX_UPLOAD_CULL;
1118 }
1119
1120 tdfxUpdateStipple(ctx);
1121 if ( fxMesa->dirty & TDFX_UPLOAD_STIPPLE ) {
1122 fxMesa->Glide.grStipplePattern ( fxMesa->Stipple.Pattern );
1123 fxMesa->Glide.grStippleMode ( fxMesa->Stipple.Mode );
1124 fxMesa->dirty &= ~TDFX_UPLOAD_STIPPLE;
1125 }
1126 }
1127
1128
1129
1130 /* Determine the rasterized primitive when not drawing unfilled
1131 * polygons.
1132 *
1133 * Used only for the default render stage which always decomposes
1134 * primitives to trianges/lines/points. For the accelerated stage,
1135 * which renders strips as strips, the equivalent calculations are
1136 * performed in tdfx_render.c.
1137 */
1138 static void tdfxRenderPrimitive( GLcontext *ctx, GLenum prim )
1139 {
1140 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1141 GLuint rprim = reduced_prim[prim];
1142
1143 fxMesa->render_primitive = prim;
1144
1145 if (rprim == GL_TRIANGLES && (ctx->_TriangleCaps & DD_TRI_UNFILLED))
1146 return;
1147
1148 if (fxMesa->raster_primitive != rprim) {
1149 tdfxRasterPrimitive( ctx, rprim );
1150 }
1151 }
1152
1153 static void tdfxRenderFinish( GLcontext *ctx )
1154 {
1155 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1156
1157 if (fxMesa->RenderIndex & TDFX_FALLBACK_BIT)
1158 _swrast_flush( ctx );
1159
1160 UNLOCK_HARDWARE(fxMesa);
1161 }
1162
1163
1164 /**********************************************************************/
1165 /* Manage total rasterization fallbacks */
1166 /**********************************************************************/
1167
1168 static char *fallbackStrings[] = {
1169 "1D/3D Texture map",
1170 "glDrawBuffer(GL_FRONT_AND_BACK)",
1171 "Separate specular color",
1172 "glEnable/Disable(GL_STENCIL_TEST)",
1173 "glRenderMode(selection or feedback)",
1174 "glLogicOp()",
1175 "Texture env mode",
1176 "Texture border",
1177 "glColorMask",
1178 "blend mode",
1179 "line stipple"
1180 };
1181
1182
1183 static char *getFallbackString(GLuint bit)
1184 {
1185 int i = 0;
1186 while (bit > 1) {
1187 i++;
1188 bit >>= 1;
1189 }
1190 return fallbackStrings[i];
1191 }
1192
1193
1194 void tdfxFallback( GLcontext *ctx, GLuint bit, GLboolean mode )
1195 {
1196 TNLcontext *tnl = TNL_CONTEXT(ctx);
1197 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1198 GLuint oldfallback = fxMesa->Fallback;
1199
1200 if (mode) {
1201 fxMesa->Fallback |= bit;
1202 if (oldfallback == 0) {
1203 /*printf("Go to software rendering, bit = 0x%x\n", bit);*/
1204 FLUSH_BATCH(fxMesa);
1205 _swsetup_Wakeup( ctx );
1206 fxMesa->RenderIndex = ~0;
1207 if (fxMesa->debugFallbacks) {
1208 fprintf(stderr, "Tdfx begin software fallback: 0x%x %s\n",
1209 bit, getFallbackString(bit));
1210 }
1211 }
1212 }
1213 else {
1214 fxMesa->Fallback &= ~bit;
1215 if (oldfallback == bit) {
1216 /*printf("Go to hardware rendering, bit = 0x%x\n", bit);*/
1217 _swrast_flush( ctx );
1218 tnl->Driver.Render.Start = tdfxRenderStart;
1219 tnl->Driver.Render.PrimitiveNotify = tdfxRenderPrimitive;
1220 tnl->Driver.Render.Finish = tdfxRenderFinish;
1221 tnl->Driver.Render.BuildVertices = tdfxBuildVertices;
1222 fxMesa->new_gl_state |= (_TDFX_NEW_RENDERSTATE|
1223 _TDFX_NEW_RASTERSETUP);
1224 if (fxMesa->debugFallbacks) {
1225 fprintf(stderr, "Tdfx end software fallback: 0x%x %s\n",
1226 bit, getFallbackString(bit));
1227 }
1228 }
1229 }
1230 }
1231
1232
1233 void tdfxDDInitTriFuncs( GLcontext *ctx )
1234 {
1235 TNLcontext *tnl = TNL_CONTEXT(ctx);
1236 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1237 static int firsttime = 1;
1238
1239 if (firsttime) {
1240 init_rast_tab();
1241 firsttime = 0;
1242 }
1243
1244 fxMesa->RenderIndex = ~0;
1245
1246 tnl->Driver.RunPipeline = tdfxRunPipeline;
1247 tnl->Driver.Render.Start = tdfxRenderStart;
1248 tnl->Driver.Render.Finish = tdfxRenderFinish;
1249 tnl->Driver.Render.PrimitiveNotify = tdfxRenderPrimitive;
1250 tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple;
1251 tnl->Driver.Render.BuildVertices = tdfxBuildVertices;
1252 tnl->Driver.Render.Multipass = NULL;
1253
1254 (void) tdfx_print_vertex;
1255 }