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

import org.lwjgl.opengl.GL20;

import speiger.src.coreengine.math.color.ColorUtils;
import speiger.src.coreengine.math.vector.floats.Vec3f;
import speiger.src.coreengine.rendering.utils.AllocationTracker;

public class UniformVec3f extends UniformBase<Vec3f> {
	static final Vec3f STORAGE = Vec3f.mutable();

	public UniformVec3f(String id) {
		super(id);
	}

	public void storeData(Vec3f data) {
		if (hasChanged(data)) {
			GL20.glUniform3f(getPosition(), data.x(), data.y(), data.z());
			AllocationTracker.INSTANCE.addGPUBytes(12L);
		}
	}

	public void storeData(int color) {
		storeData(STORAGE.set(ColorUtils.getRF(color), ColorUtils.getGF(color), ColorUtils.getBF(color)));
	}

	public void storeData(float x, float y, float z) {
		storeData(STORAGE.set(x, y, z));
	}

	@Override
	protected Vec3f setValue(Vec3f oldValue, Vec3f newValue) {
		if (oldValue != null) {
			return oldValue.set(newValue);
		}
		return Vec3f.mutable(newValue);
	}
}
