From 905c7d665bba2870923c5e67935a9acd9a36bb93 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 30 Jul 2025 15:29:28 +0200 Subject: [PATCH] inline HWR_GetTexturePalette makes ui draw slightly faster from quick test --- src/hardware/hw_cache.c | 6 ------ src/hardware/hw_draw.c | 24 ++++++++++++++++++------ src/hardware/hw_glob.h | 4 +++- src/hardware/hw_main.h | 6 ++++++ 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 3d52df320..79859686f 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -38,12 +38,6 @@ INT32 textureformat = GL_TEXFMT_P_8; // use chromakey for hole RGBA_t mapPalette[256] = {0}; // the palette for the currently loaded level or menu etc. -// Returns a pointer to the palette which should be used for caching textures. -RGBA_t *HWR_GetTexturePalette(void) -{ - return HWR_ShouldUsePaletteRendering() ? mapPalette : pLocalPalette; -} - static INT32 format2bpp(GLTextureFormat_t format) { switch (format) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 9612edd7f..0b42bdb1d 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -610,7 +610,7 @@ void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength) } else // Do TRANSMAP** fade. { - RGBA_t *palette = HWR_GetTexturePalette(); + const RGBA_t *palette = HWR_GetTexturePalette(); Surf.PolyColor.rgba = palette[color&0xFF].rgba; if (HWR_ShouldUsePaletteRendering()) @@ -798,7 +798,7 @@ void HWR_drawAMline(const fline_t *fl, INT32 color) { F2DCoord v1, v2; RGBA_t color_rgba; - RGBA_t *palette = HWR_GetTexturePalette(); + const RGBA_t *palette = HWR_GetTexturePalette(); color_rgba = palette[color&0xFF]; @@ -819,7 +819,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color) FOutVector v[4]; FSurfaceInfo Surf; float fx, fy, fw, fh, fwait = 0; - RGBA_t *palette = HWR_GetTexturePalette(); + RGBA_t *palette; if (wh < 0) return; // consistency w/ software @@ -864,11 +864,13 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color) if (fx >= vid.width || fy >= vid.height) return; + if (fx < 0) { fw += fx; fx = 0; } + if (fy < 0) { fh += fy; @@ -877,11 +879,13 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color) if (fw <= 0 || fh <= 0) return; + if (fx + fw > vid.width) { fwait = fw - (fvw- fx); fw = fvw - fx; } + if (fy + fh > vid.height) fh = fvh - fy; @@ -903,6 +907,8 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color) v[0].t = v[1].t = 0.0f; v[2].t = v[3].t = 1.0f; + palette = HWR_GetTexturePalette(); + Surf.PolyColor = palette[color&0xFF]; GL_DrawPolygon(&Surf, v, 4, @@ -917,7 +923,6 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 FOutVector v[4]; FSurfaceInfo Surf; float fx, fy, fw, fh; - RGBA_t *palette = HWR_GetTexturePalette(); if (w < 0 || h < 0) return; // consistency w/ software @@ -941,6 +946,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 if (x == 0 && y == 0 && w == BASEVIDWIDTH && h == BASEVIDHEIGHT) { + RGBA_t *palette = HWR_GetTexturePalette(); RGBA_t rgbaColour = palette[color&0xFF]; FRGBAFloat clearColour; clearColour.red = (float)rgbaColour.s.red / 255; @@ -971,6 +977,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 else if (!(options & V_SNAPTOTOP)) fy += (fvh - (FLOATBASEVIDHEIGHT * dupy)) / 2; } + if (options & V_SPLITSCREEN) fy += (FLOATBASEVIDHEIGHT * dupy)/2; if (options & V_HORZSCREEN) @@ -980,11 +987,13 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 if (fx >= vid.width || fy >= vid.height) return; + if (fx < 0) { fw += fx; fx = 0; } + if (fy < 0) { fh += fy; @@ -993,8 +1002,10 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 if (fw <= 0 || fh <= 0) return; + if (fx + fw > vid.width) fw = fvw - fx; + if (fy + fh > vid.height) fh = fvh - fy; @@ -1030,12 +1041,13 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) FOutVector v[4]; FSurfaceInfo Surf; float fx, fy, fw, fh; - UINT8 alphalevel = ((color & V_ALPHAMASK) >> V_ALPHASHIFT); - RGBA_t *palette = HWR_GetTexturePalette(); if (w < 0 || h < 0) return; // consistency w/ software + const UINT8 alphalevel = ((color & V_ALPHAMASK) >> V_ALPHASHIFT); + const RGBA_t *palette = HWR_GetTexturePalette(); + // 3--2 // | /| // |/ | diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 09956b99d..04d388e81 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -60,6 +60,9 @@ void HWR_FreeExtraSubsectors(void); // -------- // hw_cache.c // -------- + +extern RGBA_t mapPalette[256]; + void HWR_InitMapTextures(void); void HWR_LoadMapTextures(size_t pnumtextures); void HWR_FreeMapTextures(void); @@ -85,7 +88,6 @@ void HWR_ClearAllTextures(void); void HWR_FreeColormapCache(void); void HWR_UnlockCachedPatch(GLPatch_t *gpatch); -RGBA_t *HWR_GetTexturePalette(void); void HWR_SetPalette(RGBA_t *palette); void HWR_SetMapPalette(void); UINT32 HWR_CreateLightTable(UINT8 *lighttable); diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index c3cae5751..34e581ff5 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -237,6 +237,12 @@ FUNCINLINE static ATTRINLINE boolean HWR_PalRenderFlashpal(void) return (cv_glflashpal.value && HWR_ShouldUsePaletteRendering()); } +// Returns a pointer to the palette which should be used for caching textures. +FUNCINLINE static ATTRINLINE RGBA_t *HWR_GetTexturePalette(void) +{ + return HWR_ShouldUsePaletteRendering() ? mapPalette : pLocalPalette; +} + #ifdef __cplusplus }// extern "C" #endif