@ -5,54 +5,32 @@
# include "display.h"
# include <inline_c.h>
static INLINE void draw_trianglefan _lit ( SVECTOR * verts , u_char numVerts )
static INLINE void draw_triangle_lit ( SVECTOR * verts , u_long * ot )
{
int p ;
if ( ! mem_checkprim ( sizeof ( POLY_G3 ) , numVerts - 2 ) )
return ;
/ / Draw the face as a triangle fan
u_char maxVert = numVerts - 1 ;
for ( u_char vertIdx = 1 ; vertIdx < maxVert ; + + vertIdx )
{
const SVECTOR * v0 = & verts [ 0 ] ;
const SVECTOR * v1 = & verts [ vertIdx ] ;
const SVECTOR * v2 = & verts [ vertIdx + 1 ] ;
/ / Naively draw the triangle with GTE , nothing special or optimized about this
gte_ldv3 ( v0 , v1 , v2 ) ;
gte_rtpt ( ) ; / / Rotation , translation , perspective projection
/ / Average Z for depth sorting and culling
gte_avsz3 ( ) ;
gte_stotz ( & p ) ;
short depth = p > > 2 ;
if ( depth < = 0 | | depth > = OTLEN )
continue ;
/ / Draw a flat - shaded untextured colored triangle
POLY_G3 * poly = ( POLY_G3 * ) mem_prim ( sizeof ( POLY_G3 ) ) ;
setPolyG3 ( poly ) ;
gte_stsxy3_g3 ( poly ) ;
poly - > r0 = poly - > g0 = poly - > b0 = ( uint8_t ) v0 - > pad ;
poly - > r1 = poly - > g1 = poly - > b1 = ( uint8_t ) v1 - > pad ;
poly - > r2 = poly - > g2 = poly - > b2 = ( uint8_t ) v2 - > pad ;
addPrim ( curOT + depth , poly ) ;
+ + polyCount ;
}
/ / Draw a single triangle
const SVECTOR * v0 = & verts [ 0 ] ;
const SVECTOR * v1 = & verts [ 1 ] ;
const SVECTOR * v2 = & verts [ 2 ] ;
/ / Naively draw the triangle with GTE , nothing special or optimized about this
gte_ldv3 ( v0 , v1 , v2 ) ;
gte_rtpt ( ) ; / / Rotation , translation , perspective projection
/ / Draw a flat - shaded untextured colored triangle
POLY_G3 * poly = ( POLY_G3 * ) mem_prim ( sizeof ( POLY_G3 ) ) ;
setPolyG3 ( poly ) ;
gte_stsxy3_g3 ( poly ) ;
poly - > r0 = poly - > g0 = poly - > b0 = ( uint8_t ) v0 - > pad ;
poly - > r1 = poly - > g1 = poly - > b1 = ( uint8_t ) v1 - > pad ;
poly - > r2 = poly - > g2 = poly - > b2 = ( uint8_t ) v2 - > pad ;
addPrim ( ot , poly ) ;
+ + polyCount ;
}
static INLINE void draw_trianglestrip_lit ( SVECTOR * verts , u_char numVerts )
static INLINE void draw_trianglestrip_lit ( SVECTOR * verts , u_char numVerts , u_long * ot )
{
int p ;
u_char numTris = numVerts - 2 ;
if ( ! mem_checkprim ( sizeof ( POLY_G3 ) , numTris ) )
return ;
/ / Draw the face as a triangle strip
const SVECTOR * v0 , * v1 , * v2 ;
const SVECTOR * head = verts ;
@ -61,6 +39,7 @@ static INLINE void draw_trianglestrip_lit(SVECTOR *verts, u_char numVerts)
v2 = head + + ; / / Initialize first vertex to index 0 and set head to index 1
u_char numTris = numVerts - 2 ;
for ( u_char triIdx = 0 ; triIdx < numTris ; + + triIdx )
{
if ( reverse ^ = 1 )
@ -80,13 +59,6 @@ static INLINE void draw_trianglestrip_lit(SVECTOR *verts, u_char numVerts)
gte_ldv3 ( v0 , v1 , v2 ) ;
gte_rtpt ( ) ; / / Rotation , translation , perspective projection
/ / Average Z for depth sorting and culling
gte_avsz3 ( ) ;
gte_stotz ( & p ) ;
short depth = p > > 2 ;
if ( depth < = 0 | | depth > = OTLEN )
continue ;
/ / Draw a flat - shaded untextured colored triangle
POLY_G3 * poly = ( POLY_G3 * ) mem_prim ( sizeof ( POLY_G3 ) ) ;
setPolyG3 ( poly ) ;
@ -96,19 +68,13 @@ static INLINE void draw_trianglestrip_lit(SVECTOR *verts, u_char numVerts)
poly - > r1 = poly - > g1 = poly - > b1 = ( uint8_t ) v1 - > pad ;
poly - > r2 = poly - > g2 = poly - > b2 = ( uint8_t ) v2 - > pad ;
addPrim ( curOT + dep th , poly ) ;
addPrim ( o t, poly ) ;
+ + polyCount ;
}
}
static INLINE void draw_quadstrip_lit ( SVECTOR * verts , u_char numVerts )
static INLINE void draw_quadstrip_lit ( SVECTOR * verts , u_char numVerts , u_long * ot )
{
int p ;
u_char numQuads = ( numVerts - 1 ) > > 1 ;
if ( ! mem_checkprim ( sizeof ( POLY_G4 ) , numQuads ) )
return ;
/ / Draw the face as a quad strip
const SVECTOR * v0 , * v1 , * v2 , * v3 ;
const SVECTOR * head = verts ;
@ -119,6 +85,7 @@ static INLINE void draw_quadstrip_lit(SVECTOR *verts, u_char numVerts)
v3 = head + + ;
/ / Normally a quad strip would have ( N - 2 ) / 2 quads , but we might end up with a sole triangle at the end which will be drawn as a collapsed quad
u_char numQuads = ( numVerts - 1 ) > > 1 ;
for ( u_char quadIdx = 0 ; quadIdx < numQuads ; + + quadIdx )
{
v0 = v2 ;
@ -130,19 +97,10 @@ static INLINE void draw_quadstrip_lit(SVECTOR *verts, u_char numVerts)
gte_ldv3 ( v0 , v1 , v2 ) ;
gte_rtpt ( ) ; / / Rotation , translation , perspective projection
/ / Average Z for depth sorting and culling
gte_avsz3 ( ) ;
gte_stotz ( & p ) ;
short depth = p > > 2 ;
if ( depth < = 0 | | depth > = OTLEN )
continue ;
/ / Draw a flat - shaded untextured colored quad
POLY_G4 * poly = ( POLY_G4 * ) mem_prim ( sizeof ( POLY_G4 ) ) ;
setPolyG4 ( poly ) ;
gte_stsxy0 ( & poly - > x0 ) ;
gte_stsxy1 ( & poly - > x1 ) ;
gte_stsxy2 ( & poly - > x2 ) ;
gte_stsxy3_g3 ( poly ) ;
/ / Transform the fourth vertex to complete the quad
gte_ldv0 ( v3 ) ;
@ -154,22 +112,44 @@ static INLINE void draw_quadstrip_lit(SVECTOR *verts, u_char numVerts)
poly - > r2 = poly - > g2 = poly - > b2 = ( uint8_t ) v2 - > pad ;
poly - > r3 = poly - > g3 = poly - > b3 = ( uint8_t ) v3 - > pad ;
addPrim ( curOT + dep th , poly ) ;
addPrim ( o t, poly ) ;
+ + polyCount ;
}
}
static INLINE void draw_quadstrip _textured ( STVECTOR * verts , u_char numVerts , u_short tpage )
static INLINE void draw_triangle _textured ( STVECTOR * verts , u_short tpage , u_long * ot )
{
int p ;
/ / Normally a quad strip would have ( N - 2 ) / 2 quads , but we might end up with a sole triangle at the end which will be drawn as a collapsed quad
/ / NOTE : testing has shown that the PS1 is faster just rendering quads and accepting the odd collapsed quad , rather than being clever with pointer comparisons and drawing a single triangle at the end .
u_char numQuads = ( numVerts - 1 ) > > 1 ;
if ( ! mem_checkprim ( sizeof ( POLY_GT4 ) , numQuads ) )
return ;
/ / Draw a single textured triangle
const STVECTOR * v0 = & verts [ 0 ] ;
const STVECTOR * v1 = & verts [ 1 ] ;
const STVECTOR * v2 = & verts [ 2 ] ;
/ / Naively draw the triangle with GTE , nothing special or optimized about this
gte_ldv3 ( v0 , v1 , v2 ) ;
gte_rtpt ( ) ; / / Rotation , translation , perspective projection
/ / Draw a gouraud shaded textured triangle
POLY_GT3 * poly = ( POLY_GT3 * ) mem_prim ( sizeof ( POLY_GT3 ) ) ;
setPolyGT3 ( poly ) ;
gte_stsxy3_gt3 ( poly ) ;
/ / Texture UVs
setUV3 ( poly , v0 - > u , v0 - > v , v1 - > u , v1 - > v , v2 - > u , v2 - > v ) ;
poly - > clut = quake_clut ;
poly - > tpage = tpage ;
poly - > r0 = poly - > g0 = poly - > b0 = ( uint8_t ) v0 - > pad ;
poly - > r1 = poly - > g1 = poly - > b1 = ( uint8_t ) v1 - > pad ;
poly - > r2 = poly - > g2 = poly - > b2 = ( uint8_t ) v2 - > pad ;
addPrim ( ot , poly ) ;
+ + polyCount ;
}
static INLINE void draw_quadstrip_textured ( STVECTOR * verts , u_char numVerts , u_short tpage , u_long * ot )
{
/ / Draw the face as a quad strip
STVECTOR * v0 , * v1 , * v2 , * v3 ;
u_char i0 , i1 , i2 , i3 ;
u_char head = 0 ;
u_char tail = numVerts ;
@ -178,7 +158,9 @@ static INLINE void draw_quadstrip_textured(STVECTOR *verts, u_char numVerts, u_s
i2 = - - tail ;
i3 = head + + ;
STVECTOR * v0 , * v1 , * v2 , * v3 ;
/ / Normally a quad strip would have ( N - 2 ) / 2 quads , but we might end up with a sole triangle at the end which will be drawn as a collapsed quad
/ / NOTE : testing has shown that the PS1 is faster just rendering quads and accepting the odd collapsed quad , rather than being clever with pointer comparisons and drawing a single triangle at the end .
u_char numQuads = ( numVerts - 1 ) > > 1 ;
for ( u_char quadIdx = 0 ; quadIdx < numQuads ; + + quadIdx )
{
i0 = i2 ;
@ -194,19 +176,10 @@ static INLINE void draw_quadstrip_textured(STVECTOR *verts, u_char numVerts, u_s
gte_ldv3 ( v0 , v1 , v2 ) ;
gte_rtpt ( ) ; / / Rotation , translation , perspective projection
/ / Average Z for depth sorting and culling
gte_avsz3 ( ) ;
gte_stotz ( & p ) ;
short depth = p > > 2 ;
if ( depth < = 0 | | depth > = OTLEN )
return ;
/ / Draw a flat - shaded untextured colored quad
POLY_GT4 * poly = ( POLY_GT4 * ) mem_prim ( sizeof ( POLY_GT4 ) ) ;
setPolyGT4 ( poly ) ;
gte_stsxy0 ( & poly - > x0 ) ;
gte_stsxy1 ( & poly - > x1 ) ;
gte_stsxy2 ( & poly - > x2 ) ;
gte_stsxy3_gt3 ( poly ) ;
v3 = & verts [ i3 ] ;
@ -226,21 +199,15 @@ static INLINE void draw_quadstrip_textured(STVECTOR *verts, u_char numVerts, u_s
poly - > r2 = poly - > g2 = poly - > b2 = ( uint8_t ) v2 - > pad ;
poly - > r3 = poly - > g3 = poly - > b3 = ( uint8_t ) v3 - > pad ;
addPrim ( curOT + dep th , poly ) ;
addPrim ( o t, poly ) ;
+ + polyCount ;
}
}
static INLINE void draw_quadstrip_water ( STVECTOR * verts , u_char numVerts , u_short tpage )
static INLINE void draw_quadstrip_water ( STVECTOR * verts , u_char numVerts , u_short tpage , u_long * ot )
{
int p ;
/ / Normally a quad strip would have ( N - 2 ) / 2 quads , but we might end up with a sole triangle at the end which will be drawn as a collapsed quad
u_char numQuads = ( numVerts - 1 ) > > 1 ;
if ( ! mem_checkprim ( sizeof ( POLY_FT4 ) , numQuads ) )
return ;
/ / Draw the face as a quad strip
const STVECTOR * v0 , * v1 , * v2 , * v3 ;
u_char i0 , i1 , i2 , i3 ;
u_char head = 0 ;
u_char tail = numVerts ;
@ -249,7 +216,8 @@ static INLINE void draw_quadstrip_water(STVECTOR *verts, u_char numVerts, u_shor
i2 = - - tail ;
i3 = head + + ;
const STVECTOR * v0 , * v1 , * v2 , * v3 ;
/ / Normally a quad strip would have ( N - 2 ) / 2 quads , but we might end up with a sole triangle at the end which will be drawn as a collapsed quad
u_char numQuads = ( numVerts - 1 ) > > 1 ;
for ( u_char quadIdx = 0 ; quadIdx < numQuads ; + + quadIdx )
{
i0 = i2 ;
@ -265,13 +233,6 @@ static INLINE void draw_quadstrip_water(STVECTOR *verts, u_char numVerts, u_shor
gte_ldv3 ( v0 , v1 , v2 ) ;
gte_rtpt ( ) ; / / Rotation , translation , perspective projection
/ / Average Z for depth sorting and culling
gte_avsz3 ( ) ;
gte_stotz ( & p ) ;
short depth = p > > 2 ;
if ( depth < = 0 | | depth > = OTLEN )
continue ;
/ / Draw a flat - shaded untextured colored quad
POLY_FT4 * poly = ( POLY_FT4 * ) mem_prim ( sizeof ( POLY_FT4 ) ) ;
setPolyFT4 ( poly ) ;
@ -294,7 +255,7 @@ static INLINE void draw_quadstrip_water(STVECTOR *verts, u_char numVerts, u_shor
/ / Unlit
poly - > r0 = poly - > g0 = poly - > b0 = 255 ;
addPrim ( curOT + dep th , poly ) ;
addPrim ( o t, poly ) ;
+ + polyCount ;
}
}