Merge branch 'gl-colormap-update' into 'next'

Fix animated skincolors in OpenGL (resolves #187, #247, #301, #370)

Closes #187, #247, #301, and #370

See merge request STJr/SRB2!1301
This commit is contained in:
James R 2020-12-15 20:50:45 -05:00
commit cab089c5b1
6 changed files with 95 additions and 35 deletions

View File

@ -108,7 +108,7 @@ static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipm
//Hurdler: 25/04/2000: now support colormap in hardware mode
if (mipmap->colormap)
texel = mipmap->colormap[texel];
texel = mipmap->colormap->data[texel];
// hope compiler will get this switch out of the loops (dreams...)
// gcc do it ! but vcc not ! (why don't use cygwin gcc for win32 ?)
@ -218,7 +218,7 @@ static void HWR_DrawFlippedColumnInCache(const column_t *patchcol, UINT8 *block,
//Hurdler: 25/04/2000: now support colormap in hardware mode
if (mipmap->colormap)
texel = mipmap->colormap[texel];
texel = mipmap->colormap->data[texel];
// hope compiler will get this switch out of the loops (dreams...)
// gcc do it ! but vcc not ! (why don't use cygwin gcc for win32 ?)
@ -659,7 +659,10 @@ void HWR_FreeTextureColormaps(patch_t *patch)
// Free image data from memory.
if (next->data)
Z_Free(next->data);
if (next->colormap)
Z_Free(next->colormap);
next->data = NULL;
next->colormap = NULL;
HWD.pfnDeleteTexture(next);
// Free the old colormap mipmap from memory.
@ -667,16 +670,29 @@ void HWR_FreeTextureColormaps(patch_t *patch)
}
}
static boolean FreeTextureCallback(void *mem)
{
patch_t *patch = (patch_t *)mem;
HWR_FreeTexture(patch);
return false;
}
static boolean FreeColormapsCallback(void *mem)
{
patch_t *patch = (patch_t *)mem;
HWR_FreeTextureColormaps(patch);
return false;
}
static void HWR_FreePatchCache(boolean freeall)
{
INT32 i;
boolean (*callback)(void *mem) = FreeTextureCallback;
for (i = 0; i < numwadfiles; i++)
{
INT32 j = 0;
for (; j < wadfiles[i]->numlumps; j++)
(freeall ? HWR_FreeTexture : HWR_FreeTextureColormaps)(wadfiles[i]->patchcache[j]);
}
if (!freeall)
callback = FreeColormapsCallback;
Z_IterateTags(PU_PATCH, PU_PATCH_ROTATED, callback);
Z_IterateTags(PU_SPRITE, PU_HUDGFX, callback);
}
// free all textures after each level
@ -977,8 +993,28 @@ static void HWR_LoadPatchMipmap(patch_t *patch, GLMipmap_t *grMipmap)
Z_ChangeTag(grMipmap->data, PU_HWRCACHE_UNLOCKED);
}
// ----------------------+
// HWR_UpdatePatchMipmap : Updates a mipmap.
// ----------------------+
static void HWR_UpdatePatchMipmap(patch_t *patch, GLMipmap_t *grMipmap)
{
GLPatch_t *grPatch = patch->hardware;
HWR_MakePatch(patch, grPatch, grMipmap, true);
// If hardware does not have the texture, then call pfnSetTexture to upload it
// If it does have the texture, then call pfnUpdateTexture to update it
if (!grMipmap->downloaded)
HWD.pfnSetTexture(grMipmap);
else
HWD.pfnUpdateTexture(grMipmap);
HWR_SetCurrentTexture(grMipmap);
// The system-memory data can be purged now.
Z_ChangeTag(grMipmap->data, PU_HWRCACHE_UNLOCKED);
}
// -----------------+
// HWR_GetPatch : Download a patch to the hardware cache and make it ready for use
// HWR_GetPatch : Downloads a patch to the hardware cache and make it ready for use
// -----------------+
void HWR_GetPatch(patch_t *patch)
{
@ -1006,14 +1042,20 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap)
return;
}
// search for the mimmap
// search for the mipmap
// skip the first (no colormap translated)
for (grMipmap = grPatch->mipmap; grMipmap->nextcolormap; )
{
grMipmap = grMipmap->nextcolormap;
if (grMipmap->colormap == colormap)
if (grMipmap->colormap && grMipmap->colormap->source == colormap)
{
HWR_LoadPatchMipmap(patch, grMipmap);
if (memcmp(grMipmap->colormap->data, colormap, 256 * sizeof(UINT8)))
{
M_Memcpy(grMipmap->colormap->data, colormap, 256 * sizeof(UINT8));
HWR_UpdatePatchMipmap(patch, grMipmap);
}
else
HWR_LoadPatchMipmap(patch, grMipmap);
return;
}
}
@ -1029,7 +1071,10 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap)
I_Error("%s: Out of memory", "HWR_GetMappedPatch");
grMipmap->nextcolormap = newMipmap;
newMipmap->colormap = colormap;
newMipmap->colormap = Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL);
newMipmap->colormap->source = colormap;
M_Memcpy(newMipmap->colormap->data, colormap, 256 * sizeof(UINT8));
HWR_LoadPatchMipmap(patch, newMipmap);
}

