Skip to content

Commit 2b38e3f

Browse files
committed
Add GLUniform.bufferSize as a shorthand for _std430Size * max( 1, _components )
1 parent 9220f6f commit 2b38e3f

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/engine/renderer/gl_shader.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,8 +1286,7 @@ void GLShaderManager::InitShader( GLShader* shader ) {
12861286
uniform->SetLocationIndex( i );
12871287
uniform->SetUniformStorageOffset( shader->_uniformStorageSize );
12881288

1289-
const uint32_t size = uniform->_components ? uniform->_std430Size * uniform->_components : uniform->_std430Size;
1290-
shader->_uniformStorageSize += size;
1289+
shader->_uniformStorageSize += uniform->_bufferSize;
12911290
}
12921291

12931292
shader->_uniformStorageSize *= sizeof( uint32_t );

src/engine/renderer/gl_shader.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ class GLUniform {
344344
// FIXME: the uniform structs are actually std140 so it would be more relevant to provide std140 info
345345
const GLuint _std430BaseSize;
346346
const GLuint _std430Alignment;
347+
const GLuint _bufferSize;
347348
GLuint _nextUniformOffset;
348349

349350
const UpdateType _updateType;
@@ -364,6 +365,7 @@ class GLUniform {
364365
_std430BaseSize( std430Size ),
365366
_std430Size( std430Size ),
366367
_std430Alignment( std430Alignment ),
368+
_bufferSize( components ? components * 4 : std430Size ),
367369
_nextUniformOffset( components ? components * 4 : std430Size ),
368370
_updateType( updateType ),
369371
_components( components ),
@@ -388,11 +390,10 @@ class GLUniform {
388390
currentValue = p->uniformStorage + _uniformStorageOffset;
389391
}
390392

391-
const uint32_t size = _components ? _std430Size * _components : _std430Size;
392-
const bool updated = memcmp( currentValue, value, size * sizeof( uint32_t ) );
393+
const bool updated = memcmp( currentValue, value, _bufferSize * sizeof( uint32_t ) );
393394

394395
if ( updated ) {
395-
memcpy( currentValue, value, size * sizeof( uint32_t ) );
396+
memcpy( currentValue, value, _bufferSize * sizeof( uint32_t ) );
396397
_shader->uniformsUpdated = true;
397398
}
398399

@@ -423,8 +424,7 @@ class GLUniform {
423424
return buffer;
424425
}
425426

426-
const uint32_t size = _components ? _std430Size * _components : _std430Size;
427-
memcpy( buffer, currentValue, size * sizeof( uint32_t ) );
427+
memcpy( buffer, currentValue, _bufferSize * sizeof( uint32_t ) );
428428

429429
return buffer + _nextUniformOffset;
430430
}

0 commit comments

Comments
 (0)