Browse Source

Wrapped vertex copying code into a macro to make the quad drawing code more readable.

Added some generic n-bit blitting macros and started using them.
master
Nico de Poel 3 years ago
parent
commit
58b2e8dc20
  1. 100
      draw.h

100
draw.h

@ -10,6 +10,10 @@
#define setColorFast(pr, r) *((u_int*)(pr)) = *((u_int*)(r)) #define setColorFast(pr, r) *((u_int*)(pr)) = *((u_int*)(r))
#define setUVFast(pu, u) *((u_short*)(pu)) = *((u_short*)(u)) #define setUVFast(pu, u) *((u_short*)(pu)) = *((u_short*)(u))
#define blit16(dst, src) *((uint16_t*)(dst)) = *((uint16_t*)(src))
#define blit32(dst, src) *((uint32_t*)(dst)) = *((uint32_t*)(src))
#define blit64(dst, src) *((uint64_t*)(dst)) = *((uint64_t*)(src))
static u_int color_white = ((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) static INLINE void draw_triangle_lit(SVECTOR *verts, u_long *ot)
@ -340,10 +344,10 @@ typedef struct _TMPVERT
} TMPVERT; } TMPVERT;
#define copyVertFast(dst, pv, v) \ #define copyVertFast(dst, pv, v) \
setColorFast(&(dst)->r, &(pv)->r); \
setColorFast(&(dst)->vx, &(v)->vx); \
setColorFast(&(dst)->vz, &(v)->vz); \
setUVFast(&(dst)->u, &(pv)->u);
blit32(&(dst)->r, &(pv)->r); \
blit32(&(dst)->vx, &(v)->vx); \
blit32(&(dst)->vz, &(v)->vz); \
blit16(&(dst)->u, &(pv)->u);
#define lerpVert(dst, src0, src1) \ #define lerpVert(dst, src0, src1) \
(dst)->vx = (int16_t)(((int32_t)(src0)->vx + (int32_t)(src1)->vx) >> 1); \ (dst)->vx = (int16_t)(((int32_t)(src0)->vx + (int32_t)(src1)->vx) >> 1); \
@ -355,10 +359,10 @@ typedef struct _TMPVERT
(dst)->u = (uint8_t)(((uint16_t)(src0)->u + (uint16_t)(src1)->u) >> 1); \ (dst)->u = (uint8_t)(((uint16_t)(src0)->u + (uint16_t)(src1)->u) >> 1); \
(dst)->v = (uint8_t)(((uint16_t)(src0)->v + (uint16_t)(src1)->v) >> 1); (dst)->v = (uint8_t)(((uint16_t)(src0)->v + (uint16_t)(src1)->v) >> 1);
#define blitVert(dst, src) \
setColorFast(&(dst)->x, &(src)->vx); \
setColorFast(&(dst)->r, &(src)->r); \
setUVFast(&(dst)->u, &(src)->u);
#define blitVert(dst, i, src) \
blit32(&(dst)->x ## i, &(src).vx); \
blit32(&(dst)->r ## i, &(src).r); \
blit16(&(dst)->u ## i, &(src).u);
static INLINE void draw_quadstrip_tess2(const ps1bsp_vertex_t *vertices, const ps1bsp_polyvertex_t *polyVerts, u_char numVerts, u_short tpage, u_long *ot) static INLINE void draw_quadstrip_tess2(const ps1bsp_vertex_t *vertices, const ps1bsp_polyvertex_t *polyVerts, u_char numVerts, u_short tpage, u_long *ot)
{ {
@ -426,93 +430,45 @@ static INLINE void draw_quadstrip_tess2(const ps1bsp_vertex_t *vertices, const p
// Draw the first quad // Draw the first quad
POLY_GT4 *poly = (POLY_GT4*)mem_prim(sizeof(POLY_GT4)); POLY_GT4 *poly = (POLY_GT4*)mem_prim(sizeof(POLY_GT4));
setColorFast(&poly->x0, &tmp[0].vx);
setColorFast(&poly->r0, &tmp[0].r);
setUVFast(&poly->u0, &tmp[0].u);
blitVert(poly, 0, tmp[0]);
poly->clut = quake_clut; poly->clut = quake_clut;
setColorFast(&poly->x1, &tmp[3].vx);
setColorFast(&poly->r1, &tmp[3].r);
setUVFast(&poly->u1, &tmp[3].u);
blitVert(poly, 1, tmp[3]);
poly->tpage = tpage; poly->tpage = tpage;
setColorFast(&poly->x2, &tmp[1].vx);
setColorFast(&poly->r2, &tmp[1].r);
setUVFast(&poly->u2, &tmp[1].u);
setColorFast(&poly->x3, &tmp[4].vx);
setColorFast(&poly->r3, &tmp[4].r);
setUVFast(&poly->u3, &tmp[4].u);
blitVert(poly, 2, tmp[1]);
blitVert(poly, 3, tmp[4]);
setPolyGT4(poly); setPolyGT4(poly);
addPrim(ot, poly); addPrim(ot, poly);
// Second quad // Second quad
poly = (POLY_GT4*)mem_prim(sizeof(POLY_GT4)); poly = (POLY_GT4*)mem_prim(sizeof(POLY_GT4));
setColorFast(&poly->x0, &tmp[1].vx);
setColorFast(&poly->r0, &tmp[1].r);
setUVFast(&poly->u0, &tmp[1].u);
blitVert(poly, 0, tmp[1]);
poly->clut = quake_clut; poly->clut = quake_clut;
setColorFast(&poly->x1, &tmp[4].vx);
setColorFast(&poly->r1, &tmp[4].r);
setUVFast(&poly->u1, &tmp[4].u);
blitVert(poly, 1, tmp[4]);
poly->tpage = tpage; poly->tpage = tpage;
setColorFast(&poly->x2, &tmp[2].vx);
setColorFast(&poly->r2, &tmp[2].r);
setUVFast(&poly->u2, &tmp[2].u);
setColorFast(&poly->x3, &tmp[5].vx);
setColorFast(&poly->r3, &tmp[5].r);
setUVFast(&poly->u3, &tmp[5].u);
blitVert(poly, 2, tmp[2]);
blitVert(poly, 3, tmp[5]);
setPolyGT4(poly); setPolyGT4(poly);
addPrim(ot, poly); addPrim(ot, poly);
// Third quad // Third quad
poly = (POLY_GT4*)mem_prim(sizeof(POLY_GT4)); poly = (POLY_GT4*)mem_prim(sizeof(POLY_GT4));
setColorFast(&poly->x0, &tmp[3].vx);
setColorFast(&poly->r0, &tmp[3].r);
setUVFast(&poly->u0, &tmp[3].u);
blitVert(poly, 0, tmp[3]);
poly->clut = quake_clut; poly->clut = quake_clut;
setColorFast(&poly->x1, &tmp[6].vx);
setColorFast(&poly->r1, &tmp[6].r);
setUVFast(&poly->u1, &tmp[6].u);
blitVert(poly, 1, tmp[6]);
poly->tpage = tpage; poly->tpage = tpage;
setColorFast(&poly->x2, &tmp[4].vx);
setColorFast(&poly->r2, &tmp[4].r);
setUVFast(&poly->u2, &tmp[4].u);
setColorFast(&poly->x3, &tmp[7].vx);
setColorFast(&poly->r3, &tmp[7].r);
setUVFast(&poly->u3, &tmp[7].u);
blitVert(poly, 2, tmp[4]);
blitVert(poly, 3, tmp[7]);
setPolyGT4(poly); setPolyGT4(poly);
addPrim(ot, poly); addPrim(ot, poly);
// Fourth quad // Fourth quad
poly = (POLY_GT4*)mem_prim(sizeof(POLY_GT4)); poly = (POLY_GT4*)mem_prim(sizeof(POLY_GT4));
setColorFast(&poly->x0, &tmp[4].vx);
setColorFast(&poly->r0, &tmp[4].r);
setUVFast(&poly->u0, &tmp[4].u);
blitVert(poly, 0, tmp[4]);
poly->clut = quake_clut; poly->clut = quake_clut;
setColorFast(&poly->x1, &tmp[7].vx);
setColorFast(&poly->r1, &tmp[7].r);
setUVFast(&poly->u1, &tmp[7].u);
blitVert(poly, 1, tmp[7]);
poly->tpage = tpage; poly->tpage = tpage;
setColorFast(&poly->x2, &tmp[5].vx);
setColorFast(&poly->r2, &tmp[5].r);
setUVFast(&poly->u2, &tmp[5].u);
setColorFast(&poly->x3, &tmp[8].vx);
setColorFast(&poly->r3, &tmp[8].r);
setUVFast(&poly->u3, &tmp[8].u);
blitVert(poly, 2, tmp[5]);
blitVert(poly, 3, tmp[8]);
setPolyGT4(poly); setPolyGT4(poly);
addPrim(ot, poly); addPrim(ot, poly);

Loading…
Cancel
Save