SimpleJavaEngine/src/main/java/speiger/src/coreengine/rendering/shader/uniform/vec/Vec4fUniform.java

50 lines
1.5 KiB
Java

package speiger.src.coreengine.rendering.shader.uniform.vec;
import org.lwjgl.opengl.GL41;
import speiger.src.coreengine.math.vector.floats.Vec4f;
import speiger.src.coreengine.rendering.shader.uniform.Uniform;
import speiger.src.coreengine.rendering.utils.AllocationTracker;
public class Vec4fUniform extends Uniform {
Vec4f value;
public Vec4fUniform(String name, Vec4f value) {
super(name);
this.value = value.asMutable();
}
public Vec4fUniform setX(float value) {
return this.value.x() == value ? this : set(value, this.value.y(), this.value.z(), this.value.w());
}
public Vec4fUniform setY(float value) {
return this.value.y() == value ? this : set(this.value.x(), value, this.value.z(), this.value.w());
}
public Vec4fUniform setZ(float value) {
return this.value.z() == value ? this : set(this.value.x(), this.value.y(), value, this.value.w());
}
public Vec4fUniform setW(float value) {
return this.value.w() == value ? this : set(this.value.x(), this.value.y(), this.value.z(), value);
}
public Vec4fUniform set(Vec4f value) {
return set(value.x(), value.y(), value.z(), value.w());
}
public Vec4fUniform set(float x, float y, float z, float w) {
if(x != value.x() || y != value.y() || z != value.z() || w != value.z()) {
value.set(x, y, z, w);
update();
}
return this;
}
@Override
protected void processChanges(int programId, int location) {
GL41.glProgramUniform4f(programId, location, value.x(), value.y(), value.z(), value.w());
AllocationTracker.INSTANCE.addGPUBytes(16L);
}
}