ref: gl: track max height of a dynamic lightmap

This commit is contained in:
Alibek Omarov
2026-04-06 09:28:23 +05:00
parent 58692f397a
commit 7b665b3763
2 changed files with 12 additions and 11 deletions

View File

@@ -126,11 +126,13 @@ start:
goto start;
}
const float dist_sq = dist * dist;
// mark the polygons
firstsurface = node_firstsurface( node, RI.currentmodel );
numsurfaces = node_numsurfaces( node, RI.currentmodel );
for( i = 0; i < numsurfaces; i++ )
for( i = 0; i < numsurfaces && dist_sq < maxdist; i++ )
{
vec3_t impact;
float s, t, l;
@@ -157,7 +159,7 @@ start:
t = bound( 0, t, info->lightextents[1] );
t = l - t;
if( s * s + t * t + dist * dist >= maxdist )
if( s * s + t * t + dist_sq >= maxdist )
continue;
if( surf->dlightframe != tr.dlightframecount )

View File

@@ -20,6 +20,7 @@ GNU General Public License for more details.
typedef struct
{
int allocated[BLOCK_SIZE_MAX];
int max_height; // maximum height currently in use in the block
int current_lightmap_texture;
msurface_t *dynamic_surfaces;
msurface_t *lightmap_surfaces[MAX_LIGHTMAPS];
@@ -653,6 +654,7 @@ static void R_SetCacheState( msurface_t *surf )
static void LM_InitBlock( void )
{
memset( gl_lms.allocated, 0, sizeof( gl_lms.allocated ));
gl_lms.max_height = 0;
}
static int LM_AllocBlock( int w, int h, int *x, int *y )
@@ -679,6 +681,8 @@ static int LM_AllocBlock( int w, int h, int *x, int *y )
// this is a valid spot
*x = i;
*y = best = best2;
if( best == 0 )
break; // height 0 is optimal, can't do better
i++;
}
else
@@ -694,20 +698,15 @@ static int LM_AllocBlock( int w, int h, int *x, int *y )
for( i = 0; i < w; i++ )
gl_lms.allocated[*x + i] = best + h;
if( best + h > gl_lms.max_height )
gl_lms.max_height = best + h;
return true;
}
static void LM_UploadDynamicBlock( void )
{
int height = 0, i;
for( i = 0; i < BLOCK_SIZE; i++ )
{
if( gl_lms.allocated[i] > height )
height = gl_lms.allocated[i];
}
pglTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, BLOCK_SIZE, height, GL_RGBA, GL_UNSIGNED_BYTE, gl_lms.lightmap_buffer );
pglTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, BLOCK_SIZE, gl_lms.max_height, GL_RGBA, GL_UNSIGNED_BYTE, gl_lms.lightmap_buffer );
}
static void LM_UploadBlock( qboolean dynamic )