From feca368c2995e5c861e71253f3c53ebb231919b2 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Sat, 24 Feb 2001 18:25:52 +0000 Subject: Template work --- src/mesa/drivers/common/t_dd_tritmp.h | 284 +++++++++++-------- src/mesa/drivers/common/t_dd_unfilled.h | 237 +++++++++------- src/mesa/drivers/common/t_dd_vb.c | 99 +------ src/mesa/drivers/common/t_dd_vbtmp.h | 467 +++++++++++++++++++++++++------- src/mesa/main/dd.h | 22 +- src/mesa/swrast/s_context.c | 9 +- 6 files changed, 689 insertions(+), 429 deletions(-) diff --git a/src/mesa/drivers/common/t_dd_tritmp.h b/src/mesa/drivers/common/t_dd_tritmp.h index 7690d09ecf..7cd7c756f9 100644 --- a/src/mesa/drivers/common/t_dd_tritmp.h +++ b/src/mesa/drivers/common/t_dd_tritmp.h @@ -43,9 +43,40 @@ * DO_UNFILLED: Decompose triangles to lines and points where appropriate. * * HAVE_RGBA: Vertices have rgba values (otherwise index values). + * HAVE_SPEC: Vertices have secondary rgba values. + * + * VERT_X(v): Alias for vertex x value. + * VERT_Y(v): Alias for vertex x value. + * VERT_Z(v): Alias for vertex x value. + * DEPTH_SCALE: Scale for offset. + * + * VERTEX: Hardware vertex type. + * GET_VERTEX(n): Retreive vertex with index n. + * AREA_IS_CCW(a): Return true if triangle with signed area a is ccw. + * + * VERT_SET_RGBA: Assign vertex rgba from VB color. + * VERT_COPY_RGBA: Copy vertex rgba another vertex. + * VERT_SAVE_RGBA: Save vertex rgba to a local variable. + * VERT_RESTORE_RGBA: Restore vertex rgba from a local variable. + * --> Similar for IND and SPEC. + * + * LOCAL_VARS(n): (At least) define local vars for save/restore rgba. + * */ +#if HAVE_RGBA +#define VERT_SET_IND( v, c ) (void) c +#define VERT_COPY_IND( v0, v1 ) +#define VERT_SAVE_IND( idx ) +#define VERT_RESTORE_IND( idx ) +#endif +#if !HAVE_SPEC +#define VERT_SET_SPEC( v, c ) (void) c +#define VERT_COPY_SPEC( v0, v1 ) +#define VERT_SAVE_SPEC( idx ) +#define VERT_RESTORE_SPEC( idx ) +#endif static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 ) { @@ -57,9 +88,9 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 ) GLuint facing; LOCAL_VARS(3); - v[0] = GET_VERTEX(e0); - v[1] = GET_VERTEX(e1); - v[2] = GET_VERTEX(e2); + v[0] = (VERTEX *)GET_VERTEX(e0); + v[1] = (VERTEX *)GET_VERTEX(e1); + v[2] = (VERTEX *)GET_VERTEX(e2); if (DO_TWOSIDE || DO_OFFSET || DO_UNFILLED) { @@ -92,18 +123,18 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 ) if (DO_TWOSIDE && facing == 1) { if (HAVE_RGBA) { - GLubyte (*vbcolor)[4] = VB->ColorPtr[1]->data; - ASSERT(VB->ColorPtr[1]->stride == 4*sizeof(GLubyte)); + GLchan (*vbcolor)[4] = VB->ColorPtr[1]->data; + ASSERT(VB->ColorPtr[1]->stride == 4*sizeof(GLchan)); if (!DO_FLAT) { - VERT_SET_COLOR( v[0], vbcolor[e0] ); - VERT_SET_COLOR( v[1], vbcolor[e1] ); + VERT_SET_RGBA( v[0], vbcolor[e0] ); + VERT_SET_RGBA( v[1], vbcolor[e1] ); } - VERT_SET_COLOR( v[2], vbcolor[e2] ); + VERT_SET_RGBA( v[2], vbcolor[e2] ); - if (VB->SecondaryColorPtr[1]) { - GLubyte (*vbspec)[4] = VB->SecondaryColorPtr[1]->data; - ASSERT(VB->SecondaryColorPtr[1]->stride == 4*sizeof(GLubyte)); + if (HAVE_SPEC && VB->SecondaryColorPtr[1]) { + GLchan (*vbspec)[4] = VB->SecondaryColorPtr[1]->data; + ASSERT(VB->SecondaryColorPtr[1]->stride == 4*sizeof(GLchan)); if (!DO_FLAT) { VERT_SET_SPEC( v[0], vbspec[e0] ); @@ -148,22 +179,22 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 ) if (DO_FLAT) { if (HAVE_RGBA) { - VERT_SAVE_VERT_RGBA( 0 ); - VERT_SAVE_VERT_RGBA( 1 ); - VERT_COPY_VERT_RGBA( v[0], v[2] ); - VERT_COPY_VERT_RGBA( v[1], v[2] ); - if (VB->SecondaryColorPtr[0]) { - VERT_SAVE_VERT_SPEC( 0 ); - VERT_SAVE_VERT_SPEC( 1 ); - VERT_COPY_VERT_SPEC( v[0], v[2] ); - VERT_COPY_VERT_SPEC( v[1], v[2] ); + VERT_SAVE_RGBA( 0 ); + VERT_SAVE_RGBA( 1 ); + VERT_COPY_RGBA( v[0], v[2] ); + VERT_COPY_RGBA( v[1], v[2] ); + if (HAVE_SPEC && VB->SecondaryColorPtr[0]) { + VERT_SAVE_SPEC( 0 ); + VERT_SAVE_SPEC( 1 ); + VERT_COPY_SPEC( v[0], v[2] ); + VERT_COPY_SPEC( v[1], v[2] ); } } else { - VERT_SAVE_VERT_IND( 0 ); - VERT_SAVE_VERT_IND( 1 ); - VERT_COPY_VERT_IND( v[0], v[2] ); - VERT_COPY_VERT_IND( v[1], v[2] ); + VERT_SAVE_IND( 0 ); + VERT_SAVE_IND( 1 ); + VERT_COPY_IND( v[0], v[2] ); + VERT_COPY_IND( v[1], v[2] ); } } @@ -173,14 +204,14 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 ) VERT_Z(v[1]) += offset; VERT_Z(v[2]) += offset; } - UNFILLED_POINT_TRI( ctx, e0, e1, e2 ); + UNFILLED_TRI( ctx, GL_POINT, e0, e1, e2 ); } else if (mode == GL_LINE) { if (DO_OFFSET && ctx->Polygon.OffsetLine) { VERT_Z(v[0]) += offset; VERT_Z(v[1]) += offset; VERT_Z(v[2]) += offset; } - UNFILLED_LINE_TRI( ctx, e0, e1, e2 ); + UNFILLED_TRI( ctx, GL_LINE, e0, e1, e2 ); } else { if (DO_OFFSET && ctx->Polygon.OffsetFill) { VERT_Z(v[0]) += offset; @@ -188,8 +219,8 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 ) VERT_Z(v[2]) += offset; } if (DO_UNFILLED) - SET_REDUCED_PRIM( GL_TRIANGLES, GL_TRIANGLES ); - TRI( ctx, v[0], v[1], v[2] ); + RASTERIZE( GL_TRIANGLES ); + TRI( v[0], v[1], v[2] ); } if (DO_OFFSET) @@ -199,26 +230,21 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 ) VERT_Z(v[2]) = z[2]; } - /* ==> Need to import Color, SecondaryColor, Index to meet assertions - * in DO_FLAT case. - * - * ==> Copy/Restore vertex data instead? - */ if (DO_TWOSIDE && facing == 1) { if (HAVE_RGBA) { - GLubyte (*vbcolor)[4] = VB->ColorPtr[0]->data; - ASSERT(VB->ColorPtr[0]->stride == 4*sizeof(GLubyte)); + GLchan (*vbcolor)[4] = VB->ColorPtr[0]->data; + ASSERT(VB->ColorPtr[0]->stride == 4*sizeof(GLchan)); if (!DO_FLAT) { - VERT_SET_COLOR( v[0], vbcolor[e0] ); - VERT_SET_COLOR( v[1], vbcolor[e1] ); + VERT_SET_RGBA( v[0], vbcolor[e0] ); + VERT_SET_RGBA( v[1], vbcolor[e1] ); } - VERT_SET_COLOR( v[2], vbcolor[e2] ); + VERT_SET_RGBA( v[2], vbcolor[e2] ); - if (VB->SecondaryColorPtr[0]) { - GLubyte (*vbspec)[4] = VB->SecondaryColorPtr[0]->data; - ASSERT(VB->SecondaryColorPtr[0]->stride == 4*sizeof(GLubyte)); + if (HAVE_SPEC && VB->SecondaryColorPtr[0]) { + GLchan (*vbspec)[4] = VB->SecondaryColorPtr[0]->data; + ASSERT(VB->SecondaryColorPtr[0]->stride == 4*sizeof(GLchan)); if (!DO_FLAT) { VERT_SET_SPEC( v[0], vbspec[e0] ); @@ -240,16 +266,16 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 ) if (DO_FLAT) { if (HAVE_RGBA) { - VERT_RESTORE_VERT_RGBA( 0 ); - VERT_RESTORE_VERT_RGBA( 1 ); - if (VB->SecondaryColorPtr[0]) { - VERT_RESTORE_VERT_SPEC( 0 ); - VERT_RESTORE_VERT_SPEC( 1 ); + VERT_RESTORE_RGBA( 0 ); + VERT_RESTORE_RGBA( 1 ); + if (HAVE_SPEC && VB->SecondaryColorPtr[0]) { + VERT_RESTORE_SPEC( 0 ); + VERT_RESTORE_SPEC( 1 ); } } else { - VERT_RESTORE_VERT_IND( 0 ); - VERT_RESTORE_VERT_IND( 1 ); + VERT_RESTORE_IND( 0 ); + VERT_RESTORE_IND( 1 ); } } @@ -268,10 +294,10 @@ static void TAG(quad)( GLcontext *ctx, GLuint facing; LOCAL_VARS(4); - v[0] = GET_VERTEX(e0); - v[1] = GET_VERTEX(e1); - v[2] = GET_VERTEX(e2); - v[3] = GET_VERTEX(e3); + v[0] = (VERTEX *)GET_VERTEX(e0); + v[1] = (VERTEX *)GET_VERTEX(e1); + v[2] = (VERTEX *)GET_VERTEX(e2); + v[3] = (VERTEX *)GET_VERTEX(e3); if (DO_TWOSIDE || DO_OFFSET || DO_UNFILLED) { @@ -304,18 +330,18 @@ static void TAG(quad)( GLcontext *ctx, if (DO_TWOSIDE && facing == 1) { if (HAVE_RGBA) { - GLubyte (*vbcolor)[4] = VB->ColorPtr[1]->data; + GLchan (*vbcolor)[4] = VB->ColorPtr[1]->data; if (!DO_FLAT) { - VERT_SET_COLOR( v[0], vbcolor[e0] ); - VERT_SET_COLOR( v[1], vbcolor[e1] ); - VERT_SET_COLOR( v[2], vbcolor[e2] ); + VERT_SET_RGBA( v[0], vbcolor[e0] ); + VERT_SET_RGBA( v[1], vbcolor[e1] ); + VERT_SET_RGBA( v[2], vbcolor[e2] ); } - VERT_SET_COLOR( v[3], vbcolor[e3] ); + VERT_SET_RGBA( v[3], vbcolor[e3] ); - if (VB->SecondaryColorPtr[facing]) { - GLubyte (*vbspec)[4] = VB->SecondaryColorPtr[1]->data; - ASSERT(VB->SecondaryColorPtr[1]->stride == 4*sizeof(GLubyte)); + if (HAVE_SPEC && VB->SecondaryColorPtr[facing]) { + GLchan (*vbspec)[4] = VB->SecondaryColorPtr[1]->data; + ASSERT(VB->SecondaryColorPtr[1]->stride == 4*sizeof(GLchan)); if (!DO_FLAT) { VERT_SET_SPEC( v[0], vbspec[e0] ); @@ -363,28 +389,28 @@ static void TAG(quad)( GLcontext *ctx, if (DO_FLAT) { if (HAVE_RGBA) { - VERT_SAVE_VERT_RGBA( 0 ); - VERT_SAVE_VERT_RGBA( 1 ); - VERT_SAVE_VERT_RGBA( 2 ); - VERT_COPY_VERT_RGBA( v[0], v[3] ); - VERT_COPY_VERT_RGBA( v[1], v[3] ); - VERT_COPY_VERT_RGBA( v[2], v[3] ); - if (VB->SecondaryColorPtr[0]) { - VERT_SAVE_VERT_SPEC( 0 ); - VERT_SAVE_VERT_SPEC( 1 ); - VERT_SAVE_VERT_SPEC( 2 ); - VERT_COPY_VERT_SPEC( v[0], v[3] ); - VERT_COPY_VERT_SPEC( v[1], v[3] ); - VERT_COPY_VERT_SPEC( v[2], v[3] ); + VERT_SAVE_RGBA( 0 ); + VERT_SAVE_RGBA( 1 ); + VERT_SAVE_RGBA( 2 ); + VERT_COPY_RGBA( v[0], v[3] ); + VERT_COPY_RGBA( v[1], v[3] ); + VERT_COPY_RGBA( v[2], v[3] ); + if (HAVE_SPEC && VB->SecondaryColorPtr[0]) { + VERT_SAVE_SPEC( 0 ); + VERT_SAVE_SPEC( 1 ); + VERT_SAVE_SPEC( 2 ); + VERT_COPY_SPEC( v[0], v[3] ); + VERT_COPY_SPEC( v[1], v[3] ); + VERT_COPY_SPEC( v[2], v[3] ); } } else { - VERT_SAVE_VERT_IND( 0 ); - VERT_SAVE_VERT_IND( 1 ); - VERT_SAVE_VERT_IND( 2 ); - VERT_COPY_VERT_IND( v[0], v[3] ); - VERT_COPY_VERT_IND( v[1], v[3] ); - VERT_COPY_VERT_IND( v[2], v[3] ); + VERT_SAVE_IND( 0 ); + VERT_SAVE_IND( 1 ); + VERT_SAVE_IND( 2 ); + VERT_COPY_IND( v[0], v[3] ); + VERT_COPY_IND( v[1], v[3] ); + VERT_COPY_IND( v[2], v[3] ); } } @@ -395,7 +421,7 @@ static void TAG(quad)( GLcontext *ctx, VERT_Z(v[2]) += offset; VERT_Z(v[3]) += offset; } - UNFILLED_POINT_QUAD( ctx, e0, e1, e2, e3 ); + UNFILLED_QUAD( ctx, GL_POINT, e0, e1, e2, e3 ); } else if (mode == GL_LINE) { if (DO_OFFSET && ctx->Polygon.OffsetLine) { VERT_Z(v[0]) += offset; @@ -403,7 +429,7 @@ static void TAG(quad)( GLcontext *ctx, VERT_Z(v[2]) += offset; VERT_Z(v[3]) += offset; } - UNFILLED_LINE_QUAD( ctx, e0, e1, e2, e3 ); + UNFILLED_QUAD( ctx, GL_LINE, e0, e1, e2, e3 ); } else { if (DO_OFFSET && ctx->Polygon.OffsetFill) { VERT_Z(v[0]) += offset; @@ -411,8 +437,7 @@ static void TAG(quad)( GLcontext *ctx, VERT_Z(v[2]) += offset; VERT_Z(v[3]) += offset; } - if (DO_UNFILLED) - SET_REDUCED_PRIM( GL_QUADS, GL_TRIANGLES ); + RASTERIZE( GL_TRIANGLES ); QUAD( (v[0]), (v[1]), (v[2]), (v[3]) ); } @@ -427,19 +452,19 @@ static void TAG(quad)( GLcontext *ctx, if (DO_TWOSIDE && facing == 1) { if (HAVE_RGBA) { - GLubyte (*vbcolor)[4] = VB->ColorPtr[0]->data; - ASSERT(VB->ColorPtr[0]->stride == 4*sizeof(GLubyte)); + GLchan (*vbcolor)[4] = VB->ColorPtr[0]->data; + ASSERT(VB->ColorPtr[0]->stride == 4*sizeof(GLchan)); if (!DO_FLAT) { - VERT_SET_COLOR( v[0], vbcolor[e0] ); - VERT_SET_COLOR( v[1], vbcolor[e1] ); - VERT_SET_COLOR( v[2], vbcolor[e2] ); + VERT_SET_RGBA( v[0], vbcolor[e0] ); + VERT_SET_RGBA( v[1], vbcolor[e1] ); + VERT_SET_RGBA( v[2], vbcolor[e2] ); } - VERT_SET_COLOR( v[3], vbcolor[e3] ); + VERT_SET_RGBA( v[3], vbcolor[e3] ); - if (VB->SecondaryColorPtr[0]) { - GLubyte (*vbspec)[4] = VB->SecondaryColorPtr[0]->data; - ASSERT(VB->SecondaryColorPtr[0]->stride == 4*sizeof(GLubyte)); + if (HAVE_SPEC && VB->SecondaryColorPtr[0]) { + GLchan (*vbspec)[4] = VB->SecondaryColorPtr[0]->data; + ASSERT(VB->SecondaryColorPtr[0]->stride == 4*sizeof(GLchan)); if (!DO_FLAT) { VERT_SET_SPEC( v[0], vbspec[e0] ); @@ -463,19 +488,19 @@ static void TAG(quad)( GLcontext *ctx, if (DO_FLAT) { if (HAVE_RGBA) { - VERT_RESTORE_VERT_RGBA( 0 ); - VERT_RESTORE_VERT_RGBA( 1 ); - VERT_RESTORE_VERT_RGBA( 2 ); - if (VB->SecondaryColorPtr[0]) { - VERT_RESTORE_VERT_SPEC( 0 ); - VERT_RESTORE_VERT_SPEC( 1 ); - VERT_RESTORE_VERT_SPEC( 2 ); + VERT_RESTORE_RGBA( 0 ); + VERT_RESTORE_RGBA( 1 ); + VERT_RESTORE_RGBA( 2 ); + if (HAVE_SPEC && VB->SecondaryColorPtr[0]) { + VERT_RESTORE_SPEC( 0 ); + VERT_RESTORE_SPEC( 1 ); + VERT_RESTORE_SPEC( 2 ); } } else { - VERT_RESTORE_VERT_IND( 0 ); - VERT_RESTORE_VERT_IND( 1 ); - VERT_RESTORE_VERT_IND( 2 ); + VERT_RESTORE_IND( 0 ); + VERT_RESTORE_IND( 1 ); + VERT_RESTORE_IND( 2 ); } } } @@ -483,7 +508,7 @@ static void TAG(quad)( GLcontext *ctx, static void TAG(quad)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2, GLuint e3 ) { - if (IND & SS_UNFILLED_BIT) { + if (DO_UNFILLED) { struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; GLubyte ef1 = VB->EdgeFlag[e1]; GLubyte ef3 = VB->EdgeFlag[e3]; @@ -503,24 +528,25 @@ static void TAG(quad)( GLcontext *ctx, GLuint e0, static void TAG(line)( GLcontext *ctx, GLuint e0, GLuint e1 ) { + TNLvertexbuffer *VB = &TNL_CONTEXT(ctx)->vb; VERTEX *v[2]; LOCAL_VARS(2); - v[0] = GET_VERTEX(e0); - v[1] = GET_VERTEX(e1); + v[0] = (VERTEX *)GET_VERTEX(e0); + v[1] = (VERTEX *)GET_VERTEX(e1); if (DO_FLAT) { if (HAVE_RGBA) { - VERT_SAVE_VERT_RGBA( 0 ); - VERT_COPY_VERT_RGBA( v[0], v[1] ); - if (VB->SecondaryColorPtr[0]) { - VERT_SAVE_VERT_SPEC( 0 ); - VERT_COPY_VERT_SPEC( v[0], v[1] ); + VERT_SAVE_RGBA( 0 ); + VERT_COPY_RGBA( v[0], v[1] ); + if (HAVE_SPEC && VB->SecondaryColorPtr[0]) { + VERT_SAVE_SPEC( 0 ); + VERT_COPY_SPEC( v[0], v[1] ); } } else { - VERT_SAVE_VERT_IND( 0 ); - VERT_COPY_VERT_IND( v[0], v[1] ); + VERT_SAVE_IND( 0 ); + VERT_COPY_IND( v[0], v[1] ); } } @@ -528,14 +554,14 @@ static void TAG(line)( GLcontext *ctx, GLuint e0, GLuint e1 ) if (DO_FLAT) { if (HAVE_RGBA) { - VERT_RESTORE_VERT_RGBA( 0 ); + VERT_RESTORE_RGBA( 0 ); - if (VB->SecondaryColorPtr[0]) { - VERT_RESTORE_VERT_SPEC( 0 ); + if (HAVE_SPEC && VB->SecondaryColorPtr[0]) { + VERT_RESTORE_SPEC( 0 ); } } else { - VERT_RESTORE_VERT_IND( 0 ); + VERT_RESTORE_IND( 0 ); } } } @@ -550,7 +576,7 @@ static void TAG(points)( GLcontext *ctx, GLuint first, GLuint last ) if (VB->Elts == 0) { for ( i = first ; i < last ; i++ ) { if ( VB->ClipMask[i] == 0 ) { - VERTEX *v = GET_VERTEX(i); + VERTEX *v = (VERTEX *)GET_VERTEX(i); POINT( v ); } } @@ -558,12 +584,34 @@ static void TAG(points)( GLcontext *ctx, GLuint first, GLuint last ) for ( i = first ; i < last ; i++ ) { GLuint e = VB->Elts[i]; if ( VB->ClipMask[e] == 0 ) { - VERTEX *v = GET_VERTEX(e); + VERTEX *v = (VERTEX *)GET_VERTEX(e); POINT( v ); } } } } +static void TAG(init)( void ) +{ + TAB[IND].quad = TAG(quad); + TAB[IND].triangle = TAG(triangle); + TAB[IND].line = TAG(line); + TAB[IND].points = TAG(points); +} + #undef IND #undef TAG + +#if HAVE_RGBA +#undef VERT_SET_IND +#undef VERT_COPY_IND +#undef VERT_SAVE_IND +#undef VERT_RESTORE_IND +#endif + +#if !HAVE_SPEC +#undef VERT_SET_SPEC +#undef VERT_COPY_SPEC +#undef VERT_SAVE_SPEC +#undef VERT_RESTORE_SPEC +#endif diff --git a/src/mesa/drivers/common/t_dd_unfilled.h b/src/mesa/drivers/common/t_dd_unfilled.h index c1f3a92b00..59c9bfdc5a 100644 --- a/src/mesa/drivers/common/t_dd_unfilled.h +++ b/src/mesa/drivers/common/t_dd_unfilled.h @@ -1,135 +1,180 @@ +#if HAVE_RGBA +#define VERT_SET_IND( v, c ) +#define VERT_COPY_IND( v0, v1 ) +#define VERT_SAVE_IND( idx ) +#define VERT_RESTORE_IND( idx ) +#endif -static void tdfx_unfilled_tri( GLcontext *ctx, +#if !HAVE_SPEC +#define VERT_SET_SPEC( v, c ) +#define VERT_COPY_SPEC( v0, v1 ) +#define VERT_SAVE_SPEC( idx ) +#define VERT_RESTORE_SPEC( idx ) +#endif + +static void TAG(unfilled_tri)( GLcontext *ctx, GLenum mode, GLuint e0, GLuint e1, GLuint e2 ) { - tdfxContextPtr imesa = TDFX_CONTEXT(ctx); struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; GLubyte *ef = VB->EdgeFlag; - GLubyte *tdfxverts = (GLubyte *)imesa->verts; - GLuint shift = imesa->vertex_stride_shift; - tdfxVertex *v0 = (tdfxVertex *)(tdfxverts + (e0 << shift)); - tdfxVertex *v1 = (tdfxVertex *)(tdfxverts + (e1 << shift)); - tdfxVertex *v2 = (tdfxVertex *)(tdfxverts + (e2 << shift)); - GLuint c[2]; - GLuint s[2]; - GLuint coloroffset = 0; - -/* fprintf(stderr, "%s %s %d %d %d (vertsize %d)\n", __FUNCTION__, */ -/* gl_lookup_enum_by_nr(mode), e0, e1, e2, imesa->vertsize); */ - - if (ctx->_TriangleCaps & DD_FLATSHADE) { - coloroffset = (imesa->vertsize == 4) ? 3 : 4; - TDFX_COPY_COLOR(c[0], v0->ui[coloroffset]); - TDFX_COPY_COLOR(c[1], v1->ui[coloroffset]); - TDFX_COPY_COLOR(v0->ui[coloroffset], v2->ui[coloroffset]); - TDFX_COPY_COLOR(v1->ui[coloroffset], v2->ui[coloroffset]); - - if (coloroffset == 4) { - TDFX_COPY_COLOR(s[0], v0->v.specular); - TDFX_COPY_COLOR(s[1], v1->v.specular); - TDFX_COPY_COLOR(v0->v.specular, v2->v.specular); - TDFX_COPY_COLOR(v1->v.specular, v2->v.specular); + VERTEX *v[3]; + LOCAL_VARS(3); + + v[0] = (VERTEX *)GET_VERTEX(e0); + v[1] = (VERTEX *)GET_VERTEX(e1); + v[2] = (VERTEX *)GET_VERTEX(e2); + + if ((ctx->_TriangleCaps & DD_FLATSHADE) && HAVE_HW_FLATSHADE) { + if (HAVE_RGBA) { + VERT_SAVE_RGBA(0); + VERT_SAVE_RGBA(1); + VERT_COPY_RGBA(v[0], v[2]); + VERT_COPY_RGBA(v[1], v[2]); + + if (HAVE_SPEC) { + VERT_SAVE_SPEC(0); + VERT_SAVE_SPEC(1); + VERT_COPY_SPEC(v[0], v[2]); + VERT_COPY_SPEC(v[1], v[2]); + } + } else { + VERT_SAVE_IND(0); + VERT_SAVE_IND(1); + VERT_COPY_IND(v[0], v[2]); + VERT_COPY_IND(v[1], v[2]); } } if (mode == GL_POINT) { - tdfxRasterPrimitive( ctx, GL_POINTS, PR_LINES ); - if (ef[e0]) imesa->draw_point( imesa, v0 ); - if (ef[e1]) imesa->draw_point( imesa, v1 ); - if (ef[e2]) imesa->draw_point( imesa, v2 ); + RASTERIZE(GL_POINTS); + if (ef[e0]) POINT( v[0] ); + if (ef[e1]) POINT( v[1] ); + if (ef[e2]) POINT( v[2] ); } else { - tdfxRasterPrimitive( ctx, GL_LINES, PR_LINES ); - - if (imesa->render_primitive == GL_POLYGON) { - if (ef[e2]) imesa->draw_line( imesa, v2, v0 ); - if (ef[e0]) imesa->draw_line( imesa, v0, v1 ); - if (ef[e1]) imesa->draw_line( imesa, v1, v2 ); + RASTERIZE(GL_LINES); + if (RENDER_PRIMITIVE == GL_POLYGON) { + if (ef[e2]) LINE( v[2], v[0] ); + if (ef[e0]) LINE( v[0], v[1] ); + if (ef[e1]) LINE( v[1], v[2] ); } else { - if (ef[e0]) imesa->draw_line( imesa, v0, v1 ); - if (ef[e1]) imesa->draw_line( imesa, v1, v2 ); - if (ef[e2]) imesa->draw_line( imesa, v2, v0 ); + if (ef[e0]) LINE( v[0], v[1] ); + if (ef[e1]) LINE( v[1], v[2] ); + if (ef[e2]) LINE( v[2], v[0] ); } } - if (ctx->_TriangleCaps & DD_FLATSHADE) { - TDFX_COPY_COLOR(v0->ui[coloroffset], c[0]); - TDFX_COPY_COLOR(v1->ui[coloroffset], c[1]); - if (coloroffset == 4) { - TDFX_COPY_COLOR(v0->v.specular, s[0]); - TDFX_COPY_COLOR(v1->v.specular, s[1]); + if ((ctx->_TriangleCaps & DD_FLATSHADE) && HAVE_HW_FLATSHADE) { + if (HAVE_RGBA) { + VERT_RESTORE_RGBA(0); + VERT_RESTORE_RGBA(1); + + if (HAVE_SPEC) { + VERT_RESTORE_SPEC(0); + VERT_RESTORE_SPEC(1); + } + } else { + VERT_RESTORE_IND(0); + VERT_RESTORE_IND(1); } } } -static void tdfx_unfilled_quad( GLcontext *ctx, +static void TAG(unfilled_quad)( GLcontext *ctx, GLenum mode, GLuint e0, GLuint e1, GLuint e2, GLuint e3 ) { - tdfxContextPtr imesa = TDFX_CONTEXT(ctx); struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; GLubyte *ef = VB->EdgeFlag; - GLubyte *tdfxverts = (GLubyte *)imesa->verts; - GLuint shift = imesa->vertex_stride_shift; - tdfxVertex *v0 = (tdfxVertex *)(tdfxverts + (e0 << shift)); - tdfxVertex *v1 = (tdfxVertex *)(tdfxverts + (e1 << shift)); - tdfxVertex *v2 = (tdfxVertex *)(tdfxverts + (e2 << shift)); - tdfxVertex *v3 = (tdfxVertex *)(tdfxverts + (e3 << shift)); - GLuint c[3]; - GLuint s[3]; - GLuint coloroffset = 0; - - if (ctx->_TriangleCaps & DD_FLATSHADE) { - coloroffset = (imesa->vertsize == 4) ? 3 : 4; - - TDFX_COPY_COLOR(c[0], v0->ui[coloroffset]); - TDFX_COPY_COLOR(c[1], v1->ui[coloroffset]); - TDFX_COPY_COLOR(c[2], v2->ui[coloroffset]); - TDFX_COPY_COLOR(v0->ui[coloroffset], v3->ui[coloroffset]); - TDFX_COPY_COLOR(v1->ui[coloroffset], v3->ui[coloroffset]); - TDFX_COPY_COLOR(v2->ui[coloroffset], v3->ui[coloroffset]); - - if (coloroffset == 4) { - TDFX_COPY_COLOR(s[0], v0->v.specular); - TDFX_COPY_COLOR(s[1], v1->v.specular); - TDFX_COPY_COLOR(s[2], v2->v.specular); - TDFX_COPY_COLOR(v0->v.specular, v3->v.specular); - TDFX_COPY_COLOR(v1->v.specular, v3->v.specular); - TDFX_COPY_COLOR(v2->v.specular, v3->v.specular); + VERTEX *v[4]; + LOCAL_VARS(4); + + v[0] = (VERTEX *)GET_VERTEX(e0); + v[1] = (VERTEX *)GET_VERTEX(e1); + v[2] = (VERTEX *)GET_VERTEX(e2); + v[3] = (VERTEX *)GET_VERTEX(e3); + + /* Hardware flatshading breaks down here. If the hardware doesn't + * support flatshading, this will already have been done: + */ + if ((ctx->_TriangleCaps & DD_FLATSHADE) && HAVE_HW_FLATSHADE) { + if (HAVE_RGBA) { + VERT_SAVE_RGBA(0); + VERT_SAVE_RGBA(1); + VERT_SAVE_RGBA(2); + VERT_COPY_RGBA(v[0], v[3]); + VERT_COPY_RGBA(v[1], v[3]); + VERT_COPY_RGBA(v[2], v[3]); + + if (HAVE_SPEC) { + VERT_SAVE_SPEC(0); + VERT_SAVE_SPEC(1); + VERT_SAVE_SPEC(2); + VERT_COPY_SPEC(v[0], v[3]); + VERT_COPY_SPEC(v[1], v[3]); + VERT_COPY_SPEC(v[2], v[3]); + } + } else { + VERT_SAVE_IND(0); + VERT_SAVE_IND(1); + VERT_SAVE_IND(2); + VERT_COPY_IND(v[0], v[3]); + VERT_COPY_IND(v[1], v[3]); + VERT_COPY_IND(v[2], v[3]); } } if (mode == GL_POINT) { - if (imesa->reduced_primitive != GL_POINTS) - tdfxRasterPrimitive( ctx, GL_POINTS, PR_LINES ); - - if (ef[e0]) imesa->draw_point( imesa, v0 ); - if (ef[e1]) imesa->draw_point( imesa, v1 ); - if (ef[e2]) imesa->draw_point( imesa, v2 ); - if (ef[e3]) imesa->draw_point( imesa, v3 ); + RASTERIZE(GL_POINTS); + if (ef[e0]) POINT( v[0] ); + if (ef[e1]) POINT( v[1] ); + if (ef[e2]) POINT( v[2] ); + if (ef[e3]) POINT( v[3] ); } else { - if (imesa->reduced_primitive != GL_LINES) - tdfxRasterPrimitive( ctx, GL_LINES, PR_LINES ); - - if (ef[e0]) imesa->draw_line( imesa, v0, v1 ); - if (ef[e1]) imesa->draw_line( imesa, v1, v2 ); - if (ef[e2]) imesa->draw_line( imesa, v2, v3 ); - if (ef[e3]) imesa->draw_line( imesa, v3, v0 ); + RASTERIZE(GL_LINES); + if (ef[e0]) LINE( v[0], v[1] ); + if (ef[e1]) LINE( v[1], v[2] ); + if (ef[e2]) LINE( v[2], v[3] ); + if (ef[e3]) LINE( v[3], v[0] ); } - if (ctx->_TriangleCaps & DD_FLATSHADE) { - TDFX_COPY_COLOR(v0->ui[coloroffset], c[0]); - TDFX_COPY_COLOR(v1->ui[coloroffset], c[1]); - TDFX_COPY_COLOR(v2->ui[coloroffset], c[2]); - if (coloroffset == 4) { - TDFX_COPY_COLOR(v0->v.specular, s[0]); - TDFX_COPY_COLOR(v1->v.specular, s[1]); - TDFX_COPY_COLOR(v2->v.specular, s[2]); + if ((ctx->_TriangleCaps & DD_FLATSHADE) && HAVE_HW_FLATSHADE) { + if (HAVE_RGBA) { + VERT_RESTORE_RGBA(0); + VERT_RESTORE_RGBA(1); + VERT_RESTORE_RGBA(2); + + if (HAVE_SPEC) { + VERT_RESTORE_SPEC(0); + VERT_RESTORE_SPEC(1); + VERT_RESTORE_SPEC(2); + } + } else { + VERT_RESTORE_IND(0); + VERT_RESTORE_IND(1); + VERT_RESTORE_IND(2); } } } + + +#if HAVE_RGBA +#undef VERT_SET_IND +#undef VERT_COPY_IND +#undef VERT_SAVE_IND +#undef VERT_RESTORE_IND +#endif + +#if !HAVE_SPEC +#undef VERT_SET_SPEC +#undef VERT_COPY_SPEC +#undef VERT_SAVE_SPEC +#undef VERT_RESTORE_SPEC +#endif + +#undef TAG diff --git a/src/mesa/drivers/common/t_dd_vb.c b/src/mesa/drivers/common/t_dd_vb.c index 9c23900c55..1841346985 100644 --- a/src/mesa/drivers/common/t_dd_vb.c +++ b/src/mesa/drivers/common/t_dd_vb.c @@ -1,99 +1,4 @@ -/* Build an SWvertex from an tdfxVertex. This is workable because in - * states where the GrVertex is insufficent (eg seperate-specular), - * the driver initiates a total fallback, and builds SWvertices - * directly -- it recognizes that it will never have use for the - * tdfxVertex. - * - * This code is hit only when a mix of accelerated and unaccelerated - * primitives are being drawn, and only for the unaccelerated - * primitives. - */ -static void -tdfx_translate_vertex(GLcontext *ctx, const tdfxVertex *src, SWvertex *dst) -{ - tdfxContextPtr imesa = TDFX_CONTEXT( ctx ); - - if (imesa->vertsize == 4) { - dst->win[0] = src->tv.x + .5; - dst->win[1] = - src->tv.y + imesa->driDrawable->h - .5; - dst->win[2] = src->tv.z * (GLfloat)0x10000; - dst->win[3] = 1.0; - - dst->color[0] = src->tv.color.red; - dst->color[1] = src->tv.color.green; - dst->color[2] = src->tv.color.blue; - dst->color[3] = src->tv.color.alpha; - } - else { - dst->win[0] = src->v.x + .5; - dst->win[1] = - src->v.y + imesa->driDrawable->h - .5; - dst->win[2] = src->v.z * (GLfloat)0x10000; - dst->win[3] = src->v.oow; - - dst->color[0] = src->v.color.red; - dst->color[1] = src->v.color.green; - dst->color[2] = src->v.color.blue; - dst->color[3] = src->v.color.alpha; - - if (fxMesa->xxx) { - dst->texcoord[0][0] = src->v.tu0; - dst->texcoord[0][1] = src->v.tv0; - dst->texcoord[0][3] = 1.0; - - dst->texcoord[1][0] = src->v.tu1; - dst->texcoord[1][1] = src->v.tv1; - dst->texcoord[1][3] = 1.0; - } - else { - dst->texcoord[0][0] = src->pv.u0; - dst->texcoord[0][1] = src->pv.v0; - dst->texcoord[0][3] = src->pv.q0; - - dst->texcoord[1][0] = src->pv.u1; - dst->texcoord[1][1] = src->pv.v1; - dst->texcoord[1][3] = src->pv.q1; - } - } - - dst->pointSize = ctx->Point._Size; -} - - -static void -tdfx_fallback_tri( tdfxContextPtr imesa, - tdfxVertex *v0, - tdfxVertex *v1, - tdfxVertex *v2 ) -{ - GLcontext *ctx = imesa->glCtx; - SWvertex v[3]; - tdfx_translate_vertex( ctx, v0, &v[0] ); - tdfx_translate_vertex( ctx, v1, &v[1] ); - tdfx_translate_vertex( ctx, v2, &v[2] ); - _swrast_Triangle( ctx, &v[0], &v[1], &v[2] ); -} - -static void -tdfx_fallback_line( tdfxContextPtr imesa, - tdfxVertex *v0, - tdfxVertex *v1 ) -{ - GLcontext *ctx = imesa->glCtx; - SWvertex v[2]; - tdfx_translate_vertex( ctx, v0, &v[0] ); - tdfx_translate_vertex( ctx, v1, &v[1] ); - _swrast_Line( ctx, &v[0], &v[1] ); -} - - -static void -tdfx_fallback_point( tdfxContextPtr imesa, - tdfxVertex *v0 ) -{ - GLcontext *ctx = imesa->glCtx; - SWvertex v[1]; - tdfx_translate_vertex( ctx, v0, &v[0] ); - _swrast_Point( ctx, &v[0] ); -} +/* + */ diff --git a/src/mesa/drivers/common/t_dd_vbtmp.h b/src/mesa/drivers/common/t_dd_vbtmp.h index 979a2d3967..4490f099b7 100644 --- a/src/mesa/drivers/common/t_dd_vbtmp.h +++ b/src/mesa/drivers/common/t_dd_vbtmp.h @@ -38,6 +38,8 @@ * struct { char r, g, b, fog; } spec; * float u0, v0; * float u1, v1; + * float u2, v2; + * float u3, v3; * } v; * struct { * float x, y, z, w; @@ -45,6 +47,8 @@ * struct { char r, g, b, fog; } spec; * float u0, v0, q0; * float u1, v1, q1; + * float u2, v2, q2; + * float u3, v3, q3; * } pv; * struct { * float x, y, z; @@ -55,16 +59,22 @@ * unsigned char ub4[4][16]; * } * - * HW_VIEWPORT: Hardware performs viewport transform. - * HW_DIVIDE: Hardware performs perspective divide. - * + * DO_XYZW: Emit xyz and maybe w coordinates. - * DO_RGBA: Emit color, v.color is in RGBA order. - * DO_BGRA: Emit color, v.color is in BGRA order. + * DO_RGBA: Emit color. * DO_SPEC: Emit specular color. + * DO_FOG: Emit fog coordinate in specular alpha. * DO_TEX0: Emit tex0 u,v coordinates. * DO_TEX1: Emit tex1 u,v coordinates. - * DO_PTEX: Emit tex0, tex1 q coordinates where possible. + * DO_TEX2: Emit tex2 u,v coordinates. + * DO_TEX3: Emit tex3 u,v coordinates. + * DO_PTEX: Emit tex0,1,2,3 q coordinates where possible. + * + * HAVE_RGBA_COLOR: Hardware takes color in rgba order. + * HAVE_BGRA_COLOR: Hardware takes color in bgra order. + * + * HAVE_HW_VIEWPORT: Hardware performs viewport transform. + * HAVE_HW_DIVIDE: Hardware performs perspective divide. * * HAVE_TINY_VERTICES: Hardware understands v.tv format. * HAVE_PTEX_VERTICES: Hardware understands v.pv format. @@ -80,7 +90,7 @@ * an exact number of quadwords. */ -#if (HW_VIEWPORT) +#if (HAVE_HW_VIEWPORT) #define VIEWPORT_X(x) x #define VIEWPORT_Y(x) x #define VIEWPORT_Z(x) x @@ -90,7 +100,7 @@ #define VIEWPORT_Z(z) (s[10] * z + s[14]) #endif -#if (HW_DIVIDE || DO_RGBA || DO_XYZW || !HAVE_TINY_VERTICES) +#if (HAVE_HW_DIVIDE || DO_RGBA || DO_XYZW || !HAVE_TINY_VERTICES) static void TAG(emit)( GLcontext *ctx, GLuint start, GLuint end, @@ -105,9 +115,11 @@ static void TAG(emit)( GLcontext *ctx, GLfloat (*coord)[4]; GLuint coord_stride; VERTEX *v = (VERTEX *)dest; + const GLfloat *s = GET_VIEWPORT_MAT(); int i; - if (HW_VIEWPORT && HW_DIVIDE) { + if (HAVE_HW_VIEWPORT && HAVE_HW_DIVIDE) { + (void) s; coord = VB->ClipPtr->data; coord_stride = VB->ClipPtr->stride; } @@ -124,13 +136,45 @@ static void TAG(emit)( GLcontext *ctx, } if (DO_TEX1) { + if (VB->TexCoordPtr[0] == 0) + VB->TexCoordPtr[0] = VB->TexCoordPtr[1]; + tc1 = VB->TexCoordPtr[1]->data; tc1_stride = VB->TexCoordPtr[1]->stride; if (DO_PTEX) tc1_size = VB->TexCoordPtr[1]->size; } + + if (DO_TEX2) { + if (VB->TexCoordPtr[1] == 0) { + if (VB->TexCoordPtr[0] == 0) + VB->TexCoordPtr[0] = VB->TexCoordPtr[2]; + VB->TexCoordPtr[1] = VB->TexCoordPtr[2]; + } + + tc2 = VB->TexCoordPtr[2]->data; + tc2_stride = VB->TexCoordPtr[2]->stride; + if (DO_PTEX) + tc2_size = VB->TexCoordPtr[2]->size; + } + + if (DO_TEX3) { + if (VB->TexCoordPtr[2] == 0) { + if (VB->TexCoordPtr[1] == 0) { + if (VB->TexCoordPtr[0] == 0) + VB->TexCoordPtr[0] = VB->TexCoordPtr[3]; + VB->TexCoordPtr[1] = VB->TexCoordPtr[3]; + } + VB->TexCoordPtr[2] = VB->TexCoordPtr[3]; + } + + tc3 = VB->TexCoordPtr[3]->data; + tc3_stride = VB->TexCoordPtr[3]->stride; + if (DO_PTEX) + tc3_size = VB->TexCoordPtr[3]->size; + } - if (DO_RGBA || DO_BGRA) { + if (DO_RGBA) { col = VB->ColorPtr[0]->data; col_stride = VB->ColorPtr[0]->stride; } @@ -153,8 +197,12 @@ static void TAG(emit)( GLcontext *ctx, if (DO_TEX0) tc0 = (GLfloat (*)[4])((GLubyte *)tc0 + start * tc0_stride); if (DO_TEX1) - tc0 = (GLfloat (*)[4])((GLubyte *)tc1 + start * tc1_stride); - if (DO_RGBA || DO_BGRA) + tc1 = (GLfloat (*)[4])((GLubyte *)tc1 + start * tc1_stride); + if (DO_TEX2) + tc2 = (GLfloat (*)[4])((GLubyte *)tc2 + start * tc2_stride); + if (DO_TEX3) + tc3 = (GLfloat (*)[4])((GLubyte *)tc3 + start * tc3_stride); + if (DO_RGBA) STRIDE_4UB(col, start * col_stride); if (DO_SPEC) STRIDE_4UB(spec, start * spec_stride); @@ -164,7 +212,7 @@ static void TAG(emit)( GLcontext *ctx, for (i=start; i < end; i++, v = (ddVertex *)((GLubyte *)v + stride)) { if (DO_XYZW) { - if (HW_VIEWPORT || mask[i] == 0) { + if (HAVE_HW_VIEWPORT || mask[i] == 0) { VIEWPORT_X(v->v.x, coord[0][0]); VIEWPORT_Y(v->v.y, coord[0][1]); VIEWPORT_Z(v->v.z, coord[0][2]); @@ -172,16 +220,18 @@ static void TAG(emit)( GLcontext *ctx, } coord = (GLfloat (*)[4])((GLubyte *)coord + coord_stride); } + NOTE_W; if (DO_RGBA) { - *(GLuint *)&v->v.color = *(GLuint *)&col[0]; - STRIDE_4UB(col, col_stride); - } - if (DO_BGRA) { - v->v.color.blue = col[0][2]; - v->v.color.green = col[0][1]; - v->v.color.red = col[0][0]; - v->v.color.alpha = col[0][3]; - STRIDE_4UB(col, col_stride); + if (HAVE_RGBA_COLOR) { + *(GLuint *)&v->v.color = *(GLuint *)&col[0]; + STRIDE_4UB(col, col_stride); + } else { + v->v.color.blue = col[0][2]; + v->v.color.green = col[0][1]; + v->v.color.red = col[0][0]; + v->v.color.alpha = col[0][3]; + STRIDE_4UB(col, col_stride); + } } if (DO_SPEC) { v->v.specular.red = spec[0][0]; @@ -194,14 +244,14 @@ static void TAG(emit)( GLcontext *ctx, STRIDE_F(fog, fog_stride); } if (DO_TEX0) { - *(GLuint *)&v->v.tu0 = *(GLuint *)&tc0[0][0]; - *(GLuint *)&v->v.tv0 = *(GLuint *)&tc0[0][1]; + v->v.tu0 = tc0[0][0]; + v->v.tv0 = tc0[0][1]; if (DO_PTEX) { if (HAVE_PTEX_VERTICES) { if (tc0_size == 4) - *(GLuint *)&v->pv.tq0 = *(GLuint *)&tc0[0][3]; + v->pv.tq0 = tc0[0][3]; else - *(GLuint *)&v->pv.tq0 = IEEE_ONE; + v->pv.tq0 = 1.0; } else if (tc0_size == 4) { float rhw = 1.0 / tc0[0][3]; @@ -214,41 +264,75 @@ static void TAG(emit)( GLcontext *ctx, } if (DO_TEX1) { if (DO_PTEX) { - *(GLuint *)&v->pv.u1 = *(GLuint *)&tc1[0][0]; - *(GLuint *)&v->pv.v1 = *(GLuint *)&tc1[0][1]; - *(GLuint *)&v->pv.q1 = IEEE_ONE; + v->pv.u1 = tc1[0][0]; + v->pv.v1 = tc1[0][1]; if (tc1_size == 4) - *(GLuint *)&v->pv.q1 = *(GLuint *)&tc1[0][3]; + v->pv.q1 = tc1[0][3]; + else + v->pv.q1 = 1.0; } else { - *(GLuint *)&v->v.u1 = *(GLuint *)&tc1[0][0]; - *(GLuint *)&v->v.v1 = *(GLuint *)&tc1[0][1]; + v->v.u1 = tc1[0][0]; + v->v.v1 = tc1[0][1]; } tc1 = (GLfloat (*)[4])((GLubyte *)tc1 + tc1_stride); } else if (DO_PTEX) { *(GLuint *)&v->pv.q1 = 0; /* avoid culling on radeon */ } + if (DO_TEX2) { + if (DO_PTEX) { + v->pv.u2 = tc2[0][0]; + v->pv.v2 = tc2[0][1]; + if (tc2_size == 4) + v->pv.q2 = tc2[0][3]; + else + v->pv.q2 = 1.0; + } + else { + v->v.u2 = tc2[0][0]; + v->v.v2 = tc2[0][1]; + } + tc2 = (GLfloat (*)[4])((GLubyte *)tc2 + tc2_stride); + } + if (DO_TEX3) { + if (DO_PTEX) { + v->pv.u3 = tc3[0][0]; + v->pv.v3 = tc3[0][1]; + if (tc3_size == 4) + v->pv.q3 = tc3[0][3]; + else + v->pv.q3 = 1.0; + } + else { + v->v.u3 = tc3[0][0]; + v->v.v3 = tc3[0][1]; + } + tc3 = (GLfloat (*)[4])((GLubyte *)tc3 + tc3_stride); + } } } else { for (i=start; i < end; i++, v = (ddVertex *)((GLubyte *)v + stride)) { if (DO_XYZW) { - if (HW_VIEWPORT || mask[i] == 0) { + if (HAVE_HW_VIEWPORT || mask[i] == 0) { VIEWPORT_X(v->v.x, coord[i][0]); VIEWPORT_Y(v->v.y, coord[i][1]); VIEWPORT_Z(v->v.z, coord[i][2]); VIEWPORT_W(v->v.w, coord[i][3]); } } + NOTE_W; if (DO_RGBA) { - *(GLuint *)&v->v.color = *(GLuint *)&col[i]; - } - if (DO_BGRA) { - v->v.color.blue = col[i][2]; - v->v.color.green = col[i][1]; - v->v.color.red = col[i][0]; - v->v.color.alpha = col[i][3]; + if (HAVE_RGBA_COLOR) { + *(GLuint *)&v->v.color = *(GLuint *)&col[i]; + } + else { + v->v.color.blue = col[i][2]; + v->v.color.green = col[i][1]; + v->v.color.red = col[i][0]; + v->v.color.alpha = col[i][3]; + } } if (DO_SPEC) { v->v.specular.red = spec[i][0]; @@ -260,33 +344,42 @@ static void TAG(emit)( GLcontext *ctx, } if (DO_TEX0) { if (DO_PTEX) { - *(GLuint *)&v->pv.u0 = *(GLuint *)&tc0[i][0]; - *(GLuint *)&v->pv.v0 = *(GLuint *)&tc0[i][1]; - *(GLuint *)&v->pv.q0 = IEEE_ONE; - if (tc0_size == 4) - *(GLuint *)&v->pv.q0 = *(GLuint *)&tc0[i][3]; + v->pv.u0 = tc0[i][0]; + v->pv.v0 = tc0[i][1]; + if (HAVE_PTEX_VERTICES) { + if (tc0_size == 4) + v->pv.tq0 = tc0[i][3]; + else + v->pv.tq0 = 1.0; + + v->pv.q1 = 0; /* radeon */ + } + else if (tc0_size == 4) { + float rhw = 1.0 / tc0[i][3]; + v->v.w *= tc0[i][3]; + v->v.u0 *= rhw; + v->v.v0 *= rhw; + } } else { - *(GLuint *)&v->v.u0 = *(GLuint *)&tc0[i][0]; - *(GLuint *)&v->v.v0 = *(GLuint *)&tc0[i][1]; + v->v.u0 = tc0[i][0]; + v->v.v0 = tc0[i][1]; } } if (DO_TEX1) { if (DO_PTEX) { - *(GLuint *)&v->pv.u1 = *(GLuint *)&tc1[i][0]; - *(GLuint *)&v->pv.v1 = *(GLuint *)&tc1[i][1]; - *(GLuint *)&v->pv.q1 = IEEE_ONE; + v->pv.u1 = tc1[i][0]; + v->pv.v1 = tc1[i][1]; if (tc1_size == 4) - *(GLuint *)&v->pv.q1 = *(GLuint *)&tc1[i][3]; + v->pv.q1 = tc1[i][3]; + else + v->pv.q1 = 1.0; } else { - *(GLuint *)&v->v.u1 = *(GLuint *)&tc1[i][0]; - *(GLuint *)&v->v.v1 = *(GLuint *)&tc1[i][1]; + v->v.u1 = tc1[i][0]; + v->v.v1 = tc1[i][1]; } } - else if (DO_PTEX) { - *(GLuint *)&v->pv.q1 = 0; /* must be valid float to avoid culling? */ - } } } @@ -318,41 +411,45 @@ static void TAG(emit)( GLcontext *ctx, GLuint start, GLuint end, } for (i=start; i < end; i++, v+=4) { - if (HW_VIEWPORT || mask[i] == 0) { + if (HAVE_HW_VIEWPORT || mask[i] == 0) { v[0] = VIEWPORT_X(coord[0][0]); v[1] = VIEWPORT_Y(coord[0][1]); v[2] = VIEWPORT_Z(coord[0][2]); } coord = (GLfloat (*)[4])((GLubyte *)coord + coord_stride); if (DO_RGBA) { - *(GLuint *)&v[3] = *(GLuint *)col; - } - else if (DO_BGRA) { - GLubyte *b = (GLubyte *)&v[3]; - b[0] = col[0][2]; - b[1] = col[0][1]; - b[2] = col[0][0]; - b[3] = col[0][3]; + if (HAVE_RGBA_COLOR) { + *(GLuint *)&v[3] = *(GLuint *)col; + } + else { + GLubyte *b = (GLubyte *)&v[3]; + b[0] = col[0][2]; + b[1] = col[0][1]; + b[2] = col[0][0]; + b[3] = col[0][3]; + } + STRIDE_4UB( col, col_stride ); } - STRIDE_4UB( col, col_stride ); } } else { for (i=start; i < end; i++, v+=4) { - if (HW_VIEWPORT || mask[i] == 0) { + if (HAVE_HW_VIEWPORT || mask[i] == 0) { v[0] = VIEWPORT_X(coord[i][0]); v[1] = VIEWPORT_Y(coord[i][1]); v[2] = VIEWPORT_Z(coord[i][2]); } if (DO_RGBA) { - *(GLuint *)&v[3] = *(GLuint *)&col[i]; - } - else if (DO_BGRA) { - GLubyte *b = (GLubyte *)&v[3]; - b[0] = col[i][2]; - b[1] = col[i][1]; - b[2] = col[i][0]; - b[3] = col[i][3]; + if (HAVE_RGBA_COLOR) { + *(GLuint *)&v[3] = *(GLuint *)&col[i]; + } + else { + GLubyte *b = (GLubyte *)&v[3]; + b[0] = col[i][2]; + b[1] = col[i][1]; + b[2] = col[i][0]; + b[3] = col[i][3]; + } } } } @@ -361,28 +458,52 @@ static void TAG(emit)( GLcontext *ctx, GLuint start, GLuint end, #if (DO_XYZW) && (DO_RGBA) +#if (HAVE_PTEX_VERTICES) static GLboolean TAG(check_tex_sizes)( GLcontext *ctx ) { + struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; + if (DO_PTEX) return GL_TRUE; - if (DO_TEX0) { - struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; + if ((DO_TEX3 && VB->TexCoordPtr[3]->size == 4) || + (DO_TEX2 && VB->TexCoordPtr[2]->size == 4) || + (DO_TEX1 && VB->TexCoordPtr[1]->size == 4) || + (DO_TEX0 && VB->TexCoordPtr[0]->size == 4)) + return GL_FALSE; + + return GL_TRUE; +} +#else +static GLboolean TAG(check_tex_sizes)( GLcontext *ctx ) +{ + struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - if (DO_TEX1) { - if (VB->TexCoordPtr[0] == 0) - VB->TexCoordPtr[0] = VB->TexCoordPtr[1]; - - if (VB->TexCoordPtr[1]->size == 4) - return GL_FALSE; - } + if (DO_PTEX) + return GL_TRUE; + + /* No hardware support for projective texture. Can fake it for + * TEX0 only. + */ + if ((DO_TEX3 && VB->TexCoordPtr[3]->size == 4) || + (DO_TEX2 && VB->TexCoordPtr[2]->size == 4) || + (DO_TEX1 && VB->TexCoordPtr[1]->size == 4)) { + PTEX_FALLBACK(); + return GL_FALSE; + } - if (VB->TexCoordPtr[0]->size == 4) - return GL_FALSE; + if (DO_TEX0 && VB->TexCoordPtr[0]->size == 4) { + if (DO_TEX1 || DO_TEX2 || DO_TEX3) { + PTEX_FALLBACK(); + } + return GL_FALSE; } return GL_TRUE; } +#endif + + #if (!DO_PTEX || HAVE_PTEX_VERTICES) static void TAG(interp)( GLcontext *ctx, GLfloat t, @@ -394,14 +515,20 @@ static void TAG(interp)( GLcontext *ctx, GLuint shift = GET_VERTEX_STRIDE_SHIFT(); const GLfloat *dstclip = VB->ClipPtr->data[edst]; GLfloat w; + const GLfloat *s = GET_VIEWPORT_MAT(); + + (void)s; VERTEX *dst = (VERTEX *)(ddverts + (edst << shift)); VERTEX *in = (VERTEX *)(ddverts + (eout << shift)); VERTEX *out = (VERTEX *)(ddverts + (ein << shift)); + PREPARE_PROJIN; + PREPARE_PROJOUT; + /* fprintf(stderr, "%s\n", __FUNCTION__); */ - if (!HW_DIVIDE) { + if (!HAVE_HW_DIVIDE) { w = 1.0 / dstclip[3]; VIEWPORT_X( dst->v.x, dstclip[0] * w ); VIEWPORT_Y( dst->v.y, dstclip[1] * w ); @@ -414,9 +541,10 @@ static void TAG(interp)( GLcontext *ctx, w = dstclip[3]; } - if (HW_DIVIDE || DO_FOG || DO_SPEC || DO_TEX0 || DO_TEX1) { + if (HAVE_HW_DIVIDE || DO_FOG || DO_SPEC || DO_TEX0 || DO_TEX1 || + DO_TEX2 || DO_TEX3) { - if (!HW_VIEWPORT || !HW_DIVIDE) + if (!HAVE_HW_VIEWPORT || !HAVE_HW_DIVIDE) dst->v.w = w; INTERP_UB( t, dst->ub4[4][0], out->ub4[4][0], in->ub4[4][0] ); @@ -456,6 +584,26 @@ static void TAG(interp)( GLcontext *ctx, else if (DO_PTEX) { dst->pv.q0 = 0.0; /* must be a valid float on radeon */ } + if (DO_TEX2) { + if (DO_PTEX) { + INTERP_F( t, dst->pv.u2, out->pv.u2, in->pv.u2 ); + INTERP_F( t, dst->pv.v2, out->pv.v2, in->pv.v2 ); + INTERP_F( t, dst->pv.q2, out->pv.q2, in->pv.q2 ); + } else { + INTERP_F( t, dst->v.u2, out->v.u2, in->v.u2 ); + INTERP_F( t, dst->v.v2, out->v.v2, in->v.v2 ); + } + } + if (DO_TEX3) { + if (DO_PTEX) { + INTERP_F( t, dst->pv.u3, out->pv.u3, in->pv.u3 ); + INTERP_F( t, dst->pv.v3, out->pv.v3, in->pv.v3 ); + INTERP_F( t, dst->pv.q3, out->pv.q3, in->pv.q3 ); + } else { + INTERP_F( t, dst->v.u3, out->v.u3, in->v.u3 ); + INTERP_F( t, dst->v.v3, out->v.v3, in->v.v3 ); + } + } } else { /* 4-dword vertex. Color is in v[3] and there is no oow coordinate. */ @@ -465,6 +613,103 @@ static void TAG(interp)( GLcontext *ctx, INTERP_UB( t, dst->ub4[3][3], out->ub4[3][3], in->ub4[3][3] ); } } +#endif + +/* Build an SWvertex from a hardware vertex. + * + * This code is hit only when a mix of accelerated and unaccelerated + * primitives are being drawn, and only for the unaccelerated + * primitives. + */ +static void +TAG(translate_vertex)( GLcontext *ctx, const radeonVertex *src, SWvertex *dst) +{ + HW_CONTEXT; + GLfloat *s = ctx->Viewport._WindowMap.m; + + if (USE_TINY_VERT) { + if (HAVE_HW_VIEWPORT) { + dst->win[0] = s[0] * src->v.x + s[12]; + dst->win[1] = s[5] * src->v.y + s[13]; + dst->win[2] = s[10] * src->v.z + s[14]; + dst->win[3] = 1.0; + } else { + dst->win[0] = ADJ_X(src->v.x); + dst->win[1] = ADJ_Y(src->v.y); + dst->win[2] = ADJ_Z(src->v.z); + dst->win[3] = 1.0; + } + + dst->color[0] = src->tv.color.red; + dst->color[1] = src->tv.color.green; + dst->color[2] = src->tv.color.blue; + dst->color[3] = src->tv.color.alpha; + } + else { + if (HAVE_HW_VIEWPORT) { + if (HAVE_HW_DIVIDE) { + GLfloat oow = 1.0 / src->v.rhw; + dst->win[0] = s[0] * src->v.x * oow + s[12]; + dst->win[1] = s[5] * src->v.y * oow + s[13]; + dst->win[2] = s[10] * src->v.z * oow + s[14]; + dst->win[3] = oow; + } + else { + dst->win[0] = s[0] * src->v.x + s[12]; + dst->win[1] = s[5] * src->v.y + s[13]; + dst->win[2] = s[10] * src->v.z + s[14]; + dst->win[3] = src->v.rhw; + } + } else { + dst->win[0] = ADJ_X(src->v.x); + dst->win[1] = ADJ_Y(src->v.y); + dst->win[2] = ADJ_Z(src->v.z); + dst->win[3] = src->v.rhw; + } + + dst->color[0] = src->v.color.red; + dst->color[1] = src->v.color.green; + dst->color[2] = src->v.color.blue; + dst->color[3] = src->v.color.alpha; + + if (DO_SPEC) { + dst->specular[0] = src->v.specular.red; + dst->specular[1] = src->v.specular.green; + dst->specular[2] = src->v.specular.blue; + } + + if (DO_FOG) { + dst->fog = src->v.color.alpha/255.0; + } + + if (DO_PTEX) { + if (DO_TEX0) { + dst->texcoord[0][0] = src->pv.u0; + dst->texcoord[0][1] = src->pv.v0; + dst->texcoord[0][3] = src->pv.q0; + } + if (DO_TEX1) { + dst->texcoord[1][0] = src->pv.u1; + dst->texcoord[1][1] = src->pv.v1; + dst->texcoord[1][3] = src->pv.q1; + } + } else { + if (DO_TEX0) { + dst->texcoord[0][0] = src->v.u0; + dst->texcoord[0][1] = src->v.v0; + dst->texcoord[0][3] = 1.0; + } + if (DO_TEX1) { + dst->texcoord[1][0] = src->v.u1; + dst->texcoord[1][1] = src->v.v1; + dst->texcoord[1][3] = 1.0; + } + } + } + + dst->pointSize = ctx->Point._Size; +} + #endif #endif @@ -480,36 +725,64 @@ static void TAG(init)( void ) if (DO_SPEC) setup_tab[IND].copy_pv = _tnl_dd_copy_pv_rgba4_spec5; - else if (HW_DIVIDE || DO_SPEC || DO_FOG || DO_TEX0 || DO_TEX1) + else if (HAVE_HW_DIVIDE || DO_SPEC || DO_FOG || DO_TEX0 || DO_TEX1 || + DO_TEX2 || DO_TEX3) setup_tab[IND].copy_pv = _tnl_dd_copy_pv_rgba4; else setup_tab[IND].copy_pv = _tnl_dd_copy_pv_rgba3; - if (DO_TEX1) { + if (DO_TEX3) { + if (DO_PTEX) { + ASSERT(HAVE_PTEX_VERTICES); + setup_tab[IND].vertex_format = PROJ_TEX3_VERTEX_FORMAT; + setup_tab[IND].vertex_size = 18; + setup_tab[IND].vertex_stride_shift = 7; + } + else { + setup_tab[IND].vertex_format = TEX3_VERTEX_FORMAT; + setup_tab[IND].vertex_size = 14; + setup_tab[IND].vertex_stride_shift = 6; + } + } + else if (DO_TEX2) { + if (DO_PTEX) { + ASSERT(HAVE_PTEX_VERTICES); + ASSERT(0); /* issue to resolve: odd vertex size */ + setup_tab[IND].vertex_format = PROJ_TEX3_VERTEX_FORMAT; + setup_tab[IND].vertex_size = 18; + setup_tab[IND].vertex_stride_shift = 7; + } + else { + setup_tab[IND].vertex_format = TEX2_VERTEX_FORMAT; + setup_tab[IND].vertex_size = 12; + setup_tab[IND].vertex_stride_shift = 6; + } + } + else if (DO_TEX1) { if (DO_PTEX) { ASSERT(HAVE_PTEX_VERTICES); - setup_tab[IND].vc_format = PROJ_TEX_VERTEX_FORMAT; + setup_tab[IND].vertex_format = PROJ_TEX1_VERTEX_FORMAT; setup_tab[IND].vertex_size = 12; setup_tab[IND].vertex_stride_shift = 6; } else { - setup_tab[IND].vc_format = TEX1_VERTEX_FORMAT; + setup_tab[IND].vertex_format = TEX1_VERTEX_FORMAT; setup_tab[IND].vertex_size = 10; setup_tab[IND].vertex_stride_shift = 6; } } else if (DO_TEX0) { if (DO_PTEX && HAVE_PTEX_VERTICES) { - setup_tab[IND].vc_format = PROJ_TEX_VERTEX_FORMAT; + setup_tab[IND].vertex_format = PROJ_TEX1_VERTEX_FORMAT; setup_tab[IND].vertex_size = 12; setup_tab[IND].vertex_stride_shift = 6; } else { - setup_tab[IND].vc_format = TEX0_VERTEX_FORMAT; + setup_tab[IND].vertex_format = TEX0_VERTEX_FORMAT; setup_tab[IND].vertex_size = 8; setup_tab[IND].vertex_stride_shift = 5; } } - else if (!HW_DIVIDE && !DO_SPEC && !DO_FOG && HAVE_TINY_VERTICES) { + else if (!HAVE_HW_DIVIDE && !DO_SPEC && !DO_FOG && HAVE_TINY_VERTICES) { setup_tab[IND].vertex_format = TINY_VERTEX_FORMAT; setup_tab[IND].vertex_size = 4; setup_tab[IND].vertex_stride_shift = 4; @@ -518,7 +791,7 @@ static void TAG(init)( void ) setup_tab[IND].vertex_size = 6; setup_tab[IND].vertex_stride_shift = 5; } else { - setup_tab[IND].vc_format = TEX0_VERTEX_FORMAT; + setup_tab[IND].vertex_format = TEX0_VERTEX_FORMAT; setup_tab[IND].vertex_size = 8; setup_tab[IND].vertex_stride_shift = 5; } diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h index bfe3d3a50e..5604269e59 100644 --- a/src/mesa/main/dd.h +++ b/src/mesa/main/dd.h @@ -1,4 +1,4 @@ -/* $Id: dd.h,v 1.53 2001/02/19 20:02:37 brianp Exp $ */ +/* $Id: dd.h,v 1.54 2001/02/24 18:25:52 keithw Exp $ */ /* * Mesa 3-D graphics library @@ -70,17 +70,13 @@ struct gl_pixelstore_attrib; * the driver-specific context struct. See the X/Mesa or OS/Mesa interface * for an example. * - * For more information about writing a device driver see the ddsample.c - * file and other device drivers (X/xmesa[1234].c, OSMesa/osmesa.c, etc) - * for examples. - * + * For more information about writing a device driver see the drivers + * in OSmesa/ and X/ for examples. * * Look below in the dd_function_table struct definition for descriptions * of each device driver function. * - * - * In the future more function pointers may be added for glReadPixels - * glCopyPixels, etc. + * More function pointers may be added as required. * * * Notes: @@ -852,7 +848,9 @@ struct dd_function_table { render_func *RenderTabVerts; render_func *RenderTabElts; - /* XXX Description??? + /* Render whole unclipped primitives (points, lines, linestrips, + * lineloops, etc). The tables are indexed by the GL enum of the + * primitive to be rendered. */ void (*ResetLineStipple)( GLcontext *ctx ); @@ -1053,13 +1051,11 @@ typedef struct { * * Mesa will provide a set of helper functions to do eval within * accelerated vertex formats, eventually... - * - * Update: There seem to be issues re. maintaining correct values - * for 'ctx->Current' in the face of Eval and T&L fallbacks... */ GLboolean prefer_float_colors; - /* Should core send non-standard colors to glColor4f or glColor4ub + /* Should core try to send colors to glColor4f or glColor4chan, + * where it has a choice? */ diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c index 4f4ea3ee95..6f7ad2a4da 100644 --- a/src/mesa/swrast/s_context.c +++ b/src/mesa/swrast/s_context.c @@ -1,4 +1,4 @@ -/* $Id: s_context.c,v 1.14 2001/02/16 18:56:46 keithw Exp $ */ +/* $Id: s_context.c,v 1.15 2001/02/24 18:25:52 keithw Exp $ */ /* * Mesa 3-D graphics library @@ -102,13 +102,6 @@ _swrast_update_rasterflags( GLcontext *ctx ) RasterMask |= MULTI_DRAW_BIT; /* all color index bits disabled */ } - if ( ctx->Viewport.X<0 - || ctx->Viewport.X + ctx->Viewport.Width > ctx->DrawBuffer->Width - || ctx->Viewport.Y<0 - || ctx->Viewport.Y + ctx->Viewport.Height > ctx->DrawBuffer->Height) { - RasterMask |= WINCLIP_BIT; - } - SWRAST_CONTEXT(ctx)->_RasterMask = RasterMask; } -- cgit v1.2.3