View File

@ -39,6 +39,15 @@ typedef enum GLTextureFormat_e
GL_TEXFMT_ALPHA_INTENSITY_88 = 0x22,
} GLTextureFormat_t;
// Colormap structure for mipmaps.
struct GLColormap_s
{
const UINT8 *source;
UINT8 data[256];
};
typedef struct GLColormap_s GLColormap_t;
// data holds the address of the graphics data cached in heap memory
// NULL if the texture is not in Doom heap cache.
struct GLMipmap_s
@ -53,7 +62,7 @@ struct GLMipmap_s
UINT32 downloaded; // The GPU has this texture.
struct GLMipmap_s *nextcolormap;
const UINT8 *colormap;
struct GLColormap_s *colormap;
struct GLMipmap_s *nextmipmap; // Linked list of all textures
};
@ -77,7 +86,7 @@ struct GLPatch_s
{
float max_s,max_t;
GLMipmap_t *mipmap;
} ATTRPACK;
};
typedef struct GLPatch_s GLPatch_t;
#endif //_HWR_DATA_

View File

@ -5295,7 +5295,7 @@ static void HWR_ProjectSprite(mobj_t *thing)
vis->colormap = R_GetTranslationColormap(TC_DEFAULT, vis->mobj->color ? vis->mobj->color : SKINCOLOR_CYAN, GTC_CACHE);
}
else
vis->colormap = colormaps;
vis->colormap = NULL;
// set top/bottom coords
vis->gzt = gzt;
@ -5396,7 +5396,7 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing)
vis->flip = flip;
vis->mobj = (mobj_t *)thing;
vis->colormap = colormaps;
vis->colormap = NULL;
// set top/bottom coords
vis->gzt = FIXED_TO_FLOAT(thing->z + spritecachedinfo[lumpoff].topoffset);

View File

