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

import org.lwjgl.opengl.GL41;

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

public class Vec3fUniform extends Uniform {
	Vec3f value;

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