Templates are in working order.

This commit is contained in:
Keith Whitwell
2001-02-28 18:19:27 +00:00
parent be3602da41
commit feb555af03
5 changed files with 596 additions and 285 deletions

View File

@@ -39,14 +39,21 @@
* render the primitive natively. * render the primitive natively.
*/ */
#if !defined(HAVE_TRI_STRIPS) || !defined(HAVE_TRIANGLES) #if !defined(HAVE_TRIANGLES)
#error "must have at least tristrips and triangles to use render template" #error "must have at least triangles to use render template"
#endif #endif
#if !HAVE_ELTS #if !HAVE_ELTS
#define ALLOC_ELTS( nr ) #define ALLOC_ELTS( nr )
#define EMIT_ELT( offset, elt ) #define EMIT_ELT( offset, elt )
#define INCR_ELTS( nr ) #define INCR_ELTS( nr )
#define ELT_INIT(prim)
#define GET_CURRENT_VB_MAX_ELTS() 0
#define GET_SUBSEQUENT_VB_MAX_ELTS() 0
#define ALLOC_ELTS_NEW_PRIMITIVE(nr)
#define RELEASE_ELT_VERTS()
#define EMIT_INDEXED_VERTS( ctx, start, count )
#endif #endif
#ifndef EMIT_TWO_ELTS #ifndef EMIT_TWO_ELTS
@@ -67,9 +74,12 @@ static GLboolean TAG(emit_elt_verts)( GLcontext *ctx,
GLuint start, GLuint count ) GLuint start, GLuint count )
{ {
if (HAVE_ELTS) { if (HAVE_ELTS) {
LOCAL_VARS;
GLuint nr = count - start; GLuint nr = count - start;
if ( nr >= GET_SUBSEQUENT_VB_MAX_VERTS() ) if ( nr >= GET_SUBSEQUENT_VB_MAX_VERTS() ) /* assumes same packing for
* indexed and regualar verts
*/
return GL_FALSE; return GL_FALSE;
NEW_PRIMITIVE(); /* finish last prim */ NEW_PRIMITIVE(); /* finish last prim */
@@ -80,10 +90,11 @@ static GLboolean TAG(emit_elt_verts)( GLcontext *ctx,
} }
} }
#if (HAVE_ELTS)
static void TAG(emit_elts)( GLcontext *ctx, GLuint *elts, GLuint nr ) static void TAG(emit_elts)( GLcontext *ctx, GLuint *elts, GLuint nr )
{ {
GLushort *dest;
GLint i; GLint i;
LOCAL_VARS;
ELTS_VARS; ELTS_VARS;
ALLOC_ELTS( nr ); ALLOC_ELTS( nr );
@@ -93,6 +104,7 @@ static void TAG(emit_elts)( GLcontext *ctx, GLuint *elts, GLuint nr )
INCR_ELTS( 2 ); INCR_ELTS( 2 );
} }
} }
#endif
/*********************************************************************** /***********************************************************************
@@ -107,6 +119,7 @@ static void TAG(render_points_verts)( GLcontext *ctx,
GLuint flags ) GLuint flags )
{ {
if (HAVE_POINTS) { if (HAVE_POINTS) {
LOCAL_VARS;
int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS(); int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
int currentsz = GET_CURRENT_VB_MAX_VERTS(); int currentsz = GET_CURRENT_VB_MAX_VERTS();
GLuint j, nr; GLuint j, nr;
@@ -122,7 +135,7 @@ static void TAG(render_points_verts)( GLcontext *ctx,
currentsz = dmasz; currentsz = dmasz;
} }
} else { } else {
FALLBACK( ctx, start, count, flags ); VERT_FALLBACK( ctx, start, count, flags );
} }
} }
@@ -132,6 +145,7 @@ static void TAG(render_lines_verts)( GLcontext *ctx,
GLuint flags ) GLuint flags )
{ {
if (HAVE_LINES) { if (HAVE_LINES) {
LOCAL_VARS;
int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS(); int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
int currentsz = GET_CURRENT_VB_MAX_VERTS(); int currentsz = GET_CURRENT_VB_MAX_VERTS();
GLuint j, nr; GLuint j, nr;
@@ -153,7 +167,7 @@ static void TAG(render_lines_verts)( GLcontext *ctx,
currentsz = dmasz; currentsz = dmasz;
} }
} else { } else {
FALLBACK( ctx, start, count, flags ); VERT_FALLBACK( ctx, start, count, flags );
} }
} }
@@ -164,6 +178,7 @@ static void TAG(render_line_strip_verts)( GLcontext *ctx,
GLuint flags ) GLuint flags )
{ {
if (HAVE_LINE_STRIPS) { if (HAVE_LINE_STRIPS) {
LOCAL_VARS;
int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS(); int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
int currentsz = GET_CURRENT_VB_MAX_VERTS(); int currentsz = GET_CURRENT_VB_MAX_VERTS();
GLuint j, nr; GLuint j, nr;
@@ -180,7 +195,7 @@ static void TAG(render_line_strip_verts)( GLcontext *ctx,
currentsz = dmasz; currentsz = dmasz;
} }
} else { } else {
FALLBACK( ctx, start, count, flags ); VERT_FALLBACK( ctx, start, count, flags );
} }
} }
@@ -191,6 +206,7 @@ static void TAG(render_line_loop_verts)( GLcontext *ctx,
GLuint flags ) GLuint flags )
{ {
if (HAVE_LINE_STRIPS) { if (HAVE_LINE_STRIPS) {
LOCAL_VARS;
int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS(); int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
int currentsz = GET_CURRENT_VB_MAX_VERTS(); int currentsz = GET_CURRENT_VB_MAX_VERTS();
GLuint j, nr; GLuint j, nr;
@@ -221,7 +237,7 @@ static void TAG(render_line_loop_verts)( GLcontext *ctx,
EMIT_VERTS( ctx, start, 1 ); EMIT_VERTS( ctx, start, 1 );
} else { } else {
FALLBACK( ctx, start, count, flags ); VERT_FALLBACK( ctx, start, count, flags );
} }
} }
@@ -231,6 +247,7 @@ static void TAG(render_triangles_verts)( GLcontext *ctx,
GLuint count, GLuint count,
GLuint flags ) GLuint flags )
{ {
LOCAL_VARS;
int dmasz = (GET_SUBSEQUENT_VB_MAX_VERTS()/3) * 3; int dmasz = (GET_SUBSEQUENT_VB_MAX_VERTS()/3) * 3;
int currentsz = (GET_CURRENT_VB_MAX_VERTS()/3) * 3; int currentsz = (GET_CURRENT_VB_MAX_VERTS()/3) * 3;
GLuint j, nr; GLuint j, nr;
@@ -259,37 +276,42 @@ static void TAG(render_tri_strip_verts)( GLcontext *ctx,
GLuint count, GLuint count,
GLuint flags ) GLuint flags )
{ {
GLuint j, nr; if (HAVE_TRI_STRIPS) {
int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS(); LOCAL_VARS;
int currentsz; GLuint j, nr;
int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
int currentsz;
INIT(GL_TRIANGLE_STRIP); INIT(GL_TRIANGLE_STRIP);
NEW_PRIMITIVE(); NEW_PRIMITIVE();
currentsz = GET_CURRENT_VB_MAX_VERTS(); currentsz = GET_CURRENT_VB_MAX_VERTS();
if (currentsz < 8) { if (currentsz < 8) {
FIRE_VERTICES( ctx ); FIRE_VERTICES();
currentsz = dmasz; currentsz = dmasz;
}
if (flags & PRIM_PARITY) {
if (HAVE_TRI_STRIP_1 && 0) {
} else {
EMIT_VERTS( ctx, start, 1 );
currentsz--;
} }
}
/* From here on emit even numbers of tris when wrapping over buffers: if (flags & PRIM_PARITY) {
*/ if (HAVE_TRI_STRIP_1 && 0) {
dmasz -= (dmasz & 1); } else {
currentsz -= (currentsz & 1); EMIT_VERTS( ctx, start, 1 );
currentsz--;
}
}
for (j = start ; j < count - 2; j += nr - 2 ) { /* From here on emit even numbers of tris when wrapping over buffers:
nr = MIN2( currentsz, count - j ); */
EMIT_VERTS( ctx, j, nr ); dmasz -= (dmasz & 1);
currentsz = dmasz; currentsz -= (currentsz & 1);
for (j = start ; j < count - 2; j += nr - 2 ) {
nr = MIN2( currentsz, count - j );
EMIT_VERTS( ctx, j, nr );
currentsz = dmasz;
}
} else {
VERT_FALLBACK( ctx, start, count, flags );
} }
} }
@@ -298,7 +320,8 @@ static void TAG(render_tri_fan_verts)( GLcontext *ctx,
GLuint count, GLuint count,
GLuint flags ) GLuint flags )
{ {
if (HAVE_TRI_FAN) { if (HAVE_TRI_FANS) {
LOCAL_VARS;
GLuint j, nr; GLuint j, nr;
int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS(); int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
int currentsz = GET_CURRENT_VB_MAX_VERTS(); int currentsz = GET_CURRENT_VB_MAX_VERTS();
@@ -307,7 +330,7 @@ static void TAG(render_tri_fan_verts)( GLcontext *ctx,
INIT(GL_TRIANGLE_FAN); INIT(GL_TRIANGLE_FAN);
if (currentsz < 8) { if (currentsz < 8) {
FIRE_VERTICES( ctx ); FIRE_VERTICES();
currentsz = dmasz; currentsz = dmasz;
} }
@@ -322,7 +345,7 @@ static void TAG(render_tri_fan_verts)( GLcontext *ctx,
/* Could write code to emit these as indexed vertices (for the /* Could write code to emit these as indexed vertices (for the
* g400, for instance). * g400, for instance).
*/ */
FALLBACK( ctx, start, count, flags ); VERT_FALLBACK( ctx, start, count, flags );
} }
} }
@@ -332,7 +355,8 @@ static void TAG(render_poly_verts)( GLcontext *ctx,
GLuint count, GLuint count,
GLuint flags ) GLuint flags )
{ {
if (HAVE_POLYGON) { if (HAVE_POLYGONS) {
LOCAL_VARS;
GLuint j, nr; GLuint j, nr;
int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS(); int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
int currentsz = GET_CURRENT_VB_MAX_VERTS(); int currentsz = GET_CURRENT_VB_MAX_VERTS();
@@ -341,7 +365,7 @@ static void TAG(render_poly_verts)( GLcontext *ctx,
INIT(GL_POLYGON); INIT(GL_POLYGON);
if (currentsz < 8) { if (currentsz < 8) {
FIRE_VERTICES( ctx ); FIRE_VERTICES();
currentsz = dmasz; currentsz = dmasz;
} }
@@ -352,10 +376,10 @@ static void TAG(render_poly_verts)( GLcontext *ctx,
currentsz = dmasz; currentsz = dmasz;
} }
} }
else if (HAVE_TRIFAN && !(ctx->TriangleCaps & DD_FLATSHADE)) { else if (HAVE_TRI_FANS && !(ctx->_TriangleCaps & DD_FLATSHADE)) {
TAG(render_tri_fan_verts)( ctx, start, count, flags ); TAG(render_tri_fan_verts)( ctx, start, count, flags );
} else { } else {
FALLBACK( ctx, start, count, flags ); VERT_FALLBACK( ctx, start, count, flags );
} }
} }
@@ -370,8 +394,9 @@ static void TAG(render_quad_strip_verts)( GLcontext *ctx,
/* TODO. /* TODO.
*/ */
} else if (ctx->_TriangleCaps & DD_FLATSHADE) { } else if (ctx->_TriangleCaps & DD_FLATSHADE) {
if (emit_elt_verts( ctx, start, count )) { if (TAG(emit_elt_verts)( ctx, start, count )) {
int dmasz = SUBSEQUENT_VB_ELT_NR(); LOCAL_VARS;
int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
int currentsz; int currentsz;
GLuint j, nr; GLuint j, nr;
@@ -380,7 +405,7 @@ static void TAG(render_quad_strip_verts)( GLcontext *ctx,
NEW_PRIMITIVE(); NEW_PRIMITIVE();
ELT_INIT( GL_TRIANGLES ); ELT_INIT( GL_TRIANGLES );
currentsz = CURRENT_VB_ELT_NR_NEW_PRIMITIVE(); currentsz = GET_CURRENT_VB_MAX_ELTS();
/* Emit whole number of quads in total, and in each buffer. /* Emit whole number of quads in total, and in each buffer.
*/ */
@@ -420,14 +445,15 @@ static void TAG(render_quad_strip_verts)( GLcontext *ctx,
} }
else { else {
/* Vertices won't fit in a single buffer or elts not available, /* Vertices won't fit in a single buffer or elts not available,
* fallback. * VERT_FALLBACK.
*/ */
FALLBACK( ctx, start, count, flags ); VERT_FALLBACK( ctx, start, count, flags );
} }
} }
else { else if (HAVE_TRI_STRIPS) {
int dmasz = GET_SUBSEQUENT_VB_SIZE(); LOCAL_VARS;
int currentsz = GET_CURRENT_VB_SIZE(); int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
int currentsz = GET_CURRENT_VB_MAX_VERTS();
/* Emit smooth-shaded quadstrips as tristrips: /* Emit smooth-shaded quadstrips as tristrips:
*/ */
@@ -441,7 +467,7 @@ static void TAG(render_quad_strip_verts)( GLcontext *ctx,
count -= (count-start) & 1; count -= (count-start) & 1;
if (currentsz < 8) { if (currentsz < 8) {
FIRE_VERTICES( ctx ); FIRE_VERTICES();
currentsz = dmasz; currentsz = dmasz;
} }
@@ -450,6 +476,8 @@ static void TAG(render_quad_strip_verts)( GLcontext *ctx,
EMIT_VERTS( ctx, j, nr ); EMIT_VERTS( ctx, j, nr );
currentsz = dmasz; currentsz = dmasz;
} }
} else {
VERT_FALLBACK( ctx, start, count, flags );
} }
} }
@@ -460,18 +488,19 @@ static void TAG(render_quads_verts)( GLcontext *ctx,
GLuint flags ) GLuint flags )
{ {
if (HAVE_QUADS && 0) { if (HAVE_QUADS && 0) {
} else if (emit_elt_verts( ctx, start, count )) { } else if (TAG(emit_elt_verts)( ctx, start, count )) {
/* Hardware doesn't have a quad primitive type -- try to /* Hardware doesn't have a quad primitive type -- try to
* simulate it using indexed vertices and the triangle * simulate it using indexed vertices and the triangle
* primitive: * primitive:
*/ */
LOCAL_VARS;
int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS(); int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
int currentsz; int currentsz;
GLuint j, nr; GLuint j, nr;
NEW_PRIMITIVE(); NEW_PRIMITIVE();
ELT_INIT( GL_TRIANGLES ); ELT_INIT( GL_TRIANGLES );
currentsz = GET_CURRENT_VB_MAX_ELTS_NEW_PRIM(); currentsz = GET_CURRENT_VB_MAX_ELTS();
/* Emit whole number of quads in total, and in each buffer. /* Emit whole number of quads in total, and in each buffer.
*/ */
@@ -514,7 +543,7 @@ static void TAG(render_quads_verts)( GLcontext *ctx,
else { else {
/* Vertices won't fit in a single buffer, fallback. /* Vertices won't fit in a single buffer, fallback.
*/ */
FALLBACK( ctx, start, count, flags ); VERT_FALLBACK( ctx, start, count, flags );
} }
} }
@@ -528,8 +557,7 @@ static void TAG(render_noop)( GLcontext *ctx,
static void (*TAG(render_tab_verts))( GLcontext *, GLuint, static render_func TAG(render_tab_verts)[GL_POLYGON+2] =
GLuint, GLuint)[GL_POLYGON+2] =
{ {
TAG(render_points_verts), TAG(render_points_verts),
TAG(render_lines_verts), TAG(render_lines_verts),
@@ -556,6 +584,7 @@ static void TAG(render_points_elts)( GLcontext *ctx,
GLuint flags ) GLuint flags )
{ {
if (HAVE_POINTS) { if (HAVE_POINTS) {
LOCAL_VARS;
int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS(); int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
int currentsz; int currentsz;
GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts; GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
@@ -569,7 +598,7 @@ static void TAG(render_points_elts)( GLcontext *ctx,
for (j = start; j < count; j += nr ) { for (j = start; j < count; j += nr ) {
nr = MIN2( currentsz, count - j ); nr = MIN2( currentsz, count - j );
emit_elts( ctx, elts+j, nr ); TAG(emit_elts)( ctx, elts+j, nr );
NEW_PRIMITIVE(); NEW_PRIMITIVE();
currentsz = dmasz; currentsz = dmasz;
} }
@@ -586,6 +615,7 @@ static void TAG(render_lines_elts)( GLcontext *ctx,
GLuint flags ) GLuint flags )
{ {
if (HAVE_LINES) { if (HAVE_LINES) {
LOCAL_VARS;
int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS(); int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
int currentsz; int currentsz;
GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts; GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
@@ -605,7 +635,7 @@ static void TAG(render_lines_elts)( GLcontext *ctx,
for (j = start; j < count; j += nr ) { for (j = start; j < count; j += nr ) {
nr = MIN2( currentsz, count - j ); nr = MIN2( currentsz, count - j );
emit_elts( ctx, elts+j, nr ); TAG(emit_elts)( ctx, elts+j, nr );
NEW_PRIMITIVE(); NEW_PRIMITIVE();
currentsz = dmasz; currentsz = dmasz;
} }
@@ -621,6 +651,7 @@ static void TAG(render_line_strip_elts)( GLcontext *ctx,
GLuint flags ) GLuint flags )
{ {
if (HAVE_LINE_STRIPS) { if (HAVE_LINE_STRIPS) {
LOCAL_VARS;
int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS(); int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
int currentsz; int currentsz;
GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts; GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
@@ -629,13 +660,13 @@ static void TAG(render_line_strip_elts)( GLcontext *ctx,
NEW_PRIMITIVE(); /* always a new primitive */ NEW_PRIMITIVE(); /* always a new primitive */
ELT_INIT( GL_LINE_STRIP ); ELT_INIT( GL_LINE_STRIP );
currentsz = GET_CURRENT_VB_MAX_ELTS_NEW_PRIM(); currentsz = GET_CURRENT_VB_MAX_ELTS();
if (currentsz < 8) if (currentsz < 8)
currentsz = dmasz; currentsz = dmasz;
for (j = start; j < count - 1; j += nr - 1 ) { for (j = start; j < count - 1; j += nr - 1 ) {
nr = MIN2( currentsz, count - j ); nr = MIN2( currentsz, count - j );
emit_elts( ctx, elts+j, nr ); TAG(emit_elts)( ctx, elts+j, nr );
NEW_PRIMITIVE(); NEW_PRIMITIVE();
currentsz = dmasz; currentsz = dmasz;
} }
@@ -653,6 +684,7 @@ static void TAG(render_line_loop_elts)( GLcontext *ctx,
GLuint flags ) GLuint flags )
{ {
if (HAVE_LINE_STRIPS) { if (HAVE_LINE_STRIPS) {
LOCAL_VARS;
int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS(); int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
int currentsz; int currentsz;
GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts; GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
@@ -666,9 +698,9 @@ static void TAG(render_line_loop_elts)( GLcontext *ctx,
else else
j = start + 1; j = start + 1;
currentsz = GET_CURRENT_VB_MAX_ELTS_NEW_PRIM(); currentsz = GET_CURRENT_VB_MAX_ELTS();
if (currentsz < 8) { if (currentsz < 8) {
FIRE_VERTICES( ctx ); FIRE_VERTICES();
currentsz = dmasz; currentsz = dmasz;
} }
@@ -680,12 +712,12 @@ static void TAG(render_line_loop_elts)( GLcontext *ctx,
for ( ; j < count - 1; j += nr - 1 ) { for ( ; j < count - 1; j += nr - 1 ) {
nr = MIN2( currentsz, count - j ); nr = MIN2( currentsz, count - j );
/* NEW_PRIMITIVE(); */ /* NEW_PRIMITIVE(); */
emit_elts( ctx, elts+j, nr ); TAG(emit_elts)( ctx, elts+j, nr );
currentsz = dmasz; currentsz = dmasz;
} }
if (flags & PRIM_END) if (flags & PRIM_END)
emit_elts( ctx, elts+start, 1 ); TAG(emit_elts)( ctx, elts+start, 1 );
NEW_PRIMITIVE(); NEW_PRIMITIVE();
} else { } else {
@@ -704,6 +736,7 @@ static void TAG(render_triangles_elts)( GLcontext *ctx,
GLuint count, GLuint count,
GLuint flags ) GLuint flags )
{ {
LOCAL_VARS;
GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts; GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS()/3*3; int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS()/3*3;
int currentsz; int currentsz;
@@ -712,7 +745,7 @@ static void TAG(render_triangles_elts)( GLcontext *ctx,
NEW_PRIMITIVE(); NEW_PRIMITIVE();
ELT_INIT( GL_TRIANGLES ); ELT_INIT( GL_TRIANGLES );
currentsz = GET_CURRENT_VB_MAX_ELTS_NEW_PRIM(); currentsz = GET_CURRENT_VB_MAX_ELTS();
/* Emit whole number of tris in total. dmasz is already a multiple /* Emit whole number of tris in total. dmasz is already a multiple
* of 3. * of 3.
@@ -724,7 +757,7 @@ static void TAG(render_triangles_elts)( GLcontext *ctx,
for (j = start; j < count; j += nr) { for (j = start; j < count; j += nr) {
nr = MIN2( currentsz, count - j ); nr = MIN2( currentsz, count - j );
emit_elts( ctx, elts+j, nr ); TAG(emit_elts)( ctx, elts+j, nr );
NEW_PRIMITIVE(); NEW_PRIMITIVE();
currentsz = dmasz; currentsz = dmasz;
} }
@@ -737,34 +770,40 @@ static void TAG(render_tri_strip_elts)( GLcontext *ctx,
GLuint count, GLuint count,
GLuint flags ) GLuint flags )
{ {
GLuint j, nr; if (HAVE_TRI_STRIPS) {
GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts; LOCAL_VARS;
int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS(); GLuint j, nr;
int currentsz; GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
int currentsz;
NEW_PRIMITIVE();
ELT_INIT( GL_TRIANGLE_STRIP );
currentsz = GET_CURRENT_VB_MAX_ELTS_NEW_PRIM();
if (currentsz < 8) {
FIRE_VERTICES( ctx );
currentsz = dmasz;
}
if (flags & PRIM_PARITY) {
emit_elts( ctx, elts+start, 1 );
}
/* Keep the same winding over multiple buffers:
*/
dmasz -= (dmasz & 1);
currentsz -= (currentsz & 1);
for (j = start ; j < count - 2; j += nr - 2 ) {
nr = MIN2( currentsz, count - j );
emit_elts( ctx, elts+j, nr );
NEW_PRIMITIVE(); NEW_PRIMITIVE();
currentsz = dmasz; ELT_INIT( GL_TRIANGLE_STRIP );
currentsz = GET_CURRENT_VB_MAX_ELTS();
if (currentsz < 8) {
FIRE_VERTICES();
currentsz = dmasz;
}
if (flags & PRIM_PARITY) {
TAG(emit_elts)( ctx, elts+start, 1 );
}
/* Keep the same winding over multiple buffers:
*/
dmasz -= (dmasz & 1);
currentsz -= (currentsz & 1);
for (j = start ; j < count - 2; j += nr - 2 ) {
nr = MIN2( currentsz, count - j );
TAG(emit_elts)( ctx, elts+j, nr );
NEW_PRIMITIVE();
currentsz = dmasz;
}
} else {
/* TODO: try to emit as indexed triangles */
ELT_FALLBACK( ctx, start, count, flags );
} }
} }
@@ -773,7 +812,8 @@ static void TAG(render_tri_fan_elts)( GLcontext *ctx,
GLuint count, GLuint count,
GLuint flags ) GLuint flags )
{ {
if (HAVE_TRI_FAN) { if (HAVE_TRI_FANS) {
LOCAL_VARS;
GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts; GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
GLuint j, nr; GLuint j, nr;
int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS(); int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
@@ -782,16 +822,16 @@ static void TAG(render_tri_fan_elts)( GLcontext *ctx,
NEW_PRIMITIVE(); NEW_PRIMITIVE();
ELT_INIT( GL_TRIANGLE_FAN ); ELT_INIT( GL_TRIANGLE_FAN );
currentsz = GET_CURRENT_VB_MAX_ELTS_NEW_PRIM(); currentsz = GET_CURRENT_VB_MAX_ELTS();
if (currentsz < 8) { if (currentsz < 8) {
FIRE_VERTICES( ctx ); FIRE_VERTICES();
currentsz = dmasz; currentsz = dmasz;
} }
for (j = start + 1 ; j < count - 1; j += nr - 1 ) { for (j = start + 1 ; j < count - 1; j += nr - 1 ) {
nr = MIN2( currentsz, count - j + 1 ); nr = MIN2( currentsz, count - j + 1 );
emit_elts( ctx, elts+start, 1 ); TAG(emit_elts)( ctx, elts+start, 1 );
emit_elts( ctx, elts+j, nr - 1 ); TAG(emit_elts)( ctx, elts+j, nr - 1 );
NEW_PRIMITIVE(); NEW_PRIMITIVE();
currentsz = dmasz; currentsz = dmasz;
} }
@@ -807,8 +847,9 @@ static void TAG(render_poly_elts)( GLcontext *ctx,
GLuint count, GLuint count,
GLuint flags ) GLuint flags )
{ {
if (HAVE_POLYGON && 0) { if (HAVE_POLYGONS && 0) {
} else if (HAVE_TRI_FAN && !(ctx->_TriangleCaps & DD_FLATSHADE)) { } else if (HAVE_TRI_FANS && !(ctx->_TriangleCaps & DD_FLATSHADE)) {
LOCAL_VARS;
GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts; GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
GLuint j, nr; GLuint j, nr;
int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS(); int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
@@ -817,16 +858,16 @@ static void TAG(render_poly_elts)( GLcontext *ctx,
NEW_PRIMITIVE(); NEW_PRIMITIVE();
ELT_INIT( GL_TRIANGLE_FAN ); ELT_INIT( GL_TRIANGLE_FAN );
currentsz = GET_CURRENT_VB_MAX_ELTS_NEW_PRIM(); currentsz = GET_CURRENT_VB_MAX_ELTS();
if (currentsz < 8) { if (currentsz < 8) {
FIRE_VERTICES( ctx ); FIRE_VERTICES();
currentsz = dmasz; currentsz = dmasz;
} }
for (j = start + 1 ; j < count - 1 ; j += nr - 1 ) { for (j = start + 1 ; j < count - 1 ; j += nr - 1 ) {
nr = MIN2( currentsz, count - j + 1 ); nr = MIN2( currentsz, count - j + 1 );
emit_elts( ctx, elts+start, 1 ); TAG(emit_elts)( ctx, elts+start, 1 );
emit_elts( ctx, elts+j, nr - 1 ); TAG(emit_elts)( ctx, elts+j, nr - 1 );
NEW_PRIMITIVE(); NEW_PRIMITIVE();
currentsz = dmasz; currentsz = dmasz;
} }
@@ -842,13 +883,14 @@ static void TAG(render_quad_strip_elts)( GLcontext *ctx,
{ {
if (HAVE_QUAD_STRIPS && 0) { if (HAVE_QUAD_STRIPS && 0) {
} else { } else {
LOCAL_VARS;
GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts; GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS(); int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
int currentsz; int currentsz;
GLuint j, nr; GLuint j, nr;
NEW_PRIMITIVE(); NEW_PRIMITIVE();
currentsz = GET_CURRENT_VB_MAX_ELTS_NEW_PRIM(); currentsz = GET_CURRENT_VB_MAX_ELTS();
/* Emit whole number of quads in total, and in each buffer. /* Emit whole number of quads in total, and in each buffer.
*/ */
@@ -896,7 +938,7 @@ static void TAG(render_quad_strip_elts)( GLcontext *ctx,
for (j = start; j < count - 3; j += nr - 2 ) { for (j = start; j < count - 3; j += nr - 2 ) {
nr = MIN2( currentsz, count - j ); nr = MIN2( currentsz, count - j );
emit_elts( ctx, elts+j, nr ); TAG(emit_elts)( ctx, elts+j, nr );
NEW_PRIMITIVE(); NEW_PRIMITIVE();
currentsz = dmasz; currentsz = dmasz;
} }
@@ -912,13 +954,14 @@ static void TAG(render_quads_elts)( GLcontext *ctx,
{ {
if (HAVE_QUADS && 0) { if (HAVE_QUADS && 0) {
} else { } else {
LOCAL_VARS;
GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts; GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS(); int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
int currentsz; int currentsz;
GLuint j, nr; GLuint j, nr;
ELT_INIT( GL_TRIANGLES ); ELT_INIT( GL_TRIANGLES );
currentsz = GET_CURRENT_VB_MAX_ELTS_NEW_PRIM(); currentsz = GET_CURRENT_VB_MAX_ELTS();
/* Emit whole number of quads in total, and in each buffer. /* Emit whole number of quads in total, and in each buffer.
*/ */
@@ -961,8 +1004,7 @@ static void TAG(render_quads_elts)( GLcontext *ctx,
static void (*TAG(render_tab_verts))( GLcontext *, GLuint, static render_func TAG(render_tab_elts)[GL_POLYGON+2] =
GLuint, GLuint)[GL_POLYGON+2] =
{ {
TAG(render_points_elts), TAG(render_points_elts),
TAG(render_lines_elts), TAG(render_lines_elts),

View File

@@ -88,6 +88,8 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
GLuint facing; GLuint facing;
LOCAL_VARS(3); LOCAL_VARS(3);
/* fprintf(stderr, "%s\n", __FUNCTION__); */
v[0] = (VERTEX *)GET_VERTEX(e0); v[0] = (VERTEX *)GET_VERTEX(e0);
v[1] = (VERTEX *)GET_VERTEX(e1); v[1] = (VERTEX *)GET_VERTEX(e1);
v[2] = (VERTEX *)GET_VERTEX(e2); v[2] = (VERTEX *)GET_VERTEX(e2);

View File

@@ -1,4 +1,224 @@
/* /*
* Mesa 3-D graphics library
* Version: 3.5
*
* Copyright (C) 1999 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Author:
* Keith Whitwell <keithw@valinux.com>
*/ */
#if (HAVE_HW_VIEWPORT)
#define UNVIEWPORT_VARS
#define UNVIEWPORT_X(x) x
#define UNVIEWPORT_Y(x) x
#define UNVIEWPORT_Z(x) x
#endif
/* These don't need to be duplicated, but there's currently nowhere
* really convenient to put them. Need to build some actual .o files in
* this directory?
*/
static void copy_pv_rgba4_spec5( GLcontext *ctx, GLuint edst, GLuint esrc )
{
GLubyte *verts = GET_VERTEX_STORE();
GLuint shift = GET_VERTEX_STRIDE_SHIFT();
GLuint *dst = (GLuint *)(verts + (edst << shift));
GLuint *src = (GLuint *)(verts + (esrc << shift));
dst[4] = src[4];
dst[5] = src[5];
}
static void copy_pv_rgba4( GLcontext *ctx, GLuint edst, GLuint esrc )
{
GLubyte *verts = GET_VERTEX_STORE();
GLuint shift = GET_VERTEX_STRIDE_SHIFT();
GLuint *dst = (GLuint *)(verts + (edst << shift));
GLuint *src = (GLuint *)(verts + (esrc << shift));
dst[4] = src[4];
}
static void copy_pv_rgba3( GLcontext *ctx, GLuint edst, GLuint esrc )
{
GLubyte *verts = GET_VERTEX_STORE();
GLuint shift = GET_VERTEX_STRIDE_SHIFT();
GLuint *dst = (GLuint *)(verts + (edst << shift));
GLuint *src = (GLuint *)(verts + (esrc << shift));
dst[3] = src[3];
}
void TAG(translate_vertex)(GLcontext *ctx,
const VERTEX *src,
SWvertex *dst)
{
GLuint format = GET_VERTEX_FORMAT();
GLfloat *s = ctx->Viewport._WindowMap.m;
UNVIEWPORT_VARS;
if (format == TINY_VERTEX_FORMAT) {
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;
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 {
GLfloat oow = (HAVE_HW_DIVIDE) ? 1.0 / src->v.w : src->v.w;
if (HAVE_HW_VIEWPORT) {
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] = UNVIEWPORT_X( src->v.x );
dst->win[1] = UNVIEWPORT_Y( src->v.y );
dst->win[2] = UNVIEWPORT_Z( src->v.z );
dst->win[3] = 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;
dst->specular[0] = src->v.specular.red;
dst->specular[1] = src->v.specular.green;
dst->specular[2] = src->v.specular.blue;
dst->fog = src->v.color.alpha/255.0;
if (HAVE_PTEX_VERTICES &&
((HAVE_TEX2_VERTICES && format == PROJ_TEX3_VERTEX_FORMAT) ||
(format == PROJ_TEX1_VERTEX_FORMAT))) {
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;
if (HAVE_TEX2_VERTICES) {
dst->texcoord[2][0] = src->pv.u2;
dst->texcoord[2][1] = src->pv.v2;
dst->texcoord[2][3] = src->pv.q2;
}
if (HAVE_TEX3_VERTICES) {
dst->texcoord[3][0] = src->pv.u3;
dst->texcoord[3][1] = src->pv.v3;
dst->texcoord[3][3] = src->pv.q3;
}
}
else {
dst->texcoord[0][0] = src->v.u0;
dst->texcoord[0][1] = src->v.v0;
dst->texcoord[0][3] = 1.0;
dst->texcoord[1][0] = src->v.u1;
dst->texcoord[1][1] = src->v.v1;
dst->texcoord[1][3] = 1.0;
if (HAVE_TEX2_VERTICES) {
dst->texcoord[2][0] = src->v.u2;
dst->texcoord[2][1] = src->v.v2;
dst->texcoord[2][3] = 1.0;
}
if (HAVE_TEX3_VERTICES) {
dst->texcoord[3][0] = src->v.u3;
dst->texcoord[3][1] = src->v.v3;
dst->texcoord[3][3] = 1.0;
}
}
}
dst->pointSize = ctx->Point._Size;
}
#if 0
static void
mga_translate_vertex( GLcontext *ctx, const mgaVertex *src, SWvertex *dst)
{
mgaContextPtr mmesa = MGA_CONTEXT(ctx);
dst->win[0] = src->v.x - mmesa->drawX - SUBPIXEL_X;
dst->win[1] = - src->v.y + mmesa->driDrawable->h + mmesa->drawY + SUBPIXEL_Y;
dst->win[2] = src->v.z / mmesa->depth_scale;
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 (mmesa->tmu_source[0] == 0) {
dst->texcoord[0][0] = src->v.tu0;
dst->texcoord[0][1] = src->v.tv0;
dst->texcoord[0][3] = 1.0;
} else {
dst->texcoord[1][0] = src->v.tu0;
dst->texcoord[1][1] = src->v.tv0;
dst->texcoord[1][3] = 1.0;
}
dst->texcoord[1][0] = src->v.tu1;
dst->texcoord[1][1] = src->v.tv1;
dst->texcoord[1][3] = 1.0;
dst->pointSize = ctx->Point._Size;
}
#endif
void TAG(print_vertex)( GLcontext *ctx, const VERTEX *v )
{
GLuint format = GET_VERTEX_FORMAT();
if (format == TINY_VERTEX_FORMAT) {
fprintf(stderr, "x %f y %f z %f\n", v->v.x, v->v.y, v->v.z);
fprintf(stderr, "r %d g %d b %d a %d\n",
v->tv.color.red,
v->tv.color.green,
v->tv.color.blue,
v->tv.color.alpha);
}
else {
fprintf(stderr, "x %f y %f z %f oow %f\n",
v->v.x, v->v.y, v->v.z, v->v.w);
fprintf(stderr, "r %d g %d b %d a %d\n",
v->v.color.red,
v->v.color.green,
v->v.color.blue,
v->v.color.alpha);
}
fprintf(stderr, "\n");
}
#undef TAG

View File

@@ -70,8 +70,7 @@
* DO_TEX3: Emit tex3 u,v coordinates. * DO_TEX3: Emit tex3 u,v coordinates.
* DO_PTEX: Emit tex0,1,2,3 q coordinates where possible. * DO_PTEX: Emit tex0,1,2,3 q coordinates where possible.
* *
* HAVE_RGBA_COLOR: Hardware takes color in rgba order. * HAVE_RGBA_COLOR: Hardware takes color in rgba order (else bgra).
* HAVE_BGRA_COLOR: Hardware takes color in bgra order.
* *
* HAVE_HW_VIEWPORT: Hardware performs viewport transform. * HAVE_HW_VIEWPORT: Hardware performs viewport transform.
* HAVE_HW_DIVIDE: Hardware performs perspective divide. * HAVE_HW_DIVIDE: Hardware performs perspective divide.
@@ -91,16 +90,20 @@
*/ */
#if (HAVE_HW_VIEWPORT) #if (HAVE_HW_VIEWPORT)
#define VIEWPORT_X(x) x #define VIEWPORT_X(dst,x) dst = x
#define VIEWPORT_Y(x) x #define VIEWPORT_Y(dst,y) dst = y
#define VIEWPORT_Z(x) x #define VIEWPORT_Z(dst,z) dst = z
#else #else
#define VIEWPORT_X(x) (s[0] * x + s[12]) #define VIEWPORT_X(dst,x) dst = s[0] * x + s[12]
#define VIEWPORT_Y(y) (s[5] * y + s[13]) #define VIEWPORT_Y(dst,y) dst = s[5] * y + s[13]
#define VIEWPORT_Z(z) (s[10] * z + s[14]) #define VIEWPORT_Z(dst,z) dst = s[10] * z + s[14]
#endif #endif
#if (HAVE_HW_DIVIDE || DO_RGBA || DO_XYZW || !HAVE_TINY_VERTICES) #if (HAVE_HW_DIVIDE && !HAVE_PTEX_VERTICES)
#error "can't cope with this combination"
#endif
#if (HAVE_HW_DIVIDE || DO_SPEC || DO_TEX0 || DO_FOG || !HAVE_TINY_VERTICES)
static void TAG(emit)( GLcontext *ctx, static void TAG(emit)( GLcontext *ctx,
GLuint start, GLuint end, GLuint start, GLuint end,
@@ -109,15 +112,21 @@ static void TAG(emit)( GLcontext *ctx,
{ {
struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
GLfloat (*tc0)[4], (*tc1)[4], *fog; GLfloat (*tc0)[4], (*tc1)[4], *fog;
GLfloat (*tc2)[4], (*tc3)[4];
GLubyte (*col)[4], (*spec)[4]; GLubyte (*col)[4], (*spec)[4];
GLuint tc0_stride, tc1_stride, col_stride, spec_stride, fog_stride; GLuint tc0_stride, tc1_stride, col_stride, spec_stride, fog_stride;
GLuint tc2_stride, tc3_stride;
GLuint tc0_size, tc1_size; GLuint tc0_size, tc1_size;
GLuint tc2_size, tc3_size;
GLfloat (*coord)[4]; GLfloat (*coord)[4];
GLuint coord_stride; GLuint coord_stride;
VERTEX *v = (VERTEX *)dest; VERTEX *v = (VERTEX *)dest;
const GLfloat *s = GET_VIEWPORT_MAT(); const GLfloat *s = GET_VIEWPORT_MAT();
const GLubyte *mask = VB->ClipMask;
int i; int i;
/* fprintf(stderr, "%s\n", __FUNCTION__); */
if (HAVE_HW_VIEWPORT && HAVE_HW_DIVIDE) { if (HAVE_HW_VIEWPORT && HAVE_HW_DIVIDE) {
(void) s; (void) s;
coord = VB->ClipPtr->data; coord = VB->ClipPtr->data;
@@ -128,50 +137,56 @@ static void TAG(emit)( GLcontext *ctx,
coord_stride = VB->ProjectedClipPtr->stride; coord_stride = VB->ProjectedClipPtr->stride;
} }
if (DO_TEX0) { if (DO_TEX3) {
tc0_stride = VB->TexCoordPtr[0]->stride; const GLuint t3 = GET_TEXSOURCE(3);
tc0 = VB->TexCoordPtr[0]->data;
if (VB->TexCoordPtr[2] == 0) {
if (VB->TexCoordPtr[1] == 0) {
if (VB->TexCoordPtr[0] == 0)
VB->TexCoordPtr[0] = VB->TexCoordPtr[t3];
VB->TexCoordPtr[1] = VB->TexCoordPtr[t3];
}
VB->TexCoordPtr[2] = VB->TexCoordPtr[t3];
}
tc3 = VB->TexCoordPtr[t3]->data;
tc3_stride = VB->TexCoordPtr[t3]->stride;
if (DO_PTEX) if (DO_PTEX)
tc0_size = VB->TexCoordPtr[0]->size; tc3_size = VB->TexCoordPtr[t3]->size;
} }
if (DO_TEX1) { if (DO_TEX2) {
if (VB->TexCoordPtr[0] == 0) const GLuint t2 = GET_TEXSOURCE(2);
VB->TexCoordPtr[0] = VB->TexCoordPtr[1];
if (VB->TexCoordPtr[1] == 0) {
if (VB->TexCoordPtr[0] == 0)
VB->TexCoordPtr[0] = VB->TexCoordPtr[t2];
VB->TexCoordPtr[1] = VB->TexCoordPtr[t2];
}
tc2 = VB->TexCoordPtr[t2]->data;
tc2_stride = VB->TexCoordPtr[t2]->stride;
if (DO_PTEX)
tc2_size = VB->TexCoordPtr[t2]->size;
}
if (DO_TEX1) {
const GLuint t1 = GET_TEXSOURCE(1);
if (VB->TexCoordPtr[0] == 0)
VB->TexCoordPtr[0] = VB->TexCoordPtr[t1];
tc1 = VB->TexCoordPtr[1]->data; tc1 = VB->TexCoordPtr[1]->data;
tc1_stride = VB->TexCoordPtr[1]->stride; tc1_stride = VB->TexCoordPtr[1]->stride;
if (DO_PTEX) if (DO_PTEX)
tc1_size = VB->TexCoordPtr[1]->size; tc1_size = VB->TexCoordPtr[1]->size;
} }
if (DO_TEX2) { if (DO_TEX0) {
if (VB->TexCoordPtr[1] == 0) { const GLuint t0 = GET_TEXSOURCE(0);
if (VB->TexCoordPtr[0] == 0) tc0_stride = VB->TexCoordPtr[t0]->stride;
VB->TexCoordPtr[0] = VB->TexCoordPtr[2]; tc0 = VB->TexCoordPtr[t0]->data;
VB->TexCoordPtr[1] = VB->TexCoordPtr[2];
}
tc2 = VB->TexCoordPtr[2]->data;
tc2_stride = VB->TexCoordPtr[2]->stride;
if (DO_PTEX) if (DO_PTEX)
tc2_size = VB->TexCoordPtr[2]->size; tc0_size = VB->TexCoordPtr[t0]->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) { if (DO_RGBA) {
@@ -210,17 +225,16 @@ static void TAG(emit)( GLcontext *ctx,
STRIDE_F(fog, start * fog_stride); STRIDE_F(fog, start * fog_stride);
} }
for (i=start; i < end; i++, v = (ddVertex *)((GLubyte *)v + stride)) { for (i=start; i < end; i++, v = (VERTEX *)((GLubyte *)v + stride)) {
if (DO_XYZW) { if (DO_XYZW) {
if (HAVE_HW_VIEWPORT || mask[i] == 0) { if (HAVE_HW_VIEWPORT || mask[i] == 0) {
VIEWPORT_X(v->v.x, coord[0][0]); VIEWPORT_X(v->v.x, coord[0][0]);
VIEWPORT_Y(v->v.y, coord[0][1]); VIEWPORT_Y(v->v.y, coord[0][1]);
VIEWPORT_Z(v->v.z, coord[0][2]); VIEWPORT_Z(v->v.z, coord[0][2]);
VIEWPORT_W(v->v.w, coord[0][3]); v->v.w = coord[0][3];
} }
coord = (GLfloat (*)[4])((GLubyte *)coord + coord_stride); coord = (GLfloat (*)[4])((GLubyte *)coord + coord_stride);
} }
NOTE_W;
if (DO_RGBA) { if (DO_RGBA) {
if (HAVE_RGBA_COLOR) { if (HAVE_RGBA_COLOR) {
*(GLuint *)&v->v.color = *(GLuint *)&col[0]; *(GLuint *)&v->v.color = *(GLuint *)&col[0];
@@ -244,20 +258,20 @@ static void TAG(emit)( GLcontext *ctx,
STRIDE_F(fog, fog_stride); STRIDE_F(fog, fog_stride);
} }
if (DO_TEX0) { if (DO_TEX0) {
v->v.tu0 = tc0[0][0]; v->v.u0 = tc0[0][0];
v->v.tv0 = tc0[0][1]; v->v.v0 = tc0[0][1];
if (DO_PTEX) { if (DO_PTEX) {
if (HAVE_PTEX_VERTICES) { if (HAVE_PTEX_VERTICES) {
if (tc0_size == 4) if (tc0_size == 4)
v->pv.tq0 = tc0[0][3]; v->pv.q0 = tc0[0][3];
else else
v->pv.tq0 = 1.0; v->pv.q0 = 1.0;
} }
else if (tc0_size == 4) { else if (tc0_size == 4) {
float rhw = 1.0 / tc0[0][3]; float rhw = 1.0 / tc0[0][3];
v->v.w *= tc0[0][3]; v->v.w *= tc0[0][3];
v->v.u0 *= w; v->v.u0 *= rhw;
v->v.v0 *= w; v->v.v0 *= rhw;
} }
} }
tc0 = (GLfloat (*)[4])((GLubyte *)tc0 + tc0_stride); tc0 = (GLfloat (*)[4])((GLubyte *)tc0 + tc0_stride);
@@ -313,16 +327,15 @@ static void TAG(emit)( GLcontext *ctx,
} }
} }
else { else {
for (i=start; i < end; i++, v = (ddVertex *)((GLubyte *)v + stride)) { for (i=start; i < end; i++, v = (VERTEX *)((GLubyte *)v + stride)) {
if (DO_XYZW) { if (DO_XYZW) {
if (HAVE_HW_VIEWPORT || mask[i] == 0) { if (HAVE_HW_VIEWPORT || mask[i] == 0) {
VIEWPORT_X(v->v.x, coord[i][0]); VIEWPORT_X(v->v.x, coord[i][0]);
VIEWPORT_Y(v->v.y, coord[i][1]); VIEWPORT_Y(v->v.y, coord[i][1]);
VIEWPORT_Z(v->v.z, coord[i][2]); VIEWPORT_Z(v->v.z, coord[i][2]);
VIEWPORT_W(v->v.w, coord[i][3]); v->v.w = coord[i][3];
} }
} }
NOTE_W;
if (DO_RGBA) { if (DO_RGBA) {
if (HAVE_RGBA_COLOR) { if (HAVE_RGBA_COLOR) {
*(GLuint *)&v->v.color = *(GLuint *)&col[i]; *(GLuint *)&v->v.color = *(GLuint *)&col[i];
@@ -348,9 +361,9 @@ static void TAG(emit)( GLcontext *ctx,
v->pv.v0 = tc0[i][1]; v->pv.v0 = tc0[i][1];
if (HAVE_PTEX_VERTICES) { if (HAVE_PTEX_VERTICES) {
if (tc0_size == 4) if (tc0_size == 4)
v->pv.tq0 = tc0[i][3]; v->pv.q0 = tc0[i][3];
else else
v->pv.tq0 = 1.0; v->pv.q0 = 1.0;
v->pv.q1 = 0; /* radeon */ v->pv.q1 = 0; /* radeon */
} }
@@ -388,6 +401,12 @@ static void TAG(emit)( GLcontext *ctx,
} }
} }
#else #else
#if DO_XYZW
#if HAVE_HW_DIVIDE
#error "cannot use tiny vertices with hw perspective divide"
#endif
static void TAG(emit)( GLcontext *ctx, GLuint start, GLuint end, static void TAG(emit)( GLcontext *ctx, GLuint start, GLuint end,
void *dest, GLuint stride ) void *dest, GLuint stride )
{ {
@@ -397,8 +416,14 @@ static void TAG(emit)( GLcontext *ctx, GLuint start, GLuint end,
GLfloat (*coord)[4] = VB->ProjectedClipPtr->data; GLfloat (*coord)[4] = VB->ProjectedClipPtr->data;
GLuint coord_stride = VB->ProjectedClipPtr->stride; GLuint coord_stride = VB->ProjectedClipPtr->stride;
GLfloat *v = (GLfloat *)dest; GLfloat *v = (GLfloat *)dest;
const GLubyte *mask = VB->ClipMask;
const GLfloat *s = GET_VIEWPORT_MAT();
int i; int i;
(void) s;
/* fprintf(stderr, "%s (template 2)\n", __FUNCTION__); */
ASSERT(stride == 4); ASSERT(stride == 4);
/* Pack what's left into a 4-dword vertex. Color is in a different /* Pack what's left into a 4-dword vertex. Color is in a different
@@ -412,9 +437,9 @@ static void TAG(emit)( GLcontext *ctx, GLuint start, GLuint end,
for (i=start; i < end; i++, v+=4) { for (i=start; i < end; i++, v+=4) {
if (HAVE_HW_VIEWPORT || mask[i] == 0) { if (HAVE_HW_VIEWPORT || mask[i] == 0) {
v[0] = VIEWPORT_X(coord[0][0]); VIEWPORT_X(v[0], coord[0][0]);
v[1] = VIEWPORT_Y(coord[0][1]); VIEWPORT_Y(v[1], coord[0][1]);
v[2] = VIEWPORT_Z(coord[0][2]); VIEWPORT_Z(v[2], coord[0][2]);
} }
coord = (GLfloat (*)[4])((GLubyte *)coord + coord_stride); coord = (GLfloat (*)[4])((GLubyte *)coord + coord_stride);
if (DO_RGBA) { if (DO_RGBA) {
@@ -435,9 +460,9 @@ static void TAG(emit)( GLcontext *ctx, GLuint start, GLuint end,
else { else {
for (i=start; i < end; i++, v+=4) { for (i=start; i < end; i++, v+=4) {
if (HAVE_HW_VIEWPORT || mask[i] == 0) { if (HAVE_HW_VIEWPORT || mask[i] == 0) {
v[0] = VIEWPORT_X(coord[i][0]); VIEWPORT_X(v[0], coord[i][0]);
v[1] = VIEWPORT_Y(coord[i][1]); VIEWPORT_Y(v[1], coord[i][1]);
v[2] = VIEWPORT_Z(coord[i][2]); VIEWPORT_Z(v[2], coord[i][2]);
} }
if (DO_RGBA) { if (DO_RGBA) {
if (HAVE_RGBA_COLOR) { if (HAVE_RGBA_COLOR) {
@@ -454,7 +479,42 @@ static void TAG(emit)( GLcontext *ctx, GLuint start, GLuint end,
} }
} }
} }
#endif #else
static void TAG(emit)( GLcontext *ctx, GLuint start, GLuint end,
void *dest, GLuint stride )
{
struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
GLubyte (*col)[4] = VB->ColorPtr[0]->data;
GLuint col_stride = VB->ColorPtr[0]->stride;
GLfloat *v = (GLfloat *)dest;
int i;
if (start)
STRIDE_4UB(col, col_stride * start);
/* Need to figure out where color is:
*/
if (GET_VERTEX_FORMAT() == TINY_VERTEX_FORMAT)
v += 3;
else
v += 4;
for (i=start; i < end; i++, STRIDE_F(v, stride)) {
if (HAVE_RGBA_COLOR) {
*(GLuint *)v = *(GLuint *)col[0];
}
else {
GLubyte *b = (GLubyte *)v;
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 );
}
}
#endif /* emit */
#endif /* emit */
#if (DO_XYZW) && (DO_RGBA) #if (DO_XYZW) && (DO_RGBA)
@@ -501,10 +561,9 @@ static GLboolean TAG(check_tex_sizes)( GLcontext *ctx )
return GL_TRUE; return GL_TRUE;
} }
#endif #endif /* ptex */
#if (!DO_PTEX || HAVE_PTEX_VERTICES)
static void TAG(interp)( GLcontext *ctx, static void TAG(interp)( GLcontext *ctx,
GLfloat t, GLfloat t,
GLuint edst, GLuint eout, GLuint ein, GLuint edst, GLuint eout, GLuint ein,
@@ -517,14 +576,11 @@ static void TAG(interp)( GLcontext *ctx,
GLfloat w; GLfloat w;
const GLfloat *s = GET_VIEWPORT_MAT(); const GLfloat *s = GET_VIEWPORT_MAT();
(void)s;
VERTEX *dst = (VERTEX *)(ddverts + (edst << shift)); VERTEX *dst = (VERTEX *)(ddverts + (edst << shift));
VERTEX *in = (VERTEX *)(ddverts + (eout << shift)); VERTEX *in = (VERTEX *)(ddverts + (eout << shift));
VERTEX *out = (VERTEX *)(ddverts + (ein << shift)); VERTEX *out = (VERTEX *)(ddverts + (ein << shift));
PREPARE_PROJIN; (void)s;
PREPARE_PROJOUT;
/* fprintf(stderr, "%s\n", __FUNCTION__); */ /* fprintf(stderr, "%s\n", __FUNCTION__); */
@@ -561,10 +617,29 @@ static void TAG(interp)( GLcontext *ctx,
INTERP_UB( t, dst->ub4[5][3], out->ub4[5][3], in->ub4[5][3] ); INTERP_UB( t, dst->ub4[5][3], out->ub4[5][3], in->ub4[5][3] );
} }
if (DO_TEX0) { if (DO_TEX0) {
if (DO_PTEX && HAVE_PTEX_VERTICES) { if (DO_PTEX) {
INTERP_F( t, dst->pv.u0, out->pv.u0, in->pv.u0 ); if (HAVE_PTEX_VERTICES) {
INTERP_F( t, dst->pv.v0, out->pv.v0, in->pv.v0 ); INTERP_F( t, dst->pv.u0, out->pv.u0, in->pv.u0 );
INTERP_F( t, dst->pv.q0, out->pv.q0, in->pv.q0 ); INTERP_F( t, dst->pv.v0, out->pv.v0, in->pv.v0 );
INTERP_F( t, dst->pv.q0, out->pv.q0, in->pv.q0 );
} else {
GLfloat wout = VB->ProjectedClipPtr->data[eout][3];
GLfloat win = VB->ProjectedClipPtr->data[ein][3];
GLfloat qout = out->pv.w / wout;
GLfloat qin = in->pv.w / win;
GLfloat qdst, rqdst;
ASSERT( !HAVE_HW_DIVIDE );
INTERP_F( t, dst->v.u0, out->v.u0 * qout, in->v.u0 * qin );
INTERP_F( t, dst->v.v0, out->v.v0 * qout, in->v.v0 * qin );
INTERP_F( t, qdst, qout, qin );
rqdst = 1.0 / qdst;
dst->v.u0 *= rqdst;
dst->v.v0 *= rqdst;
dst->v.w *= rqdst;
}
} }
else { else {
INTERP_F( t, dst->v.u0, out->v.u0, in->v.u0 ); INTERP_F( t, dst->v.u0, out->v.u0, in->v.u0 );
@@ -613,105 +688,8 @@ static void TAG(interp)( GLcontext *ctx,
INTERP_UB( t, dst->ub4[3][3], out->ub4[3][3], in->ub4[3][3] ); INTERP_UB( t, dst->ub4[3][3], out->ub4[3][3], in->ub4[3][3] );
} }
} }
#endif
/* Build an SWvertex from a hardware vertex. #endif /* rgba && xyzw */
*
* 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
static void TAG(init)( void ) static void TAG(init)( void )
@@ -724,12 +702,12 @@ static void TAG(init)( void )
#endif #endif
if (DO_SPEC) if (DO_SPEC)
setup_tab[IND].copy_pv = _tnl_dd_copy_pv_rgba4_spec5; setup_tab[IND].copy_pv = copy_pv_rgba4_spec5;
else if (HAVE_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) DO_TEX2 || DO_TEX3)
setup_tab[IND].copy_pv = _tnl_dd_copy_pv_rgba4; setup_tab[IND].copy_pv = copy_pv_rgba4;
else else
setup_tab[IND].copy_pv = _tnl_dd_copy_pv_rgba3; setup_tab[IND].copy_pv = copy_pv_rgba3;
if (DO_TEX3) { if (DO_TEX3) {
if (DO_PTEX) { if (DO_PTEX) {
@@ -747,7 +725,6 @@ static void TAG(init)( void )
else if (DO_TEX2) { else if (DO_TEX2) {
if (DO_PTEX) { if (DO_PTEX) {
ASSERT(HAVE_PTEX_VERTICES); 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_format = PROJ_TEX3_VERTEX_FORMAT;
setup_tab[IND].vertex_size = 18; setup_tab[IND].vertex_size = 18;
setup_tab[IND].vertex_stride_shift = 7; setup_tab[IND].vertex_stride_shift = 7;

View File

@@ -0,0 +1,70 @@
/*
* Mesa 3-D graphics library
* Version: 3.5
*
* Copyright (C) 1999 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Author:
* Keith Whitwell <keithw@valinux.com>
*/
#if (COLOR_IS_RBGA)
typedef struct {
GLubyte red;
GLubyte green;
GLubyte blue;
GLubyte alpha;
} TAG(_color);
#else
typedef struct {
GLubyte blue;
GLubyte green;
GLubyte red;
GLubyte alpha;
} TAG(_color);
#endif
typedef union {
struct {
float x, y, z, w;
TAG(_color) color;
TAG(_color) specular;
float u0, v0;
float u1, v1;
float u2, v2;
float u3, v3;
} v;
struct {
float x, y, z, w;
TAG(_color) color;
TAG(_color) specular;
float u0, v0, q0;
float u1, v1, q1;
float u2, v2, q2;
float u3, v3, q3;
} pv;
struct {
float x, y, z;
TAG(_color) color;
} tv;
float f[16];
unsigned int ui[16];
unsigned char ub4[4][16];
} TAG(Vertex), *TAG(VertexPtr);