Skip to content

Commit 8d941a7

Browse files
committed
GLUniform: add bufferSize
1 parent 7281bfd commit 8d941a7

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
@@ -1281,8 +1281,7 @@ void GLShaderManager::InitShader( GLShader* shader ) {
12811281
uniform->SetLocationIndex( i );
12821282
uniform->SetUniformStorageOffset( shader->_uniformStorageSize );
12831283

1284-
const uint32_t size = uniform->_components ? uniform->_std430Size * uniform->_components : uniform->_std430Size;
1285-
shader->_uniformStorageSize += size;
1284+
shader->_uniformStorageSize += uniform->_bufferSize;
12861285
}
12871286

12881287
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
@@ -347,6 +347,7 @@ class GLUniform {
347347
const GLuint _std430BaseSize;
348348
GLuint _std430Size; // includes padding that depends on the other uniforms in the struct
349349
const GLuint _std430Alignment;
350+
const GLuint _bufferSize;
350351
GLuint _nextUniformOffset;
351352

352353
const UpdateType _updateType;
@@ -366,6 +367,7 @@ class GLUniform {
366367
_std430BaseSize( std430Size ),
367368
_std430Size( std430Size ),
368369
_std430Alignment( std430Alignment ),
370+
_bufferSize( components ? components * 4 : std430Size ),
369371
_nextUniformOffset( components ? components * 4 : std430Size ),
370372
_updateType( updateType ),
371373
_components( components ),
@@ -389,11 +391,10 @@ class GLUniform {
389391
currentValue = p->uniformStorage + _uniformStorageOffset;
390392
}
391393

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

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

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

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

430430
return buffer + _nextUniformOffset;
431431
}

0 commit comments

Comments
 (0)