Fix OpenGL

This commit is contained in:
Jaime Passos 2020-01-07 14:07:14 -03:00
parent 5b5f371b0c
commit 1358507785
5 changed files with 98 additions and 35 deletions

View File

@ -1024,7 +1024,7 @@ void HWR_GetLevelFlat(levelflat_t *levelflat)
INT32 texturenum = levelflat->u.texture.num;
#ifdef PARANOIA
if ((unsigned)texturenum >= gr_numtextures)
I_Error("HWR_GetLevelFlat: texturenum >= numtextures\n");
I_Error("HWR_GetLevelFlat: texturenum >= numtextures");
#endif
// Who knows?
@ -1044,6 +1044,58 @@ void HWR_GetLevelFlat(levelflat_t *levelflat)
// The system-memory data can be purged now.
Z_ChangeTag(grtex->mipmap.grInfo.data, PU_HWRCACHE_UNLOCKED);
}
else if (levelflat->type == LEVELFLAT_PATCH)
{
GLPatch_t *patch = W_CachePatchNum(levelflat->u.flat.lumpnum, PU_CACHE);
levelflat->width = (UINT16)SHORT(patch->width);
levelflat->height = (UINT16)SHORT(patch->height);
HWR_GetPatch(patch);
}
#ifndef NO_PNG_LUMPS
else if (levelflat->type == LEVELFLAT_PNG)
{
INT32 pngwidth, pngheight;
GLMipmap_t *mipmap = levelflat->mipmap;
UINT8 *flat;
size_t size;
// Cache the picture.
if (!levelflat->picture)
{
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);
levelflat->width = (UINT16)pngwidth;
levelflat->height = (UINT16)pngheight;
}
// Make the mipmap.
if (mipmap == NULL)
{
mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_LEVEL, NULL);
mipmap->grInfo.format = GR_TEXFMT_P_8;
mipmap->flags = TF_WRAPXY|TF_CHROMAKEYED;
#ifdef GLIDE_API_COMPATIBILITY
mipmap->grInfo.smallLodLog2 = GR_LOD_LOG2_64;
mipmap->grInfo.largeLodLog2 = GR_LOD_LOG2_64;
mipmap->grInfo.aspectRatioLog2 = GR_ASPECT_LOG2_1x1;
#endif
levelflat->mipmap = mipmap;
}
if (!mipmap->grInfo.data && !mipmap->downloaded)
{
mipmap->width = levelflat->width;
mipmap->height = levelflat->height;
size = (mipmap->width * mipmap->height);
flat = Z_Malloc(size, PU_LEVEL, &mipmap->grInfo.data);
if (levelflat->picture == NULL)
I_Error("HWR_GetLevelFlat: levelflat->picture == NULL");
M_Memcpy(flat, levelflat->picture, size);
}
// Tell the hardware driver to bind the current texture to the flat's mipmap
HWD.pfnSetTexture(mipmap);
}
#endif
else // set no texture
HWD.pfnSetTexture(NULL);
}

View File

@ -480,7 +480,6 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is
float fflatwidth = 64.0f, fflatheight = 64.0f;
INT32 flatflag = 63;
boolean texflat = false;
size_t len;
float scrollx = 0.0f, scrolly = 0.0f;
angle_t angle = 0;
FSurfaceInfo Surf;
@ -546,16 +545,9 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is
// set texture for polygon
if (levelflat != NULL)
{
if (levelflat->type == LEVELFLAT_TEXTURE)
if (levelflat->type == LEVELFLAT_FLAT)
{
fflatwidth = textures[levelflat->u.texture.num]->width;
fflatheight = textures[levelflat->u.texture.num]->height;
texflat = true;
}
else if (levelflat->type == LEVELFLAT_FLAT)
{
len = W_LumpLength(levelflat->u.flat.lumpnum);
size_t len = W_LumpLength(levelflat->u.flat.lumpnum);
switch (len)
{
case 4194304: // 2048x2048 lump
@ -580,9 +572,22 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is
fflatwidth = fflatheight = 64.0f;
break;
}
flatflag = ((INT32)fflatwidth)-1;
}
else
{
if (levelflat->type == LEVELFLAT_TEXTURE)
{
fflatwidth = textures[levelflat->u.texture.num]->width;
fflatheight = textures[levelflat->u.texture.num]->height;
}
else if (levelflat->type == LEVELFLAT_PATCH || levelflat->type == LEVELFLAT_PNG)
{
fflatwidth = levelflat->width;
fflatheight = levelflat->height;
}
texflat = true;
}
}
else // set no texture
HWD.pfnSetTexture(NULL);
@ -3142,7 +3147,6 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling,
float fflatwidth = 64.0f, fflatheight = 64.0f;
INT32 flatflag = 63;
boolean texflat = false;
size_t len;
float scrollx = 0.0f, scrolly = 0.0f;
angle_t angle = 0;
FSurfaceInfo Surf;
@ -3176,16 +3180,9 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling,
// set texture for polygon
if (levelflat != NULL)
{
if (levelflat->type == LEVELFLAT_TEXTURE)
if (levelflat->type == LEVELFLAT_FLAT)
{
fflatwidth = textures[levelflat->u.texture.num]->width;
fflatheight = textures[levelflat->u.texture.num]->height;
texflat = true;
}
else if (levelflat->type == LEVELFLAT_FLAT)
{
len = W_LumpLength(levelflat->u.flat.lumpnum);
size_t len = W_LumpLength(levelflat->u.flat.lumpnum);
switch (len)
{
case 4194304: // 2048x2048 lump
@ -3210,9 +3207,22 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling,
fflatwidth = fflatheight = 64.0f;
break;
}
flatflag = ((INT32)fflatwidth)-1;
}
else
{
if (levelflat->type == LEVELFLAT_TEXTURE)
{
fflatwidth = textures[levelflat->u.texture.num]->width;
fflatheight = textures[levelflat->u.texture.num]->height;
}
else if (levelflat->type == LEVELFLAT_PATCH || levelflat->type == LEVELFLAT_PNG)
{
fflatwidth = levelflat->width;
fflatheight = levelflat->height;
}
texflat = true;
}
}
else // set no texture
HWD.pfnSetTexture(NULL);

