Merge branch 'gl-levelflat-fix' into 'next'

Fix a misuse of levelflat_t.picture in OpenGL

See merge request STJr/SRB2!1327
This commit is contained in:
LJ Sonic 2021-01-25 16:40:02 -05:00
commit 14ee92ef67
4 changed files with 22 additions and 14 deletions

View File

@ -866,7 +866,7 @@ static void HWR_CacheTextureAsFlat(GLMipmap_t *grMipmap, INT32 texturenum)
}
// Download a Doom 'flat' to the hardware cache and make it ready for use
void HWR_LiterallyGetFlat(lumpnum_t flatlumpnum)
void HWR_GetRawFlat(lumpnum_t flatlumpnum)
{
GLMipmap_t *grmip;
patch_t *patch;
@ -895,7 +895,7 @@ void HWR_GetLevelFlat(levelflat_t *levelflat)
return;
if (levelflat->type == LEVELFLAT_FLAT)
HWR_LiterallyGetFlat(levelflat->u.flat.lumpnum);
HWR_GetRawFlat(levelflat->u.flat.lumpnum);
else if (levelflat->type == LEVELFLAT_TEXTURE)
{
GLMapTexture_t *grtex;
@ -934,15 +934,17 @@ void HWR_GetLevelFlat(levelflat_t *levelflat)
#ifndef NO_PNG_LUMPS
else if (levelflat->type == LEVELFLAT_PNG)
{
INT32 pngwidth = 0, pngheight = 0;
GLMipmap_t *mipmap = levelflat->mipmap;
UINT8 *flat;
size_t size;
// Cache the picture.
if (!levelflat->picture)
if (!levelflat->mippic)
{
levelflat->picture = Picture_PNGConvert(W_CacheLumpNum(levelflat->u.flat.lumpnum, PU_CACHE), PICFMT_FLAT, &pngwidth, &pngheight, NULL, NULL, W_LumpLength(levelflat->u.flat.lumpnum), NULL, 0);
INT32 pngwidth = 0, pngheight = 0;
void *pic = Picture_PNGConvert(W_CacheLumpNum(levelflat->u.flat.lumpnum, PU_CACHE), PICFMT_FLAT, &pngwidth, &pngheight, NULL, NULL, W_LumpLength(levelflat->u.flat.lumpnum), NULL, 0);
Z_ChangeTag(pic, PU_LEVEL);
Z_SetUser(pic, &levelflat->mippic);
levelflat->width = (UINT16)pngwidth;
levelflat->height = (UINT16)pngheight;
}
@ -950,7 +952,7 @@ void HWR_GetLevelFlat(levelflat_t *levelflat)
// Make the mipmap.
if (mipmap == NULL)
{
mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_LEVEL, NULL);
mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_STATIC, NULL);
mipmap->format = GL_TEXFMT_P_8;
mipmap->flags = TF_WRAPXY|TF_CHROMAKEYED;
levelflat->mipmap = mipmap;
@ -958,17 +960,22 @@ void HWR_GetLevelFlat(levelflat_t *levelflat)
if (!mipmap->data && !mipmap->downloaded)
{
UINT8 *flat;
size_t size;
if (levelflat->mippic == NULL)
I_Error("HWR_GetLevelFlat: levelflat->mippic == NULL");
mipmap->width = levelflat->width;
mipmap->height = levelflat->height;
size = (mipmap->width * mipmap->height);
flat = Z_Malloc(size, PU_LEVEL, &mipmap->data);
if (levelflat->picture == NULL)
I_Error("HWR_GetLevelFlat: levelflat->picture == NULL");
M_Memcpy(flat, levelflat->picture, size);
M_Memcpy(flat, levelflat->mippic, size);
}
// Tell the hardware driver to bind the current texture to the flat's mipmap
HWD.pfnSetTexture(mipmap);
HWR_SetCurrentTexture(mipmap);
}
#endif
else // set no texture

View File

@ -639,7 +639,7 @@ void HWR_DrawFlatFill (INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum
v[0].t = v[1].t = (float)((y & flatflag)/dflatsize);
v[2].t = v[3].t = (float)(v[0].t + h/dflatsize);
HWR_LiterallyGetFlat(flatlumpnum);
HWR_GetRawFlat(flatlumpnum);
//Hurdler: Boris, the same comment as above... but maybe for pics
// it not a problem since they don't have any transparent pixel

View File

@ -118,7 +118,7 @@ patch_t *HWR_GetPic(lumpnum_t lumpnum);
GLMapTexture_t *HWR_GetTexture(INT32 tex);
void HWR_GetLevelFlat(levelflat_t *levelflat);
void HWR_LiterallyGetFlat(lumpnum_t flatlumpnum);
void HWR_GetRawFlat(lumpnum_t flatlumpnum);
void HWR_FreeTexture(patch_t *patch);
void HWR_FreeTextureData(patch_t *patch);

View File

@ -80,6 +80,7 @@ typedef struct
UINT8 *picture;
#ifdef HWRENDER
void *mipmap;
void *mippic;
#endif
} levelflat_t;