Browse Source

Added a special case for drawing faces that are single triangles.

This is just as fast in DuckStation and shows a small performance increase on real hardware, so worth the effort.
master
Nico de Poel 3 years ago
parent
commit
21101b3287
  1. 37
      draw.h
  2. 10
      world.c

37
draw.h

@ -178,31 +178,40 @@ static INLINE void draw_quadstrip_colored(const ps1bsp_vertex_t *vertices, const
}
}
static INLINE void draw_triangle_textured(STVECTOR *verts, u_short tpage, u_long *ot)
static INLINE void draw_triangle_textured(const ps1bsp_vertex_t *vertices, const ps1bsp_polyvertex_t *polyVerts, u_short tpage, u_long *ot)
{
// Draw a single textured triangle
const STVECTOR *v0 = &verts[0];
const STVECTOR *v1 = &verts[1];
const STVECTOR *v2 = &verts[2];
const ps1bsp_polyvertex_t *v0, *v1, *v2;
// Naively draw the triangle with GTE, nothing special or optimized about this
gte_ldv3(v0, v1, v2);
v0 = &polyVerts[0];
v1 = &polyVerts[1];
v2 = &polyVerts[2];
// Transform the three vertices
gte_ldv3(&vertices[v0->index], &vertices[v1->index], &vertices[v2->index]);
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);
// Fill out the quad's data fields in struct order, to optimize data access
// First vertex and texture CLUT
setColorFast(&poly->r0, &v0->r);
setUVFast(&poly->u0, &v0->u);
gte_stsxy0(&poly->x0);
poly->clut = quake_clut;
// Second vertex and texture page
setColorFast(&poly->r1, &v1->r);
gte_stsxy1(&poly->x1);
setUVFast(&poly->u1, &v1->u);
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;
// Third vertex
setColorFast(&poly->r2, &v2->r);
gte_stsxy2(&poly->x2);
setUVFast(&poly->u2, &v2->u);
setPolyGT3(poly);
addPrim(ot, poly);
++polyCount;
}

10
world.c

@ -147,7 +147,15 @@ static void world_drawface_textured(const world_t *world, const ps1bsp_face_t *f
for (u_char polyIdx = 0; polyIdx < face->numPolygons; ++polyIdx, ++poly)
{
const ps1bsp_polyvertex_t *polyVertices = &world->polyVertices[poly->firstPolyVertex];
draw_quadstrip_textured(world->vertices, polyVertices, poly->numPolyVertices, texture->tpage, ot);
switch (poly->numPolyVertices)
{
case 3:
draw_triangle_textured(world->vertices, polyVertices, texture->tpage, ot);
break;
default:
draw_quadstrip_textured(world->vertices, polyVertices, poly->numPolyVertices, texture->tpage, ot);
break;
}
}
}
}

Loading…
Cancel
Save