From 5c98cbdabdbe0555fa89ca6833b4fee47115d636 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 6 Nov 2021 17:03:54 -0300 Subject: [PATCH] Fix Shader:send with storage buffers when the shader uses more than 1. --- src/modules/graphics/opengl/Shader.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/modules/graphics/opengl/Shader.cpp b/src/modules/graphics/opengl/Shader.cpp index 9bacf446e..63c1845e0 100644 --- a/src/modules/graphics/opengl/Shader.cpp +++ b/src/modules/graphics/opengl/Shader.cpp @@ -358,6 +358,7 @@ void Shader::mapActiveUniforms() glGetProgramInterfaceiv(program, GL_SHADER_STORAGE_BLOCK, GL_ACTIVE_RESOURCES, &numstoragebuffers); char namebuffer[2048] = { '\0' }; + int nextstoragebufferbinding = 0; for (int sindex = 0; sindex < numstoragebuffers; sindex++) { @@ -405,8 +406,11 @@ void Shader::mapActiveUniforms() memset(u.buffers, 0, sizeof(Buffer*)* u.count); } - GLenum props[] = { GL_BUFFER_BINDING }; - glGetProgramResourceiv(program, GL_SHADER_STORAGE_BLOCK, sindex, 1, props, 1, nullptr, u.ints); + // Unlike local uniforms and attributes, OpenGL doesn't auto-assign storage + // block bindings if they're unspecified in the shader. So we overwrite them + // regardless, here. + u.ints[0] = nextstoragebufferbinding++; + glShaderStorageBlockBinding(program, sindex, u.ints[0]); BufferBinding binding; binding.bindingindex = u.ints[0]; @@ -1198,6 +1202,9 @@ Shader::MatrixSize Shader::getMatrixSize(GLenum type) const m.columns = 4; m.rows = 3; break; + default: + m.columns = m.rows = 0; + break; } return m;