49 lines
1.1 KiB
Java
49 lines
1.1 KiB
Java
package speiger.src.coreengine.rendering.shader.uniforms;
|
|
|
|
import org.lwjgl.opengl.GL20;
|
|
|
|
import speiger.src.coreengine.math.misc.ColorUtils;
|
|
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(int color)
|
|
{
|
|
storeData(STORAGE.set(ColorUtils.getRF(color), ColorUtils.getGF(color), ColorUtils.getBF(color), ColorUtils.getAF(color)));
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|