@ -1106,11 +1106,19 @@ static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendpatch, INT32 ski
for (grMipmap = grPatch->mipmap; grMipmap->nextcolormap; )
{
grMipmap = grMipmap->nextcolormap;
if (grMipmap->colormap == colormap)
if (grMipmap->colormap && grMipmap->colormap->source == colormap)
{
if (grMipmap->downloaded && grMipmap->data)
{
HWD.pfnSetTexture(grMipmap); // found the colormap, set it to the correct texture
if (memcmp(grMipmap->colormap->data, colormap, 256 * sizeof(UINT8)))
{
M_Memcpy(grMipmap->colormap->data, colormap, 256 * sizeof(UINT8));
HWR_CreateBlendedTexture(patch, blendpatch, grMipmap, skinnum, color);
HWD.pfnUpdateTexture(grMipmap);
}
else
HWD.pfnSetTexture(grMipmap); // found the colormap, set it to the correct texture
Z_ChangeTag(grMipmap->data, PU_HWRMODELTEXTURE_UNLOCKED);
return;
}
@ -1128,7 +1136,10 @@ static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendpatch, INT32 ski
if (newMipmap == NULL)
I_Error("%s: Out of memory", "HWR_GetBlendedTexture");
grMipmap->nextcolormap = newMipmap;
newMipmap->colormap = colormap;
newMipmap->colormap = Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL);
newMipmap->colormap->source = colormap;
M_Memcpy(newMipmap->colormap->data, colormap, 256 * sizeof(UINT8));
HWR_CreateBlendedTexture(patch, blendpatch, newMipmap, skinnum, color);

View File

@ -8421,7 +8421,7 @@ static void M_DrawLoadGameData(void)
sprdef = &charbotskin->sprites[SPR2_SIGN];
if (!sprdef->numframes)
goto skipbot;
colormap = R_GetTranslationColormap(savegameinfo[savetodraw].botskin-1, charbotskin->prefcolor, 0);
colormap = R_GetTranslationColormap(savegameinfo[savetodraw].botskin-1, charbotskin->prefcolor, GTC_CACHE);
sprframe = &sprdef->spriteframes[0];
patch = W_CachePatchNum(sprframe->lumppat[0], PU_PATCH);
@ -8431,8 +8431,6 @@ static void M_DrawLoadGameData(void)
charbotskin->highresscale,
0, patch, colormap);
Z_Free(colormap);
tempx -= (20<<FRACBITS);
//flip = V_FLIP;
}
@ -8441,7 +8439,7 @@ skipbot:
if (!charskin) // shut up compiler
goto skipsign;
sprdef = &charskin->sprites[SPR2_SIGN];
colormap = R_GetTranslationColormap(savegameinfo[savetodraw].skinnum, charskin->prefcolor, 0);
colormap = R_GetTranslationColormap(savegameinfo[savetodraw].skinnum, charskin->prefcolor, GTC_CACHE);
if (!sprdef->numframes)
goto skipsign;
sprframe = &sprdef->spriteframes[0];
@ -8481,8 +8479,6 @@ skipsign:
charskin->highresscale/2,
0, patch, colormap);
skiplife:
if (colormap)
Z_Free(colormap);
patch = W_CachePatchName("STLIVEX", PU_PATCH);
@ -11753,7 +11749,7 @@ static void M_DrawSetupMultiPlayerMenu(void)
goto faildraw;
// ok, draw player sprite for sure now
colormap = R_GetTranslationColormap(setupm_fakeskin, setupm_fakecolor->color, 0);
colormap = R_GetTranslationColormap(setupm_fakeskin, setupm_fakecolor->color, GTC_CACHE);
if (multi_frame >= sprdef->numframes)
multi_frame = 0;
@ -11771,7 +11767,6 @@ static void M_DrawSetupMultiPlayerMenu(void)
FixedDiv(skins[setupm_fakeskin].highresscale, skins[setupm_fakeskin].shieldscale),
flags, patch, colormap);
Z_Free(colormap);
goto colordraw;
faildraw:

View File

@ -813,12 +813,12 @@ static void Command_Memfree_f(void)
#ifdef HWRENDER
if (rendermode == render_opengl)
{
CONS_Printf(M_GetText("Patch info headers: %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHINFO)>>10));
CONS_Printf(M_GetText("Mipmap patches : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHCOLMIPMAP)>>10));
CONS_Printf(M_GetText("HW Texture cache : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRCACHE)>>10));
CONS_Printf(M_GetText("Plane polygons : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPLANE)>>10));
CONS_Printf(M_GetText("HW model textures : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRMODELTEXTURE)>>10));
CONS_Printf(M_GetText("HW Texture used : %7d KB\n"), HWR_GetTextureUsed()>>10);
CONS_Printf(M_GetText("Patch info headers : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHINFO)>>10));
CONS_Printf(M_GetText("Cached textures : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRCACHE)>>10));
CONS_Printf(M_GetText("Texture colormaps : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHCOLMIPMAP)>>10));
CONS_Printf(M_GetText("Model textures : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRMODELTEXTURE)>>10));
CONS_Printf(M_GetText("Plane polygons : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPLANE)>>10));
CONS_Printf(M_GetText("All GPU textures : %7d KB\n"), HWR_GetTextureUsed()>>10);
}
#endif