mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-21 20:21:09 +00:00
renders: lightmap generation, trust caller about size of provided buffer
This commit is contained in:
parent
d3239738e9
commit
1eb55aa3de
6 changed files with 9 additions and 27 deletions
|
@ -294,7 +294,7 @@ R_SetCacheState(msurface_t *surf, const refdef_t *refdef)
|
|||
|
||||
static void
|
||||
R_AddDynamicLights(const msurface_t *surf, const refdef_t *r_newrefdef,
|
||||
float *s_blocklights, const float *s_blocklights_max)
|
||||
float *s_blocklights)
|
||||
{
|
||||
int lnum;
|
||||
int smax, tmax;
|
||||
|
@ -380,7 +380,7 @@ R_AddDynamicLights(const msurface_t *surf, const refdef_t *r_newrefdef,
|
|||
fdist = td + (sd >> 1);
|
||||
}
|
||||
|
||||
if ((fdist < fminlight) && (plightdest < (s_blocklights_max - 3)))
|
||||
if (fdist < fminlight)
|
||||
{
|
||||
float diff = frad - fdist;
|
||||
int j;
|
||||
|
@ -492,7 +492,7 @@ R_GetTemporaryLMBuffer(size_t size)
|
|||
}
|
||||
|
||||
static void
|
||||
R_StoreLightMap(byte *dest, int stride, const byte *destmax, int smax, int tmax)
|
||||
R_StoreLightMap(byte *dest, int stride, int smax, int tmax)
|
||||
{
|
||||
float *bl;
|
||||
int i;
|
||||
|
@ -501,12 +501,6 @@ R_StoreLightMap(byte *dest, int stride, const byte *destmax, int smax, int tmax)
|
|||
stride -= (smax << 2);
|
||||
bl = s_blocklights;
|
||||
|
||||
if ((dest + (stride * (tmax - 1)) + smax * LIGHTMAP_BYTES) > destmax)
|
||||
{
|
||||
Com_Error(ERR_DROP, "%s destination too small for lightmap %d > " YQ2_COM_PRIdS,
|
||||
__func__, (stride * (tmax - 1)) + smax * LIGHTMAP_BYTES, destmax - dest);
|
||||
}
|
||||
|
||||
for (i = 0; i < tmax; i++, dest += stride)
|
||||
{
|
||||
int j;
|
||||
|
@ -583,8 +577,8 @@ R_StoreLightMap(byte *dest, int stride, const byte *destmax, int smax, int tmax)
|
|||
* Combine and scale multiple lightmaps into the floating format in blocklights
|
||||
*/
|
||||
void
|
||||
R_BuildLightMap(const msurface_t *surf, byte *dest, int stride, const byte *destmax,
|
||||
const refdef_t *r_newrefdef, float modulate, int r_framecount)
|
||||
R_BuildLightMap(const msurface_t *surf, byte *dest, int stride, const refdef_t *r_newrefdef,
|
||||
float modulate, int r_framecount)
|
||||
{
|
||||
int smax, tmax;
|
||||
int i, size, numlightmaps;
|
||||
|
@ -604,11 +598,6 @@ R_BuildLightMap(const msurface_t *surf, byte *dest, int stride, const byte *dest
|
|||
|
||||
R_ResizeTemporaryLMBuffer(size * 3);
|
||||
|
||||
if ((s_blocklights + size * 3) >= s_blocklights_max)
|
||||
{
|
||||
Com_Error(ERR_DROP, "%s temporary blocklights too small for lightmap", __func__);
|
||||
}
|
||||
|
||||
/* set to full bright if no light data */
|
||||
if (!surf->samples)
|
||||
{
|
||||
|
@ -617,7 +606,7 @@ R_BuildLightMap(const msurface_t *surf, byte *dest, int stride, const byte *dest
|
|||
s_blocklights[i] = 255;
|
||||
}
|
||||
|
||||
R_StoreLightMap(dest, stride, destmax, smax, tmax);
|
||||
R_StoreLightMap(dest, stride, smax, tmax);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -712,10 +701,10 @@ R_BuildLightMap(const msurface_t *surf, byte *dest, int stride, const byte *dest
|
|||
/* add all the dynamic lights */
|
||||
if (surf->dlightframe == r_framecount)
|
||||
{
|
||||
R_AddDynamicLights(surf, r_newrefdef, s_blocklights, s_blocklights_max);
|
||||
R_AddDynamicLights(surf, r_newrefdef, s_blocklights);
|
||||
}
|
||||
|
||||
R_StoreLightMap(dest, stride, destmax, smax, tmax);
|
||||
R_StoreLightMap(dest, stride, smax, tmax);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -262,7 +262,6 @@ LM_CreateSurfaceLightmap(msurface_t *surf)
|
|||
|
||||
R_SetCacheState(surf, &r_newrefdef);
|
||||
R_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES,
|
||||
gl_lms.lightmap_buffer + sizeof(gl_lms.lightmap_buffer),
|
||||
&r_newrefdef, r_modulate->value, r_framecount);
|
||||
}
|
||||
|
||||
|
|
|
@ -324,7 +324,6 @@ R_BlendLightmaps(const model_t *currentmodel)
|
|||
surf->dlight_s) * LIGHTMAP_BYTES;
|
||||
|
||||
R_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES,
|
||||
gl_lms.lightmap_buffer + sizeof(gl_lms.lightmap_buffer),
|
||||
&r_newrefdef, r_modulate->value, r_framecount);
|
||||
}
|
||||
else
|
||||
|
@ -372,7 +371,6 @@ R_BlendLightmaps(const model_t *currentmodel)
|
|||
surf->dlight_s) * LIGHTMAP_BYTES;
|
||||
|
||||
R_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES,
|
||||
gl_lms.lightmap_buffer + sizeof(gl_lms.lightmap_buffer),
|
||||
&r_newrefdef, r_modulate->value, r_framecount);
|
||||
}
|
||||
}
|
||||
|
@ -501,7 +499,6 @@ R_RenderBrushPoly(const entity_t *currententity, msurface_t *fa)
|
|||
temp = R_GetTemporaryLMBuffer(size);
|
||||
|
||||
R_BuildLightMap(fa, temp, smax * 4,
|
||||
temp + size,
|
||||
&r_newrefdef, r_modulate->value, r_framecount);
|
||||
R_SetCacheState(fa, &r_newrefdef);
|
||||
|
||||
|
|
|
@ -404,7 +404,7 @@ extern bspxlightgrid_t *Mod_LoadBSPXLightGrid(const bspx_header_t *bspx_header,
|
|||
extern void R_LightPoint(const bspxlightgrid_t *grid, const entity_t *currententity, refdef_t *refdef, const msurface_t *surfaces,
|
||||
const mnode_t *nodes, vec3_t p, vec3_t color, float modulate, vec3_t lightspot);
|
||||
extern void R_SetCacheState(msurface_t *surf, const refdef_t *r_newrefdef);
|
||||
extern void R_BuildLightMap(const msurface_t *surf, byte *dest, int stride, const byte *destmax,
|
||||
extern void R_BuildLightMap(const msurface_t *surf, byte *dest, int stride,
|
||||
const refdef_t *r_newrefdef, float modulate, int r_framecount);
|
||||
extern void R_InitTemporaryLMBuffer(void);
|
||||
extern void R_FreeTemporaryLMBuffer(void);
|
||||
|
|
|
@ -245,7 +245,6 @@ LM_CreateSurfaceLightmap(msurface_t *surf)
|
|||
|
||||
R_SetCacheState(surf, &r_newrefdef);
|
||||
R_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES,
|
||||
vk_lms.lightmap_buffer + sizeof(vk_lms.lightmap_buffer),
|
||||
&r_newrefdef, r_modulate->value, r_framecount);
|
||||
}
|
||||
|
||||
|
|
|
@ -249,7 +249,6 @@ R_RenderBrushPoly(msurface_t *fa, const float *modelMatrix, float alpha,
|
|||
temp = R_GetTemporaryLMBuffer(size);
|
||||
|
||||
R_BuildLightMap(fa, temp, smax * 4,
|
||||
temp + size,
|
||||
&r_newrefdef, r_modulate->value, r_framecount);
|
||||
R_SetCacheState(fa, &r_newrefdef);
|
||||
|
||||
|
@ -457,7 +456,6 @@ Vk_RenderLightmappedPoly(msurface_t *surf, const float *modelMatrix, float alpha
|
|||
temp = R_GetTemporaryLMBuffer(size);
|
||||
|
||||
R_BuildLightMap(surf, temp, smax * 4,
|
||||
temp + size,
|
||||
&r_newrefdef, r_modulate->value, r_framecount);
|
||||
|
||||
if ((surf->styles[map] >= 32 || surf->styles[map] == 0) && (surf->dlightframe != r_framecount))
|
||||
|
|
Loading…
Reference in a new issue