mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-15 09:11:48 +00:00
Fix animated skincolors in OpenGL
This commit is contained in:
parent
d004515d6a
commit
18ee97c583
6 changed files with 95 additions and 35 deletions
|
@ -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,13 +1042,19 @@ 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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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_
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
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);
|
||||
|
||||
|
|
11
src/m_menu.c
11
src/m_menu.c
|
@ -8423,7 +8423,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);
|
||||
|
||||
|
@ -8433,8 +8433,6 @@ static void M_DrawLoadGameData(void)
|
|||
charbotskin->highresscale,
|
||||
0, patch, colormap);
|
||||
|
||||
Z_Free(colormap);
|
||||
|
||||
tempx -= (20<<FRACBITS);
|
||||
//flip = V_FLIP;
|
||||
}
|
||||
|
@ -8443,7 +8441,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];
|
||||
|
@ -8483,8 +8481,6 @@ skipsign:
|
|||
charskin->highresscale/2,
|
||||
0, patch, colormap);
|
||||
skiplife:
|
||||
if (colormap)
|
||||
Z_Free(colormap);
|
||||
|
||||
patch = W_CachePatchName("STLIVEX", PU_PATCH);
|
||||
|
||||
|
@ -11755,7 +11751,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;
|
||||
|
@ -11773,7 +11769,6 @@ static void M_DrawSetupMultiPlayerMenu(void)
|
|||
FixedDiv(skins[setupm_fakeskin].highresscale, skins[setupm_fakeskin].shieldscale),
|
||||
flags, patch, colormap);
|
||||
|
||||
Z_Free(colormap);
|
||||
goto colordraw;
|
||||
|
||||
faildraw:
|
||||
|
|
|
@ -814,11 +814,11 @@ static void Command_Memfree_f(void)
|
|||
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("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("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("All GPU textures : %7d KB\n"), HWR_GetTextureUsed()>>10);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in a new issue