test: replace gl colormap mipmap linked list with unordered map for faster lookup
so far this seems to cut the time searching for an existing colormipmap in half, needs some testing as this is finicky code that may leak badly if not handled correctly models currently broken, for reasons above
This commit is contained in:
1 parent
b49a3e5875
commit
87923973e3
3 files changed
+52
-31
No files matched your search
+44
-30
@@ -16,6 +16,7 @@
|
||||
#ifdef HWRENDER
|
||||
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "hw_main.h"
|
||||
#include "hw_glob.h"
|
||||
@@ -35,6 +36,10 @@
|
||||
#include "../p_spec.h" // anim_t
|
||||
#include "../r_sky.h"
|
||||
|
||||
struct ColorMipMap {
|
||||
std::unordered_map<const UINT8*, GLMipmap_t*> map;
|
||||
};
|
||||
|
||||
INT32 patchformat = GL_TEXFMT_AP_88; // use alpha for holes
|
||||
INT32 textureformat = GL_TEXFMT_P_8; // use chromakey for hole
|
||||
|
||||
@@ -504,34 +509,31 @@ static void HWR_FreeTextureColormaps(patch_t *patch)
|
||||
return;
|
||||
|
||||
// The mipmap must be valid, obviously
|
||||
while (pat->mipmap)
|
||||
if (!pat->mipmap)
|
||||
return;
|
||||
|
||||
if (pat->mipmap->nextcolormap)
|
||||
{
|
||||
// Confusing at first, but pat->mipmap->nextcolormap
|
||||
// at the beginning of the loop is the first colormap
|
||||
// from the linked list of colormaps.
|
||||
GLMipmap_t *next = NULL;
|
||||
for (auto& pair : pat->mipmap->nextcolormap->map)
|
||||
{
|
||||
GLMipmap_t *glMipmap = pair.second;
|
||||
|
||||
// No mipmap in this patch, break out of the loop.
|
||||
if (!pat->mipmap)
|
||||
break;
|
||||
if (glMipmap)
|
||||
{
|
||||
// Free image data from memory.
|
||||
Z_Free(glMipmap->data);
|
||||
Z_Free(glMipmap->colormap);
|
||||
glMipmap->data = NULL;
|
||||
glMipmap->colormap = NULL;
|
||||
GL_DeleteTexture(glMipmap);
|
||||
|
||||
// No colormap mipmaps either.
|
||||
if (!pat->mipmap->nextcolormap)
|
||||
break;
|
||||
// Free the colormap mipmap from memory.
|
||||
free(glMipmap);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the first colormap to the one that comes after it.
|
||||
next = pat->mipmap->nextcolormap;
|
||||
pat->mipmap->nextcolormap = next->nextcolormap;
|
||||
|
||||
// Free image data from memory.
|
||||
Z_Free(next->data);
|
||||
Z_Free(next->colormap);
|
||||
next->data = NULL;
|
||||
next->colormap = NULL;
|
||||
GL_DeleteTexture(next);
|
||||
|
||||
// Free the old colormap mipmap from memory.
|
||||
free(next);
|
||||
delete pat->mipmap->nextcolormap;
|
||||
pat->mipmap->nextcolormap = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1088,7 +1090,7 @@ void HWR_GetPatch(patch_t *patch)
|
||||
void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap)
|
||||
{
|
||||
GLPatch_t *glPatch;
|
||||
GLMipmap_t *glMipmap, *newMipmap;
|
||||
GLMipmap_t *newMipmap;
|
||||
|
||||
if (!patch->hardware)
|
||||
Patch_CreateGL(patch);
|
||||
@@ -1102,11 +1104,19 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap)
|
||||
return;
|
||||
}
|
||||
|
||||
// search for the mipmap
|
||||
// skip the first (no colormap translated)
|
||||
for (glMipmap = glPatch->mipmap; glMipmap->nextcolormap;)
|
||||
// gotta make our map if theres none
|
||||
if (!glPatch->mipmap->nextcolormap)
|
||||
{
|
||||
glMipmap = glMipmap->nextcolormap;
|
||||
glPatch->mipmap->nextcolormap = new ColorMipMap();
|
||||
}
|
||||
|
||||
// search for the mipmap
|
||||
auto& map = glPatch->mipmap->nextcolormap->map;
|
||||
auto it = map.find(colormap);
|
||||
|
||||
if (it != map.end())
|
||||
{
|
||||
GLMipmap_t *glMipmap = it->second;
|
||||
|
||||
if (glMipmap->colormap && glMipmap->colormap->source == colormap)
|
||||
{
|
||||
@@ -1116,7 +1126,9 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap)
|
||||
HWR_UpdatePatchMipmap(patch, glMipmap);
|
||||
}
|
||||
else
|
||||
{
|
||||
HWR_LoadPatchMipmap(patch, glMipmap);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -1131,7 +1143,9 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap)
|
||||
newMipmap = static_cast<GLMipmap_t *>(calloc(1, sizeof (*newMipmap)));
|
||||
if (newMipmap == NULL)
|
||||
I_Error("%s: Out of memory", "HWR_GetMappedPatch");
|
||||
glMipmap->nextcolormap = newMipmap;
|
||||
|
||||
// add to nextcolormap map
|
||||
map[colormap] = newMipmap;
|
||||
|
||||
newMipmap->colormap = static_cast<GLColormap_t *>(Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL));
|
||||
newMipmap->colormap->source = colormap;
|
||||
|
||||
@@ -54,7 +54,7 @@ struct GLMipmap_s
|
||||
UINT16 width, height;
|
||||
UINT32 downloaded; // The GPU has this texture.
|
||||
|
||||
struct GLMipmap_s *nextcolormap;
|
||||
struct ColorMipMap *nextcolormap;
|
||||
struct GLColormap_s *colormap;
|
||||
};
|
||||
typedef struct GLMipmap_s GLMipmap_t;
|
||||
|
||||
@@ -1033,6 +1033,12 @@ skippixel:
|
||||
|
||||
static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendgpatch, INT32 skinnum, const UINT8 *colormap, skincolors_t color)
|
||||
{
|
||||
(void)patch;
|
||||
(void)blendgpatch;
|
||||
(void)skinnum;
|
||||
(void)colormap;
|
||||
(void)color;
|
||||
/*
|
||||
// mostly copied from HWR_GetMappedPatch, hence the similarities and comment
|
||||
GLPatch_t *glPatch = patch->hardware;
|
||||
GLMipmap_t *glMipmap, *newMipmap;
|
||||
@@ -1090,6 +1096,7 @@ static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendgpatch, INT32 sk
|
||||
|
||||
GL_SetTexture(newMipmap);
|
||||
Z_ChangeTag(newMipmap->data, PU_HWRMODELTEXTURE_UNLOCKED);
|
||||
*/
|
||||
}
|
||||
|
||||
// -----------------+
|
||||
|
||||
Reference in new issue
Block a user