Skip to content

Commit 4a85964

Browse files
committed
Add back padding to material uniforms struct
1 parent 7246e45 commit 4a85964

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/engine/renderer/gl_shader.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,7 @@ std::string GLShaderManager::RemoveUniformsFromShaderText( const std::string& sh
15471547

15481548
void GLShaderManager::GenerateUniformStructDefinesText( const std::vector<GLUniform*>& uniforms,
15491549
const std::string& definesName, std::string& uniformStruct, std::string& uniformDefines ) {
1550+
int pad = 0;
15501551
for ( GLUniform* uniform : uniforms ) {
15511552
uniformStruct += " " + ( uniform->_isTexture ? "uvec2" : uniform->_type ) + " " + uniform->_name;
15521553

@@ -1555,6 +1556,10 @@ void GLShaderManager::GenerateUniformStructDefinesText( const std::vector<GLUnif
15551556
}
15561557
uniformStruct += ";\n";
15571558

1559+
for (int p = uniform->_std430Size - uniform->_std430BaseSize; p--; ) {
1560+
uniformStruct += "\tfloat _pad" + std::to_string( ++pad ) + ";\n";
1561+
}
1562+
15581563
uniformDefines += "#define ";
15591564
uniformDefines += uniform->_name;
15601565

@@ -2132,6 +2137,7 @@ void GLShader::PostProcessUniforms() {
21322137
++std430Size;
21332138
++_materialSystemUniforms.back()->_std430Size;
21342139
} else {
2140+
( *iterNext )->_std430Size = ( *iterNext )->_std430BaseSize;
21352141
std430Size += ( *iterNext )->_std430Size;
21362142
align = std::max( align, ( *iterNext )->_std430Alignment );
21372143
_materialSystemUniforms.push_back( *iterNext );

src/engine/renderer/gl_shader.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ class GLUniform {
317317
const std::string _type;
318318

319319
// In multiples of 4 bytes
320-
GLuint _std430Size;
320+
const GLuint _std430BaseSize;
321+
GLuint _std430Size; // includes padding that depends on the other uniforms in the struct
321322
const GLuint _std430Alignment;
322323

323324
const bool _global; // This uniform won't go into the materials UBO if true
@@ -334,6 +335,7 @@ class GLUniform {
334335
const bool isTexture = false ) :
335336
_name( name ),
336337
_type( type ),
338+
_std430BaseSize( std430Size ),
337339
_std430Size( std430Size ),
338340
_std430Alignment( std430Alignment ),
339341
_global( global ),

0 commit comments

Comments
 (0)