mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-31 13:40:45 +00:00
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:
commit
cab089c5b1
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
|
//Hurdler: 25/04/2000: now support colormap in hardware mode
|
||||||
if (mipmap->colormap)
|
if (mipmap->colormap)
|
||||||
texel = mipmap->colormap[texel];
|
texel = mipmap->colormap->data[texel];
|
||||||
|
|
||||||
// hope compiler will get this switch out of the loops (dreams...)
|
// 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 ?)
|
// 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
|
//Hurdler: 25/04/2000: now support colormap in hardware mode
|
||||||
if (mipmap->colormap)
|
if (mipmap->colormap)
|
||||||
texel = mipmap->colormap[texel];
|
texel = mipmap->colormap->data[texel];
|
||||||
|
|
||||||
// hope compiler will get this switch out of the loops (dreams...)
|
// 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 ?)
|
// 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.
|
// Free image data from memory.
|
||||||
if (next->data)
|
if (next->data)
|
||||||
Z_Free(next->data);
|
Z_Free(next->data);
|
||||||
|
if (next->colormap)
|
||||||
|
Z_Free(next->colormap);
|
||||||
next->data = NULL;
|
next->data = NULL;
|
||||||
|
next->colormap = NULL;
|
||||||
HWD.pfnDeleteTexture(next);
|
HWD.pfnDeleteTexture(next);
|
||||||
|
|
||||||
// Free the old colormap mipmap from memory.
|
// 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)
|
static void HWR_FreePatchCache(boolean freeall)
|
||||||
{
|
{
|
||||||
INT32 i;
|
boolean (*callback)(void *mem) = FreeTextureCallback;
|
||||||
|
|
||||||
for (i = 0; i < numwadfiles; i++)
|
if (!freeall)
|
||||||
{
|
callback = FreeColormapsCallback;
|
||||||
INT32 j = 0;
|
|
||||||
for (; j < wadfiles[i]->numlumps; j++)
|
Z_IterateTags(PU_PATCH, PU_PATCH_ROTATED, callback);
|
||||||
(freeall ? HWR_FreeTexture : HWR_FreeTextureColormaps)(wadfiles[i]->patchcache[j]);
|
Z_IterateTags(PU_SPRITE, PU_HUDGFX, callback);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// free all textures after each level
|
// 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);
|
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)
|
void HWR_GetPatch(patch_t *patch)
|
||||||
{
|
{
|
||||||
|
@ -1006,13 +1042,19 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// search for the mimmap
|
// search for the mipmap
|
||||||
// skip the first (no colormap translated)
|
// skip the first (no colormap translated)
|
||||||
for (grMipmap = grPatch->mipmap; grMipmap->nextcolormap; )
|
for (grMipmap = grPatch->mipmap; grMipmap->nextcolormap; )
|
||||||
{
|
{
|
||||||
grMipmap = 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);
|
HWR_LoadPatchMipmap(patch, grMipmap);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1029,7 +1071,10 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap)
|
||||||
I_Error("%s: Out of memory", "HWR_GetMappedPatch");
|
I_Error("%s: Out of memory", "HWR_GetMappedPatch");
|
||||||
grMipmap->nextcolormap = newMipmap;
|
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);
|
HWR_LoadPatchMipmap(patch, newMipmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,15 @@ typedef enum GLTextureFormat_e
|
||||||
GL_TEXFMT_ALPHA_INTENSITY_88 = 0x22,
|
GL_TEXFMT_ALPHA_INTENSITY_88 = 0x22,
|
||||||
} GLTextureFormat_t;
|
} 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
|
// data holds the address of the graphics data cached in heap memory
|
||||||
// NULL if the texture is not in Doom heap cache.
|
// NULL if the texture is not in Doom heap cache.
|
||||||
struct GLMipmap_s
|
struct GLMipmap_s
|
||||||
|
@ -53,7 +62,7 @@ struct GLMipmap_s
|
||||||
UINT32 downloaded; // The GPU has this texture.
|
UINT32 downloaded; // The GPU has this texture.
|
||||||
|
|
||||||
struct GLMipmap_s *nextcolormap;
|
struct GLMipmap_s *nextcolormap;
|
||||||
const UINT8 *colormap;
|
struct GLColormap_s *colormap;
|
||||||
|
|
||||||
struct GLMipmap_s *nextmipmap; // Linked list of all textures
|
struct GLMipmap_s *nextmipmap; // Linked list of all textures
|
||||||
};
|
};
|
||||||
|
@ -77,7 +86,7 @@ struct GLPatch_s
|
||||||
{
|
{
|
||||||
float max_s,max_t;
|
float max_s,max_t;
|
||||||
GLMipmap_t *mipmap;
|
GLMipmap_t *mipmap;
|
||||||
} ATTRPACK;
|
};
|
||||||
typedef struct GLPatch_s GLPatch_t;
|
typedef struct GLPatch_s GLPatch_t;
|
||||||
|
|
||||||
#endif //_HWR_DATA_
|
#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);
|
vis->colormap = R_GetTranslationColormap(TC_DEFAULT, vis->mobj->color ? vis->mobj->color : SKINCOLOR_CYAN, GTC_CACHE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
vis->colormap = colormaps;
|
vis->colormap = NULL;
|
||||||
|
|
||||||
// set top/bottom coords
|
// set top/bottom coords
|
||||||
vis->gzt = gzt;
|
vis->gzt = gzt;
|
||||||
|
@ -5396,7 +5396,7 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing)
|
||||||
vis->flip = flip;
|
vis->flip = flip;
|
||||||
vis->mobj = (mobj_t *)thing;
|
vis->mobj = (mobj_t *)thing;
|
||||||
|
|
||||||
vis->colormap = colormaps;
|
vis->colormap = NULL;
|
||||||
|
|
||||||
// set top/bottom coords
|
// set top/bottom coords
|
||||||
vis->gzt = FIXED_TO_FLOAT(thing->z + spritecachedinfo[lumpoff].topoffset);
|
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; )
|
for (grMipmap = grPatch->mipmap; grMipmap->nextcolormap; )
|
||||||
{
|
{
|
||||||
grMipmap = grMipmap->nextcolormap;
|
grMipmap = grMipmap->nextcolormap;
|
||||||
if (grMipmap->colormap == colormap)
|
if (grMipmap->colormap && grMipmap->colormap->source == colormap)
|
||||||
{
|
{
|
||||||
if (grMipmap->downloaded && grMipmap->data)
|
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
|
HWD.pfnSetTexture(grMipmap); // found the colormap, set it to the correct texture
|
||||||
|
|
||||||
Z_ChangeTag(grMipmap->data, PU_HWRMODELTEXTURE_UNLOCKED);
|
Z_ChangeTag(grMipmap->data, PU_HWRMODELTEXTURE_UNLOCKED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1128,7 +1136,10 @@ static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendpatch, INT32 ski
|
||||||
if (newMipmap == NULL)
|
if (newMipmap == NULL)
|
||||||
I_Error("%s: Out of memory", "HWR_GetBlendedTexture");
|
I_Error("%s: Out of memory", "HWR_GetBlendedTexture");
|
||||||
grMipmap->nextcolormap = newMipmap;
|
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);
|
HWR_CreateBlendedTexture(patch, blendpatch, newMipmap, skinnum, color);
|
||||||
|
|
||||||
|
|
11
src/m_menu.c
11
src/m_menu.c
|
@ -8421,7 +8421,7 @@ static void M_DrawLoadGameData(void)
|
||||||
sprdef = &charbotskin->sprites[SPR2_SIGN];
|
sprdef = &charbotskin->sprites[SPR2_SIGN];
|
||||||
if (!sprdef->numframes)
|
if (!sprdef->numframes)
|
||||||
goto skipbot;
|
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];
|
sprframe = &sprdef->spriteframes[0];
|
||||||
patch = W_CachePatchNum(sprframe->lumppat[0], PU_PATCH);
|
patch = W_CachePatchNum(sprframe->lumppat[0], PU_PATCH);
|
||||||
|
|
||||||
|
@ -8431,8 +8431,6 @@ static void M_DrawLoadGameData(void)
|
||||||
charbotskin->highresscale,
|
charbotskin->highresscale,
|
||||||
0, patch, colormap);
|
0, patch, colormap);
|
||||||
|
|
||||||
Z_Free(colormap);
|
|
||||||
|
|
||||||
tempx -= (20<<FRACBITS);
|
tempx -= (20<<FRACBITS);
|
||||||
//flip = V_FLIP;
|
//flip = V_FLIP;
|
||||||
}
|
}
|
||||||
|
@ -8441,7 +8439,7 @@ skipbot:
|
||||||
if (!charskin) // shut up compiler
|
if (!charskin) // shut up compiler
|
||||||
goto skipsign;
|
goto skipsign;
|
||||||
sprdef = &charskin->sprites[SPR2_SIGN];
|
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)
|
if (!sprdef->numframes)
|
||||||
goto skipsign;
|
goto skipsign;
|
||||||
sprframe = &sprdef->spriteframes[0];
|
sprframe = &sprdef->spriteframes[0];
|
||||||
|
@ -8481,8 +8479,6 @@ skipsign:
|
||||||
charskin->highresscale/2,
|
charskin->highresscale/2,
|
||||||
0, patch, colormap);
|
0, patch, colormap);
|
||||||
skiplife:
|
skiplife:
|
||||||
if (colormap)
|
|
||||||
Z_Free(colormap);
|
|
||||||
|
|
||||||
patch = W_CachePatchName("STLIVEX", PU_PATCH);
|
patch = W_CachePatchName("STLIVEX", PU_PATCH);
|
||||||
|
|
||||||
|
@ -11753,7 +11749,7 @@ static void M_DrawSetupMultiPlayerMenu(void)
|
||||||
goto faildraw;
|
goto faildraw;
|
||||||
|
|
||||||
// ok, draw player sprite for sure now
|
// 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)
|
if (multi_frame >= sprdef->numframes)
|
||||||
multi_frame = 0;
|
multi_frame = 0;
|
||||||
|
@ -11771,7 +11767,6 @@ static void M_DrawSetupMultiPlayerMenu(void)
|
||||||
FixedDiv(skins[setupm_fakeskin].highresscale, skins[setupm_fakeskin].shieldscale),
|
FixedDiv(skins[setupm_fakeskin].highresscale, skins[setupm_fakeskin].shieldscale),
|
||||||
flags, patch, colormap);
|
flags, patch, colormap);
|
||||||
|
|
||||||
Z_Free(colormap);
|
|
||||||
goto colordraw;
|
goto colordraw;
|
||||||
|
|
||||||
faildraw:
|
faildraw:
|
||||||
|
|
10
src/z_zone.c
10
src/z_zone.c
|
@ -813,12 +813,12 @@ static void Command_Memfree_f(void)
|
||||||
#ifdef HWRENDER
|
#ifdef HWRENDER
|
||||||
if (rendermode == render_opengl)
|
if (rendermode == render_opengl)
|
||||||
{
|
{
|
||||||
CONS_Printf(M_GetText("Patch info headers: %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHINFO)>>10));
|
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("Cached textures : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRCACHE)>>10));
|
||||||
CONS_Printf(M_GetText("HW Texture cache : %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("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("All GPU textures : %7d KB\n"), HWR_GetTextureUsed()>>10);
|
||||||
CONS_Printf(M_GetText("HW Texture used : %7d KB\n"), HWR_GetTextureUsed()>>10);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue