Skip to content

Commit 98478ee

Browse files
committed
GLUniform: add bufferSize
1 parent 12089df commit 98478ee

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 ),
@@ -390,11 +392,10 @@ class GLUniform {
390392
currentValue = p->uniformStorage + _uniformStorageOffset;
391393
}
392394

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

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

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

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

431431
return buffer + _nextUniformOffset;
432432
}

0 commit comments

Comments
 (0)