Share Mod_LoadBSPXDecoupledLM between renders

This commit is contained in:
Denis Pauk 2023-10-07 14:11:28 +03:00
parent 9b235a1711
commit 073f9896f4
4 changed files with 42 additions and 82 deletions

View file

@ -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;

View file

@ -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)

View file

@ -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 */

View file

@ -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)