package speiger.src.coreengine.rendering.shader.uniform.vec;

import org.lwjgl.opengl.GL41;

import speiger.src.coreengine.math.vector.floats.Vec2f;
import speiger.src.coreengine.rendering.shader.uniform.Uniform;
import speiger.src.coreengine.rendering.utils.AllocationTracker;

public class Vec2fUniform extends Uniform {
	Vec2f value;

	public Vec2fUniform(String name, Vec2f value) {
		super(name);
		this.value = value.asMutable();
	}
	
	public Vec2fUniform setX(float value) {
		return this.value.x() == value ? this : set(value, this.value.y());
	}
	
	public Vec2fUniform setY(float value) {
		return this.value.y() == value ? this : set(this.value.x(), value);
	}
	
	public Vec2fUniform set(Vec2f value) {
		return set(value.x(), value.y());
	}
	
	public Vec2fUniform set(float x, float y) {
		if(x != value.x() || y != value.y()) {
			value.set(x, y);
			update();
		}
		return this;
	}
	
	@Override
	protected void processChanges(int programId, int location) {
		GL41.glProgramUniform2f(programId, location, value.x(), value.y());
		AllocationTracker.INSTANCE.addGPUBytes(8L);
	}
}
