@@ -1332,6 +1332,12 @@ void GLShaderManager::InitShader( GLShader* shader ) {
13321332 ShaderDescriptor* desc = FindShader ( shader->_name , shaderType.mainText , shaderType.GLType , shaderType.headers ,
13331333 uniqueMacros, compileMacros, true );
13341334
1335+ if ( desc && glConfig.pushBufferAvailable ) {
1336+ desc->shaderSource = RemoveUniformsFromShaderText ( desc->shaderSource , shader->_pushUniforms );
1337+
1338+ desc->shaderSource .insert ( shaderType.offset , globalUniformBlock );
1339+ }
1340+
13351341 if ( desc && glConfig.usingMaterialSystem && shader->_useMaterialSystem ) {
13361342 desc->shaderSource = ShaderPostProcess ( shader, desc->shaderSource , shaderType.offset );
13371343 }
@@ -1585,7 +1591,7 @@ void GLShaderManager::PostProcessGlobalUniforms() {
15851591 GLuint padding;
15861592 std::vector<GLUniform*>* uniforms = &( ( GLShader* ) globalUBOProxy )->_uniforms ;
15871593 std::vector<GLUniform*> constUniforms =
1588- ProcessUniforms ( GLUniform::CONST, GLUniform::CONST, false , *uniforms, size, padding );
1594+ ProcessUniforms ( GLUniform::CONST, GLUniform::CONST, !glConfig. usingBindlessTextures , *uniforms, size, padding );
15891595
15901596 GenerateUniformStructDefinesText ( constUniforms, padding, 0 , " globalUniforms" , uniformStruct, uniformDefines );
15911597
@@ -1594,7 +1600,7 @@ void GLShaderManager::PostProcessGlobalUniforms() {
15941600 pushBuffer.constUniformsSize = size + padding;
15951601
15961602 std::vector<GLUniform*> frameUniforms =
1597- ProcessUniforms ( GLUniform::FRAME, GLUniform::FRAME, false , *uniforms, size, padding );
1603+ ProcessUniforms ( GLUniform::FRAME, GLUniform::FRAME, !glConfig. usingBindlessTextures , *uniforms, size, padding );
15981604
15991605 GenerateUniformStructDefinesText ( frameUniforms, padding, paddingCount, " globalUniforms" , uniformStruct, uniformDefines );
16001606
@@ -2191,6 +2197,29 @@ GLuint GLShaderManager::SortUniforms( std::vector<GLUniform*>& uniforms ) {
21912197 return structSize;
21922198}
21932199
2200+ std::vector<GLUniform*> GLShaderManager::ProcessUniforms ( const GLUniform::UpdateType minType, const GLUniform::UpdateType maxType,
2201+ const bool skipTextures,
2202+ std::vector<GLUniform*>& uniforms, GLuint& structSize, GLuint& padding ) {
2203+ std::vector<GLUniform*> tmp;
2204+
2205+ tmp.reserve ( uniforms.size () );
2206+ for ( GLUniform* uniform : uniforms ) {
2207+ if ( uniform->_updateType >= minType && uniform->_updateType <= maxType
2208+ && ( !uniform->_isTexture || !skipTextures ) ) {
2209+ tmp.emplace_back ( uniform );
2210+ }
2211+ }
2212+
2213+ structSize = SortUniforms ( tmp );
2214+
2215+ const GLuint structAlignment = 4 ; // Material buffer is now a UBO, so it uses std140 layout, which is aligned to vec4
2216+ if ( structSize > 0 ) {
2217+ padding = ( structAlignment - ( structSize % structAlignment ) ) % structAlignment;
2218+ }
2219+
2220+ return tmp;
2221+ }
2222+
21942223void GLShader::PostProcessUniforms () {
21952224 if ( _useMaterialSystem ) {
21962225 _materialSystemUniforms = gl_shaderManager.ProcessUniforms ( GLUniform::MATERIAL_OR_PUSH, GLUniform::MATERIAL_OR_PUSH,
@@ -2200,7 +2229,7 @@ void GLShader::PostProcessUniforms() {
22002229 if ( glConfig.pushBufferAvailable && !pushSkip ) {
22012230 GLuint unused;
22022231 _pushUniforms = gl_shaderManager.ProcessUniforms ( GLUniform::CONST, GLUniform::FRAME,
2203- false , _uniforms, unused, unused );
2232+ !glConfig. usingBindlessTextures , _uniforms, unused, unused );
22042233 }
22052234}
22062235
0 commit comments