2
* Copyright 2000-2001 VA Linux Systems, Inc.
5
* Permission is hereby granted, free of charge, to any person obtaining a
6
* copy of this software and associated documentation files (the "Software"),
7
* to deal in the Software without restriction, including without limitation
8
* on the rights to use, copy, modify, merge, publish, distribute, sub
9
* license, and/or sell copies of the Software, and to permit persons to whom
10
* the Software is furnished to do so, subject to the following conditions:
12
* The above copyright notice and this permission notice (including the next
13
* paragraph) shall be included in all copies or substantial portions of the
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19
* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
* OTHER DEALINGS IN THE SOFTWARE.
25
* Keith Whitwell <keith@tungstengraphics.com>
27
/* $XFree86: xc/lib/GL/mesa/src/drv/mga/mgatris.c,v 1.10 2002/10/30 12:51:36 alanh Exp $ */
35
#include "swrast/swrast.h"
36
#include "swrast_setup/swrast_setup.h"
37
#include "tnl/t_context.h"
38
#include "tnl/t_pipeline.h"
41
#include "mgacontext.h"
48
static void mgaRenderPrimitive( GLcontext *ctx, GLenum prim );
50
/***********************************************************************
51
* Functions to draw basic primitives *
52
***********************************************************************/
55
#if defined (USE_X86_ASM)
56
#define EMIT_VERT( j, vb, vertex_size, v ) \
58
__asm__ __volatile__( "rep ; movsl" \
59
: "=%c" (j), "=D" (vb), "=S" (__tmp) \
60
: "0" (vertex_size), \
65
#define EMIT_VERT( j, vb, vertex_size, v ) \
67
for ( j = 0 ; j < vertex_size ; j++ ) \
73
static void __inline__ mga_draw_triangle( mgaContextPtr mmesa,
78
GLuint vertex_size = mmesa->vertex_size;
79
GLuint *vb = mgaAllocDmaLow( mmesa, 3 * 4 * vertex_size );
82
EMIT_VERT( j, vb, vertex_size, v0 );
83
EMIT_VERT( j, vb, vertex_size, v1 );
84
EMIT_VERT( j, vb, vertex_size, v2 );
88
static void __inline__ mga_draw_quad( mgaContextPtr mmesa,
94
GLuint vertex_size = mmesa->vertex_size;
95
GLuint *vb = mgaAllocDmaLow( mmesa, 6 * 4 * vertex_size );
98
EMIT_VERT( j, vb, vertex_size, v0 );
99
EMIT_VERT( j, vb, vertex_size, v1 );
100
EMIT_VERT( j, vb, vertex_size, v3 );
101
EMIT_VERT( j, vb, vertex_size, v1 );
102
EMIT_VERT( j, vb, vertex_size, v2 );
103
EMIT_VERT( j, vb, vertex_size, v3 );
107
static __inline__ void mga_draw_point( mgaContextPtr mmesa,
110
GLfloat sz = mmesa->glCtx->Point._Size * .5;
111
int vertex_size = mmesa->vertex_size;
112
GLuint *vb = mgaAllocDmaLow( mmesa, 6 * 4 * vertex_size );
116
v0->v.x += PNT_X_OFFSET - TRI_X_OFFSET;
117
v0->v.y += PNT_Y_OFFSET - TRI_Y_OFFSET;
120
/* Draw a point as two triangles.
122
*(float *)&vb[0] = tmp->v.x - sz;
123
*(float *)&vb[1] = tmp->v.y - sz;
124
for (j = 2 ; j < vertex_size ; j++)
128
*(float *)&vb[0] = tmp->v.x + sz;
129
*(float *)&vb[1] = tmp->v.y - sz;
130
for (j = 2 ; j < vertex_size ; j++)
134
*(float *)&vb[0] = tmp->v.x + sz;
135
*(float *)&vb[1] = tmp->v.y + sz;
136
for (j = 2 ; j < vertex_size ; j++)
140
*(float *)&vb[0] = tmp->v.x + sz;
141
*(float *)&vb[1] = tmp->v.y + sz;
142
for (j = 2 ; j < vertex_size ; j++)
146
*(float *)&vb[0] = tmp->v.x - sz;
147
*(float *)&vb[1] = tmp->v.y + sz;
148
for (j = 2 ; j < vertex_size ; j++)
152
*(float *)&vb[0] = tmp->v.x - sz;
153
*(float *)&vb[1] = tmp->v.y - sz;
154
for (j = 2 ; j < vertex_size ; j++)
158
v0->v.x -= PNT_X_OFFSET - TRI_X_OFFSET;
159
v0->v.y -= PNT_Y_OFFSET - TRI_Y_OFFSET;
164
static __inline__ void mga_draw_line( mgaContextPtr mmesa,
168
GLuint vertex_size = mmesa->vertex_size;
169
GLuint *vb = mgaAllocDmaLow( mmesa, 6 * 4 * vertex_size );
170
GLfloat dx, dy, ix, iy;
171
GLfloat width = mmesa->glCtx->Line._Width;
175
v0->v.x += LINE_X_OFFSET - TRI_X_OFFSET;
176
v0->v.y += LINE_Y_OFFSET - TRI_Y_OFFSET;
177
v1->v.x += LINE_X_OFFSET - TRI_X_OFFSET;
178
v1->v.y += LINE_Y_OFFSET - TRI_Y_OFFSET;
181
dx = v0->v.x - v1->v.x;
182
dy = v0->v.y - v1->v.y;
184
ix = width * .5; iy = 0;
185
if (dx * dx > dy * dy) {
189
*(float *)&vb[0] = v0->v.x - ix;
190
*(float *)&vb[1] = v0->v.y - iy;
191
for (j = 2 ; j < vertex_size ; j++)
195
*(float *)&vb[0] = v1->v.x + ix;
196
*(float *)&vb[1] = v1->v.y + iy;
197
for (j = 2 ; j < vertex_size ; j++)
201
*(float *)&vb[0] = v0->v.x + ix;
202
*(float *)&vb[1] = v0->v.y + iy;
203
for (j = 2 ; j < vertex_size ; j++)
207
*(float *)&vb[0] = v0->v.x - ix;
208
*(float *)&vb[1] = v0->v.y - iy;
209
for (j = 2 ; j < vertex_size ; j++)
213
*(float *)&vb[0] = v1->v.x - ix;
214
*(float *)&vb[1] = v1->v.y - iy;
215
for (j = 2 ; j < vertex_size ; j++)
219
*(float *)&vb[0] = v1->v.x + ix;
220
*(float *)&vb[1] = v1->v.y + iy;
221
for (j = 2 ; j < vertex_size ; j++)
226
v0->v.x -= LINE_X_OFFSET - TRI_X_OFFSET;
227
v0->v.y -= LINE_Y_OFFSET - TRI_Y_OFFSET;
228
v1->v.x -= LINE_X_OFFSET - TRI_X_OFFSET;
229
v1->v.y -= LINE_Y_OFFSET - TRI_Y_OFFSET;
233
/***********************************************************************
234
* Macros for t_dd_tritmp.h to draw basic primitives *
235
***********************************************************************/
237
#define TRI( a, b, c ) \
240
mmesa->draw_tri( mmesa, a, b, c ); \
242
mga_draw_triangle( mmesa, a, b, c ); \
245
#define QUAD( a, b, c, d ) \
248
mmesa->draw_tri( mmesa, a, b, d ); \
249
mmesa->draw_tri( mmesa, b, c, d ); \
251
mga_draw_quad( mmesa, a, b, c, d ); \
255
#define LINE( v0, v1 ) \
258
mmesa->draw_line( mmesa, v0, v1 ); \
260
mga_draw_line( mmesa, v0, v1 ); \
264
#define POINT( v0 ) \
267
mmesa->draw_point( mmesa, v0 ); \
269
mga_draw_point( mmesa, v0 ); \
274
/***********************************************************************
275
* Fallback to swrast for basic primitives *
276
***********************************************************************/
278
/* This code is hit only when a mix of accelerated and unaccelerated
279
* primitives are being drawn, and only for the unaccelerated
284
mga_fallback_tri( mgaContextPtr mmesa,
289
GLcontext *ctx = mmesa->glCtx;
291
mga_translate_vertex( ctx, v0, &v[0] );
292
mga_translate_vertex( ctx, v1, &v[1] );
293
mga_translate_vertex( ctx, v2, &v[2] );
294
_swrast_Triangle( ctx, &v[0], &v[1], &v[2] );
299
mga_fallback_line( mgaContextPtr mmesa,
303
GLcontext *ctx = mmesa->glCtx;
305
mga_translate_vertex( ctx, v0, &v[0] );
306
mga_translate_vertex( ctx, v1, &v[1] );
307
_swrast_Line( ctx, &v[0], &v[1] );
312
mga_fallback_point( mgaContextPtr mmesa,
315
GLcontext *ctx = mmesa->glCtx;
317
mga_translate_vertex( ctx, v0, &v[0] );
318
_swrast_Point( ctx, &v[0] );
321
/***********************************************************************
322
* Build render functions from dd templates *
323
***********************************************************************/
326
#define MGA_UNFILLED_BIT 0x1
327
#define MGA_OFFSET_BIT 0x2
328
#define MGA_TWOSIDE_BIT 0x4
329
#define MGA_FLAT_BIT 0x8 /* mga can't flatshade? */
330
#define MGA_FALLBACK_BIT 0x10
331
#define MGA_MAX_TRIFUNC 0x20
336
triangle_func triangle;
338
} rast_tab[MGA_MAX_TRIFUNC];
340
#define DO_FALLBACK (IND & MGA_FALLBACK_BIT)
341
#define DO_OFFSET (IND & MGA_OFFSET_BIT)
342
#define DO_UNFILLED (IND & MGA_UNFILLED_BIT)
343
#define DO_TWOSIDE (IND & MGA_TWOSIDE_BIT)
344
#define DO_FLAT (IND & MGA_FLAT_BIT)
349
#define DO_FULL_QUAD 1
352
#define HAVE_BACK_COLORS 0
354
#define HAVE_HW_FLATSHADE 0
355
#define VERTEX mgaVertex
358
#define MGA_COLOR( dst, src ) \
366
#define MGA_SPEC( dst, src ) \
373
#define DEPTH_SCALE mmesa->depth_scale
374
#define UNFILLED_TRI unfilled_tri
375
#define UNFILLED_QUAD unfilled_quad
376
#define VERT_X(_v) _v->v.x
377
#define VERT_Y(_v) _v->v.y
378
#define VERT_Z(_v) _v->v.z
379
#define AREA_IS_CCW( a ) (a > 0)
380
#define GET_VERTEX(e) (mmesa->verts + (e<<mmesa->vertex_stride_shift))
382
#define VERT_SET_RGBA( v, c ) MGA_COLOR( v->ub4[4], c )
383
#define VERT_COPY_RGBA( v0, v1 ) v0->ui[4] = v1->ui[4]
384
#define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[4]
385
#define VERT_RESTORE_RGBA( idx ) v[idx]->ui[4] = color[idx]
387
#define VERT_SET_SPEC( v, c ) MGA_SPEC( v->ub4[5], c )
388
#define VERT_COPY_SPEC( v0, v1 ) COPY_3V(v0->ub4[5], v1->ub4[5])
389
#define VERT_SAVE_SPEC( idx ) spec[idx] = v[idx]->ui[5]
390
#define VERT_RESTORE_SPEC( idx ) v[idx]->ui[5] = spec[idx]
392
#define LOCAL_VARS(n) \
393
mgaContextPtr mmesa = MGA_CONTEXT(ctx); \
394
GLuint color[n], spec[n]; \
395
(void) color; (void) spec;
399
/***********************************************************************
400
* Functions to draw basic unfilled primitives *
401
***********************************************************************/
403
#define RASTERIZE(x) if (mmesa->raster_primitive != x) \
404
mgaRasterPrimitive( ctx, x, MGA_WA_TRIANGLES )
405
#define RENDER_PRIMITIVE mmesa->render_primitive
406
#define IND MGA_FALLBACK_BIT
408
#include "tnl_dd/t_dd_unfilled.h"
411
/***********************************************************************
412
* Functions to draw GL primitives *
413
***********************************************************************/
417
#include "tnl_dd/t_dd_tritmp.h"
419
#define IND (MGA_OFFSET_BIT)
420
#define TAG(x) x##_offset
421
#include "tnl_dd/t_dd_tritmp.h"
423
#define IND (MGA_TWOSIDE_BIT)
424
#define TAG(x) x##_twoside
425
#include "tnl_dd/t_dd_tritmp.h"
427
#define IND (MGA_TWOSIDE_BIT|MGA_OFFSET_BIT)
428
#define TAG(x) x##_twoside_offset
429
#include "tnl_dd/t_dd_tritmp.h"
431
#define IND (MGA_UNFILLED_BIT)
432
#define TAG(x) x##_unfilled
433
#include "tnl_dd/t_dd_tritmp.h"
435
#define IND (MGA_OFFSET_BIT|MGA_UNFILLED_BIT)
436
#define TAG(x) x##_offset_unfilled
437
#include "tnl_dd/t_dd_tritmp.h"
439
#define IND (MGA_TWOSIDE_BIT|MGA_UNFILLED_BIT)
440
#define TAG(x) x##_twoside_unfilled
441
#include "tnl_dd/t_dd_tritmp.h"
443
#define IND (MGA_TWOSIDE_BIT|MGA_OFFSET_BIT|MGA_UNFILLED_BIT)
444
#define TAG(x) x##_twoside_offset_unfilled
445
#include "tnl_dd/t_dd_tritmp.h"
447
#define IND (MGA_FALLBACK_BIT)
448
#define TAG(x) x##_fallback
449
#include "tnl_dd/t_dd_tritmp.h"
451
#define IND (MGA_OFFSET_BIT|MGA_FALLBACK_BIT)
452
#define TAG(x) x##_offset_fallback
453
#include "tnl_dd/t_dd_tritmp.h"
455
#define IND (MGA_TWOSIDE_BIT|MGA_FALLBACK_BIT)
456
#define TAG(x) x##_twoside_fallback
457
#include "tnl_dd/t_dd_tritmp.h"
459
#define IND (MGA_TWOSIDE_BIT|MGA_OFFSET_BIT|MGA_FALLBACK_BIT)
460
#define TAG(x) x##_twoside_offset_fallback
461
#include "tnl_dd/t_dd_tritmp.h"
463
#define IND (MGA_UNFILLED_BIT|MGA_FALLBACK_BIT)
464
#define TAG(x) x##_unfilled_fallback
465
#include "tnl_dd/t_dd_tritmp.h"
467
#define IND (MGA_OFFSET_BIT|MGA_UNFILLED_BIT|MGA_FALLBACK_BIT)
468
#define TAG(x) x##_offset_unfilled_fallback
469
#include "tnl_dd/t_dd_tritmp.h"
471
#define IND (MGA_TWOSIDE_BIT|MGA_UNFILLED_BIT|MGA_FALLBACK_BIT)
472
#define TAG(x) x##_twoside_unfilled_fallback
473
#include "tnl_dd/t_dd_tritmp.h"
475
#define IND (MGA_TWOSIDE_BIT|MGA_OFFSET_BIT|MGA_UNFILLED_BIT| \
477
#define TAG(x) x##_twoside_offset_unfilled_fallback
478
#include "tnl_dd/t_dd_tritmp.h"
481
/* Mga doesn't support provoking-vertex flat-shading?
483
#define IND (MGA_FLAT_BIT)
484
#define TAG(x) x##_flat
485
#include "tnl_dd/t_dd_tritmp.h"
487
#define IND (MGA_OFFSET_BIT|MGA_FLAT_BIT)
488
#define TAG(x) x##_offset_flat
489
#include "tnl_dd/t_dd_tritmp.h"
491
#define IND (MGA_TWOSIDE_BIT|MGA_FLAT_BIT)
492
#define TAG(x) x##_twoside_flat
493
#include "tnl_dd/t_dd_tritmp.h"
495
#define IND (MGA_TWOSIDE_BIT|MGA_OFFSET_BIT|MGA_FLAT_BIT)
496
#define TAG(x) x##_twoside_offset_flat
497
#include "tnl_dd/t_dd_tritmp.h"
499
#define IND (MGA_UNFILLED_BIT|MGA_FLAT_BIT)
500
#define TAG(x) x##_unfilled_flat
501
#include "tnl_dd/t_dd_tritmp.h"
503
#define IND (MGA_OFFSET_BIT|MGA_UNFILLED_BIT|MGA_FLAT_BIT)
504
#define TAG(x) x##_offset_unfilled_flat
505
#include "tnl_dd/t_dd_tritmp.h"
507
#define IND (MGA_TWOSIDE_BIT|MGA_UNFILLED_BIT|MGA_FLAT_BIT)
508
#define TAG(x) x##_twoside_unfilled_flat
509
#include "tnl_dd/t_dd_tritmp.h"
511
#define IND (MGA_TWOSIDE_BIT|MGA_OFFSET_BIT|MGA_UNFILLED_BIT|MGA_FLAT_BIT)
512
#define TAG(x) x##_twoside_offset_unfilled_flat
513
#include "tnl_dd/t_dd_tritmp.h"
515
#define IND (MGA_FALLBACK_BIT|MGA_FLAT_BIT)
516
#define TAG(x) x##_fallback_flat
517
#include "tnl_dd/t_dd_tritmp.h"
519
#define IND (MGA_OFFSET_BIT|MGA_FALLBACK_BIT|MGA_FLAT_BIT)
520
#define TAG(x) x##_offset_fallback_flat
521
#include "tnl_dd/t_dd_tritmp.h"
523
#define IND (MGA_TWOSIDE_BIT|MGA_FALLBACK_BIT|MGA_FLAT_BIT)
524
#define TAG(x) x##_twoside_fallback_flat
525
#include "tnl_dd/t_dd_tritmp.h"
527
#define IND (MGA_TWOSIDE_BIT|MGA_OFFSET_BIT|MGA_FALLBACK_BIT|MGA_FLAT_BIT)
528
#define TAG(x) x##_twoside_offset_fallback_flat
529
#include "tnl_dd/t_dd_tritmp.h"
531
#define IND (MGA_UNFILLED_BIT|MGA_FALLBACK_BIT|MGA_FLAT_BIT)
532
#define TAG(x) x##_unfilled_fallback_flat
533
#include "tnl_dd/t_dd_tritmp.h"
535
#define IND (MGA_OFFSET_BIT|MGA_UNFILLED_BIT|MGA_FALLBACK_BIT|MGA_FLAT_BIT)
536
#define TAG(x) x##_offset_unfilled_fallback_flat
537
#include "tnl_dd/t_dd_tritmp.h"
539
#define IND (MGA_TWOSIDE_BIT|MGA_UNFILLED_BIT|MGA_FALLBACK_BIT|MGA_FLAT_BIT)
540
#define TAG(x) x##_twoside_unfilled_fallback_flat
541
#include "tnl_dd/t_dd_tritmp.h"
543
#define IND (MGA_TWOSIDE_BIT|MGA_OFFSET_BIT|MGA_UNFILLED_BIT| \
544
MGA_FALLBACK_BIT|MGA_FLAT_BIT)
545
#define TAG(x) x##_twoside_offset_unfilled_fallback_flat
546
#include "tnl_dd/t_dd_tritmp.h"
549
static void init_rast_tab( void )
554
init_twoside_offset();
556
init_offset_unfilled();
557
init_twoside_unfilled();
558
init_twoside_offset_unfilled();
560
init_offset_fallback();
561
init_twoside_fallback();
562
init_twoside_offset_fallback();
563
init_unfilled_fallback();
564
init_offset_unfilled_fallback();
565
init_twoside_unfilled_fallback();
566
init_twoside_offset_unfilled_fallback();
571
init_twoside_offset_flat();
572
init_unfilled_flat();
573
init_offset_unfilled_flat();
574
init_twoside_unfilled_flat();
575
init_twoside_offset_unfilled_flat();
576
init_fallback_flat();
577
init_offset_fallback_flat();
578
init_twoside_fallback_flat();
579
init_twoside_offset_fallback_flat();
580
init_unfilled_fallback_flat();
581
init_offset_unfilled_fallback_flat();
582
init_twoside_unfilled_fallback_flat();
583
init_twoside_offset_unfilled_fallback_flat();
586
/**********************************************************************/
587
/* Render whole begin/end objects */
588
/**********************************************************************/
591
#define VERT(x) (mgaVertex *)(vertptr + ((x)<<vertshift))
592
#define RENDER_POINTS( start, count ) \
593
for ( ; start < count ; start++) \
594
mga_draw_point( mmesa, VERT(ELT(start)) );
595
#define RENDER_LINE( v0, v1 ) \
596
mga_draw_line( mmesa, VERT(v0), VERT(v1) )
597
#define RENDER_TRI( v0, v1, v2 ) \
598
mga_draw_triangle( mmesa, VERT(v0), VERT(v1), VERT(v2) )
599
#define RENDER_QUAD( v0, v1, v2, v3 ) \
600
mga_draw_quad( mmesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
601
#define INIT(x) mgaRenderPrimitive( ctx, x )
604
mgaContextPtr mmesa = MGA_CONTEXT(ctx); \
605
GLubyte *vertptr = (GLubyte *)mmesa->verts; \
606
const GLuint vertshift = mmesa->vertex_stride_shift; \
607
const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
609
#define RESET_STIPPLE
610
#define RESET_OCCLUSION
611
#define PRESERVE_VB_DEFS
613
#define TAG(x) mga_##x##_verts
614
#include "tnl/t_vb_rendertmp.h"
617
#define TAG(x) mga_##x##_elts
618
#define ELT(x) elt[x]
619
#include "tnl/t_vb_rendertmp.h"
622
/**********************************************************************/
623
/* Render clipped primitives */
624
/**********************************************************************/
628
static void mgaRenderClippedPoly( GLcontext *ctx, const GLuint *elts, GLuint n )
630
mgaContextPtr mmesa = MGA_CONTEXT(ctx);
631
TNLcontext *tnl = TNL_CONTEXT(ctx);
632
struct vertex_buffer *VB = &tnl->vb;
633
GLuint prim = mmesa->render_primitive;
635
/* Render the new vertices as an unclipped polygon.
638
GLuint *tmp = VB->Elts;
639
VB->Elts = (GLuint *)elts;
640
tnl->Driver.Render.PrimTabElts[GL_POLYGON]( ctx, 0, n, PRIM_BEGIN|PRIM_END );
644
/* Restore the render primitive
646
if (prim != GL_POLYGON)
647
tnl->Driver.Render.PrimitiveNotify( ctx, prim );
650
static void mgaRenderClippedLine( GLcontext *ctx, GLuint ii, GLuint jj )
652
TNLcontext *tnl = TNL_CONTEXT(ctx);
653
tnl->Driver.Render.Line( ctx, ii, jj );
656
static void mgaFastRenderClippedPoly( GLcontext *ctx, const GLuint *elts,
659
mgaContextPtr mmesa = MGA_CONTEXT( ctx );
660
GLuint vertex_size = mmesa->vertex_size;
661
GLuint *vb = mgaAllocDmaLow( mmesa, (n-2) * 3 * 4 * vertex_size );
662
GLubyte *vertptr = (GLubyte *)mmesa->verts;
663
const GLuint vertshift = mmesa->vertex_stride_shift;
664
const GLuint *start = (const GLuint *)VERT(elts[0]);
667
for (i = 2 ; i < n ; i++) {
668
EMIT_VERT( j, vb, vertex_size, (mgaVertexPtr) VERT(elts[i-1]) );
669
EMIT_VERT( j, vb, vertex_size, (mgaVertexPtr) VERT(elts[i]) );
670
EMIT_VERT( j, vb, vertex_size, (mgaVertexPtr) start );
674
/**********************************************************************/
675
/* Choose render functions */
676
/**********************************************************************/
680
#define _MGA_NEW_RENDERSTATE (_DD_NEW_LINE_STIPPLE | \
681
_DD_NEW_TRI_UNFILLED | \
682
_DD_NEW_TRI_LIGHT_TWOSIDE | \
683
_DD_NEW_TRI_OFFSET | \
684
_DD_NEW_TRI_STIPPLE | \
688
#define POINT_FALLBACK (DD_POINT_SMOOTH)
689
#define LINE_FALLBACK (DD_LINE_SMOOTH | DD_LINE_STIPPLE)
690
#define TRI_FALLBACK (DD_TRI_SMOOTH | DD_TRI_UNFILLED)
691
#define ANY_FALLBACK_FLAGS (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK| \
693
#define ANY_RASTER_FLAGS (DD_FLATSHADE|DD_TRI_LIGHT_TWOSIDE|DD_TRI_OFFSET| \
696
static void mgaChooseRenderState(GLcontext *ctx)
698
TNLcontext *tnl = TNL_CONTEXT(ctx);
699
mgaContextPtr mmesa = MGA_CONTEXT(ctx);
700
GLuint flags = ctx->_TriangleCaps;
703
if (flags & (ANY_FALLBACK_FLAGS|ANY_RASTER_FLAGS)) {
704
if (flags & ANY_RASTER_FLAGS) {
705
if (flags & DD_TRI_LIGHT_TWOSIDE) index |= MGA_TWOSIDE_BIT;
706
if (flags & DD_TRI_OFFSET) index |= MGA_OFFSET_BIT;
707
if (flags & DD_TRI_UNFILLED) index |= MGA_UNFILLED_BIT;
708
if (flags & DD_FLATSHADE) index |= MGA_FLAT_BIT;
711
mmesa->draw_point = mga_draw_point;
712
mmesa->draw_line = mga_draw_line;
713
mmesa->draw_tri = mga_draw_triangle;
715
/* Hook in fallbacks for specific primitives.
717
if (flags & ANY_FALLBACK_FLAGS)
719
if (flags & POINT_FALLBACK)
720
mmesa->draw_point = mga_fallback_point;
722
if (flags & LINE_FALLBACK)
723
mmesa->draw_line = mga_fallback_line;
725
if (flags & TRI_FALLBACK)
726
mmesa->draw_tri = mga_fallback_tri;
728
if ((flags & DD_TRI_STIPPLE) && !mmesa->haveHwStipple)
729
mmesa->draw_tri = mga_fallback_tri;
731
index |= MGA_FALLBACK_BIT;
735
if (mmesa->RenderIndex != index) {
736
mmesa->RenderIndex = index;
738
tnl->Driver.Render.Points = rast_tab[index].points;
739
tnl->Driver.Render.Line = rast_tab[index].line;
740
tnl->Driver.Render.Triangle = rast_tab[index].triangle;
741
tnl->Driver.Render.Quad = rast_tab[index].quad;
744
tnl->Driver.Render.PrimTabVerts = mga_render_tab_verts;
745
tnl->Driver.Render.PrimTabElts = mga_render_tab_elts;
746
tnl->Driver.Render.ClippedLine = line; /* from tritmp.h */
747
tnl->Driver.Render.ClippedPolygon = mgaFastRenderClippedPoly;
749
tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
750
tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
751
tnl->Driver.Render.ClippedLine = mgaRenderClippedLine;
752
tnl->Driver.Render.ClippedPolygon = mgaRenderClippedPoly;
757
/**********************************************************************/
758
/* Runtime render state and callbacks */
759
/**********************************************************************/
762
static void mgaRunPipeline( GLcontext *ctx )
764
mgaContextPtr mmesa = MGA_CONTEXT(ctx);
766
if (mmesa->new_state) {
767
mgaDDUpdateHwState( ctx );
770
if (!mmesa->Fallback && mmesa->new_gl_state) {
771
if (mmesa->new_gl_state & _MGA_NEW_RASTERSETUP)
772
mgaChooseVertexState( ctx );
774
if (mmesa->new_gl_state & _MGA_NEW_RENDERSTATE)
775
mgaChooseRenderState( ctx );
777
mmesa->new_gl_state = 0;
779
/* Circularity: mgaDDUpdateHwState can affect mmesa->Fallback,
780
* but mgaChooseVertexState can affect mmesa->new_state. Hence
781
* the second check. (Fix this...)
783
if (mmesa->new_state) {
784
mgaDDUpdateHwState( ctx );
788
_tnl_run_pipeline( ctx );
792
static GLenum reduced_prim[GL_POLYGON+1] = {
807
/* Always called between RenderStart and RenderFinish --> We already
810
void mgaRasterPrimitive( GLcontext *ctx, GLenum prim, GLuint hwprim )
812
mgaContextPtr mmesa = MGA_CONTEXT( ctx );
814
FLUSH_BATCH( mmesa );
815
mmesa->raster_primitive = prim;
816
/* mmesa->hw_primitive = hwprim; */
817
mmesa->hw_primitive = MGA_WA_TRIANGLES; /* disable mgarender.c for now */
820
if (ctx->Polygon.StippleFlag && mmesa->haveHwStipple)
822
mmesa->dirty |= MGA_UPLOAD_CONTEXT;
823
if (mmesa->raster_primitive == GL_TRIANGLES)
824
mmesa->setup.dwgctl |= mmesa->poly_stipple;
826
mmesa->setup.dwgctl &= ~(0xf<<20);
832
/* Determine the rasterized primitive when not drawing unfilled
835
* Used only for the default render stage which always decomposes
836
* primitives to trianges/lines/points. For the accelerated stage,
837
* which renders strips as strips, the equivalent calculations are
838
* performed in mgarender.c.
840
static void mgaRenderPrimitive( GLcontext *ctx, GLenum prim )
842
mgaContextPtr mmesa = MGA_CONTEXT(ctx);
843
GLuint rprim = reduced_prim[prim];
845
mmesa->render_primitive = prim;
847
if (rprim == GL_TRIANGLES && (ctx->_TriangleCaps & DD_TRI_UNFILLED))
850
if (mmesa->raster_primitive != rprim) {
851
mgaRasterPrimitive( ctx, rprim, MGA_WA_TRIANGLES );
855
static void mgaRenderFinish( GLcontext *ctx )
857
if (MGA_CONTEXT(ctx)->RenderIndex & MGA_FALLBACK_BIT)
858
_swrast_flush( ctx );
863
/**********************************************************************/
864
/* Manage total rasterization fallbacks */
865
/**********************************************************************/
867
void mgaFallback( GLcontext *ctx, GLuint bit, GLboolean mode )
869
TNLcontext *tnl = TNL_CONTEXT(ctx);
870
mgaContextPtr mmesa = MGA_CONTEXT(ctx);
871
GLuint oldfallback = mmesa->Fallback;
874
mmesa->Fallback |= bit;
875
if (oldfallback == 0) {
877
_swsetup_Wakeup( ctx );
878
mmesa->RenderIndex = ~0;
882
mmesa->Fallback &= ~bit;
883
if (oldfallback == bit) {
884
_swrast_flush( ctx );
885
tnl->Driver.Render.Start = mgaCheckTexSizes;
886
tnl->Driver.Render.PrimitiveNotify = mgaRenderPrimitive;
887
tnl->Driver.Render.Finish = mgaRenderFinish;
888
tnl->Driver.Render.BuildVertices = mgaBuildVertices;
889
mmesa->new_gl_state |= (_MGA_NEW_RENDERSTATE |
890
_MGA_NEW_RASTERSETUP);
896
void mgaDDInitTriFuncs( GLcontext *ctx )
898
TNLcontext *tnl = TNL_CONTEXT(ctx);
899
mgaContextPtr mmesa = MGA_CONTEXT(ctx);
900
static int firsttime = 1;
906
mmesa->RenderIndex = ~0;
908
tnl->Driver.RunPipeline = mgaRunPipeline;
909
tnl->Driver.Render.Start = mgaCheckTexSizes;
910
tnl->Driver.Render.Finish = mgaRenderFinish;
911
tnl->Driver.Render.PrimitiveNotify = mgaRenderPrimitive;
912
tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple;
913
tnl->Driver.Render.BuildVertices = mgaBuildVertices;
914
tnl->Driver.Render.Multipass = NULL;