I am attempting to bind the uniform variables to a certain location, but I currently can't work out how:
To bind attributes (so for example vertex/normal data), I use the following code:
Override
protected void bindAttributes() {
super.bindAttribute(1, "position");
super.bindAttribute(2, "textureCoords");
super.bindAttribute(3, "normal");
}
protected void bindAttribute(int attribute, String variableName){
GL20.glBindAttribLocation(programID, attribute, variableName);
}
I would like to do the same sort of thing for uniform variables.
Currently, I am getting the automatically-assigned locations like this:
public int location_transformationMatrix;
public int location_lightPosition;
public int location_lightColour;
@Override
public void getAllUniformLocations(){
location_transformationMatrix = super.getUniformLocation("transformationMatrix");
location_lightPosition = super.getUniformLocation("lightPosition");
location_lightColour = super.getUniformLocation("lightColour");
}
However, since I am then binding the attributes, this is, at best, resulting in the loss of data such as lighting and normals, and at worst, is crashing the game for about 60% of people who try to play it.
Shader uniforms can, starting from OpenGL 4.3, be set by using layout qualifiers:
layout(location = 2) uniform mat4 modelToWorldMatrix;
will for example bind the locationn of the uniform modelToWorldMatrix
to location 2. For more details have a look here.
Before 4.3 (or better to say without the ARB_explicit_uniform_location extension) there was no way to fix a uniforms location.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With