mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-10 07:12:07 +00:00
gl1,vk: move s_blocklights reallocation to files/light
This commit is contained in:
parent
2790b0de92
commit
1ab6214ff0
13 changed files with 78 additions and 131 deletions
|
@ -26,6 +26,9 @@
|
|||
|
||||
#include "../ref_shared.h"
|
||||
|
||||
static float *s_blocklights = NULL, *s_blocklights_max = NULL;
|
||||
|
||||
|
||||
static int
|
||||
BSPX_LightGridSingleValue(const bspxlightgrid_t *grid, const lightstyle_t *lightstyles, int x, int y, int z, vec3_t res_diffuse)
|
||||
{
|
||||
|
@ -391,12 +394,59 @@ R_AddDynamicLights(msurface_t *surf, refdef_t *r_newrefdef,
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
R_InitTemporaryLMBuffer(void)
|
||||
{
|
||||
s_blocklights = NULL;
|
||||
s_blocklights_max = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
R_FreeTemporaryLMBuffer(void)
|
||||
{
|
||||
/* Cleanup buffers */
|
||||
if (s_blocklights)
|
||||
{
|
||||
free(s_blocklights);
|
||||
}
|
||||
|
||||
s_blocklights = NULL;
|
||||
s_blocklights_max = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
R_ResizeTemporaryLMBuffer(size_t size)
|
||||
{
|
||||
if (!s_blocklights || ((s_blocklights + size) >= s_blocklights_max))
|
||||
{
|
||||
int new_size = ROUNDUP(size, 1024);
|
||||
|
||||
if (new_size < 4096)
|
||||
{
|
||||
new_size = 4096;
|
||||
}
|
||||
|
||||
if (s_blocklights)
|
||||
{
|
||||
free(s_blocklights);
|
||||
}
|
||||
|
||||
s_blocklights = malloc(new_size * sizeof(float));
|
||||
s_blocklights_max = s_blocklights + new_size;
|
||||
|
||||
if (!s_blocklights)
|
||||
{
|
||||
Com_Error(ERR_DROP, "Can't alloc s_blocklights");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Combine and scale multiple lightmaps into the floating format in blocklights
|
||||
*/
|
||||
void
|
||||
R_BuildLightMap(msurface_t *surf, byte *dest, int stride, refdef_t *r_newrefdef,
|
||||
float *s_blocklights, const float *s_blocklights_max, float modulate, int r_framecount)
|
||||
float modulate, int r_framecount)
|
||||
{
|
||||
int smax, tmax;
|
||||
int r, g, b, a, max;
|
||||
|
@ -416,11 +466,7 @@ R_BuildLightMap(msurface_t *surf, byte *dest, int stride, refdef_t *r_newrefdef,
|
|||
tmax = (surf->extents[1] >> surf->lmshift) + 1;
|
||||
size = smax * tmax;
|
||||
|
||||
if ((size * 3) >= (s_blocklights_max - s_blocklights))
|
||||
{
|
||||
Com_Error(ERR_DROP, "%s lighmap requires more space %ld < %d",
|
||||
__func__, s_blocklights_max - s_blocklights, size * 3);
|
||||
}
|
||||
R_ResizeTemporaryLMBuffer(size * 3);
|
||||
|
||||
/* set to full bright if no light data */
|
||||
if (!surf->samples)
|
||||
|
@ -701,5 +747,4 @@ void R_PushDlights(refdef_t *r_newrefdef, mnode_t *nodes, int r_dlightframecount
|
|||
{
|
||||
R_MarkLights(l, 1 << i, nodes, r_dlightframecount, surfaces);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -129,44 +129,3 @@ RI_PushDlights(void)
|
|||
R_PushDlights(&r_newrefdef, r_worldmodel->nodes, r_dlightframecount,
|
||||
r_worldmodel->surfaces);
|
||||
}
|
||||
|
||||
float *s_blocklights = NULL, *s_blocklights_max = NULL;
|
||||
|
||||
/*
|
||||
* Combine and scale multiple lightmaps into the floating format in blocklights
|
||||
*/
|
||||
void
|
||||
RI_BuildLightMap(msurface_t *surf, byte *dest, int stride)
|
||||
{
|
||||
int size, smax, tmax;
|
||||
|
||||
smax = (surf->extents[0] >> surf->lmshift) + 1;
|
||||
tmax = (surf->extents[1] >> surf->lmshift) + 1;
|
||||
size = smax * tmax;
|
||||
|
||||
if (!s_blocklights || (s_blocklights + (size * 3) >= s_blocklights_max))
|
||||
{
|
||||
int new_size = ROUNDUP(size * 3, 1024);
|
||||
|
||||
if (new_size < 4096)
|
||||
{
|
||||
new_size = 4096;
|
||||
}
|
||||
|
||||
if (s_blocklights)
|
||||
{
|
||||
free(s_blocklights);
|
||||
}
|
||||
|
||||
s_blocklights = malloc(new_size * sizeof(float));
|
||||
s_blocklights_max = s_blocklights + new_size;
|
||||
|
||||
if (!s_blocklights)
|
||||
{
|
||||
Com_Error(ERR_DROP, "Can't alloc s_blocklights");
|
||||
}
|
||||
}
|
||||
|
||||
R_BuildLightMap(surf, dest, stride, &r_newrefdef, s_blocklights, s_blocklights_max,
|
||||
r_modulate->value, r_framecount);
|
||||
}
|
||||
|
|
|
@ -28,8 +28,6 @@
|
|||
|
||||
extern gllightmapstate_t gl_lms;
|
||||
|
||||
void RI_BuildLightMap(msurface_t *surf, byte *dest, int stride);
|
||||
|
||||
void
|
||||
LM_InitBlock(void)
|
||||
{
|
||||
|
@ -255,7 +253,8 @@ LM_CreateSurfaceLightmap(msurface_t *surf)
|
|||
base += (surf->light_t * BLOCK_WIDTH + surf->light_s) * LIGHTMAP_BYTES;
|
||||
|
||||
R_SetCacheState(surf, &r_newrefdef);
|
||||
RI_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES);
|
||||
R_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES,
|
||||
&r_newrefdef, r_modulate->value, r_framecount);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1169,8 +1169,7 @@ void
|
|||
R_Register(void)
|
||||
{
|
||||
/* Init default value */
|
||||
s_blocklights = NULL;
|
||||
s_blocklights_max = NULL;
|
||||
R_InitTemporaryLMBuffer();
|
||||
|
||||
gl_lefthand = ri.Cvar_Get("hand", "0", CVAR_USERINFO | CVAR_ARCHIVE);
|
||||
r_gunfov = ri.Cvar_Get("r_gunfov", "80", CVAR_ARCHIVE);
|
||||
|
@ -1598,14 +1597,7 @@ RI_Shutdown(void)
|
|||
/* shutdown our QGL subsystem */
|
||||
QGL_Shutdown();
|
||||
|
||||
/* Cleanup buffers */
|
||||
if (s_blocklights)
|
||||
{
|
||||
free(s_blocklights);
|
||||
}
|
||||
|
||||
s_blocklights = NULL;
|
||||
s_blocklights_max = NULL;
|
||||
R_FreeTemporaryLMBuffer();
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -39,8 +39,6 @@ void LM_InitBlock(void);
|
|||
void LM_UploadBlock(qboolean dynamic);
|
||||
qboolean LM_AllocBlock(int w, int h, int *x, int *y);
|
||||
|
||||
void RI_BuildLightMap(msurface_t *surf, byte *dest, int stride);
|
||||
|
||||
static void
|
||||
R_DrawGLPoly(mpoly_t *p)
|
||||
{
|
||||
|
@ -328,7 +326,8 @@ R_BlendLightmaps(const model_t *currentmodel)
|
|||
base += (surf->dlight_t * BLOCK_WIDTH +
|
||||
surf->dlight_s) * LIGHTMAP_BYTES;
|
||||
|
||||
RI_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES);
|
||||
R_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES,
|
||||
&r_newrefdef, r_modulate->value, r_framecount);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -374,7 +373,8 @@ R_BlendLightmaps(const model_t *currentmodel)
|
|||
base += (surf->dlight_t * BLOCK_WIDTH +
|
||||
surf->dlight_s) * LIGHTMAP_BYTES;
|
||||
|
||||
RI_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES);
|
||||
RI_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES,
|
||||
&r_newrefdef, r_modulate->value, r_framecount);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -508,7 +508,8 @@ R_RenderBrushPoly(entity_t *currententity, msurface_t *fa)
|
|||
smax = (fa->extents[0] >> fa->lmshift) + 1;
|
||||
tmax = (fa->extents[1] >> fa->lmshift) + 1;
|
||||
|
||||
RI_BuildLightMap(fa, (void *)temp, smax * 4);
|
||||
RI_BuildLightMap(fa, (void *)temp, smax * 4,
|
||||
&r_newrefdef, r_modulate->value, r_framecount);
|
||||
R_SetCacheState(fa, &r_newrefdef);
|
||||
|
||||
R_Bind(gl_state.lightmap_textures + fa->lightmaptexturenum);
|
||||
|
|
|
@ -235,7 +235,6 @@ void R_TexEnv(GLenum value);
|
|||
|
||||
void RI_PushDlights(void);
|
||||
|
||||
extern float *s_blocklights, *s_blocklights_max;
|
||||
extern model_t *r_worldmodel;
|
||||
extern unsigned d_8to24table[256];
|
||||
extern int registration_sequence;
|
||||
|
|
|
@ -379,7 +379,9 @@ extern void R_LightPoint(const bspxlightgrid_t *grid, const entity_t *currentent
|
|||
const mnode_t *nodes, vec3_t p, vec3_t color, float modulate, vec3_t lightspot);
|
||||
extern void R_SetCacheState(msurface_t *surf, refdef_t *r_newrefdef);
|
||||
extern void R_BuildLightMap(msurface_t *surf, byte *dest, int stride, refdef_t *r_newrefdef,
|
||||
float *s_blocklights, const float *s_blocklights_max, float modulate, int r_framecount);
|
||||
float modulate, int r_framecount);
|
||||
extern void R_InitTemporaryLMBuffer(void);
|
||||
extern void R_FreeTemporaryLMBuffer(void);
|
||||
|
||||
/* Warp Sky logic */
|
||||
extern void R_ClipSkyPolygon(int nump, vec3_t vecs, int stage,
|
||||
|
|
|
@ -32,7 +32,7 @@ static int r_numvblocks;
|
|||
static unsigned char *r_source, *r_sourcemax;
|
||||
static unsigned *r_lightptr;
|
||||
|
||||
void RI_BuildLightMap (drawsurf_t *drawsurf);
|
||||
void RI_BuildLightMap(drawsurf_t *drawsurf);
|
||||
|
||||
static int sc_size;
|
||||
static surfcache_t *sc_rover;
|
||||
|
@ -482,10 +482,10 @@ D_CacheSurface (const entity_t *currententity, msurface_t *surface, int miplevel
|
|||
c_surf++;
|
||||
|
||||
// calculate the lightings
|
||||
RI_BuildLightMap (&r_drawsurf);
|
||||
RI_BuildLightMap(&r_drawsurf);
|
||||
|
||||
// rasterize the surface into the cache
|
||||
R_DrawSurface (&r_drawsurf);
|
||||
R_DrawSurface(&r_drawsurf);
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
|
|
@ -158,8 +158,6 @@ extern int c_visible_textures;
|
|||
|
||||
extern float r_viewproj_matrix[16];
|
||||
|
||||
extern float *s_blocklights, *s_blocklights_max;
|
||||
|
||||
//====================================================================
|
||||
|
||||
extern model_t *r_worldmodel;
|
||||
|
@ -192,7 +190,6 @@ void R_DrawBrushModel(entity_t *currententity, const model_t *currentmodel);
|
|||
void R_DrawBeam(entity_t *currententity);
|
||||
void R_DrawWorld(void);
|
||||
void R_RenderDlights(void);
|
||||
void RI_BuildLightMap(msurface_t *surf, byte *dest, int stride);
|
||||
void R_DrawAlphaSurfaces(void);
|
||||
void RE_InitParticleTexture(void);
|
||||
void Draw_InitLocal(void);
|
||||
|
|
|
@ -119,44 +119,3 @@ RI_PushDlights(void)
|
|||
R_PushDlights(&r_newrefdef, r_worldmodel->nodes,
|
||||
r_dlightframecount, r_worldmodel->surfaces);
|
||||
}
|
||||
|
||||
float *s_blocklights = NULL, *s_blocklights_max = NULL;
|
||||
|
||||
/*
|
||||
* Combine and scale multiple lightmaps into the floating format in blocklights
|
||||
*/
|
||||
void
|
||||
RI_BuildLightMap(msurface_t *surf, byte *dest, int stride)
|
||||
{
|
||||
int size, smax, tmax;
|
||||
|
||||
smax = (surf->extents[0] >> surf->lmshift) + 1;
|
||||
tmax = (surf->extents[1] >> surf->lmshift) + 1;
|
||||
size = smax * tmax;
|
||||
|
||||
if (!s_blocklights || (s_blocklights + (size * 3) >= s_blocklights_max))
|
||||
{
|
||||
int new_size = ROUNDUP(size * 3, 1024);
|
||||
|
||||
if (new_size < 4096)
|
||||
{
|
||||
new_size = 4096;
|
||||
}
|
||||
|
||||
if (s_blocklights)
|
||||
{
|
||||
free(s_blocklights);
|
||||
}
|
||||
|
||||
s_blocklights = malloc(new_size * sizeof(float));
|
||||
s_blocklights_max = s_blocklights + new_size;
|
||||
|
||||
if (!s_blocklights)
|
||||
{
|
||||
Com_Error(ERR_DROP, "Can't alloc s_blocklights");
|
||||
}
|
||||
}
|
||||
|
||||
R_BuildLightMap(surf, dest, stride, &r_newrefdef, s_blocklights, s_blocklights_max,
|
||||
r_modulate->value, r_framecount);
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ LM_InitBlock(void)
|
|||
memset(vk_lms.allocated, 0, sizeof(vk_lms.allocated));
|
||||
}
|
||||
|
||||
void
|
||||
LM_UploadBlock()
|
||||
static void
|
||||
LM_UploadBlock(void)
|
||||
{
|
||||
int texture;
|
||||
|
||||
|
@ -44,7 +44,6 @@ LM_UploadBlock()
|
|||
|
||||
if (vk_state.lightmap_textures[texture].resource.image != VK_NULL_HANDLE)
|
||||
{
|
||||
/* FIXME: Incorrect lightmap load: mgu3m2 */
|
||||
QVk_UpdateTextureData(&vk_state.lightmap_textures[texture], vk_lms.lightmap_buffer, 0, 0, BLOCK_WIDTH, BLOCK_HEIGHT);
|
||||
}
|
||||
else
|
||||
|
@ -238,7 +237,8 @@ Vk_CreateSurfaceLightmap(msurface_t *surf)
|
|||
base += (surf->light_t * BLOCK_WIDTH + surf->light_s) * LIGHTMAP_BYTES;
|
||||
|
||||
R_SetCacheState(surf, &r_newrefdef);
|
||||
RI_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES);
|
||||
R_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES,
|
||||
&r_newrefdef, r_modulate->value, r_framecount);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1119,8 +1119,7 @@ static void
|
|||
R_Register(void)
|
||||
{
|
||||
/* Init default value */
|
||||
s_blocklights = NULL;
|
||||
s_blocklights_max = NULL;
|
||||
R_InitTemporaryLMBuffer();
|
||||
|
||||
r_lefthand = ri.Cvar_Get("hand", "0", CVAR_USERINFO | CVAR_ARCHIVE);
|
||||
r_norefresh = ri.Cvar_Get("r_norefresh", "0", 0);
|
||||
|
@ -1349,14 +1348,7 @@ RE_Shutdown(void)
|
|||
|
||||
QVk_WaitAndShutdownAll();
|
||||
|
||||
/* Cleanup buffers */
|
||||
if (s_blocklights)
|
||||
{
|
||||
free(s_blocklights);
|
||||
}
|
||||
|
||||
s_blocklights = NULL;
|
||||
s_blocklights_max = NULL;
|
||||
R_FreeTemporaryLMBuffer();
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -247,7 +247,8 @@ R_RenderBrushPoly(msurface_t *fa, float *modelMatrix, float alpha, entity_t *cur
|
|||
smax = (fa->extents[0] >> fa->lmshift) + 1;
|
||||
tmax = (fa->extents[1] >> fa->lmshift) + 1;
|
||||
|
||||
RI_BuildLightMap(fa, (void *)temp, smax * 4);
|
||||
R_BuildLightMap(fa, (void *)temp, smax * 4,
|
||||
&r_newrefdef, r_modulate->value, r_framecount);
|
||||
R_SetCacheState(fa, &r_newrefdef);
|
||||
|
||||
QVk_UpdateTextureData(&vk_state.lightmap_textures[fa->lightmaptexturenum], (unsigned char*)temp, fa->light_s, fa->light_t, smax, tmax);
|
||||
|
@ -448,7 +449,8 @@ Vk_RenderLightmappedPoly(msurface_t *surf, float *modelMatrix, float alpha, enti
|
|||
smax = (surf->extents[0] >> surf->lmshift) + 1;
|
||||
tmax = (surf->extents[1] >> surf->lmshift) + 1;
|
||||
|
||||
RI_BuildLightMap(surf, (void *)temp, smax * 4);
|
||||
R_BuildLightMap(surf, (void *)temp, smax * 4,
|
||||
&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