@@ -1346,6 +1346,12 @@ void GLShaderManager::InitShader( GLShader* shader ) {
13461346 ShaderDescriptor* desc = FindShader ( shader->_name , shaderType.mainText , shaderType.GLType , shaderType.headers ,
13471347 uniqueMacros, compileMacros, true );
13481348
1349+ if ( desc && glConfig.pushBufferAvailable ) {
1350+ desc->shaderSource = RemoveUniformsFromShaderText ( desc->shaderSource , shader->_pushUniforms );
1351+
1352+ desc->shaderSource .insert ( shaderType.offset , globalUniformBlock );
1353+ }
1354+
13491355 if ( desc && glConfig.usingMaterialSystem && shader->_useMaterialSystem ) {
13501356 desc->shaderSource = ShaderPostProcess ( shader, desc->shaderSource , shaderType.offset );
13511357 }
@@ -1599,7 +1605,7 @@ void GLShaderManager::PostProcessGlobalUniforms() {
15991605 GLuint padding;
16001606 std::vector<GLUniform*>* uniforms = &( ( GLShader* ) globalUBOProxy )->_uniforms ;
16011607 std::vector<GLUniform*> constUniforms =
1602- ProcessUniforms ( GLUniform::CONST, GLUniform::CONST, false , *uniforms, size, padding );
1608+ ProcessUniforms ( GLUniform::CONST, GLUniform::CONST, !glConfig. usingBindlessTextures , *uniforms, size, padding );
16031609
16041610 GenerateUniformStructDefinesText ( constUniforms, padding, 0 , " globalUniforms" , uniformStruct, uniformDefines );
16051611
@@ -1608,7 +1614,7 @@ void GLShaderManager::PostProcessGlobalUniforms() {
16081614 pushBuffer.constUniformsSize = size + padding;
16091615
16101616 std::vector<GLUniform*> frameUniforms =
1611- ProcessUniforms ( GLUniform::FRAME, GLUniform::FRAME, false , *uniforms, size, padding );
1617+ ProcessUniforms ( GLUniform::FRAME, GLUniform::FRAME, !glConfig. usingBindlessTextures , *uniforms, size, padding );
16121618
16131619 GenerateUniformStructDefinesText ( frameUniforms, padding, paddingCount, " globalUniforms" , uniformStruct, uniformDefines );
16141620
@@ -2205,6 +2211,29 @@ GLuint GLShaderManager::SortUniforms( std::vector<GLUniform*>& uniforms ) {
22052211 return structSize;
22062212}
22072213
2214+ std::vector<GLUniform*> GLShaderManager::ProcessUniforms ( const GLUniform::UpdateType minType, const GLUniform::UpdateType maxType,
2215+ const bool skipTextures,
2216+ std::vector<GLUniform*>& uniforms, GLuint& structSize, GLuint& padding ) {
2217+ std::vector<GLUniform*> tmp;
2218+
2219+ tmp.reserve ( uniforms.size () );
2220+ for ( GLUniform* uniform : uniforms ) {
2221+ if ( uniform->_updateType >= minType && uniform->_updateType <= maxType
2222+ && ( !uniform->_isTexture || !skipTextures ) ) {
2223+ tmp.emplace_back ( uniform );
2224+ }
2225+ }
2226+
2227+ structSize = SortUniforms ( tmp );
2228+
2229+ const GLuint structAlignment = 4 ; // Material buffer is now a UBO, so it uses std140 layout, which is aligned to vec4
2230+ if ( structSize > 0 ) {
2231+ padding = ( structAlignment - ( structSize % structAlignment ) ) % structAlignment;
2232+ }
2233+
2234+ return tmp;
2235+ }
2236+
22082237void GLShader::PostProcessUniforms () {
22092238 if ( _useMaterialSystem ) {
22102239 _materialSystemUniforms = gl_shaderManager.ProcessUniforms ( GLUniform::MATERIAL_OR_PUSH, GLUniform::MATERIAL_OR_PUSH,
@@ -2214,7 +2243,7 @@ void GLShader::PostProcessUniforms() {
22142243 if ( glConfig.pushBufferAvailable && !pushSkip ) {
22152244 GLuint unused;
22162245 _pushUniforms = gl_shaderManager.ProcessUniforms ( GLUniform::CONST, GLUniform::FRAME,
2217- false , _uniforms, unused, unused );
2246+ !glConfig. usingBindlessTextures , _uniforms, unused, unused );
22182247 }
22192248}
22202249
0 commit comments