Skip to content

Commit 0cddd7e

Browse files
committed
Respect GL_MAX_UNIFORM_BLOCK_SIZE for dlights buffer
1 parent 99bcb38 commit 0cddd7e

7 files changed

Lines changed: 12 additions & 7 deletions

File tree

src/engine/renderer/GLUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ struct GLConfig
147147

148148
bool colorGrading;
149149
bool realtimeLighting;
150+
int maxRealtimeLights;
150151
int realtimeLightLayers;
151152
bool deluxeMapping;
152153
bool normalMapping;

src/engine/renderer/gl_shader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ static std::string GenEngineConstants() {
678678
AddDefine( str, "r_zNear", r_znear->value );
679679

680680
AddDefine( str, "M_PI", static_cast< float >( M_PI ) );
681-
AddDefine( str, "MAX_REF_LIGHTS", MAX_REF_LIGHTS );
681+
AddDefine( str, "MAX_REALTIME_LIGHTS", glConfig.maxRealtimeLights );
682682
AddDefine( str, "NUM_LIGHT_LAYERS", glConfig.realtimeLightLayers );
683683
AddDefine( str, "TILE_SIZE", TILE_SIZE );
684684

src/engine/renderer/glsl_source/computeLight_fp.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ layout(std140, binding = BIND_LIGHTS) uniform u_Lights {
164164
#else
165165
layout(std140) uniform u_Lights {
166166
#endif
167-
Light lights[MAX_REF_LIGHTS];
167+
Light lights[MAX_REALTIME_LIGHTS];
168168
};
169169

170170
#define GetLight( idx ) lights[idx]

src/engine/renderer/glsl_source/lighttile_fp.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ layout(std140, binding = BIND_LIGHTS) uniform u_Lights {
5252
#else
5353
layout(std140) uniform u_Lights {
5454
#endif
55-
Light lights[MAX_REF_LIGHTS];
55+
Light lights[MAX_REALTIME_LIGHTS];
5656
};
5757

5858
Light GetLight( in uint idx ) {

src/engine/renderer/tr_scene.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ void RE_AddDynamicLightToScene( const vec3_t org, float radius, float r, float g
336336
return;
337337
}
338338

339-
if ( r_numLights >= MAX_REF_LIGHTS )
339+
if ( r_numLights >= glConfig.maxRealtimeLights )
340340
{
341341
return;
342342
}

src/engine/renderer/tr_shade.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,19 @@ static void EnableAvailableFeatures()
7373
}
7474

7575
if ( glConfig.realtimeLighting ) {
76+
// Minimum possible is 16384 / 48 = 341
77+
glConfig.maxRealtimeLights =
78+
std::min<size_t>( MAX_REF_LIGHTS, glConfig.maxUniformBlockSize / sizeof( shaderLight_t ) );
79+
7680
glConfig.realtimeLightLayers = r_realtimeLightLayers.Get();
7781

7882
if ( glConfig.realtimeLightLayers > glConfig.max3DTextureSize ) {
7983
glConfig.realtimeLightLayers = glConfig.max3DTextureSize;
8084
Log::Notice( "r_realtimeLightLayers exceeds maximum 3D texture size, using %i instead.", glConfig.max3DTextureSize );
8185
}
8286

83-
Log::Notice( "Using %i dynamic light layers, %i dynamic lights available per tile", glConfig.realtimeLightLayers,
84-
glConfig.realtimeLightLayers * 16 );
87+
Log::Notice( "Using %i dynamic light layers, %i dynamic lights available per tile, max %d lights",
88+
glConfig.realtimeLightLayers, glConfig.realtimeLightLayers * 16, glConfig.maxRealtimeLights );
8589
}
8690

8791
glConfig.colorGrading = r_colorGrading.Get();

src/engine/renderer/tr_vbo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ static void R_InitLightUBO()
698698
if( glConfig.uniformBufferObjectAvailable ) {
699699
glGenBuffers( 1, &tr.dlightUBO );
700700
glBindBuffer( GL_UNIFORM_BUFFER, tr.dlightUBO );
701-
glBufferData( GL_UNIFORM_BUFFER, MAX_REF_LIGHTS * sizeof( shaderLight_t ), nullptr, GL_DYNAMIC_DRAW );
701+
glBufferData( GL_UNIFORM_BUFFER, glConfig.maxRealtimeLights * sizeof( shaderLight_t ), nullptr, GL_DYNAMIC_DRAW );
702702
glBindBuffer( GL_UNIFORM_BUFFER, 0 );
703703
}
704704
}

0 commit comments

Comments
 (0)