Skip to content

Commit fc2fff3

Browse files
committed
Add GLUniform.bufferSize as a shorthand for _std430Size * max( 1, _components )
1 parent cf65a5c commit fc2fff3

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
@@ -1292,8 +1292,7 @@ void GLShaderManager::InitShader( GLShader* shader ) {
12921292
uniform->SetLocationIndex( i );
12931293
uniform->SetUniformStorageOffset( shader->_uniformStorageSize );
12941294

1295-
const uint32_t size = uniform->_components ? uniform->_std430Size * uniform->_components : uniform->_std430Size;
1296-
shader->_uniformStorageSize += size;
1295+
shader->_uniformStorageSize += uniform->_bufferSize;
12971296
}
12981297

12991298
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
// In multiples of 4 bytes
345345
const GLuint _std430Size;
346346
const GLuint _std430Alignment;
347+
const GLuint _bufferSize;
347348
GLuint _nextUniformOffset;
348349

349350
const UpdateType _updateType;
@@ -362,6 +363,7 @@ class GLUniform {
362363
_type( type ),
363364
_std430Size( std430Size ),
364365
_std430Alignment( std430Alignment ),
366+
_bufferSize( components ? components * 4 : std430Size ),
365367
_nextUniformOffset( components ? components * 4 : std430Size ),
366368
_updateType( updateType ),
367369
_components( components ),
@@ -385,11 +387,10 @@ class GLUniform {
385387
currentValue = p->uniformStorage + _uniformStorageOffset;
386388
}
387389

388-
const uint32_t size = _components ? _std430Size * _components : _std430Size;
389-
const bool updated = memcmp( currentValue, value, size * sizeof( uint32_t ) );
390+
const bool updated = memcmp( currentValue, value, _bufferSize * sizeof( uint32_t ) );
390391

391392
if ( updated ) {
392-
memcpy( currentValue, value, size * sizeof( uint32_t ) );
393+
memcpy( currentValue, value, _bufferSize * sizeof( uint32_t ) );
393394
_shader->uniformsUpdated = true;
394395
}
395396

@@ -420,8 +421,7 @@ class GLUniform {
420421
return buffer;
421422
}
422423

423-
const uint32_t size = _components ? _std430Size * _components : _std430Size;
424-
memcpy( buffer, currentValue, size * sizeof( uint32_t ) );
424+
memcpy( buffer, currentValue, _bufferSize * sizeof( uint32_t ) );
425425

426426
return buffer + _nextUniformOffset;
427427
}

0 commit comments

Comments
 (0)