Skip to content

Commit

Permalink
Add PO2 flat cases for sizes smaller than 32x32
Browse files Browse the repository at this point in the history
  • Loading branch information
Lactozilla authored and HybridEidolon committed Nov 16, 2022
1 parent fb038a8 commit 86a0525
Show file tree
Hide file tree
Showing 15 changed files with 343 additions and 390 deletions.
37 changes: 5 additions & 32 deletions src/hardware/hw_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,45 +804,18 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex)

static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum)
{
size_t size, pflatsize;
size_t size = W_LumpLength(flatlumpnum);
UINT16 pflatsize = R_GetFlatSize(size);

// setup the texture info
grMipmap->format = GL_TEXFMT_P_8;
grMipmap->flags = TF_WRAPXY|TF_CHROMAKEYED;

size = W_LumpLength(flatlumpnum);

switch (size)
{
case 4194304: // 2048x2048 lump
pflatsize = 2048;
break;
case 1048576: // 1024x1024 lump
pflatsize = 1024;
break;
case 262144:// 512x512 lump
pflatsize = 512;
break;
case 65536: // 256x256 lump
pflatsize = 256;
break;
case 16384: // 128x128 lump
pflatsize = 128;
break;
case 1024: // 32x32 lump
pflatsize = 32;
break;
default: // 64x64 lump
pflatsize = 64;
break;
}

grMipmap->width = (UINT16)pflatsize;
grMipmap->height = (UINT16)pflatsize;
grMipmap->width = pflatsize;
grMipmap->height = pflatsize;

// the flat raw data needn't be converted with palettized textures
W_ReadLump(flatlumpnum, Z_Malloc(W_LumpLength(flatlumpnum),
PU_HWRCACHE, &grMipmap->data));
W_ReadLump(flatlumpnum, Z_Malloc(size, PU_HWRCACHE, &grMipmap->data));
}

