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

import org.lwjgl.opengl.GL20;

import speiger.src.coreengine.math.misc.ColorObject;
import speiger.src.coreengine.math.vector.floats.Vec4f;
import speiger.src.coreengine.rendering.utils.AllocationTracker;

public class UniformVec4f extends UniformBase<Vec4f>
{
	static final Vec4f STORAGE = Vec4f.newMutable();

	public UniformVec4f(String id)
	{
		super(id);
	}
	
	public void storeData(Vec4f data)
	{
		if(hasChanged(data))
		{
			GL20.glUniform4f(getPosition(), data.getX(), data.getY(), data.getZ(), data.getW());
			AllocationTracker.INSTANCE.addGPUBytes(16L);
		}
	}
	
	public void storeData(ColorObject color)
	{
		STORAGE.set(color.getRedFloat(), color.getGreenFloat(), color.getBlueFloat(), color.getAlphaFloat());
		storeData(STORAGE);
	}
	
	public void storeData(float x, float y, float z, float w)
	{
		STORAGE.set(x, y, z, w);
		storeData(STORAGE);
	}
	
	@Override
	protected Vec4f setValue(Vec4f oldValue, Vec4f newValue)
	{
		if(oldValue != null)
		{
			oldValue.set(newValue);
			return oldValue;
		}
		return Vec4f.newMutable(newValue);
	}
}
