Skip to content

Commit 7101d4f

Browse files
committed
Only update PushBuffer if any uniform has actually changed
Also mutualises `uniformFirewall` and `currentValue` and removes a bunch of unneeded code.
1 parent 590ffd2 commit 7101d4f

File tree

4 files changed

+133
-347
lines changed

4 files changed

+133
-347
lines changed

src/engine/renderer/gl_shader.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ GLShaderManager::~GLShaderManager()
218218
= default;
219219

220220
void GLShaderManager::FreeAll() {
221+
for ( const std::unique_ptr<GLShader>& shader : _shaders ) {
222+
if ( shader.get()->uniformStorage ) {
223+
Z_Free( shader.get()->uniformStorage );
224+
}
225+
}
226+
221227
_shaders.clear();
222228

223229
deformShaderCount = 0;
@@ -236,8 +242,8 @@ void GLShaderManager::FreeAll() {
236242
Z_Free( program.uniformBlockIndexes );
237243
}
238244

239-
if ( program.uniformFirewall ) {
240-
Z_Free( program.uniformFirewall );
245+
if ( program.uniformStorage ) {
246+
Z_Free( program.uniformStorage );
241247
}
242248
}
243249

@@ -266,7 +272,7 @@ void GLShaderManager::UpdateShaderProgramUniformLocations( GLShader* shader, Sha
266272
shaderProgram->uniformLocations = ( GLint* ) Z_Malloc( sizeof( GLint ) * numUniforms );
267273

268274
// create buffer for uniform firewall
269-
shaderProgram->uniformFirewall = ( byte* ) Z_Malloc( uniformSize );
275+
shaderProgram->uniformStorage = ( uint32_t* ) Z_Malloc( uniformSize );
270276

271277
// update uniforms
272278
for (GLUniform *uniform : shader->_uniforms)
@@ -1273,10 +1279,16 @@ void GLShaderManager::InitShader( GLShader* shader ) {
12731279
for ( std::size_t i = 0; i < shader->_uniforms.size(); i++ ) {
12741280
GLUniform* uniform = shader->_uniforms[i];
12751281
uniform->SetLocationIndex( i );
1276-
uniform->SetFirewallIndex( shader->_uniformStorageSize );
1277-
shader->_uniformStorageSize += uniform->GetSize();
1282+
uniform->SetUniformStorageOffset( shader->_uniformStorageSize );
1283+
1284+
const uint32_t size = uniform->_components ? uniform->_std430Size * uniform->_components : uniform->_std430Size;
1285+
shader->_uniformStorageSize += size;
12781286
}
12791287

1288+
shader->_uniformStorageSize *= sizeof( uint32_t );
1289+
1290+
shader->uniformStorage = ( uint32_t* ) Z_Malloc( shader->_uniformStorageSize );
1291+
12801292
for ( std::size_t i = 0; i < shader->_uniformBlocks.size(); i++ ) {
12811293
GLUniformBlock* uniformBlock = shader->_uniformBlocks[i];
12821294
uniformBlock->SetLocationIndex( i );
@@ -2136,10 +2148,6 @@ bool GLCompileMacro_USE_BSP_SURFACE::HasConflictingMacros(size_t permutation, co
21362148
return false;
21372149
}
21382150

2139-
uint32_t* GLUniform::WriteToBuffer( uint32_t * ) {
2140-
Sys::Error( "WriteToBuffer not implemented for GLUniform '%s'", _name );
2141-
}
2142-
21432151
void GLShader::RegisterUniform( GLUniform* uniform ) {
21442152
_uniforms.push_back( uniform );
21452153
}
@@ -2425,6 +2433,8 @@ void GLShader::WriteUniformsToBuffer( uint32_t* buffer, const Mode mode, const i
24252433
bufPtr = uniform->WriteToBuffer( bufPtr );
24262434
}
24272435
}
2436+
2437+
uniformsUpdated = false;
24282438
}
24292439

24302440
GLShader_generic::GLShader_generic() :

0 commit comments

Comments
 (0)