static void HWR_CacheTextureAsFlat(GLMipmap_t *grMipmap, INT32 texturenum)
Expand Down
39 changes: 3 additions & 36 deletions src/hardware/hw_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,42 +705,10 @@ void HWR_DrawPic(INT32 x, INT32 y, lumpnum_t lumpnum)
// --------------------------------------------------------------------------
void HWR_DrawFlatFill (INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum)
{
FOutVector v[4];
double dflatsize;
INT32 flatflag;
FOutVector v[4];
const size_t len = W_LumpLength(flatlumpnum);

switch (len)
{
case 4194304: // 2048x2048 lump
dflatsize = 2048.0f;
flatflag = 2047;
break;
case 1048576: // 1024x1024 lump
dflatsize = 1024.0f;
flatflag = 1023;
break;
case 262144:// 512x512 lump
dflatsize = 512.0f;
flatflag = 511;
break;
case 65536: // 256x256 lump
dflatsize = 256.0f;
flatflag = 255;
break;
case 16384: // 128x128 lump
dflatsize = 128.0f;
flatflag = 127;
break;
case 1024: // 32x32 lump
dflatsize = 32.0f;
flatflag = 31;
break;
default: // 64x64 lump
dflatsize = 64.0f;
flatflag = 63;
break;
}
UINT16 flatflag = R_GetFlatSize(len) - 1;
double dflatsize = (double)(flatflag + 1);

// 3--2
// | /|
Expand All @@ -754,7 +722,6 @@ void HWR_DrawFlatFill (INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum

v[0].z = v[1].z = v[2].z = v[3].z = 1.0f;

// flat is 64x64 lod and texture offsets are [0.0, 1.0]
v[0].s = v[3].s = (float)((x & flatflag)/dflatsize);
v[2].s = v[1].s = (float)(v[0].s + w/dflatsize);
v[0].t = v[1].t = (float)((y & flatflag)/dflatsize);
Expand Down
127 changes: 39 additions & 88 deletions src/hardware/hw_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,30 +360,39 @@ static FUINT HWR_CalcSlopeLight(FUINT lightnum, angle_t dir, fixed_t delta)
// -----------------+
static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, FBITFIELD PolyFlags, INT32 lightlevel, levelflat_t *levelflat, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap)
{
polyvertex_t * pv;
float height; //constant y for all points on the convex flat polygon
FOutVector *v3d;
INT32 nrPlaneVerts; //verts original define of convex flat polygon
INT32 i;
float flatxref,flatyref;
FSurfaceInfo Surf;
FOutVector *v3d;
polyvertex_t *pv;
pslope_t *slope = NULL;
INT32 shader = SHADER_DEFAULT;

size_t nrPlaneVerts;
INT32 i;

float height; // constant y for all points on the convex flat polygon
float flatxref, flatyref, anglef = 0.0f;
float fflatwidth = 64.0f, fflatheight = 64.0f;
INT32 flatflag = 63;
UINT16 flatflag = 63;

boolean texflat = false;
float scrollx = 0.0f, scrolly = 0.0f, anglef = 0.0f;
angle_t angle = 0;
FSurfaceInfo Surf;

float tempxsow, tempytow;
pslope_t *slope = NULL;
float scrollx = 0.0f, scrolly = 0.0f;
angle_t angle = 0;

static FOutVector *planeVerts = NULL;
static UINT16 numAllocedPlaneVerts = 0;

INT32 shader = SHADER_DEFAULT;

// no convex poly were generated for this subsector
if (!xsub->planepoly)
return;

pv = xsub->planepoly->pts;
nrPlaneVerts = xsub->planepoly->numpts;

if (nrPlaneVerts < 3) // not even a triangle?
return;

// Get the slope pointer to simplify future code
if (FOFsector)
{
Expand All @@ -406,12 +415,6 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool

height = FIXED_TO_FLOAT(fixedheight);

pv = xsub->planepoly->pts;
nrPlaneVerts = xsub->planepoly->numpts;

if (nrPlaneVerts < 3) //not even a triangle ?
return;

// Allocate plane-vertex buffer if we need to
if (!planeVerts || nrPlaneVerts > numAllocedPlaneVerts)
{
Expand All @@ -426,31 +429,8 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool
if (levelflat->type == LEVELFLAT_FLAT)
{
size_t len = W_LumpLength(levelflat->u.flat.lumpnum);
switch (len)
{
case 4194304: // 2048x2048 lump
fflatwidth = fflatheight = 2048.0f;
break;
case 1048576: // 1024x1024 lump
fflatwidth = fflatheight = 1024.0f;
break;
case 262144:// 512x512 lump
fflatwidth = fflatheight = 512.0f;
break;
case 65536: // 256x256 lump
fflatwidth = fflatheight = 256.0f;
break;
case 16384: // 128x128 lump
fflatwidth = fflatheight = 128.0f;
break;
case 1024: // 32x32 lump
fflatwidth = fflatheight = 32.0f;
break;
default: // 64x64 lump
fflatwidth = fflatheight = 64.0f;
break;
}
flatflag = ((INT32)fflatwidth)-1;
flatflag = R_GetFlatSize(len) - 1;
fflatwidth = fflatheight = (float)(flatflag + 1);
}
else
{
Expand Down Expand Up @@ -550,7 +530,7 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool
}\
}

for (i = 0, v3d = planeVerts; i < nrPlaneVerts; i++,v3d++,pv++)
for (i = 0, v3d = planeVerts; i < (INT32)nrPlaneVerts; i++,v3d++,pv++)
SETUP3DVERT(v3d, pv->x, pv->y);

if (slope)
Expand Down Expand Up @@ -2693,13 +2673,13 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling,
float height = FIXED_TO_FLOAT(fixedheight); // constant y for all points on the convex flat polygon
float flatxref, flatyref;
float fflatwidth = 64.0f, fflatheight = 64.0f;
INT32 flatflag = 63;
UINT16 flatflag = 63;

boolean texflat = false;

float scrollx = 0.0f, scrolly = 0.0f;
float tempxsow, tempytow, anglef = 0.0f;
angle_t angle = 0;
fixed_t tempxs, tempyt;

static FOutVector *planeVerts = NULL;
static UINT16 numAllocedPlaneVerts = 0;
Expand All @@ -2726,31 +2706,8 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling,
if (levelflat->type == LEVELFLAT_FLAT)
{
size_t len = W_LumpLength(levelflat->u.flat.lumpnum);
switch (len)
{
case 4194304: // 2048x2048 lump
fflatwidth = fflatheight = 2048.0f;
break;
case 1048576: // 1024x1024 lump
fflatwidth = fflatheight = 1024.0f;
break;
case 262144:// 512x512 lump
fflatwidth = fflatheight = 512.0f;
break;
case 65536: // 256x256 lump
fflatwidth = fflatheight = 256.0f;
break;
case 16384: // 128x128 lump
fflatwidth = fflatheight = 128.0f;
break;
case 1024: // 32x32 lump
fflatwidth = fflatheight = 32.0f;
break;
default: // 64x64 lump
fflatwidth = fflatheight = 64.0f;
break;
}
flatflag = ((INT32)fflatwidth)-1;
flatflag = R_GetFlatSize(len) - 1;
fflatwidth = fflatheight = (float)(flatflag + 1);
}
else
{
Expand Down Expand Up @@ -2813,20 +2770,13 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling,

if (angle) // Only needs to be done if there's an altered angle
{
angle = (InvAngle(angle))>>ANGLETOFINESHIFT;
tempxsow = flatxref;
tempytow = flatyref;

// This needs to be done so that it scrolls in a different direction after rotation like software
/*tempxs = FLOAT_TO_FIXED(scrollx);
tempyt = FLOAT_TO_FIXED(scrolly);
scrollx = (FIXED_TO_FLOAT(FixedMul(tempxs, FINECOSINE(angle)) - FixedMul(tempyt, FINESINE(angle))));
scrolly = (FIXED_TO_FLOAT(FixedMul(tempxs, FINESINE(angle)) + FixedMul(tempyt, FINECOSINE(angle))));*/
anglef = ANG2RAD(InvAngle(angle));

// This needs to be done so everything aligns after rotation
// It would be done so that rotation is done, THEN the translation, but I couldn't get it to rotate AND scroll like software does
tempxs = FLOAT_TO_FIXED(flatxref);
tempyt = FLOAT_TO_FIXED(flatyref);
flatxref = (FIXED_TO_FLOAT(FixedMul(tempxs, FINECOSINE(angle)) - FixedMul(tempyt, FINESINE(angle))));
flatyref = (FIXED_TO_FLOAT(FixedMul(tempxs, FINESINE(angle)) + FixedMul(tempyt, FINECOSINE(angle))));
flatxref = (tempxsow * cos(anglef)) - (tempytow * sin(anglef));
flatyref = (tempxsow * sin(anglef)) + (tempytow * cos(anglef));
}

for (i = 0; i < (INT32)nrPlaneVerts; i++,v3d++)
Expand All @@ -2847,10 +2797,11 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling,
// Need to rotate before translate
if (angle) // Only needs to be done if there's an altered angle
{
tempxs = FLOAT_TO_FIXED(v3d->s);
tempyt = FLOAT_TO_FIXED(v3d->t);
v3d->s = (FIXED_TO_FLOAT(FixedMul(tempxs, FINECOSINE(angle)) - FixedMul(tempyt, FINESINE(angle))));
v3d->t = (FIXED_TO_FLOAT(FixedMul(tempxs, FINESINE(angle)) + FixedMul(tempyt, FINECOSINE(angle))));
tempxsow = v3d->s;
tempytow = v3d->t;

v3d->s = (tempxsow * cos(anglef)) - (tempytow * sin(anglef));
v3d->t = (tempxsow * sin(anglef)) + (tempytow * cos(anglef));
}

v3d->x = FIXED_TO_FLOAT(polysector->vertices[i]->x);
Expand Down
2 changes: 1 addition & 1 deletion src/r_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fixed_t ds_xfrac, ds_yfrac, ds_xstep, ds_ystep;
INT32 ds_waterofs, ds_bgofs;

UINT16 ds_flatwidth, ds_flatheight;
boolean ds_powersoftwo;
boolean ds_powersoftwo, ds_solidcolor;

UINT8 *ds_source; // points to the start of a flat
UINT8 *ds_transmap; // one of the translucency tables
Expand Down
17 changes: 12 additions & 5 deletions src/r_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extern fixed_t ds_xfrac, ds_yfrac, ds_xstep, ds_ystep;
extern INT32 ds_waterofs, ds_bgofs;

extern UINT16 ds_flatwidth, ds_flatheight;
extern boolean ds_powersoftwo;
extern boolean ds_powersoftwo, ds_solidcolor;

extern UINT8 *ds_source;
extern UINT8 *ds_transmap;
Expand Down Expand Up @@ -194,8 +194,8 @@ void R_DrawTranslucentFloorSprite_8(void);
void R_DrawTiltedFloorSprite_8(void);
void R_DrawTiltedTranslucentFloorSprite_8(void);

void R_DrawTranslucentWaterSpan_8(void);
void R_DrawTiltedTranslucentWaterSpan_8(void);
void R_DrawWaterSpan_8(void);
void R_DrawTiltedWaterSpan_8(void);

void R_DrawFogSpan_8(void);
void R_DrawTiltedFogSpan_8(void);
Expand All @@ -215,8 +215,15 @@ void R_DrawTranslucentFloorSprite_NPO2_8(void);
void R_DrawTiltedFloorSprite_NPO2_8(void);
void R_DrawTiltedTranslucentFloorSprite_NPO2_8(void);

void R_DrawTranslucentWaterSpan_NPO2_8(void);
void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void);
void R_DrawWaterSpan_NPO2_8(void);
void R_DrawTiltedWaterSpan_NPO2_8(void);

void R_DrawSolidColorSpan_8(void);
void R_DrawTransSolidColorSpan_8(void);
void R_DrawTiltedSolidColorSpan_8(void);
void R_DrawTiltedTransSolidColorSpan_8(void);
void R_DrawWaterSolidColorSpan_8(void);
void R_DrawTiltedWaterSolidColorSpan_8(void);

#ifdef USEASM
void ASMCALL R_DrawColumn_8_ASM(void);
Expand Down
Loading

0 comments on commit 86a0525

Please sign in to comment.