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