no more 3dfx

This commit is contained in:
Jaime Passos 2020-01-28 00:56:22 -03:00
parent b0ba9d22a8
commit a321ec9135

View file

@ -26,9 +26,6 @@
#include "../r_patch.h" #include "../r_patch.h"
#include "../p_setup.h" #include "../p_setup.h"
// Values set after a call to HWR_ResizeBlock()
static INT32 blocksize, blockwidth, blockheight;
INT32 patchformat = GR_TEXFMT_AP_88; // use alpha for holes INT32 patchformat = GR_TEXFMT_AP_88; // use alpha for holes
INT32 textureformat = GR_TEXFMT_P_8; // use chromakey for hole INT32 textureformat = GR_TEXFMT_P_8; // use chromakey for hole
@ -315,7 +312,7 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap,
I_Error("HWR_DrawPatchInCache: no drawer defined for this bpp (%d)\n",bpp); I_Error("HWR_DrawPatchInCache: no drawer defined for this bpp (%d)\n",bpp);
// NOTE: should this actually be pblockwidth*bpp? // NOTE: should this actually be pblockwidth*bpp?
blockmodulo = blockwidth*bpp; blockmodulo = pblockwidth*bpp;
// Draw each column to the block cache // Draw each column to the block cache
for (; ncols--; block += bpp, xfrac += xfracstep) for (; ncols--; block += bpp, xfrac += xfracstep)
@ -408,7 +405,7 @@ static void HWR_DrawTexturePatchInCache(GLMipmap_t *mipmap,
I_Error("HWR_DrawPatchInCache: no drawer defined for this bpp (%d)\n",bpp); I_Error("HWR_DrawPatchInCache: no drawer defined for this bpp (%d)\n",bpp);
// NOTE: should this actually be pblockwidth*bpp? // NOTE: should this actually be pblockwidth*bpp?
blockmodulo = blockwidth*bpp; blockmodulo = pblockwidth*bpp;
// Draw each column to the block cache // Draw each column to the block cache
for (block += col*bpp; ncols--; block += bpp, xfrac += xfracstep) for (block += col*bpp; ncols--; block += bpp, xfrac += xfracstep)
@ -426,29 +423,12 @@ static void HWR_DrawTexturePatchInCache(GLMipmap_t *mipmap,
} }
} }
// resize the patch to be 3dfx compliant
// set : blocksize = blockwidth * blockheight (no bpp used)
// blockwidth
// blockheight
//note : 8bit (1 byte per pixel) palettized format
static void HWR_ResizeBlock(INT32 originalwidth, INT32 originalheight,
GrTexInfo *grInfo)
{
(void)grInfo;
blockwidth = originalwidth;
blockheight = originalheight;
blocksize = blockwidth * blockheight;
//CONS_Debug(DBG_RENDER, "Width is %d, Height is %d\n", blockwidth, blockheight);
}
static UINT8 *MakeBlock(GLMipmap_t *grMipmap) static UINT8 *MakeBlock(GLMipmap_t *grMipmap)
{ {
UINT8 *block; UINT8 *block;
INT32 bpp, i; INT32 bpp, i;
UINT16 bu16 = ((0x00 <<8) | HWR_PATCHES_CHROMAKEY_COLORINDEX); UINT16 bu16 = ((0x00 <<8) | HWR_PATCHES_CHROMAKEY_COLORINDEX);
INT32 blocksize = (grMipmap->width * grMipmap->height);
bpp = format2bpp[grMipmap->grInfo.format]; bpp = format2bpp[grMipmap->grInfo.format];
block = Z_Malloc(blocksize*bpp, PU_HWRCACHE, &(grMipmap->grInfo.data)); block = Z_Malloc(blocksize*bpp, PU_HWRCACHE, &(grMipmap->grInfo.data));
@ -479,6 +459,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLTexture_t *grtex)
texpatch_t *patch; texpatch_t *patch;
patch_t *realpatch; patch_t *realpatch;
UINT8 *pdata; UINT8 *pdata;
INT32 blockwidth, blockheight, blocksize;
INT32 i; INT32 i;
boolean skyspecial = false; //poor hack for Legacy large skies.. boolean skyspecial = false; //poor hack for Legacy large skies..
@ -499,11 +480,13 @@ static void HWR_GenerateTexture(INT32 texnum, GLTexture_t *grtex)
else else
grtex->mipmap.flags = TF_CHROMAKEYED | TF_WRAPXY; grtex->mipmap.flags = TF_CHROMAKEYED | TF_WRAPXY;
HWR_ResizeBlock (texture->width, texture->height, &grtex->mipmap.grInfo); grtex->mipmap.width = (UINT16)texture->width;
grtex->mipmap.width = (UINT16)blockwidth; grtex->mipmap.height = (UINT16)texture->height;
grtex->mipmap.height = (UINT16)blockheight;
grtex->mipmap.grInfo.format = textureformat; grtex->mipmap.grInfo.format = textureformat;
blockwidth = texture->width;
blockheight = texture->height;
blocksize = (blockwidth * blockheight);
block = MakeBlock(&grtex->mipmap); block = MakeBlock(&grtex->mipmap);
if (skyspecial) //Hurdler: not efficient, but better than holes in the sky (and it's done only at level loading) if (skyspecial) //Hurdler: not efficient, but better than holes in the sky (and it's done only at level loading)
@ -572,8 +555,6 @@ static void HWR_GenerateTexture(INT32 texnum, GLTexture_t *grtex)
// patch may be NULL if grMipmap has been initialised already and makebitmap is false // patch may be NULL if grMipmap has been initialised already and makebitmap is false
void HWR_MakePatch (const patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipmap, boolean makebitmap) void HWR_MakePatch (const patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipmap, boolean makebitmap)
{ {
INT32 newwidth, newheight;
#ifndef NO_PNG_LUMPS #ifndef NO_PNG_LUMPS
// lump is a png so convert it // lump is a png so convert it
size_t len = W_LumpLengthPwad(grPatch->wadnum, grPatch->lumpnum); size_t len = W_LumpLengthPwad(grPatch->wadnum, grPatch->lumpnum);
@ -592,42 +573,29 @@ void HWR_MakePatch (const patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipm
grPatch->leftoffset = SHORT(patch->leftoffset); grPatch->leftoffset = SHORT(patch->leftoffset);
grPatch->topoffset = SHORT(patch->topoffset); grPatch->topoffset = SHORT(patch->topoffset);
// find the good 3dfx size (boring spec) grMipmap->width = (UINT16)SHORT(patch->width);
HWR_ResizeBlock (SHORT(patch->width), SHORT(patch->height), &grMipmap->grInfo); grMipmap->height = (UINT16)SHORT(patch->height);
grMipmap->width = (UINT16)blockwidth;
grMipmap->height = (UINT16)blockheight;
// no wrap around, no chroma key // no wrap around, no chroma key
grMipmap->flags = 0; grMipmap->flags = 0;
// setup the texture info // setup the texture info
grMipmap->grInfo.format = patchformat; grMipmap->grInfo.format = patchformat;
} }
else
{
blockwidth = grMipmap->width;
blockheight = grMipmap->height;
blocksize = blockwidth * blockheight;
}
Z_Free(grMipmap->grInfo.data); Z_Free(grMipmap->grInfo.data);
grMipmap->grInfo.data = NULL; grMipmap->grInfo.data = NULL;
// no rounddown, do not size up patches, so they don't look 'scaled'
newwidth = min(grPatch->width, blockwidth);
newheight = min(grPatch->height, blockheight);
if (makebitmap) if (makebitmap)
{ {
MakeBlock(grMipmap); MakeBlock(grMipmap);
HWR_DrawPatchInCache(grMipmap, HWR_DrawPatchInCache(grMipmap,
newwidth, newheight, grPatch->width, grPatch->height,
grPatch->width, grPatch->height, grPatch->width, grPatch->height,
patch); patch);
} }
grPatch->max_s = (float)newwidth / (float)blockwidth; grPatch->max_s = grPatch->max_t = 1.0f;
grPatch->max_t = (float)newheight / (float)blockheight;
} }
@ -1098,7 +1066,6 @@ GLPatch_t *HWR_GetPic(lumpnum_t lumpnum)
pic_t *pic; pic_t *pic;
UINT8 *block; UINT8 *block;
size_t len; size_t len;
INT32 newwidth, newheight;
pic = W_CacheLumpNum(lumpnum, PU_CACHE); pic = W_CacheLumpNum(lumpnum, PU_CACHE);
grpatch->width = SHORT(pic->width); grpatch->width = SHORT(pic->width);
@ -1108,10 +1075,8 @@ GLPatch_t *HWR_GetPic(lumpnum_t lumpnum)
grpatch->leftoffset = 0; grpatch->leftoffset = 0;
grpatch->topoffset = 0; grpatch->topoffset = 0;
// find the good 3dfx size (boring spec) grpatch->mipmap->width = (UINT16)grpatch->width;
HWR_ResizeBlock (grpatch->width, grpatch->height, &grpatch->mipmap->grInfo); grpatch->mipmap->height = (UINT16)grpatch->height;
grpatch->mipmap->width = (UINT16)blockwidth;
grpatch->mipmap->height = (UINT16)blockheight;
if (pic->mode == PALETTE) if (pic->mode == PALETTE)
grpatch->mipmap->grInfo.format = textureformat; // can be set by driver grpatch->mipmap->grInfo.format = textureformat; // can be set by driver
@ -1123,20 +1088,16 @@ GLPatch_t *HWR_GetPic(lumpnum_t lumpnum)
// allocate block // allocate block
block = MakeBlock(grpatch->mipmap); block = MakeBlock(grpatch->mipmap);
// no rounddown, do not size up patches, so they don't look 'scaled' if (grpatch->width == SHORT(pic->width) &&
newwidth = min(SHORT(pic->width),blockwidth); grpatch->height == SHORT(pic->height) &&
newheight = min(SHORT(pic->height),blockheight);
if (grpatch->width == blockwidth &&
grpatch->height == blockheight &&
format2bpp[grpatch->mipmap->grInfo.format] == format2bpp[picmode2GR[pic->mode]]) format2bpp[grpatch->mipmap->grInfo.format] == format2bpp[picmode2GR[pic->mode]])
{ {
// no conversion needed // no conversion needed
M_Memcpy(grpatch->mipmap->grInfo.data, pic->data,len); M_Memcpy(grpatch->mipmap->grInfo.data, pic->data,len);
} }
else else
HWR_DrawPicInCache(block, newwidth, newheight, HWR_DrawPicInCache(block, SHORT(pic->width), SHORT(pic->height),
blockwidth*format2bpp[grpatch->mipmap->grInfo.format], SHORT(pic->width)*format2bpp[grpatch->mipmap->grInfo.format],
pic, pic,
format2bpp[grpatch->mipmap->grInfo.format]); format2bpp[grpatch->mipmap->grInfo.format]);
@ -1144,8 +1105,7 @@ GLPatch_t *HWR_GetPic(lumpnum_t lumpnum)
Z_ChangeTag(block, PU_HWRCACHE_UNLOCKED); Z_ChangeTag(block, PU_HWRCACHE_UNLOCKED);
grpatch->mipmap->flags = 0; grpatch->mipmap->flags = 0;
grpatch->max_s = (float)newwidth / (float)blockwidth; grpatch->max_s = grpatch->max_t = 1.0f;
grpatch->max_t = (float)newheight / (float)blockheight;
} }
HWD.pfnSetTexture(grpatch->mipmap); HWD.pfnSetTexture(grpatch->mipmap);
//CONS_Debug(DBG_RENDER, "picloaded at %x as texture %d\n",grpatch->mipmap.grInfo.data, grpatch->mipmap.downloaded); //CONS_Debug(DBG_RENDER, "picloaded at %x as texture %d\n",grpatch->mipmap.grInfo.data, grpatch->mipmap.downloaded);
@ -1181,7 +1141,7 @@ static void HWR_DrawFadeMaskInCache(GLMipmap_t *mipmap, INT32 pblockwidth, INT32
{ {
INT32 i,j; INT32 i,j;
fixed_t posx, posy, stepx, stepy; fixed_t posx, posy, stepx, stepy;
UINT8 *block = mipmap->grInfo.data; // places the data directly into here, it already has the space allocated from HWR_ResizeBlock UINT8 *block = mipmap->grInfo.data; // places the data directly into here
UINT8 *flat; UINT8 *flat;
UINT8 *dest, *src, texel; UINT8 *dest, *src, texel;
RGBA_t col; RGBA_t col;
@ -1196,7 +1156,7 @@ static void HWR_DrawFadeMaskInCache(GLMipmap_t *mipmap, INT32 pblockwidth, INT32
for (j = 0; j < pblockheight; j++) for (j = 0; j < pblockheight; j++)
{ {
posx = 0; posx = 0;
dest = &block[j*blockwidth]; // 1bpp dest = &block[j*(mipmap->width)]; // 1bpp
src = &flat[(posy>>FRACBITS)*SHORT(fmwidth)]; src = &flat[(posy>>FRACBITS)*SHORT(fmwidth)];
for (i = 0; i < pblockwidth;i++) for (i = 0; i < pblockwidth;i++)
{ {
@ -1250,14 +1210,12 @@ static void HWR_CacheFadeMask(GLMipmap_t *grMipmap, lumpnum_t fademasklumpnum)
} }
// Thankfully, this will still work for this scenario // Thankfully, this will still work for this scenario
HWR_ResizeBlock(fmwidth, fmheight, &grMipmap->grInfo); grMipmap->width = fmwidth;
grMipmap->height = fmheight;
grMipmap->width = blockwidth;
grMipmap->height = blockheight;
MakeBlock(grMipmap); MakeBlock(grMipmap);
HWR_DrawFadeMaskInCache(grMipmap, blockwidth, blockheight, fademasklumpnum, fmwidth, fmheight); HWR_DrawFadeMaskInCache(grMipmap, fmwidth, fmheight, fademasklumpnum, fmwidth, fmheight);
// I DO need to convert this because it isn't power of 2 and we need the alpha // I DO need to convert this because it isn't power of 2 and we need the alpha
} }