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

import org.lwjgl.opengl.GL20;

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

public class UniformVec2f extends UniformBase<Vec2f> {
	static final Vec2f STORED = Vec2f.mutable();
	
	public UniformVec2f(String id) {
		super(id);
	}
	
	@Override
	protected Vec2f setValue(Vec2f oldValue, Vec2f newValue) {
		if (oldValue != null) {
			oldValue.set(newValue.x(), newValue.y());
			return oldValue;
		}
		return Vec2f.mutable(newValue);
	}
	
	public void storeData(Vec2f data) {
		if (hasChanged(data)) {
			GL20.glUniform2f(getPosition(), data.x(), data.y());
			AllocationTracker.INSTANCE.addGPUBytes(8L);
		}
	}
	
	public void storeData(float x, float y) {
		STORED.set(x, y);
		storeData(STORED);
	}
}
