Browse Source

Ditched the copy-to-scratch-RAM step for drawing textured faces, which apparently is no longer needed to run on real hardware.

Simpler code, less work to do, better performance. An all-round win.
unrollquadloop
Nico de Poel 3 years ago
parent
commit
be7eb87685
  1. 55
      draw.h
  2. 34
      world.c

55
draw.h

@ -146,10 +146,9 @@ static INLINE void draw_triangle_textured(STVECTOR *verts, u_short tpage, u_long
++polyCount;
}
static INLINE void draw_quadstrip_textured(STVECTOR *verts, u_char numVerts, u_short tpage, u_long *ot)
static INLINE void draw_quadstrip_textured(const ps1bsp_vertex_t *vertices, const ps1bsp_polyvertex_t *polyVerts, u_char numVerts, u_short tpage, u_long *ot)
{
// Draw the face as a quad strip
STVECTOR *v0, *v1, *v2, *v3;
const ps1bsp_polyvertex_t *v0, *v1, *v2, *v3;
u_char i0, i1, i2, i3;
u_char head = 0;
u_char tail = numVerts;
@ -168,23 +167,22 @@ static INLINE void draw_quadstrip_textured(STVECTOR *verts, u_char numVerts, u_s
i2 = --tail;
i3 = head++;
v0 = &verts[i0];
v1 = &verts[i1];
v2 = &verts[i2];
v0 = &polyVerts[i0];
v1 = &polyVerts[i1];
v2 = &polyVerts[i2];
v3 = &polyVerts[i3];
// Naively draw the quad with GTE, nothing special or optimized about this
gte_ldv3(v0, v1, v2);
// Transform the first three vertices
gte_ldv3(&vertices[v0->index], &vertices[v1->index], &vertices[v2->index]);
gte_rtpt(); // Rotation, translation, perspective projection
// Draw a flat-shaded untextured colored quad
// Draw a gouraud shaded textured quad
POLY_GT4 *poly = (POLY_GT4*)mem_prim(sizeof(POLY_GT4));
setPolyGT4(poly);
gte_stsxy3_gt3(poly);
v3 = &verts[i3];
// Transform the fourth vertex to complete the quad
gte_ldv0(v3);
gte_ldv0(&vertices[v3->index]);
gte_rtps();
gte_stsxy(&poly->x3);
@ -194,20 +192,20 @@ static INLINE void draw_quadstrip_textured(STVECTOR *verts, u_char numVerts, u_s
poly->tpage = tpage;
// Vertex color lighting
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;
poly->r3 = poly->g3 = poly->b3 = (uint8_t)v3->pad;
poly->r0 = poly->g0 = poly->b0 = (uint8_t)v0->light;
poly->r1 = poly->g1 = poly->b1 = (uint8_t)v1->light;
poly->r2 = poly->g2 = poly->b2 = (uint8_t)v2->light;
poly->r3 = poly->g3 = poly->b3 = (uint8_t)v3->light;
addPrim(ot, poly);
++polyCount;
}
}
static INLINE void draw_quadstrip_water(STVECTOR *verts, u_char numVerts, u_short tpage, u_long *ot)
static INLINE void draw_quadstrip_water(const ps1bsp_vertex_t *vertices, const ps1bsp_polyvertex_t *polyVerts, u_char numVerts, u_short tpage, u_long *ot)
{
// Draw the face as a quad strip
const STVECTOR *v0, *v1, *v2, *v3;
const ps1bsp_polyvertex_t *v0, *v1, *v2, *v3;
u_char i0, i1, i2, i3;
u_char head = 0;
u_char tail = numVerts;
@ -225,25 +223,22 @@ static INLINE void draw_quadstrip_water(STVECTOR *verts, u_char numVerts, u_shor
i2 = --tail;
i3 = head++;
v0 = &verts[i0];
v1 = &verts[i1];
v2 = &verts[i2];
v0 = &polyVerts[i0];
v1 = &polyVerts[i1];
v2 = &polyVerts[i2];
v3 = &polyVerts[i3];
// Naively draw the quad with GTE, nothing special or optimized about this
gte_ldv3(v0, v1, v2);
// Transform the first three vertices
gte_ldv3(&vertices[v0->index], &vertices[v1->index], &vertices[v2->index]);
gte_rtpt(); // Rotation, translation, perspective projection
// Draw a flat-shaded untextured colored quad
// Draw a flat-shaded textured quad
POLY_FT4 *poly = (POLY_FT4*)mem_prim(sizeof(POLY_FT4));
setPolyFT4(poly);
gte_stsxy0(&poly->x0);
gte_stsxy1(&poly->x1);
gte_stsxy2(&poly->x2);
v3 = &verts[i3];
gte_stsxy3_ft3(poly);
// Transform the fourth vertex to complete the quad
gte_ldv0(v3);
gte_ldv0(&vertices[v3->index]);
gte_rtps();
gte_stsxy(&poly->x3);

34
world.c

@ -167,47 +167,23 @@ static void world_drawface_textured(const world_t *world, const ps1bsp_face_t *f
return;
// Draw textured, vertex colored polygons
STVECTOR *verts = (STVECTOR*)(scratchpad + 256);
ps1bsp_texture_t *faceTexture = &world->textures[face->textureId];
const ps1bsp_texture_t *texture = &world->textures[face->textureId];
const ps1bsp_polygon_t* poly = &world->polygons[face->firstPolygon];
if (face->flags & SURF_DRAWWATER)
{
for (u_char polyIdx = 0; polyIdx < face->numPolygons; ++polyIdx, ++poly)
{
ps1bsp_polyvertex_t *polyVertex = &world->polyVertices[poly->firstPolyVertex];
STVECTOR *curVert = verts;
for (u_char vertIdx = 0; vertIdx < poly->numPolyVertices; ++vertIdx, ++polyVertex, ++curVert)
{
const ps1bsp_vertex_t *vert = &world->vertices[polyVertex->index];
curVert->vx = vert->x;
curVert->vy = vert->y;
curVert->vz = vert->z;
curVert->u = (u_short)polyVertex->u;
curVert->v = (u_short)polyVertex->v;
}
draw_quadstrip_water(verts, poly->numPolyVertices, faceTexture->tpage, ot);
ps1bsp_polyvertex_t *polyVertices = &world->polyVertices[poly->firstPolyVertex];
draw_quadstrip_water(world->vertices, polyVertices, poly->numPolyVertices, texture->tpage, ot);
}
}
else
{
for (u_char polyIdx = 0; polyIdx < face->numPolygons; ++polyIdx, ++poly)
{
ps1bsp_polyvertex_t *polyVertex = &world->polyVertices[poly->firstPolyVertex];
STVECTOR *curVert = verts;
for (u_char vertIdx = 0; vertIdx < poly->numPolyVertices; ++vertIdx, ++polyVertex, ++curVert)
{
const ps1bsp_vertex_t *vert = &world->vertices[polyVertex->index];
curVert->vx = vert->x;
curVert->vy = vert->y;
curVert->vz = vert->z;
curVert->u = (u_short)polyVertex->u;
curVert->v = (u_short)polyVertex->v;
curVert->pad = polyVertex->light;
}
draw_quadstrip_textured(verts, poly->numPolyVertices, faceTexture->tpage, ot);
ps1bsp_polyvertex_t *polyVertices = &world->polyVertices[poly->firstPolyVertex];
draw_quadstrip_textured(world->vertices, polyVertices, poly->numPolyVertices, texture->tpage, ot);
}
}
}

Loading…
Cancel
Save