View File

@ -649,8 +649,6 @@ flatfound:
Only need eight bytes for PNG headers.
FIXME: Put this elsewhere.
*/
if (flatpatch)
Z_Free(flatpatch);
W_ReadLumpHeader(flatnum, buffer, 8, 0);
if (Picture_IsLumpPNG(buffer, lumplength))
levelflat->type = LEVELFLAT_PNG;
@ -658,6 +656,8 @@ flatfound:
#endif/*NO_PNG_LUMPS*/
levelflat->type = LEVELFLAT_FLAT;/* phew */
}
if (flatpatch)
Z_Free(flatpatch);
levelflat->u.flat. lumpnum = flatnum;
levelflat->u.flat.baselumpnum = LUMPERROR;

View File

@ -37,9 +37,7 @@ enum
LEVELFLAT_NONE,/* HOM time my friend */
LEVELFLAT_FLAT,
LEVELFLAT_PATCH,
#ifndef NO_PNG_LUMPS
LEVELFLAT_PNG,
#endif
LEVELFLAT_TEXTURE,
};
@ -78,8 +76,11 @@ typedef struct
INT32 numpics;
INT32 speed;
// for patchflats
UINT8 *flatpatch;
// for textures
UINT8 *picture;
#ifdef HWRENDER
void *mipmap;
#endif
} levelflat_t;
extern size_t numlevelflats;

View File

@ -529,7 +529,7 @@ void *R_GetLevelFlat(levelflat_t *levelflat)
}
// If the texture changed, or the patch doesn't exist, convert either of them to a flat.
if (levelflat->flatpatch == NULL || texturechanged)
if (levelflat->picture == NULL || texturechanged)
{
// Level texture
if (leveltexture)
@ -546,7 +546,7 @@ void *R_GetLevelFlat(levelflat_t *levelflat)
M_Memcpy(texflat->flat, converted, size);
Z_Free(converted);
levelflat->flatpatch = texflat->flat;
levelflat->picture = texflat->flat;
levelflat->width = ds_flatwidth;
levelflat->height = ds_flatheight;
}
@ -557,7 +557,7 @@ void *R_GetLevelFlat(levelflat_t *levelflat)
{
INT32 pngwidth, pngheight;
levelflat->flatpatch = Picture_PNGConvert(W_CacheLumpNum(levelflat->u.flat.lumpnum, PU_CACHE), PICFMT_FLAT, &pngwidth, &pngheight, NULL, NULL, W_LumpLength(levelflat->u.flat.lumpnum), NULL, 0);
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);
levelflat->width = (UINT16)pngwidth;
levelflat->height = (UINT16)pngheight;
@ -575,9 +575,9 @@ void *R_GetLevelFlat(levelflat_t *levelflat)
levelflat->width = ds_flatwidth = SHORT(patch->width);
levelflat->height = ds_flatheight = SHORT(patch->height);
levelflat->flatpatch = Z_Malloc(levelflat->width * levelflat->height, PU_LEVEL, NULL);
levelflat->picture = Z_Malloc(levelflat->width * levelflat->height, PU_LEVEL, NULL);
converted = Picture_FlatConvert(PICFMT_PATCH, patch, PICFMT_FLAT, 0, &size, levelflat->width, levelflat->height, patch->topoffset, patch->leftoffset, 0);
M_Memcpy(levelflat->flatpatch, converted, size);
M_Memcpy(levelflat->picture, converted, size);
Z_Free(converted);
}
}
@ -591,7 +591,7 @@ void *R_GetLevelFlat(levelflat_t *levelflat)
levelflat->u.texture.lastnum = levelflat->u.texture.num;
if (flatdata == NULL)
flatdata = levelflat->flatpatch;
flatdata = levelflat->picture;
return flatdata;
}