Hello! I am using LWJGL3 to make a renderer. Let "Materials" be a UBO in a shader, defined this way:
layout(std140, binding=1) uniform Materials {
Material materials[];
};
and there is the uniform material_index:
uniform int material_index = 0;
In the fragment shader, to determine the material the geometry should be rendered with, I am doing this:
Material mat = materials[material_index];
, which throws an error that is caught with
glGetProgrami(programId, GL_LINK_STATUS)
, but no error log is produced by glGetShaderInfoLog(). The automatic Opengl error callback throws a LOT of errors regarding that the program is not linked correctly when it is used afterwards.
So, modern Opengl (#version 460) should allow array indexes to be uniforms because they are read-only, but it doesn't. Why?
I know there is this workaround:
if(material_index == 0)
mat = materials[0];
if(material_index == 1)
mat = materials[1];
...
but it is slow and long and I don't want to use it.