From 073f9896f49cdc3a36cfe56b17dd0c2d89ad3ad8 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sat, 7 Oct 2023 14:11:28 +0300 Subject: [PATCH] Share Mod_LoadBSPXDecoupledLM between renders --- src/client/refresh/files/models.c | 41 ++++++++++++++++++++++++++++++ src/client/refresh/gl1/gl1_model.c | 41 ------------------------------ src/client/refresh/ref_shared.h | 1 + src/client/refresh/vk/vk_model.c | 41 ------------------------------ 4 files changed, 42 insertions(+), 82 deletions(-) diff --git a/src/client/refresh/files/models.c b/src/client/refresh/files/models.c index 2ca18879..eff83e4a 100644 --- a/src/client/refresh/files/models.c +++ b/src/client/refresh/files/models.c @@ -2148,6 +2148,47 @@ Mod_LoadBSPX(int filesize, const byte *mod_base) return xheader; } +/* Extension to support lightmaps that aren't tied to texture scale. */ +int +Mod_LoadBSPXDecoupledLM(const dlminfo_t* lminfos, int surfnum, msurface_t *out) +{ + const dlminfo_t *lminfo; + unsigned short lmwidth, lmheight; + + if (lminfos == NULL) { + return -1; + } + + lminfo = lminfos + surfnum; + + lmwidth = LittleShort(lminfo->lmwidth); + lmheight = LittleShort(lminfo->lmheight); + + if (lmwidth <= 0 || lmheight <= 0) { + return -1; + } + + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 4; j++) { + out->lmvecs[i][j] = LittleFloat(lminfo->vecs[i][j]); + } + } + + out->extents[0] = (short)(lmwidth - 1); + out->extents[1] = (short)(lmheight - 1); + out->lmshift = 0; + out->texturemins[0] = 0; + out->texturemins[1] = 0; + + float v0 = VectorLength(out->lmvecs[0]); + out->lmvlen[0] = v0 > 0.0f ? 1.0f / v0 : 0.0f; + + float v1 = VectorLength(out->lmvecs[1]); + out->lmvlen[1] = v1 > 0.0f ? 1.0f / v1 : 0.0f; + + return LittleLong(lminfo->lightofs); +} + /* Need to clean */ struct rctx_s { const byte *data; diff --git a/src/client/refresh/gl1/gl1_model.c b/src/client/refresh/gl1/gl1_model.c index 69bcd1f9..c7ee9d0a 100644 --- a/src/client/refresh/gl1/gl1_model.c +++ b/src/client/refresh/gl1/gl1_model.c @@ -337,47 +337,6 @@ calcTexinfoAndQFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *t return ret; } -/* Extension to support lightmaps that aren't tied to texture scale. */ -static int -Mod_LoadBSPXDecoupledLM(const dlminfo_t* lminfos, int surfnum, msurface_t *out) -{ - const dlminfo_t *lminfo; - unsigned short lmwidth, lmheight; - - if (lminfos == NULL) { - return -1; - } - - lminfo = lminfos + surfnum; - - lmwidth = LittleShort(lminfo->lmwidth); - lmheight = LittleShort(lminfo->lmheight); - - if (lmwidth <= 0 || lmheight <= 0) { - return -1; - } - - for (int i = 0; i < 2; i++) { - for (int j = 0; j < 4; j++) { - out->lmvecs[i][j] = LittleFloat(lminfo->vecs[i][j]); - } - } - - out->extents[0] = (short)(lmwidth - 1); - out->extents[1] = (short)(lmheight - 1); - out->lmshift = 0; - out->texturemins[0] = 0; - out->texturemins[1] = 0; - - float v0 = VectorLength(out->lmvecs[0]); - out->lmvlen[0] = v0 > 0.0f ? 1.0f / v0 : 0.0f; - - float v1 = VectorLength(out->lmvecs[1]); - out->lmvlen[1] = v1 > 0.0f ? 1.0f / v1 : 0.0f; - - return LittleLong(lminfo->lightofs); -} - static void Mod_LoadFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, const bspx_header_t *bspx_header) diff --git a/src/client/refresh/ref_shared.h b/src/client/refresh/ref_shared.h index 2b9ddc0e..281021ee 100644 --- a/src/client/refresh/ref_shared.h +++ b/src/client/refresh/ref_shared.h @@ -357,6 +357,7 @@ extern mleaf_t *Mod_PointInLeaf(const vec3_t p, mnode_t *node); extern const void *Mod_LoadBSPXFindLump(const bspx_header_t *bspx_header, const char *lumpname, int *plumpsize, const byte *mod_base); extern const bspx_header_t *Mod_LoadBSPX(int filesize, const byte *mod_base); +extern int Mod_LoadBSPXDecoupledLM(const dlminfo_t* lminfos, int surfnum, msurface_t *out); extern int Mod_LoadFile(char *name, void **buffer); /* Surface logic */ diff --git a/src/client/refresh/vk/vk_model.c b/src/client/refresh/vk/vk_model.c index 9717b9b9..78f5464d 100644 --- a/src/client/refresh/vk/vk_model.c +++ b/src/client/refresh/vk/vk_model.c @@ -307,47 +307,6 @@ calcTexinfoAndQFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *t return ret; } -/* Extension to support lightmaps that aren't tied to texture scale. */ -static int -Mod_LoadBSPXDecoupledLM(const dlminfo_t* lminfos, int surfnum, msurface_t *out) -{ - const dlminfo_t *lminfo; - unsigned short lmwidth, lmheight; - - if (lminfos == NULL) { - return -1; - } - - lminfo = lminfos + surfnum; - - lmwidth = LittleShort(lminfo->lmwidth); - lmheight = LittleShort(lminfo->lmheight); - - if (lmwidth <= 0 || lmheight <= 0) { - return -1; - } - - for (int i = 0; i < 2; i++) { - for (int j = 0; j < 4; j++) { - out->lmvecs[i][j] = LittleFloat(lminfo->vecs[i][j]); - } - } - - out->extents[0] = (short)(lmwidth - 1); - out->extents[1] = (short)(lmheight - 1); - out->lmshift = 0; - out->texturemins[0] = 0; - out->texturemins[1] = 0; - - float v0 = VectorLength(out->lmvecs[0]); - out->lmvlen[0] = v0 > 0.0f ? 1.0f / v0 : 0.0f; - - float v1 = VectorLength(out->lmvecs[1]); - out->lmvlen[1] = v1 > 0.0f ? 1.0f / v1 : 0.0f; - - return LittleLong(lminfo->lightofs); -} - static void Mod_LoadFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, const bspx_header_t *bspx_header)