Browse Source

Fixed a few issues and further optimized the quad drawing code.

unrollquadloop
Nico de Poel 3 years ago
parent
commit
32237fc6ec
  1. 18
      draw.h
  2. 4
      ps1bsp.h
  3. BIN
      test.ps1bsp
  4. 2
      world.c

18
draw.h

@ -10,7 +10,7 @@
#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 u_int color_white = ((255 << 16) | (255 << 8) | 255);
static INLINE void draw_triangle_lit(SVECTOR *verts, u_long *ot)
{
@ -243,8 +243,8 @@ static INLINE void draw_quadstrip_textured(const ps1bsp_vertex_t *vertices, cons
// Fill out the quad's data fields in struct order, to optimize data access
// First vertex and texture CLUT
setColorFast(&poly->r0, &v0->r);
gte_stsxy0(&poly->x0);
setUVFast(&poly->u0, &v0->u);
gte_stsxy0(&poly->x0);
poly->clut = quake_clut;
// Second vertex and texture page
@ -264,8 +264,8 @@ static INLINE void draw_quadstrip_textured(const ps1bsp_vertex_t *vertices, cons
// Fourth vertex
setColorFast(&poly->r3, &v3->r);
gte_stsxy(&poly->x3);
setUVFast(&poly->u3, &v3->u);
gte_stsxy(&poly->x3);
setPolyGT4(poly);
addPrim(ot, poly);
@ -309,29 +309,29 @@ static INLINE void draw_quadstrip_water(const ps1bsp_vertex_t *vertices, const p
// 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;
gte_stsxy0(&poly->x0);
poly->clut = water_clut;
// Second vertex and texture page
gte_stsxy1(&poly->x1);
setUVFast(&poly->u1, &v1->u);
poly->tpage = tpage;
gte_stsxy1(&poly->x1);
// Third vertex
gte_stsxy2(&poly->x2);
setUVFast(&poly->u2, &v2->u);
gte_stsxy2(&poly->x2);
// Transform the fourth vertex to complete the quad
gte_ldv0(&vertices[v3->index]);
gte_rtps();
// Fourth vertex
gte_stsxy(&poly->x3);
setUVFast(&poly->u3, &v3->u);
gte_stsxy(&poly->x3);
setPolyFT4(poly);
setSemiTrans(poly, semiTrans);
if (semiTrans) poly->code |= 2;
addPrim(ot, poly);
++polyCount;
}

4
ps1bsp.h

@ -59,9 +59,9 @@ typedef struct
// TODO: break up into poly vertex (index + uv) and surface vertex (index + light) shared between polygons. Will reduce this struct size to 4 bytes and eliminate duplicate light values.
typedef struct
{
unsigned short index;
unsigned char u, v;
unsigned char r, g, b, pad;
unsigned char u, v;
unsigned short index;
} ps1bsp_polyvertex_t;
// Faces are broken up into one or more polygons, each of which can be drawn as a quad/triangle strip with a single texture.

BIN
test.ps1bsp

2
world.c

@ -316,7 +316,7 @@ void world_draw(const world_t *world)
world_drawface = &world_drawface_lit;
ps1bsp_leaf_t *firstLeaf = NULL;
world_sortLeafs(world, world->models[0].nodeId, pvs, &firstLeaf);
world_sortLeafs(world, 0, pvs, &firstLeaf);
ps1bsp_face_t *firstFace = world_sortFaces(world, firstLeaf);
world_drawFaces(world, firstFace);
}
Loading…
Cancel
Save