From bcda8cccaf51be21ac7ee7bcd2712f5c3474c870 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sat, 22 Jun 2024 23:34:26 +0300 Subject: [PATCH] vid: cache colormap --- src/client/vid/header/vid.h | 2 ++ src/client/vid/image.c | 51 ++++++++++++++++++++++++++++++++----- src/client/vid/vid.c | 5 ++++ 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/client/vid/header/vid.h b/src/client/vid/header/vid.h index a176ae86..d1343b42 100644 --- a/src/client/vid/header/vid.h +++ b/src/client/vid/header/vid.h @@ -48,6 +48,8 @@ qboolean VID_HasRenderer(const char *renderer); void VID_Init(void); void VID_Shutdown(void); void VID_CheckChanges(void); +void VID_ImageInit(void); +void VID_ImageDestroy(void); void VID_MenuInit(void); void VID_MenuDraw(void); diff --git a/src/client/vid/image.c b/src/client/vid/image.c index 0692520e..e0712a80 100644 --- a/src/client/vid/image.c +++ b/src/client/vid/image.c @@ -112,6 +112,10 @@ static unsigned char quitscreenfix[] = { 1,40,4,4,40,4,29,28,31,45,47,28,47,47,4,40,28,28 }; +static byte *colormap_cache = NULL; +static unsigned d_8to24table_cache[256]; + + static void fixQuitScreen(byte* px) { @@ -353,13 +357,8 @@ GenerateColormap(const byte *palette, byte *out_colormap) } } -/* -=============== -VID_GetPalette -=============== -*/ -void -VID_GetPalette(byte **colormap, unsigned *d_8to24table) +static void +LoadPalette(byte **colormap, unsigned *d_8to24table) { const char * filename; int bytesPerPixel; @@ -470,6 +469,44 @@ VID_GetPalette(byte **colormap, unsigned *d_8to24table) } } +/* +=============== +VID_GetPalette +=============== +*/ +void +VID_GetPalette(byte **colormap, unsigned *d_8to24table) +{ + if (!colormap_cache) + { + LoadPalette(&colormap_cache, d_8to24table_cache); + } + + if (!colormap_cache) + { + return; + } + + *colormap = malloc(256 * 320); + memcpy(*colormap, colormap_cache, 256 * 320); + memcpy(d_8to24table, d_8to24table_cache, sizeof(d_8to24table_cache)); +} + +void +VID_ImageInit(void) +{ + colormap_cache = NULL; +} + +void +VID_ImageDestroy(void) +{ + if (colormap_cache) + { + free(colormap_cache); + } +} + void VID_GetPalette24to8(const byte *d_8to24table, byte** d_16to8table) { diff --git a/src/client/vid/vid.c b/src/client/vid/vid.c index eec94a38..09705fde 100644 --- a/src/client/vid/vid.c +++ b/src/client/vid/vid.c @@ -602,6 +602,8 @@ VID_Init(void) Com_Error(ERR_FATAL, "Couldn't initialize the graphics subsystem!\n"); } + VID_ImageInit(); + // Load the renderer and get things going. VID_CheckChanges(); } @@ -613,6 +615,9 @@ void VID_Shutdown(void) { VID_ShutdownRenderer(); + + VID_ImageDestroy(); + GLimp_Shutdown(); }