mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-24 22:24:27 +00:00
Get rid of some allocations, and use immutable variants for the suppliers (#1612)
This commit is contained in:
1 parent
7d8c8d306d
commit
ffb4ca9472
13 files changed
+92
-69
No files matched your search
@@ -1,11 +1,10 @@
|
||||
package net.coderbot.iris.gl.uniform;
|
||||
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector3i;
|
||||
import org.joml.Vector2ic;
|
||||
import org.joml.Vector3ic;
|
||||
import org.joml.Vector4f;
|
||||
import org.joml.Vector4i;
|
||||
import org.joml.Vector4fc;
|
||||
import org.joml.Vector4ic;
|
||||
|
||||
import java.util.function.DoubleSupplier;
|
||||
import java.util.function.IntSupplier;
|
||||
@@ -38,7 +37,7 @@ public interface DynamicLocationalUniformHolder extends LocationalUniformHolder,
|
||||
return this;
|
||||
}
|
||||
|
||||
default DynamicLocationalUniformHolder uniform2i(String name, Supplier<Vector2i> value, ValueUpdateNotifier notifier) {
|
||||
default DynamicLocationalUniformHolder uniform2i(String name, Supplier<Vector2ic> value, ValueUpdateNotifier notifier) {
|
||||
location(name, UniformType.VEC2I).ifPresent(id -> addDynamicUniform(new Vector2IntegerJomlUniform(id, value, notifier), notifier));
|
||||
|
||||
return this;
|
||||
@@ -50,7 +49,7 @@ public interface DynamicLocationalUniformHolder extends LocationalUniformHolder,
|
||||
return this;
|
||||
}
|
||||
|
||||
default DynamicUniformHolder uniform4f(String name, Supplier<Vector4f> value, ValueUpdateNotifier notifier) {
|
||||
default DynamicUniformHolder uniform4f(String name, Supplier<Vector4fc> value, ValueUpdateNotifier notifier) {
|
||||
location(name, UniformType.VEC4).ifPresent(id -> addDynamicUniform(new Vector4Uniform(id, value, notifier), notifier));
|
||||
|
||||
return this;
|
||||
@@ -61,7 +60,7 @@ public interface DynamicLocationalUniformHolder extends LocationalUniformHolder,
|
||||
return this;
|
||||
}
|
||||
|
||||
default DynamicUniformHolder uniform4i(String name, Supplier<Vector4i> value, ValueUpdateNotifier notifier) {
|
||||
default DynamicUniformHolder uniform4i(String name, Supplier<Vector4ic> value, ValueUpdateNotifier notifier) {
|
||||
location(name, UniformType.VEC4I).ifPresent(id -> addDynamicUniform(new Vector4IntegerJomlUniform(id, value, notifier), notifier));
|
||||
|
||||
return this;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package net.coderbot.iris.gl.uniform;
|
||||
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector3i;
|
||||
import org.joml.Vector2ic;
|
||||
import org.joml.Vector3ic;
|
||||
import org.joml.Vector4f;
|
||||
import org.joml.Vector4i;
|
||||
import org.joml.Vector4fc;
|
||||
import org.joml.Vector4ic;
|
||||
|
||||
import java.util.function.DoubleSupplier;
|
||||
import java.util.function.IntSupplier;
|
||||
@@ -16,9 +15,9 @@ public interface DynamicUniformHolder extends UniformHolder {
|
||||
DynamicUniformHolder uniform1f(String name, IntSupplier value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform1f(String name, DoubleSupplier value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform1i(String name, IntSupplier value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform2i(String name, Supplier<Vector2i> value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform2i(String name, Supplier<Vector2ic> value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform3i(String name, Supplier<Vector3ic> value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform4f(String name, Supplier<Vector4f> value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform4f(String name, Supplier<Vector4fc> value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform4fArray(String name, Supplier<float[]> value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform4i(String name, Supplier<Vector4i> value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform4i(String name, Supplier<Vector4ic> value, ValueUpdateNotifier notifier);
|
||||
}
|
||||
@@ -4,13 +4,13 @@ import net.minecraft.util.Vec3;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Matrix4fc;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector2ic;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3fc;
|
||||
import org.joml.Vector3i;
|
||||
import org.joml.Vector3ic;
|
||||
import org.joml.Vector4f;
|
||||
import org.joml.Vector4fc;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
import java.util.function.BooleanSupplier;
|
||||
@@ -66,7 +66,7 @@ public interface LocationalUniformHolder extends UniformHolder {
|
||||
}
|
||||
|
||||
@Override
|
||||
default LocationalUniformHolder uniform2i(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector2i> value) {
|
||||
default LocationalUniformHolder uniform2i(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector2ic> value) {
|
||||
location(name, UniformType.VEC2I).ifPresent(id -> addUniform(updateFrequency, new Vector2IntegerJomlUniform(id, value)));
|
||||
|
||||
return this;
|
||||
@@ -94,7 +94,7 @@ public interface LocationalUniformHolder extends UniformHolder {
|
||||
}
|
||||
|
||||
@Override
|
||||
default LocationalUniformHolder uniformTruncated3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4f> value) {
|
||||
default LocationalUniformHolder uniformTruncated3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4fc> value) {
|
||||
location(name, UniformType.VEC3).ifPresent(id -> addUniform(updateFrequency, Vector3Uniform.truncated(id, value)));
|
||||
|
||||
return this;
|
||||
@@ -108,7 +108,7 @@ public interface LocationalUniformHolder extends UniformHolder {
|
||||
}
|
||||
|
||||
@Override
|
||||
default LocationalUniformHolder uniform4f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4f> value) {
|
||||
default LocationalUniformHolder uniform4f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4fc> value) {
|
||||
location(name, UniformType.VEC4).ifPresent(id -> addUniform(updateFrequency, new Vector4Uniform(id, value)));
|
||||
|
||||
return this;
|
||||
|
||||
@@ -3,12 +3,12 @@ package net.coderbot.iris.gl.uniform;
|
||||
import net.minecraft.util.Vec3;
|
||||
import org.joml.Matrix4fc;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector2ic;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3fc;
|
||||
import org.joml.Vector3i;
|
||||
import org.joml.Vector3ic;
|
||||
import org.joml.Vector4f;
|
||||
import org.joml.Vector4fc;
|
||||
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.DoubleSupplier;
|
||||
@@ -28,7 +28,7 @@ public interface UniformHolder {
|
||||
|
||||
UniformHolder uniform2f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector2f> value);
|
||||
|
||||
UniformHolder uniform2i(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector2i> value);
|
||||
UniformHolder uniform2i(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector2ic> value);
|
||||
|
||||
UniformHolder uniform3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector3fc> value);
|
||||
|
||||
@@ -36,11 +36,11 @@ public interface UniformHolder {
|
||||
|
||||
UniformHolder uniformVanilla3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vec3> value);
|
||||
|
||||
UniformHolder uniformTruncated3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4f> value);
|
||||
UniformHolder uniformTruncated3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4fc> value);
|
||||
|
||||
UniformHolder uniform3d(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector3d> value);
|
||||
|
||||
UniformHolder uniform4f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4f> value);
|
||||
UniformHolder uniform4f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4fc> value);
|
||||
|
||||
UniformHolder uniform4fArray(UniformUpdateFrequency updateFrequency, String name, Supplier<float[]> value);
|
||||
|
||||
|
||||
@@ -3,21 +3,22 @@ package net.coderbot.iris.gl.uniform;
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector2ic;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Vector2IntegerJomlUniform extends Uniform {
|
||||
private Vector2i cachedValue;
|
||||
private final Supplier<Vector2i> value;
|
||||
private final Vector2i cachedValue;
|
||||
private final Supplier<Vector2ic> value;
|
||||
|
||||
Vector2IntegerJomlUniform(int location, Supplier<Vector2i> value) {
|
||||
Vector2IntegerJomlUniform(int location, Supplier<Vector2ic> value) {
|
||||
this(location, value, null);
|
||||
}
|
||||
|
||||
Vector2IntegerJomlUniform(int location, Supplier<Vector2i> value, ValueUpdateNotifier notifier) {
|
||||
Vector2IntegerJomlUniform(int location, Supplier<Vector2ic> value, ValueUpdateNotifier notifier) {
|
||||
super(location, notifier);
|
||||
|
||||
this.cachedValue = null;
|
||||
this.cachedValue = new Vector2i();
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -31,11 +32,11 @@ public class Vector2IntegerJomlUniform extends Uniform {
|
||||
}
|
||||
|
||||
private void updateValue() {
|
||||
Vector2i newValue = value.get();
|
||||
Vector2ic newValue = value.get();
|
||||
|
||||
if (cachedValue == null || !newValue.equals(cachedValue)) {
|
||||
cachedValue = newValue;
|
||||
RenderSystem.uniform2i(this.location, newValue.x, newValue.y);
|
||||
if (!newValue.equals(cachedValue)) {
|
||||
cachedValue.set(newValue.x(), newValue.y());
|
||||
RenderSystem.uniform2i(this.location, cachedValue.x, cachedValue.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3fc;
|
||||
import org.joml.Vector4f;
|
||||
import org.joml.Vector4fc;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -31,11 +31,11 @@ public class Vector3Uniform extends Uniform {
|
||||
});
|
||||
}
|
||||
|
||||
static Vector3Uniform truncated(int location, Supplier<Vector4f> value) {
|
||||
static Vector3Uniform truncated(int location, Supplier<Vector4fc> value) {
|
||||
Vector3f held = new Vector3f();
|
||||
|
||||
return new Vector3Uniform(location, () -> {
|
||||
Vector4f updated = value.get();
|
||||
Vector4fc updated = value.get();
|
||||
|
||||
held.set(updated.x(), updated.y(), updated.z());
|
||||
|
||||
|
||||
@@ -3,21 +3,22 @@ package net.coderbot.iris.gl.uniform;
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import org.joml.Vector4i;
|
||||
import org.joml.Vector4ic;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Vector4IntegerJomlUniform extends Uniform {
|
||||
private Vector4i cachedValue;
|
||||
private final Supplier<Vector4i> value;
|
||||
private final Vector4i cachedValue;
|
||||
private final Supplier<Vector4ic> value;
|
||||
|
||||
Vector4IntegerJomlUniform(int location, Supplier<Vector4i> value) {
|
||||
Vector4IntegerJomlUniform(int location, Supplier<Vector4ic> value) {
|
||||
this(location, value, null);
|
||||
}
|
||||
|
||||
Vector4IntegerJomlUniform(int location, Supplier<Vector4i> value, ValueUpdateNotifier notifier) {
|
||||
Vector4IntegerJomlUniform(int location, Supplier<Vector4ic> value, ValueUpdateNotifier notifier) {
|
||||
super(location, notifier);
|
||||
|
||||
this.cachedValue = null;
|
||||
this.cachedValue = new Vector4i();
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -31,11 +32,11 @@ public class Vector4IntegerJomlUniform extends Uniform {
|
||||
}
|
||||
|
||||
private void updateValue() {
|
||||
Vector4i newValue = value.get();
|
||||
Vector4ic newValue = value.get();
|
||||
|
||||
if (cachedValue == null || !newValue.equals(cachedValue)) {
|
||||
cachedValue = newValue;
|
||||
RenderSystem.uniform4i(this.location, newValue.x, newValue.y, newValue.z, newValue.w);
|
||||
if (!newValue.equals(cachedValue)) {
|
||||
cachedValue.set(newValue.x(), newValue.y(), newValue.z(), newValue.w());
|
||||
RenderSystem.uniform4i(this.location, cachedValue.x, cachedValue.y, cachedValue.z, cachedValue.w);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,18 +3,19 @@ package net.coderbot.iris.gl.uniform;
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import org.joml.Vector4f;
|
||||
import org.joml.Vector4fc;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Vector4Uniform extends Uniform {
|
||||
private final Vector4f cachedValue;
|
||||
private final Supplier<Vector4f> value;
|
||||
private final Supplier<Vector4fc> value;
|
||||
|
||||
Vector4Uniform(int location, Supplier<Vector4f> value) {
|
||||
Vector4Uniform(int location, Supplier<Vector4fc> value) {
|
||||
this(location, value, null);
|
||||
}
|
||||
|
||||
Vector4Uniform(int location, Supplier<Vector4f> value, ValueUpdateNotifier notifier) {
|
||||
Vector4Uniform(int location, Supplier<Vector4fc> value, ValueUpdateNotifier notifier) {
|
||||
super(location, notifier);
|
||||
|
||||
this.cachedValue = new Vector4f();
|
||||
@@ -31,7 +32,7 @@ public class Vector4Uniform extends Uniform {
|
||||
}
|
||||
|
||||
private void updateValue() {
|
||||
Vector4f newValue = value.get();
|
||||
Vector4fc newValue = value.get();
|
||||
|
||||
if (!newValue.equals(cachedValue)) {
|
||||
cachedValue.set(newValue.x(), newValue.y(), newValue.z(), newValue.w());
|
||||
|
||||
@@ -41,9 +41,12 @@ import static net.coderbot.iris.gl.uniform.UniformUpdateFrequency.ONCE;
|
||||
public final class CommonUniforms {
|
||||
private static final Minecraft client = Minecraft.getMinecraft();
|
||||
private static final Vector2i ZERO_VECTOR_2i = new Vector2i();
|
||||
private static final Vector4i ZERO_VECTOR_4i = new Vector4i(0, 0, 0, 0);
|
||||
private static final Vector3d ZERO_VECTOR_3d = new Vector3d();
|
||||
|
||||
// Scratch vectors for push-notified suppliers -- GL thread only, never escapes
|
||||
private static final Vector2i scratch2i = new Vector2i();
|
||||
private static final Vector4i scratch4i = new Vector4i();
|
||||
|
||||
private CommonUniforms() {
|
||||
// no construction allowed
|
||||
}
|
||||
@@ -79,26 +82,26 @@ public final class CommonUniforms {
|
||||
final AbstractTexture texture = TextureTracker.INSTANCE.getTexture(glId);
|
||||
if (texture instanceof TextureMap) {
|
||||
final TextureInfo info = TextureInfoCache.INSTANCE.getInfo(glId);
|
||||
return new Vector2i(info.getWidth(), info.getHeight());
|
||||
return scratch2i.set(info.getWidth(), info.getHeight());
|
||||
}
|
||||
|
||||
return ZERO_VECTOR_2i;
|
||||
return scratch2i.set(0, 0);
|
||||
}, StateUpdateNotifiers.bindTextureNotifier);
|
||||
|
||||
uniforms.uniform2i("gtextureSize", () -> {
|
||||
final int glId = GLStateManager.getBoundTextureForServerState(0);
|
||||
|
||||
final TextureInfo info = TextureInfoCache.INSTANCE.getInfo(glId);
|
||||
return new Vector2i(info.getWidth(), info.getHeight());
|
||||
return scratch2i.set(info.getWidth(), info.getHeight());
|
||||
|
||||
}, StateUpdateNotifiers.bindTextureNotifier);
|
||||
|
||||
uniforms.uniform4i("blendFunc", () -> {
|
||||
if(GLStateManager.getBlendMode().isEnabled()) {
|
||||
final BlendState blend = GLStateManager.getBlendState();
|
||||
return new Vector4i(blend.getSrcRgb(), blend.getDstRgb(), blend.getSrcAlpha(), blend.getDstAlpha());
|
||||
return scratch4i.set(blend.getSrcRgb(), blend.getDstRgb(), blend.getSrcAlpha(), blend.getDstAlpha());
|
||||
}
|
||||
return ZERO_VECTOR_4i;
|
||||
return scratch4i.set(0, 0, 0, 0);
|
||||
}, StateUpdateNotifiers.blendFuncNotifier);
|
||||
|
||||
uniforms.uniform1i("renderStage", () -> GbufferPrograms.getCurrentPhase().ordinal(), StateUpdateNotifiers.phaseChangeNotifier);
|
||||
|
||||
+7
-6
@@ -22,12 +22,13 @@ import net.minecraft.util.Vec3;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Matrix4fc;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector2ic;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3fc;
|
||||
import org.joml.Vector3ic;
|
||||
import org.joml.Vector4f;
|
||||
import org.joml.Vector4fc;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
@@ -112,7 +113,7 @@ public class CustomUniformFixedInputUniformsHolder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder uniform2i(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector2i> value) {
|
||||
public Builder uniform2i(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector2ic> value) {
|
||||
return this.put(name, new Int2VectorCachedUniform(name, updateFrequency, value));
|
||||
}
|
||||
|
||||
@@ -132,10 +133,10 @@ public class CustomUniformFixedInputUniformsHolder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder uniformTruncated3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4f> value) {
|
||||
public Builder uniformTruncated3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4fc> value) {
|
||||
Vector3f held = new Vector3f();
|
||||
return this.put(name, new Float3VectorCachedUniform(name, updateFrequency, () -> {
|
||||
Vector4f vec = value.get();
|
||||
final Vector4fc vec = value.get();
|
||||
held.set(vec.x(), vec.y(), vec.z());
|
||||
return held;
|
||||
}));
|
||||
@@ -152,10 +153,10 @@ public class CustomUniformFixedInputUniformsHolder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public UniformHolder uniform4f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4f> value) {
|
||||
public UniformHolder uniform4f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4fc> value) {
|
||||
Vector4f held = new Vector4f();
|
||||
return this.put(name, new Float4VectorCachedUniform(name, updateFrequency, () -> {
|
||||
Vector4f vec = value.get();
|
||||
final Vector4fc vec = value.get();
|
||||
held.set(vec.x(), vec.y(), vec.z(), vec.w());
|
||||
return held;
|
||||
}));
|
||||
|
||||
+11
-2
@@ -3,14 +3,23 @@ package net.coderbot.iris.uniforms.custom.cached;
|
||||
import net.coderbot.iris.gl.uniform.UniformUpdateFrequency;
|
||||
import net.coderbot.iris.parsing.VectorType;
|
||||
import org.joml.Vector4f;
|
||||
import org.joml.Vector4fc;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Float4VectorCachedUniform extends VectorCachedUniform<Vector4f> {
|
||||
|
||||
public Float4VectorCachedUniform(String name, UniformUpdateFrequency updateFrequency, Supplier<Vector4f> supplier) {
|
||||
super(name, updateFrequency, new Vector4f(), supplier);
|
||||
public Float4VectorCachedUniform(String name, UniformUpdateFrequency updateFrequency, Supplier<Vector4fc> supplier) {
|
||||
super(name, updateFrequency, new Vector4f(), adapt(supplier));
|
||||
}
|
||||
|
||||
private static Supplier<Vector4f> adapt(Supplier<Vector4fc> supplier) {
|
||||
final Vector4f scratch = new Vector4f();
|
||||
return () -> {
|
||||
final Vector4fc v = supplier.get();
|
||||
return scratch.set(v.x(), v.y(), v.z(), v.w());
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+11
-2
@@ -4,14 +4,23 @@ import kroppeb.stareval.function.FunctionReturn;
|
||||
import net.coderbot.iris.gl.uniform.UniformUpdateFrequency;
|
||||
import net.coderbot.iris.parsing.VectorType;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector2ic;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Int2VectorCachedUniform extends VectorCachedUniform<Vector2i> {
|
||||
|
||||
public Int2VectorCachedUniform(String name, UniformUpdateFrequency updateFrequency, Supplier<Vector2i> supplier) {
|
||||
super(name, updateFrequency, new Vector2i(), supplier);
|
||||
public Int2VectorCachedUniform(String name, UniformUpdateFrequency updateFrequency, Supplier<Vector2ic> supplier) {
|
||||
super(name, updateFrequency, new Vector2i(), adapt(supplier));
|
||||
}
|
||||
|
||||
private static Supplier<Vector2i> adapt(Supplier<Vector2ic> supplier) {
|
||||
final Vector2i scratch = new Vector2i();
|
||||
return () -> {
|
||||
final Vector2ic v = supplier.get();
|
||||
return scratch.set(v.x(), v.y());
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.coderbot.iris.uniforms.transforms;
|
||||
|
||||
import net.coderbot.iris.uniforms.FrameUpdateNotifier;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector2ic;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -10,9 +10,9 @@ public class SmoothedVec2f implements Supplier<Vector2f> {
|
||||
private final SmoothedFloat x;
|
||||
private final SmoothedFloat y;
|
||||
|
||||
public SmoothedVec2f(float halfLifeUp, float halfLifeDown, Supplier<Vector2i> unsmoothed, FrameUpdateNotifier updateNotifier) {
|
||||
x = new SmoothedFloat(halfLifeUp, halfLifeDown, () -> unsmoothed.get().x, updateNotifier);
|
||||
y = new SmoothedFloat(halfLifeUp, halfLifeDown, () -> unsmoothed.get().y, updateNotifier);
|
||||
public SmoothedVec2f(float halfLifeUp, float halfLifeDown, Supplier<Vector2ic> unsmoothed, FrameUpdateNotifier updateNotifier) {
|
||||
x = new SmoothedFloat(halfLifeUp, halfLifeDown, () -> unsmoothed.get().x(), updateNotifier);
|
||||
y = new SmoothedFloat(halfLifeUp, halfLifeDown, () -> unsmoothed.get().y(), updateNotifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user