Fix Alan Barnett's 'try10' display list bug.
[mesa.git] / src / mesa / drivers / glide / fxtris.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/fx/fxtris.c,v 1.5 2000/09/24 13:51:04 alanh Exp $ */
27
28 /* Authors:
29 * Keith Whitwell <keithw@valinux.com>
30 */
31
32 #include <stdio.h>
33 #include <math.h>
34
35 #ifdef FX
36
37 #include "glheader.h"
38 #include "mtypes.h"
39 #include "macros.h"
40 #include "colormac.h"
41
42 #include "swrast/swrast.h"
43 #include "swrast_setup/swrast_setup.h"
44 #include "tnl/t_context.h"
45 #include "tnl/t_pipeline.h"
46
47 #include "fxdrv.h"
48
49
50 /*
51 * Subpixel offsets to adjust Mesa's (true) window coordinates to
52 * Glide coordinates. We need these to ensure precise rasterization.
53 * Otherwise, we'll fail a bunch of conformance tests.
54 */
55 #define TRI_X_OFFSET ( 0.0F)
56 #define TRI_Y_OFFSET ( 0.0F)
57 #define LINE_X_OFFSET ( 0.0F)
58 #define LINE_Y_OFFSET ( 0.125F)
59 #define PNT_X_OFFSET ( 0.375F)
60 #define PNT_Y_OFFSET ( 0.375F)
61
62 static void fxRasterPrimitive( GLcontext *ctx, GLenum prim );
63 static void fxRenderPrimitive( GLcontext *ctx, GLenum prim );
64
65 /***********************************************************************
66 * Macros for t_dd_tritmp.h to draw basic primitives *
67 ***********************************************************************/
68
69 #define TRI( a, b, c ) \
70 do { \
71 if (DO_FALLBACK) \
72 fxMesa->draw_tri( fxMesa, a, b, c ); \
73 else \
74 grDrawTriangle( a, b, c ); \
75 } while (0) \
76
77 #define QUAD( a, b, c, d ) \
78 do { \
79 if (DO_FALLBACK) { \
80 fxMesa->draw_tri( fxMesa, a, b, d ); \
81 fxMesa->draw_tri( fxMesa, b, c, d ); \
82 } else { \
83 grDrawTriangle( a, b, d ); \
84 grDrawTriangle( b, c, d ); \
85 } \
86 } while (0)
87
88 #define LINE( v0, v1 ) \
89 do { \
90 if (DO_FALLBACK) \
91 fxMesa->draw_line( fxMesa, v0, v1 ); \
92 else { \
93 v0->x += LINE_X_OFFSET - TRI_X_OFFSET; \
94 v0->y += LINE_Y_OFFSET - TRI_Y_OFFSET; \
95 v1->x += LINE_X_OFFSET - TRI_X_OFFSET; \
96 v1->y += LINE_Y_OFFSET - TRI_Y_OFFSET; \
97 grDrawLine( v0, v1 ); \
98 v0->x -= LINE_X_OFFSET - TRI_X_OFFSET; \
99 v0->y -= LINE_Y_OFFSET - TRI_Y_OFFSET; \
100 v1->x -= LINE_X_OFFSET - TRI_X_OFFSET; \
101 v1->y -= LINE_Y_OFFSET - TRI_Y_OFFSET; \
102 } \
103 } while (0)
104
105 #define POINT( v0 ) \
106 do { \
107 if (DO_FALLBACK) \
108 fxMesa->draw_point( fxMesa, v0 ); \
109 else { \
110 v0->x += PNT_X_OFFSET - TRI_X_OFFSET; \
111 v0->y += PNT_Y_OFFSET - TRI_Y_OFFSET; \
112 grDrawPoint( v0 ); \
113 v0->x -= PNT_X_OFFSET - TRI_X_OFFSET; \
114 v0->y -= PNT_Y_OFFSET - TRI_Y_OFFSET; \
115 } \
116 } while (0)
117
118
119 /***********************************************************************
120 * Fallback to swrast for basic primitives *
121 ***********************************************************************/
122
123 /* Build an SWvertex from a hardware vertex.
124 *
125 * This code is hit only when a mix of accelerated and unaccelerated
126 * primitives are being drawn, and only for the unaccelerated
127 * primitives.
128 */
129 static void
130 fx_translate_vertex( GLcontext *ctx, const GrVertex *src, SWvertex *dst)
131 {
132 fxMesaContext fxMesa = FX_CONTEXT(ctx);
133 GLuint ts0 = fxMesa->tmu_source[0];
134 GLuint ts1 = fxMesa->tmu_source[1];
135 GLfloat w = 1.0 / src->oow;
136
137 dst->win[0] = src->x;
138 dst->win[1] = src->y;
139 dst->win[2] = src->ooz;
140 dst->win[3] = src->oow;
141
142 dst->color[0] = (GLubyte) src->r;
143 dst->color[1] = (GLubyte) src->g;
144 dst->color[2] = (GLubyte) src->b;
145 dst->color[3] = (GLubyte) src->a;
146
147 dst->texcoord[ts0][0] = fxMesa->inv_s0scale * src->tmuvtx[0].sow * w;
148 dst->texcoord[ts0][1] = fxMesa->inv_t0scale * src->tmuvtx[0].tow * w;
149
150 if (fxMesa->stw_hint_state & GR_STWHINT_W_DIFF_TMU0)
151 dst->texcoord[ts0][3] = src->tmuvtx[0].oow * w;
152 else
153 dst->texcoord[ts0][3] = 1.0;
154
155 if (fxMesa->SetupIndex & SETUP_TMU1) {
156 dst->texcoord[ts1][0] = fxMesa->inv_s1scale * src->tmuvtx[1].sow * w;
157 dst->texcoord[ts1][1] = fxMesa->inv_t1scale * src->tmuvtx[1].tow * w;
158
159 if (fxMesa->stw_hint_state & GR_STWHINT_W_DIFF_TMU1)
160 dst->texcoord[ts1][3] = src->tmuvtx[1].oow * w;
161 else
162 dst->texcoord[ts1][3] = 1.0;
163 }
164
165 dst->pointSize = ctx->Point._Size;
166 }
167
168
169 static void
170 fx_fallback_tri( fxMesaContext fxMesa,
171 GrVertex *v0,
172 GrVertex *v1,
173 GrVertex *v2 )
174 {
175 GLcontext *ctx = fxMesa->glCtx;
176 SWvertex v[3];
177 fx_translate_vertex( ctx, v0, &v[0] );
178 fx_translate_vertex( ctx, v1, &v[1] );
179 fx_translate_vertex( ctx, v2, &v[2] );
180 _swrast_Triangle( ctx, &v[0], &v[1], &v[2] );
181 }
182
183
184 static void
185 fx_fallback_line( fxMesaContext fxMesa,
186 GrVertex *v0,
187 GrVertex *v1 )
188 {
189 GLcontext *ctx = fxMesa->glCtx;
190 SWvertex v[2];
191 fx_translate_vertex( ctx, v0, &v[0] );
192 fx_translate_vertex( ctx, v1, &v[1] );
193 _swrast_Line( ctx, &v[0], &v[1] );
194 }
195
196
197 static void
198 fx_fallback_point( fxMesaContext fxMesa,
199 GrVertex *v0 )
200 {
201 GLcontext *ctx = fxMesa->glCtx;
202 SWvertex v[1];
203 fx_translate_vertex( ctx, v0, &v[0] );
204 _swrast_Point( ctx, &v[0] );
205 }
206
207 /***********************************************************************
208 * Functions to draw basic primitives *
209 ***********************************************************************/
210
211 static void fx_print_vertex( GLcontext *ctx, const GrVertex *v )
212 {
213 fprintf(stderr, "vertex at %p\n", v);
214
215 fprintf(stderr, "x %f y %f z %f oow %f\n",
216 v->x, v->y, v->ooz, v->oow);
217 fprintf(stderr, "r %f g %f b %f a %f\n",
218 v->r,
219 v->g,
220 v->b,
221 v->a);
222
223 fprintf(stderr, "\n");
224 }
225
226 #define DO_FALLBACK 0
227
228 /* Need to do clip loop at each triangle when mixing swrast and hw
229 * rendering. These functions are only used when mixed-mode rendering
230 * is occurring.
231 */
232 static void fx_draw_quad( fxMesaContext fxMesa,
233 GrVertex *v0,
234 GrVertex *v1,
235 GrVertex *v2,
236 GrVertex *v3 )
237 {
238 QUAD( v0, v1, v2, v3 );
239 }
240
241 static void fx_draw_triangle( fxMesaContext fxMesa,
242 GrVertex *v0,
243 GrVertex *v1,
244 GrVertex *v2 )
245 {
246 TRI( v0, v1, v2 );
247 }
248
249 static void fx_draw_line( fxMesaContext fxMesa,
250 GrVertex *v0,
251 GrVertex *v1 )
252 {
253 /* No support for wide lines (avoid wide/aa line fallback).
254 */
255 LINE(v0, v1);
256 }
257
258 static void fx_draw_point( fxMesaContext fxMesa,
259 GrVertex *v0 )
260 {
261 /* No support for wide points.
262 */
263 POINT( v0 );
264 }
265
266 #undef DO_FALLBACK
267
268
269 #define FX_UNFILLED_BIT 0x1
270 #define FX_OFFSET_BIT 0x2
271 #define FX_TWOSIDE_BIT 0x4
272 #define FX_FLAT_BIT 0x8
273 #define FX_FALLBACK_BIT 0x10
274 #define FX_MAX_TRIFUNC 0x20
275
276 static struct {
277 points_func points;
278 line_func line;
279 triangle_func triangle;
280 quad_func quad;
281 } rast_tab[FX_MAX_TRIFUNC];
282
283 #define DO_FALLBACK (IND & FX_FALLBACK_BIT)
284 #define DO_OFFSET (IND & FX_OFFSET_BIT)
285 #define DO_UNFILLED (IND & FX_UNFILLED_BIT)
286 #define DO_TWOSIDE (IND & FX_TWOSIDE_BIT)
287 #define DO_FLAT (IND & FX_FLAT_BIT)
288 #define DO_TRI 1
289 #define DO_QUAD 1
290 #define DO_LINE 1
291 #define DO_POINTS 1
292 #define DO_FULL_QUAD 1
293
294 #define HAVE_RGBA 1
295 #define HAVE_SPEC 0
296 #define HAVE_HW_FLATSHADE 0
297 #define HAVE_BACK_COLORS 0
298 #define VERTEX GrVertex
299 #define TAB rast_tab
300
301 #define DEPTH_SCALE 1.0
302 #define UNFILLED_TRI unfilled_tri
303 #define UNFILLED_QUAD unfilled_quad
304 #define VERT_X(_v) _v->x
305 #define VERT_Y(_v) _v->y
306 #define VERT_Z(_v) _v->ooz
307 #define AREA_IS_CCW( a ) (a < 0)
308 #define GET_VERTEX(e) (fxMesa->verts + e)
309
310 #define VERT_SET_RGBA( dst, f ) \
311 do { \
312 dst->r = (GLfloat)f[0]; \
313 dst->g = (GLfloat)f[1]; \
314 dst->b = (GLfloat)f[2]; \
315 dst->a = (GLfloat)f[3]; \
316 } while (0)
317
318 #define VERT_COPY_RGBA( v0, v1 ) \
319 do { \
320 v0->r = v1->r; \
321 v0->g = v1->g; \
322 v0->b = v1->b; \
323 v0->a = v1->a; \
324 } while (0)
325
326 #define VERT_SAVE_RGBA( idx ) \
327 do { \
328 color[idx][0] = v[idx]->r; \
329 color[idx][1] = v[idx]->g; \
330 color[idx][1] = v[idx]->b; \
331 color[idx][3] = v[idx]->a; \
332 } while (0)
333
334
335 #define VERT_RESTORE_RGBA( idx ) \
336 do { \
337 v[idx]->r = color[idx][0]; \
338 v[idx]->g = color[idx][1]; \
339 v[idx]->b = color[idx][2]; \
340 v[idx]->a = color[idx][3]; \
341 } while (0)
342
343
344 #define LOCAL_VARS(n) \
345 fxMesaContext fxMesa = FX_CONTEXT(ctx); \
346 GLfloat color[n][4]; \
347 (void) color;
348
349
350
351 /***********************************************************************
352 * Functions to draw basic unfilled primitives *
353 ***********************************************************************/
354
355 #define RASTERIZE(x) if (fxMesa->raster_primitive != x) \
356 fxRasterPrimitive( ctx, x )
357 #define RENDER_PRIMITIVE fxMesa->render_primitive
358 #define IND FX_FALLBACK_BIT
359 #define TAG(x) x
360 #include "tnl_dd/t_dd_unfilled.h"
361 #undef IND
362
363 /***********************************************************************
364 * Functions to draw GL primitives *
365 ***********************************************************************/
366
367 #define IND (0)
368 #define TAG(x) x
369 #include "tnl_dd/t_dd_tritmp.h"
370
371 #define IND (FX_OFFSET_BIT)
372 #define TAG(x) x##_offset
373 #include "tnl_dd/t_dd_tritmp.h"
374
375 #define IND (FX_TWOSIDE_BIT)
376 #define TAG(x) x##_twoside
377 #include "tnl_dd/t_dd_tritmp.h"
378
379 #define IND (FX_TWOSIDE_BIT|FX_OFFSET_BIT)
380 #define TAG(x) x##_twoside_offset
381 #include "tnl_dd/t_dd_tritmp.h"
382
383 #define IND (FX_UNFILLED_BIT)
384 #define TAG(x) x##_unfilled
385 #include "tnl_dd/t_dd_tritmp.h"
386
387 #define IND (FX_OFFSET_BIT|FX_UNFILLED_BIT)
388 #define TAG(x) x##_offset_unfilled
389 #include "tnl_dd/t_dd_tritmp.h"
390
391 #define IND (FX_TWOSIDE_BIT|FX_UNFILLED_BIT)
392 #define TAG(x) x##_twoside_unfilled
393 #include "tnl_dd/t_dd_tritmp.h"
394
395 #define IND (FX_TWOSIDE_BIT|FX_OFFSET_BIT|FX_UNFILLED_BIT)
396 #define TAG(x) x##_twoside_offset_unfilled
397 #include "tnl_dd/t_dd_tritmp.h"
398
399 #define IND (FX_FALLBACK_BIT)
400 #define TAG(x) x##_fallback
401 #include "tnl_dd/t_dd_tritmp.h"
402
403 #define IND (FX_OFFSET_BIT|FX_FALLBACK_BIT)
404 #define TAG(x) x##_offset_fallback
405 #include "tnl_dd/t_dd_tritmp.h"
406
407 #define IND (FX_TWOSIDE_BIT|FX_FALLBACK_BIT)
408 #define TAG(x) x##_twoside_fallback
409 #include "tnl_dd/t_dd_tritmp.h"
410
411 #define IND (FX_TWOSIDE_BIT|FX_OFFSET_BIT|FX_FALLBACK_BIT)
412 #define TAG(x) x##_twoside_offset_fallback
413 #include "tnl_dd/t_dd_tritmp.h"
414
415 #define IND (FX_UNFILLED_BIT|FX_FALLBACK_BIT)
416 #define TAG(x) x##_unfilled_fallback
417 #include "tnl_dd/t_dd_tritmp.h"
418
419 #define IND (FX_OFFSET_BIT|FX_UNFILLED_BIT|FX_FALLBACK_BIT)
420 #define TAG(x) x##_offset_unfilled_fallback
421 #include "tnl_dd/t_dd_tritmp.h"
422
423 #define IND (FX_TWOSIDE_BIT|FX_UNFILLED_BIT|FX_FALLBACK_BIT)
424 #define TAG(x) x##_twoside_unfilled_fallback
425 #include "tnl_dd/t_dd_tritmp.h"
426
427 #define IND (FX_TWOSIDE_BIT|FX_OFFSET_BIT|FX_UNFILLED_BIT| \
428 FX_FALLBACK_BIT)
429 #define TAG(x) x##_twoside_offset_unfilled_fallback
430 #include "tnl_dd/t_dd_tritmp.h"
431
432
433 /* Fx doesn't support provoking-vertex flat-shading?
434 */
435 #define IND (FX_FLAT_BIT)
436 #define TAG(x) x##_flat
437 #include "tnl_dd/t_dd_tritmp.h"
438
439 #define IND (FX_OFFSET_BIT|FX_FLAT_BIT)
440 #define TAG(x) x##_offset_flat
441 #include "tnl_dd/t_dd_tritmp.h"
442
443 #define IND (FX_TWOSIDE_BIT|FX_FLAT_BIT)
444 #define TAG(x) x##_twoside_flat
445 #include "tnl_dd/t_dd_tritmp.h"
446
447 #define IND (FX_TWOSIDE_BIT|FX_OFFSET_BIT|FX_FLAT_BIT)
448 #define TAG(x) x##_twoside_offset_flat
449 #include "tnl_dd/t_dd_tritmp.h"
450
451 #define IND (FX_UNFILLED_BIT|FX_FLAT_BIT)
452 #define TAG(x) x##_unfilled_flat
453 #include "tnl_dd/t_dd_tritmp.h"
454
455 #define IND (FX_OFFSET_BIT|FX_UNFILLED_BIT|FX_FLAT_BIT)
456 #define TAG(x) x##_offset_unfilled_flat
457 #include "tnl_dd/t_dd_tritmp.h"
458
459 #define IND (FX_TWOSIDE_BIT|FX_UNFILLED_BIT|FX_FLAT_BIT)
460 #define TAG(x) x##_twoside_unfilled_flat
461 #include "tnl_dd/t_dd_tritmp.h"
462
463 #define IND (FX_TWOSIDE_BIT|FX_OFFSET_BIT|FX_UNFILLED_BIT|FX_FLAT_BIT)
464 #define TAG(x) x##_twoside_offset_unfilled_flat
465 #include "tnl_dd/t_dd_tritmp.h"
466
467 #define IND (FX_FALLBACK_BIT|FX_FLAT_BIT)
468 #define TAG(x) x##_fallback_flat
469 #include "tnl_dd/t_dd_tritmp.h"
470
471 #define IND (FX_OFFSET_BIT|FX_FALLBACK_BIT|FX_FLAT_BIT)
472 #define TAG(x) x##_offset_fallback_flat
473 #include "tnl_dd/t_dd_tritmp.h"
474
475 #define IND (FX_TWOSIDE_BIT|FX_FALLBACK_BIT|FX_FLAT_BIT)
476 #define TAG(x) x##_twoside_fallback_flat
477 #include "tnl_dd/t_dd_tritmp.h"
478
479 #define IND (FX_TWOSIDE_BIT|FX_OFFSET_BIT|FX_FALLBACK_BIT|FX_FLAT_BIT)
480 #define TAG(x) x##_twoside_offset_fallback_flat
481 #include "tnl_dd/t_dd_tritmp.h"
482
483 #define IND (FX_UNFILLED_BIT|FX_FALLBACK_BIT|FX_FLAT_BIT)
484 #define TAG(x) x##_unfilled_fallback_flat
485 #include "tnl_dd/t_dd_tritmp.h"
486
487 #define IND (FX_OFFSET_BIT|FX_UNFILLED_BIT|FX_FALLBACK_BIT|FX_FLAT_BIT)
488 #define TAG(x) x##_offset_unfilled_fallback_flat
489 #include "tnl_dd/t_dd_tritmp.h"
490
491 #define IND (FX_TWOSIDE_BIT|FX_UNFILLED_BIT|FX_FALLBACK_BIT|FX_FLAT_BIT)
492 #define TAG(x) x##_twoside_unfilled_fallback_flat
493 #include "tnl_dd/t_dd_tritmp.h"
494
495 #define IND (FX_TWOSIDE_BIT|FX_OFFSET_BIT|FX_UNFILLED_BIT| \
496 FX_FALLBACK_BIT|FX_FLAT_BIT)
497 #define TAG(x) x##_twoside_offset_unfilled_fallback_flat
498 #include "tnl_dd/t_dd_tritmp.h"
499
500
501 static void init_rast_tab( void )
502 {
503 init();
504 init_offset();
505 init_twoside();
506 init_twoside_offset();
507 init_unfilled();
508 init_offset_unfilled();
509 init_twoside_unfilled();
510 init_twoside_offset_unfilled();
511 init_fallback();
512 init_offset_fallback();
513 init_twoside_fallback();
514 init_twoside_offset_fallback();
515 init_unfilled_fallback();
516 init_offset_unfilled_fallback();
517 init_twoside_unfilled_fallback();
518 init_twoside_offset_unfilled_fallback();
519
520 init_flat();
521 init_offset_flat();
522 init_twoside_flat();
523 init_twoside_offset_flat();
524 init_unfilled_flat();
525 init_offset_unfilled_flat();
526 init_twoside_unfilled_flat();
527 init_twoside_offset_unfilled_flat();
528 init_fallback_flat();
529 init_offset_fallback_flat();
530 init_twoside_fallback_flat();
531 init_twoside_offset_fallback_flat();
532 init_unfilled_fallback_flat();
533 init_offset_unfilled_fallback_flat();
534 init_twoside_unfilled_fallback_flat();
535 init_twoside_offset_unfilled_fallback_flat();
536 }
537
538
539
540 /**********************************************************************/
541 /* Render whole (indexed) begin/end objects */
542 /**********************************************************************/
543
544
545 #define VERT(x) (vertptr + x)
546
547 #define RENDER_POINTS( start, count ) \
548 for ( ; start < count ; start++) \
549 grDrawPoint( VERT(ELT(start)) );
550
551 #define RENDER_LINE( v0, v1 ) \
552 grDrawLine( VERT(v0), VERT(v1) )
553
554 #define RENDER_TRI( v0, v1, v2 ) \
555 grDrawTriangle( VERT(v0), VERT(v1), VERT(v2) )
556
557 #define RENDER_QUAD( v0, v1, v2, v3 ) \
558 fx_draw_quad( fxMesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
559
560 #define INIT(x) fxRenderPrimitive( ctx, x )
561
562 #undef LOCAL_VARS
563 #define LOCAL_VARS \
564 fxMesaContext fxMesa = FX_CONTEXT(ctx); \
565 GrVertex *vertptr = fxMesa->verts; \
566 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
567 (void) elt;
568
569 #define RESET_STIPPLE
570 #define RESET_OCCLUSION
571 #define PRESERVE_VB_DEFS
572
573 /* Elts, no clipping.
574 */
575 #undef ELT
576 #undef TAG
577 #define TAG(x) fx_##x##_elts
578 #define ELT(x) elt[x]
579 #include "tnl_dd/t_dd_rendertmp.h"
580
581 /* Verts, no clipping.
582 */
583 #undef ELT
584 #undef TAG
585 #define TAG(x) fx_##x##_verts
586 #define ELT(x) x
587 #include "tnl_dd/t_dd_rendertmp.h"
588
589
590
591 /**********************************************************************/
592 /* Render clipped primitives */
593 /**********************************************************************/
594
595
596
597 static void fxRenderClippedPoly( GLcontext *ctx, const GLuint *elts,
598 GLuint n )
599 {
600 fxMesaContext fxMesa = FX_CONTEXT(ctx);
601 TNLcontext *tnl = TNL_CONTEXT(ctx);
602 struct vertex_buffer *VB = &tnl->vb;
603 GLuint prim = fxMesa->render_primitive;
604
605 /* Render the new vertices as an unclipped polygon.
606 */
607 {
608 GLuint *tmp = VB->Elts;
609 VB->Elts = (GLuint *)elts;
610 tnl->Driver.Render.PrimTabElts[GL_POLYGON]( ctx, 0, n,
611 PRIM_BEGIN|PRIM_END );
612 VB->Elts = tmp;
613 }
614
615 /* Restore the render primitive
616 */
617 if (prim != GL_POLYGON)
618 tnl->Driver.Render.PrimitiveNotify( ctx, prim );
619 }
620
621
622 static void fxFastRenderClippedPoly( GLcontext *ctx, const GLuint *elts,
623 GLuint n )
624 {
625 fxMesaContext fxMesa = FX_CONTEXT( ctx );
626 GrVertex *vertptr = fxMesa->verts;
627 const GrVertex *start = VERT(elts[0]);
628 int i;
629
630 for (i = 2 ; i < n ; i++) {
631 grDrawTriangle( start, VERT(elts[i-1]), VERT(elts[i]) );
632 }
633 }
634
635 /**********************************************************************/
636 /* Choose render functions */
637 /**********************************************************************/
638
639
640 #define POINT_FALLBACK (DD_POINT_SMOOTH)
641 #define LINE_FALLBACK (DD_LINE_STIPPLE)
642 #define TRI_FALLBACK (DD_TRI_SMOOTH)
643 #define ANY_FALLBACK_FLAGS (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK|DD_TRI_STIPPLE)
644 #define ANY_RASTER_FLAGS (DD_FLATSHADE|DD_TRI_LIGHT_TWOSIDE|DD_TRI_OFFSET| \
645 DD_TRI_UNFILLED)
646
647
648
649 static void fxChooseRenderState(GLcontext *ctx)
650 {
651 TNLcontext *tnl = TNL_CONTEXT(ctx);
652 fxMesaContext fxMesa = FX_CONTEXT(ctx);
653 GLuint flags = ctx->_TriangleCaps;
654 GLuint index = 0;
655
656 /* fprintf(stderr, "%s\n", __FUNCTION__); */
657
658 if (flags & (ANY_FALLBACK_FLAGS|ANY_RASTER_FLAGS)) {
659 if (flags & ANY_RASTER_FLAGS) {
660 if (flags & DD_TRI_LIGHT_TWOSIDE) index |= FX_TWOSIDE_BIT;
661 if (flags & DD_TRI_OFFSET) index |= FX_OFFSET_BIT;
662 if (flags & DD_TRI_UNFILLED) index |= FX_UNFILLED_BIT;
663 if (flags & DD_FLATSHADE) index |= FX_FLAT_BIT;
664 }
665
666 fxMesa->draw_point = fx_draw_point;
667 fxMesa->draw_line = fx_draw_line;
668 fxMesa->draw_tri = fx_draw_triangle;
669
670 /* Hook in fallbacks for specific primitives.
671 *
672 *
673 */
674 if (flags & (POINT_FALLBACK|
675 LINE_FALLBACK|
676 TRI_FALLBACK))
677 {
678 if (flags & POINT_FALLBACK)
679 fxMesa->draw_point = fx_fallback_point;
680
681 if (flags & LINE_FALLBACK)
682 fxMesa->draw_line = fx_fallback_line;
683
684 if (flags & TRI_FALLBACK)
685 fxMesa->draw_tri = fx_fallback_tri;
686
687 index |= FX_FALLBACK_BIT;
688 }
689 }
690
691 tnl->Driver.Render.Points = rast_tab[index].points;
692 tnl->Driver.Render.Line = rast_tab[index].line;
693 tnl->Driver.Render.ClippedLine = rast_tab[index].line;
694 tnl->Driver.Render.Triangle = rast_tab[index].triangle;
695 tnl->Driver.Render.Quad = rast_tab[index].quad;
696
697 if (index == 0) {
698 tnl->Driver.Render.PrimTabVerts = fx_render_tab_verts;
699 tnl->Driver.Render.PrimTabElts = fx_render_tab_elts;
700 tnl->Driver.Render.ClippedPolygon = fxFastRenderClippedPoly;
701 } else {
702 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
703 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
704 tnl->Driver.Render.ClippedPolygon = fxRenderClippedPoly;
705 }
706 }
707
708 /**********************************************************************/
709 /* Runtime render state and callbacks */
710 /**********************************************************************/
711
712
713 static GLenum reduced_prim[GL_POLYGON+1] = {
714 GL_POINTS,
715 GL_LINES,
716 GL_LINES,
717 GL_LINES,
718 GL_TRIANGLES,
719 GL_TRIANGLES,
720 GL_TRIANGLES,
721 GL_TRIANGLES,
722 GL_TRIANGLES,
723 GL_TRIANGLES
724 };
725
726
727
728 /* Always called between RenderStart and RenderFinish --> We already
729 * hold the lock.
730 */
731 static void fxRasterPrimitive( GLcontext *ctx, GLenum prim )
732 {
733 fxMesaContext fxMesa = FX_CONTEXT( ctx );
734
735 fxMesa->raster_primitive = prim;
736 if (prim == GL_TRIANGLES)
737 grCullMode( fxMesa->cullMode );
738 else
739 grCullMode( GR_CULL_DISABLE );
740 }
741
742
743
744 /* Determine the rasterized primitive when not drawing unfilled
745 * polygons.
746 */
747 static void fxRenderPrimitive( GLcontext *ctx, GLenum prim )
748 {
749 fxMesaContext fxMesa = FX_CONTEXT(ctx);
750 GLuint rprim = reduced_prim[prim];
751
752 fxMesa->render_primitive = prim;
753
754 if (rprim == GL_TRIANGLES && (ctx->_TriangleCaps & DD_TRI_UNFILLED))
755 return;
756
757 if (fxMesa->raster_primitive != rprim) {
758 fxRasterPrimitive( ctx, rprim );
759 }
760 }
761
762
763
764 /**********************************************************************/
765 /* Manage total rasterization fallbacks */
766 /**********************************************************************/
767
768
769 void fxCheckIsInHardware( GLcontext *ctx )
770 {
771 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
772 TNLcontext *tnl = TNL_CONTEXT(ctx);
773 GLuint oldfallback = !fxMesa->is_in_hardware;
774 GLuint newfallback;
775
776 fxMesa->is_in_hardware = check_IsInHardware( ctx );
777 newfallback = !fxMesa->is_in_hardware;
778
779 if (newfallback) {
780 if (oldfallback == 0) {
781 _swsetup_Wakeup( ctx );
782 }
783 }
784 else {
785 if (oldfallback) {
786 _swrast_flush( ctx );
787 tnl->Driver.Render.Start = fxCheckTexSizes;
788 tnl->Driver.Render.Finish = _swrast_flush;
789 tnl->Driver.Render.PrimitiveNotify = fxRenderPrimitive;
790 tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon;
791 tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine;
792 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
793 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
794 tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple;
795 tnl->Driver.Render.BuildVertices = fxBuildVertices;
796 tnl->Driver.Render.Multipass = 0;
797 fxDDChooseSetupState(ctx);
798 fxDDChooseRenderState(ctx);
799 }
800 }
801 }
802
803 void fxDDInitTriFuncs( GLcontext *ctx )
804 {
805 TNLcontext *tnl = TNL_CONTEXT(ctx);
806 fxMesaContext fxMesa = FX_CONTEXT(ctx);
807 static int firsttime = 1;
808
809 if (firsttime) {
810 init_rast_tab();
811 firsttime = 0;
812 }
813
814 tnl->Driver.Render.Start = fxCheckTexSizes;
815 tnl->Driver.Render.Finish = _swrast_flush;
816 tnl->Driver.Render.PrimitiveNotify = fxRenderPrimitive;
817 tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon;
818 tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine;
819 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
820 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
821 tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple;
822 tnl->Driver.Render.BuildVertices = fxBuildVertices;
823 tnl->Driver.Render.Multipass = 0;
824
825 (void) fx_print_vertex;
826 }
827
828 #else
829
830
831 /*
832 * Need this to provide at least one external definition.
833 */
834
835 extern int gl_fx_dummy_function_tris(void);
836 int
837 gl_fx_dummy_function_tris(void)
838 {
839 return 0;
840 }
841
842 #endif /* FX */