Browse Source

Fix Shader:send with storage buffers when the shader uses more than 1.

Alex Szpakowski 3 years ago
parent
commit
5c98cbdabd
1 changed files with 9 additions and 2 deletions
  1. 9 2
      src/modules/graphics/opengl/Shader.cpp

+ 9 - 2
src/modules/graphics/opengl/Shader.cpp

@@ -358,6 +358,7 @@ void Shader::mapActiveUniforms()
 		glGetProgramInterfaceiv(program, GL_SHADER_STORAGE_BLOCK, GL_ACTIVE_RESOURCES, &numstoragebuffers);
 		glGetProgramInterfaceiv(program, GL_SHADER_STORAGE_BLOCK, GL_ACTIVE_RESOURCES, &numstoragebuffers);
 
 
 		char namebuffer[2048] = { '\0' };
 		char namebuffer[2048] = { '\0' };
+		int nextstoragebufferbinding = 0;
 
 
 		for (int sindex = 0; sindex < numstoragebuffers; sindex++)
 		for (int sindex = 0; sindex < numstoragebuffers; sindex++)
 		{
 		{
@@ -405,8 +406,11 @@ void Shader::mapActiveUniforms()
 				memset(u.buffers, 0, sizeof(Buffer*)* u.count);
 				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;
 			BufferBinding binding;
 			binding.bindingindex = u.ints[0];
 			binding.bindingindex = u.ints[0];
@@ -1198,6 +1202,9 @@ Shader::MatrixSize Shader::getMatrixSize(GLenum type) const
 		m.columns = 4;
 		m.columns = 4;
 		m.rows = 3;
 		m.rows = 3;
 		break;
 		break;
+	default:
+		m.columns = m.rows = 0;
+		break;
 	}
 	}
 
 
 	return m;
 	return m;