in my shaders I like to use a syntax like this:
layout (location = 0) in vec3 aPos;
So that I can just use the index 0
in glVertexAttribPointer
and the such, saving the effort for the glGetAttribLocation
call. I'd like to do the same with uniform
values, but if I do
layout (location = 2) uniform float offset;
My vertex shader fails to compile. Is there any way to achieve the same behavior and not use glGetUniformLocation
?
OpenGL 4.3 or the ARB_explicit_uniform_location extension allows you to specify uniform locations within the shader using that syntax. So your shader #version
needs to be 430 or you need to activate the extension in your shader to be able to use this syntax.