package speiger.src.coreengine.rendering.shaderOld.uniforms;

import org.lwjgl.opengl.GL20;

import speiger.src.coreengine.rendering.shaderOld.ShaderProgram;
import speiger.src.coreengine.utils.io.GameLog;

public abstract class Uniform
{
	protected String name;
	protected int position;
	protected boolean optional = false;
	
	public Uniform(String id) {
		name = id;
	}
	
	public int getPosition() {
		return position;
	}
	
	@SuppressWarnings("unchecked")
	public <T extends Uniform> T setOptional() {
		optional = true;
		return (T)this;
	}
	
	public void loadUniform(ShaderProgram prog) {
		position = GL20.glGetUniformLocation(prog.getShaderID(), name);
		if(position == -1 && !optional)
			GameLog.error("Couldn't find Shader Uniform: "+name+", Shader: "+"("+prog.getClass().getSimpleName()+".java:0) ("+prog.getShaderID()+")");
	}
}
