diff --git a/draw.h b/draw.h index e3602ba..7fd3bf6 100644 --- a/draw.h +++ b/draw.h @@ -5,6 +5,13 @@ #include "display.h" #include +// Macros for quickly blitting RGB and UV values with a single copy +// This is faster than copying each value individually +#define setColorFast(pr, r) *((u_int*)(pr)) = *((u_int*)(r)) +#define setUVFast(pu, u) *((u_short*)(pu)) = *((u_short*)(u)) + +static u_int color_white = ((255 << 24) | (255 << 16) | (255 << 8) | 255); + static INLINE void draw_triangle_lit(SVECTOR *verts, u_long *ot) { // Draw a single triangle @@ -234,32 +241,31 @@ static INLINE void draw_quadstrip_textured(const ps1bsp_vertex_t *vertices, cons POLY_GT4 *poly = (POLY_GT4*)mem_prim(sizeof(POLY_GT4)); // Fill out the quad's data fields in struct order, to optimize data access - // RGB and UV fields are blitted as a single value, which is faster than copying each value individually // First vertex and texture CLUT - *((u_int*)&poly->r0) = *((u_int*)&v0->r); + setColorFast(&poly->r0, &v0->r); gte_stsxy0(&poly->x0); - *((u_short*)&poly->u0) = *((u_short*)&v0->u); + setUVFast(&poly->u0, &v0->u); poly->clut = quake_clut; // Second vertex and texture page - *((u_int*)&poly->r1) = *((u_int*)&v1->r); + setColorFast(&poly->r1, &v1->r); gte_stsxy1(&poly->x1); - *((u_short*)&poly->u1) = *((u_short*)&v1->u); + setUVFast(&poly->u1, &v1->u); poly->tpage = tpage; // Third vertex - *((u_int*)&poly->r2) = *((u_int*)&v2->r); + setColorFast(&poly->r2, &v2->r); gte_stsxy2(&poly->x2); - *((u_short*)&poly->u2) = *((u_short*)&v2->u); + setUVFast(&poly->u2, &v2->u); // Transform the fourth vertex to complete the quad gte_ldv0(&vertices[v3->index]); gte_rtps(); // Fourth vertex - *((u_int*)&poly->r3) = *((u_int*)&v3->r); + setColorFast(&poly->r3, &v3->r); gte_stsxy(&poly->x3); - *((u_short*)&poly->u3) = *((u_short*)&v3->u); + setUVFast(&poly->u3, &v3->u); setPolyGT4(poly); addPrim(ot, poly); @@ -299,23 +305,33 @@ static INLINE void draw_quadstrip_water(const ps1bsp_vertex_t *vertices, const p // Draw a flat-shaded textured quad POLY_FT4 *poly = (POLY_FT4*)mem_prim(sizeof(POLY_FT4)); - setPolyFT4(poly); - setSemiTrans(poly, semiTrans); - gte_stsxy3_ft3(poly); + + // Fill out the quad's data fields in struct order, to optimize data access + // First vertex and texture CLUT + setColorFast(&poly->r0, &color_white); + gte_stsxy0(&poly->x0); + setUVFast(&poly->u0, &v0->u); + poly->clut = quake_clut; + + // Second vertex and texture page + gte_stsxy1(&poly->x1); + setUVFast(&poly->u1, &v1->u); + poly->tpage = tpage; + + // Third vertex + gte_stsxy2(&poly->x2); + setUVFast(&poly->u2, &v2->u); // Transform the fourth vertex to complete the quad gte_ldv0(&vertices[v3->index]); gte_rtps(); - gte_stsxy(&poly->x3); - // Texture UVs - setUV4(poly, v0->u, v0->v, v1->u, v1->v, v2->u, v2->v, v3->u, v3->v); - poly->clut = water_clut; - poly->tpage = tpage; - - // Unlit - poly->r0 = poly->g0 = poly->b0 = 255; + // Fourth vertex + gte_stsxy(&poly->x3); + setUVFast(&poly->u3, &v3->u); + setPolyFT4(poly); + setSemiTrans(poly, semiTrans); addPrim(ot, poly); ++polyCount; }