mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-10 07:12:07 +00:00
Share Mod_CalcSurfaceExtents between renders
This commit is contained in:
parent
3b7170c4bd
commit
9b235a1711
7 changed files with 92 additions and 318 deletions
|
@ -1694,6 +1694,78 @@ SetSurfaceLighting(byte *lightdata, int size, msurface_t *out, byte *styles, int
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Fills in s->texturemins[] and s->extents[]
|
||||
*/
|
||||
void
|
||||
Mod_CalcSurfaceExtents(int *surfedges, mvertex_t *vertexes, medge_t *edges,
|
||||
msurface_t *s)
|
||||
{
|
||||
float mins[2], maxs[2], val;
|
||||
int i;
|
||||
mtexinfo_t *tex;
|
||||
int bmins[2], bmaxs[2];
|
||||
|
||||
mins[0] = mins[1] = 999999;
|
||||
maxs[0] = maxs[1] = -99999;
|
||||
|
||||
tex = s->texinfo;
|
||||
|
||||
for (i = 0; i < s->numedges; i++)
|
||||
{
|
||||
int e, j;
|
||||
mvertex_t *v;
|
||||
|
||||
e = surfedges[s->firstedge + i];
|
||||
|
||||
if (e >= 0)
|
||||
{
|
||||
v = &vertexes[edges[e].v[0]];
|
||||
}
|
||||
else
|
||||
{
|
||||
v = &vertexes[edges[-e].v[1]];
|
||||
}
|
||||
|
||||
for (j = 0; j < 2; j++)
|
||||
{
|
||||
val = v->position[0] * tex->vecs[j][0] +
|
||||
v->position[1] * tex->vecs[j][1] +
|
||||
v->position[2] * tex->vecs[j][2] +
|
||||
tex->vecs[j][3];
|
||||
|
||||
if (val < mins[j])
|
||||
{
|
||||
mins[j] = val;
|
||||
}
|
||||
|
||||
if (val > maxs[j])
|
||||
{
|
||||
maxs[j] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
bmins[i] = floor(mins[i] / 16);
|
||||
bmaxs[i] = ceil(maxs[i] / 16);
|
||||
|
||||
s->texturemins[i] = bmins[i] * 16;
|
||||
s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
|
||||
if (s->extents[i] < 16)
|
||||
{
|
||||
/* take at least one cache block */
|
||||
s->extents[i] = 16;
|
||||
}
|
||||
|
||||
if (!(tex->flags & (SURF_WARP | SURF_SKY)) && s->extents[i] > 256)
|
||||
{
|
||||
ri.Sys_Error(ERR_DROP, "%s: Bad surface extents", __func__);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
Mod_LoadTexinfo
|
||||
|
|
|
@ -185,67 +185,6 @@ Mod_LoadSubmodels(model_t *loadmodel, const byte *mod_base, const lump_t *l)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Fills in s->texturemins[] and s->extents[]
|
||||
*/
|
||||
static void
|
||||
Mod_CalcSurfaceExtents(model_t *loadmodel, msurface_t *s)
|
||||
{
|
||||
float mins[2], maxs[2], val;
|
||||
int i;
|
||||
mtexinfo_t *tex;
|
||||
int bmins[2], bmaxs[2];
|
||||
|
||||
mins[0] = mins[1] = 999999;
|
||||
maxs[0] = maxs[1] = -99999;
|
||||
|
||||
tex = s->texinfo;
|
||||
|
||||
for (i = 0; i < s->numedges; i++)
|
||||
{
|
||||
int e, j;
|
||||
mvertex_t *v;
|
||||
|
||||
e = loadmodel->surfedges[s->firstedge + i];
|
||||
|
||||
if (e >= 0)
|
||||
{
|
||||
v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
|
||||
}
|
||||
else
|
||||
{
|
||||
v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
|
||||
}
|
||||
|
||||
for (j = 0; j < 2; j++)
|
||||
{
|
||||
val = v->position[0] * tex->vecs[j][0] +
|
||||
v->position[1] * tex->vecs[j][1] +
|
||||
v->position[2] * tex->vecs[j][2] +
|
||||
tex->vecs[j][3];
|
||||
|
||||
if (val < mins[j])
|
||||
{
|
||||
mins[j] = val;
|
||||
}
|
||||
|
||||
if (val > maxs[j])
|
||||
{
|
||||
maxs[j] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
bmins[i] = floor(mins[i] / 16);
|
||||
bmaxs[i] = ceil(maxs[i] / 16);
|
||||
|
||||
s->texturemins[i] = bmins[i] * 16;
|
||||
s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
calcTexinfoAndFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *tl)
|
||||
{
|
||||
|
@ -518,7 +457,8 @@ Mod_LoadFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
|
|||
out->lmvlen[0] = 1.0f;
|
||||
out->lmvlen[1] = 1.0f;
|
||||
|
||||
Mod_CalcSurfaceExtents(loadmodel, out);
|
||||
Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes,
|
||||
loadmodel->edges, out);
|
||||
|
||||
lightofs = in->lightofs;
|
||||
}
|
||||
|
@ -642,7 +582,8 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
|
|||
out->lmvlen[0] = 1.0f;
|
||||
out->lmvlen[1] = 1.0f;
|
||||
|
||||
Mod_CalcSurfaceExtents(loadmodel, out);
|
||||
Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes,
|
||||
loadmodel->edges, out);
|
||||
|
||||
lightofs = in->lightofs;
|
||||
}
|
||||
|
|
|
@ -182,67 +182,6 @@ Mod_LoadSubmodels(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Fills in s->texturemins[] and s->extents[]
|
||||
*/
|
||||
static void
|
||||
Mod_CalcSurfaceExtents(gl3model_t *loadmodel, msurface_t *s)
|
||||
{
|
||||
float mins[2], maxs[2], val;
|
||||
int i;
|
||||
mtexinfo_t *tex;
|
||||
int bmins[2], bmaxs[2];
|
||||
|
||||
mins[0] = mins[1] = 999999;
|
||||
maxs[0] = maxs[1] = -99999;
|
||||
|
||||
tex = s->texinfo;
|
||||
|
||||
for (i = 0; i < s->numedges; i++)
|
||||
{
|
||||
int e, j;
|
||||
mvertex_t *v;
|
||||
|
||||
e = loadmodel->surfedges[s->firstedge + i];
|
||||
|
||||
if (e >= 0)
|
||||
{
|
||||
v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
|
||||
}
|
||||
else
|
||||
{
|
||||
v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
|
||||
}
|
||||
|
||||
for (j = 0; j < 2; j++)
|
||||
{
|
||||
val = v->position[0] * tex->vecs[j][0] +
|
||||
v->position[1] * tex->vecs[j][1] +
|
||||
v->position[2] * tex->vecs[j][2] +
|
||||
tex->vecs[j][3];
|
||||
|
||||
if (val < mins[j])
|
||||
{
|
||||
mins[j] = val;
|
||||
}
|
||||
|
||||
if (val > maxs[j])
|
||||
{
|
||||
maxs[j] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
bmins[i] = floor(mins[i] / 16);
|
||||
bmaxs[i] = ceil(maxs[i] / 16);
|
||||
|
||||
s->texturemins[i] = bmins[i] * 16;
|
||||
s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
|
||||
}
|
||||
}
|
||||
|
||||
extern void
|
||||
GL3_SubdivideSurface(msurface_t *fa, gl3model_t* loadmodel);
|
||||
|
||||
|
@ -463,7 +402,8 @@ Mod_LoadFaces(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l,
|
|||
out->texinfo = loadmodel->texinfo + ti;
|
||||
out->lmshift = DEFAULT_LMSHIFT;
|
||||
|
||||
Mod_CalcSurfaceExtents(loadmodel, out);
|
||||
Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes,
|
||||
loadmodel->edges, out);
|
||||
|
||||
SetSurfaceLighting(loadmodel->lightdata, loadmodel->numlightdata,
|
||||
out, in->styles, in->lightofs);
|
||||
|
@ -570,7 +510,8 @@ Mod_LoadQFaces(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l,
|
|||
out->texinfo = loadmodel->texinfo + ti;
|
||||
out->lmshift = DEFAULT_LMSHIFT;
|
||||
|
||||
Mod_CalcSurfaceExtents(loadmodel, out);
|
||||
Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes,
|
||||
loadmodel->edges, out);
|
||||
|
||||
SetSurfaceLighting(loadmodel->lightdata, loadmodel->numlightdata,
|
||||
out, in->styles, in->lightofs);
|
||||
|
|
|
@ -180,65 +180,6 @@ Mod_LoadSubmodels(gl4model_t *loadmodel, byte *mod_base, lump_t *l)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Fills in s->texturemins[] and s->extents[]
|
||||
*/
|
||||
static void
|
||||
Mod_CalcSurfaceExtents(gl4model_t *loadmodel, msurface_t *s)
|
||||
{
|
||||
float mins[2], maxs[2], val;
|
||||
int i, j, e;
|
||||
mvertex_t *v;
|
||||
mtexinfo_t *tex;
|
||||
int bmins[2], bmaxs[2];
|
||||
|
||||
mins[0] = mins[1] = 999999;
|
||||
maxs[0] = maxs[1] = -99999;
|
||||
|
||||
tex = s->texinfo;
|
||||
|
||||
for (i = 0; i < s->numedges; i++)
|
||||
{
|
||||
e = loadmodel->surfedges[s->firstedge + i];
|
||||
|
||||
if (e >= 0)
|
||||
{
|
||||
v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
|
||||
}
|
||||
else
|
||||
{
|
||||
v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
|
||||
}
|
||||
|
||||
for (j = 0; j < 2; j++)
|
||||
{
|
||||
val = v->position[0] * tex->vecs[j][0] +
|
||||
v->position[1] * tex->vecs[j][1] +
|
||||
v->position[2] * tex->vecs[j][2] +
|
||||
tex->vecs[j][3];
|
||||
|
||||
if (val < mins[j])
|
||||
{
|
||||
mins[j] = val;
|
||||
}
|
||||
|
||||
if (val > maxs[j])
|
||||
{
|
||||
maxs[j] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
bmins[i] = floor(mins[i] / 16);
|
||||
bmaxs[i] = ceil(maxs[i] / 16);
|
||||
|
||||
s->texturemins[i] = bmins[i] * 16;
|
||||
s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
|
||||
}
|
||||
}
|
||||
|
||||
extern void
|
||||
GL4_SubdivideSurface(msurface_t *fa, gl4model_t* loadmodel);
|
||||
|
||||
|
@ -375,7 +316,8 @@ Mod_LoadFaces(gl4model_t *loadmodel, byte *mod_base, lump_t *l)
|
|||
out->texinfo = loadmodel->texinfo + ti;
|
||||
out->lmshift = DEFAULT_LMSHIFT;
|
||||
|
||||
Mod_CalcSurfaceExtents(loadmodel, out);
|
||||
Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes,
|
||||
loadmodel->edges, out);
|
||||
|
||||
SetSurfaceLighting(loadmodel->lightdata, loadmodel->numlightdata,
|
||||
out, in->styles, in->lightofs);
|
||||
|
|
|
@ -339,6 +339,8 @@ extern void Mod_LoadVertexes(const char *name, mvertex_t **vertexes, int *numver
|
|||
extern void Mod_LoadVisibility(dvis_t **vis, const byte *mod_base, const lump_t *l);
|
||||
extern void Mod_LoadLighting(byte **lightdata, int *size, const byte *mod_base, const lump_t *l);
|
||||
extern void SetSurfaceLighting(byte *lightdata, int size, msurface_t *out, byte *styles, int lightofs);
|
||||
extern void Mod_CalcSurfaceExtents(int *surfedges, mvertex_t *vertexes, medge_t *edges,
|
||||
msurface_t *s);
|
||||
extern void Mod_LoadTexinfo(const char *name, mtexinfo_t **texinfo, int *numtexinfo,
|
||||
const byte *mod_base, const lump_t *l, findimage_t find_image,
|
||||
struct image_s *notexture, int extra);
|
||||
|
|
|
@ -184,73 +184,6 @@ Mod_LoadSubmodels(model_t *loadmodel, const byte *mod_base, const lump_t *l)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Fills in s->texturemins[] and s->extents[]
|
||||
*/
|
||||
static void
|
||||
Mod_CalcSurfaceExtents(model_t *loadmodel, msurface_t *s)
|
||||
{
|
||||
float mins[2], maxs[2], val;
|
||||
int i;
|
||||
mtexinfo_t *tex;
|
||||
int bmins[2], bmaxs[2];
|
||||
|
||||
mins[0] = mins[1] = (float)INT_MAX; // Set maximum values for world range
|
||||
maxs[0] = maxs[1] = (float)INT_MIN; // Set minimal values for world range
|
||||
|
||||
tex = s->texinfo;
|
||||
|
||||
for (i = 0; i < s->numedges; i++)
|
||||
{
|
||||
int e, j;
|
||||
mvertex_t *v;
|
||||
|
||||
e = loadmodel->surfedges[s->firstedge + i];
|
||||
|
||||
if (e >= 0)
|
||||
{
|
||||
v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
|
||||
}
|
||||
else
|
||||
{
|
||||
v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
|
||||
}
|
||||
|
||||
for (j = 0; j < 2; j++)
|
||||
{
|
||||
val = v->position[0] * tex->vecs[j][0] +
|
||||
v->position[1] * tex->vecs[j][1] +
|
||||
v->position[2] * tex->vecs[j][2] +
|
||||
tex->vecs[j][3];
|
||||
|
||||
if (val < mins[j])
|
||||
{
|
||||
mins[j] = val;
|
||||
}
|
||||
|
||||
if (val > maxs[j])
|
||||
{
|
||||
maxs[j] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
bmins[i] = floor(mins[i] / 16);
|
||||
bmaxs[i] = ceil(maxs[i] / 16);
|
||||
|
||||
s->texturemins[i] = bmins[i] * 16;
|
||||
s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
|
||||
if (s->extents[i] < 16)
|
||||
s->extents[i] = 16; // take at least one cache block
|
||||
if ( !(tex->flags & (SURF_WARP|SURF_SKY)) && s->extents[i] > 256)
|
||||
{
|
||||
ri.Sys_Error(ERR_DROP, "%s: Bad surface extents", __func__);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Mod_LoadFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
|
||||
const bspx_header_t *bspx_header)
|
||||
|
@ -313,7 +246,8 @@ Mod_LoadFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
|
|||
out->texinfo = loadmodel->texinfo + ti;
|
||||
out->lmshift = DEFAULT_LMSHIFT;
|
||||
|
||||
Mod_CalcSurfaceExtents(loadmodel, out);
|
||||
Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes,
|
||||
loadmodel->edges, out);
|
||||
|
||||
SetSurfaceLighting(loadmodel->lightdata, loadmodel->numlightdata,
|
||||
out, in->styles, in->lightofs);
|
||||
|
@ -421,7 +355,8 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
|
|||
out->texinfo = loadmodel->texinfo + ti;
|
||||
out->lmshift = DEFAULT_LMSHIFT;
|
||||
|
||||
Mod_CalcSurfaceExtents (loadmodel, out);
|
||||
Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes,
|
||||
loadmodel->edges, out);
|
||||
|
||||
SetSurfaceLighting(loadmodel->lightdata, loadmodel->numlightdata,
|
||||
out, in->styles, in->lightofs);
|
||||
|
|
|
@ -155,67 +155,6 @@ Mod_LoadSubmodels(model_t *loadmodel, const byte *mod_base, const lump_t *l)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Fills in s->texturemins[] and s->extents[]
|
||||
*/
|
||||
static void
|
||||
Mod_CalcSurfaceExtents(model_t *loadmodel, msurface_t *s)
|
||||
{
|
||||
float mins[2], maxs[2], val;
|
||||
int i;
|
||||
mtexinfo_t *tex;
|
||||
int bmins[2], bmaxs[2];
|
||||
|
||||
mins[0] = mins[1] = 999999;
|
||||
maxs[0] = maxs[1] = -99999;
|
||||
|
||||
tex = s->texinfo;
|
||||
|
||||
for (i = 0; i < s->numedges; i++)
|
||||
{
|
||||
int e, j;
|
||||
mvertex_t *v;
|
||||
|
||||
e = loadmodel->surfedges[s->firstedge + i];
|
||||
|
||||
if (e >= 0)
|
||||
{
|
||||
v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
|
||||
}
|
||||
else
|
||||
{
|
||||
v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
|
||||
}
|
||||
|
||||
for (j = 0; j < 2; j++)
|
||||
{
|
||||
val = v->position[0] * tex->vecs[j][0] +
|
||||
v->position[1] * tex->vecs[j][1] +
|
||||
v->position[2] * tex->vecs[j][2] +
|
||||
tex->vecs[j][3];
|
||||
|
||||
if (val < mins[j])
|
||||
{
|
||||
mins[j] = val;
|
||||
}
|
||||
|
||||
if (val > maxs[j])
|
||||
{
|
||||
maxs[j] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
bmins[i] = floor(mins[i] / 16);
|
||||
bmaxs[i] = ceil(maxs[i] / 16);
|
||||
|
||||
s->texturemins[i] = bmins[i] * 16;
|
||||
s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
calcTexinfoAndFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *tl)
|
||||
{
|
||||
|
@ -488,7 +427,8 @@ Mod_LoadFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
|
|||
out->lmvlen[0] = 1.0f;
|
||||
out->lmvlen[1] = 1.0f;
|
||||
|
||||
Mod_CalcSurfaceExtents(loadmodel, out);
|
||||
Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes,
|
||||
loadmodel->edges, out);
|
||||
|
||||
lightofs = in->lightofs;
|
||||
}
|
||||
|
@ -612,7 +552,8 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
|
|||
out->lmvlen[0] = 1.0f;
|
||||
out->lmvlen[1] = 1.0f;
|
||||
|
||||
Mod_CalcSurfaceExtents(loadmodel, out);
|
||||
Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes,
|
||||
loadmodel->edges, out);
|
||||
|
||||
lightofs = in->lightofs;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue