Files
Angelica/src/main/java/net/coderbot/iris/gl/sampler/SamplerBinding.java
T

37 lines
1.0 KiB
Java

package net.coderbot.iris.gl.sampler;
import com.gtnewhorizons.angelica.glsm.RenderSystem;
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
import net.coderbot.iris.gl.texture.TextureType;
import java.util.function.IntSupplier;
public class SamplerBinding {
private final TextureType textureType;
private final int textureUnit;
private final IntSupplier texture;
private final int sampler;
private final ValueUpdateNotifier notifier;
public SamplerBinding(TextureType type, int textureUnit, IntSupplier texture, GlSampler sampler, ValueUpdateNotifier notifier) {
this.textureType = type;
this.textureUnit = textureUnit;
this.texture = texture;
this.sampler = sampler == null ? 0 : sampler.getId();
this.notifier = notifier;
}
public void update() {
updateSampler();
if (notifier != null) {
notifier.setListener(this::updateSampler);
}
}
private void updateSampler() {
RenderSystem.bindSamplerToUnit(textureUnit, sampler);
RenderSystem.bindTextureToUnit(textureType.getGlType(), textureUnit, texture.getAsInt());
}
}