Skip to content

Commit fedb60c

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

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
@@ -343,6 +343,7 @@ class GLUniform {
343343
// In multiples of 4 bytes
344344
const GLuint _std430Size;
345345
const GLuint _std430Alignment;
346+
const GLuint _bufferSize;
346347
GLuint _nextUniformOffset;
347348

348349
const UpdateType _updateType;
@@ -361,6 +362,7 @@ class GLUniform {
361362
_type( type ),
362363
_std430Size( std430Size ),
363364
_std430Alignment( std430Alignment ),
365+
_bufferSize( components ? components * 4 : std430Size ),
364366
_nextUniformOffset( components ? components * 4 : std430Size ),
365367
_updateType( updateType ),
366368
_components( components ),
@@ -384,11 +386,10 @@ class GLUniform {
384386
currentValue = p->uniformStorage + _uniformStorageOffset;
385387
}
386388

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

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

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

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

425425
return buffer + _nextUniformOffset;
426426
}

0 commit comments

Comments
 (0)