@@ -218,6 +218,12 @@ GLShaderManager::~GLShaderManager()
218218= default ;
219219
220220void 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 )
@@ -1278,10 +1284,16 @@ void GLShaderManager::InitShader( GLShader* shader ) {
12781284 for ( std::size_t i = 0 ; i < shader->_uniforms .size (); i++ ) {
12791285 GLUniform* uniform = shader->_uniforms [i];
12801286 uniform->SetLocationIndex ( i );
1281- uniform->SetFirewallIndex ( shader->_uniformStorageSize );
1282- shader->_uniformStorageSize += uniform->GetSize ();
1287+ uniform->SetUniformStorageOffset ( shader->_uniformStorageSize );
1288+
1289+ const uint32_t size = uniform->_components ? uniform->_std430Size * uniform->_components : uniform->_std430Size ;
1290+ shader->_uniformStorageSize += size;
12831291 }
12841292
1293+ shader->_uniformStorageSize *= sizeof ( uint32_t );
1294+
1295+ shader->uniformStorage = ( uint32_t * ) Z_Malloc ( shader->_uniformStorageSize );
1296+
12851297 for ( std::size_t i = 0 ; i < shader->_uniformBlocks .size (); i++ ) {
12861298 GLUniformBlock* uniformBlock = shader->_uniformBlocks [i];
12871299 uniformBlock->SetLocationIndex ( i );
@@ -2141,10 +2153,6 @@ bool GLCompileMacro_USE_BSP_SURFACE::HasConflictingMacros(size_t permutation, co
21412153 return false ;
21422154}
21432155
2144- uint32_t * GLUniform::WriteToBuffer ( uint32_t * ) {
2145- Sys::Error ( " WriteToBuffer not implemented for GLUniform '%s'" , _name );
2146- }
2147-
21482156void GLShader::RegisterUniform ( GLUniform* uniform ) {
21492157 _uniforms.push_back ( uniform );
21502158}
@@ -2184,7 +2192,7 @@ GLuint GLShaderManager::SortUniforms( std::vector<GLUniform*>& uniforms ) {
21842192 auto iterNext = FindUniformForOffset ( uniformQueue, structSize );
21852193 if ( iterNext == uniformQueue.end () ) {
21862194 // add 1 unit of padding
2187- ASSERT ( !_materialSystemUniforms .back ()->_components ); // array WriteToBuffer impls don't handle padding correctly
2195+ ASSERT ( !uniforms .back ()->_components ); // array WriteToBuffer impls don't handle padding correctly
21882196 ++structSize;
21892197 ++uniforms.back ()->_std430Size ;
21902198 } else {
@@ -2440,6 +2448,8 @@ void GLShader::WriteUniformsToBuffer( uint32_t* buffer, const Mode mode, const i
24402448 bufPtr = uniform->WriteToBuffer ( bufPtr );
24412449 }
24422450 }
2451+
2452+ uniformsUpdated = false ;
24432453}
24442454
24452455GLShader_generic::GLShader_generic () :
0 commit comments