diff --git a/build.gradle b/build.gradle index 46343283f..685a645e2 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,7 @@ java.toolchain.languageVersion = JavaLanguageVersion.of(16) println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch')) minecraft { mappings channel: 'official', version: "${minecraft_version}" - accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') + //accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') runs { client { diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/MappedBuffer.java b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/MappedBuffer.java index 0fa839915..60c5e85f8 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/MappedBuffer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/MappedBuffer.java @@ -1,6 +1,7 @@ package com.jozufozu.flywheel.backend.gl.buffer; import java.nio.ByteBuffer; +import java.nio.FloatBuffer; import org.lwjgl.opengl.GL15; import org.lwjgl.system.MemoryUtil; @@ -48,6 +49,12 @@ public abstract class MappedBuffer extends VecBuffer implements AutoCloseable { return this; } + public MappedBuffer put(FloatBuffer floats) { + checkAndMap(); + super.put(floats); + return this; + } + public int position() { checkAndMap(); return super.position(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/VecBuffer.java b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/VecBuffer.java index 76fcfcccb..96171c80b 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/VecBuffer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/VecBuffer.java @@ -3,6 +3,7 @@ package com.jozufozu.flywheel.backend.gl.buffer; import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.nio.FloatBuffer; public class VecBuffer { @@ -48,6 +49,15 @@ public class VecBuffer { return this; } + public VecBuffer put(FloatBuffer floats) { + + int remainingBytes = floats.remaining() * 4; + internal.asFloatBuffer().put(floats); + internal.position(internal.position() + remainingBytes); + + return this; + } + public int position() { return internal.position(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlProgram.java b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlProgram.java index 692002529..eade29843 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlProgram.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlProgram.java @@ -6,6 +6,11 @@ import static org.lwjgl.opengl.GL20.glUniform1i; import static org.lwjgl.opengl.GL20.glUniformMatrix4fv; import static org.lwjgl.opengl.GL20.glUseProgram; +import java.nio.FloatBuffer; + +import org.lwjgl.system.MemoryStack; +import org.lwjgl.system.MemoryUtil; + import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.gl.GlObject; import com.jozufozu.flywheel.util.RenderUtil; @@ -65,7 +70,10 @@ public abstract class GlProgram extends GlObject { } protected static void uploadMatrixUniform(int uniform, Matrix4f mat) { - glUniformMatrix4fv(uniform, false, RenderUtil.writeMatrix(mat)); + FloatBuffer floatBuffer = MemoryStack.stackGet() + .mallocFloat(16); + mat.store(floatBuffer); + glUniformMatrix4fv(uniform, false, floatBuffer); } @Override diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelData.java b/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelData.java index ff225c0ea..8b36c186e 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelData.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelData.java @@ -1,5 +1,7 @@ package com.jozufozu.flywheel.core.materials.model; +import java.nio.FloatBuffer; + import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; import com.jozufozu.flywheel.core.materials.BasicData; import com.jozufozu.flywheel.util.RenderUtil; @@ -8,10 +10,14 @@ import com.mojang.blaze3d.vertex.PoseStack; public class ModelData extends BasicData { private static final float[] empty = new float[25]; - public float[] matrices = empty; + public final float[] matrices = empty.clone(); + private final FloatBuffer buf = FloatBuffer.wrap(matrices); public ModelData setTransform(PoseStack stack) { - matrices = RenderUtil.writeMatrixStack(stack); + this.buf.reset(); + + stack.last().pose().store(this.buf); + stack.last().normal().store(this.buf); markDirty(); return this; } @@ -24,7 +30,8 @@ public class ModelData extends BasicData { *
*/ public ModelData setEmptyTransform() { - matrices = empty; + this.buf.reset(); + this.buf.put(empty); markDirty(); return this; } @@ -32,6 +39,6 @@ public class ModelData extends BasicData { @Override public void write(VecBuffer buf) { super.write(buf); - buf.putFloatArray(matrices); + buf.put(this.buf); } } diff --git a/src/main/java/com/jozufozu/flywheel/mixin/PausedPartialTickAccessor.java b/src/main/java/com/jozufozu/flywheel/mixin/PausedPartialTickAccessor.java new file mode 100644 index 000000000..550f6d4ab --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/mixin/PausedPartialTickAccessor.java @@ -0,0 +1,13 @@ +package com.jozufozu.flywheel.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import net.minecraft.client.Minecraft; + +@Mixin(Minecraft.class) +public interface PausedPartialTickAccessor { + + @Accessor("pausePartialTick") + float getPausePartialTick(); +} diff --git a/src/main/java/com/jozufozu/flywheel/util/AnimationTickHolder.java b/src/main/java/com/jozufozu/flywheel/util/AnimationTickHolder.java index d5143f3a2..0a8374f42 100644 --- a/src/main/java/com/jozufozu/flywheel/util/AnimationTickHolder.java +++ b/src/main/java/com/jozufozu/flywheel/util/AnimationTickHolder.java @@ -1,5 +1,7 @@ package com.jozufozu.flywheel.util; +import com.jozufozu.flywheel.mixin.PausedPartialTickAccessor; + import net.minecraft.client.Minecraft; public class AnimationTickHolder { @@ -35,6 +37,6 @@ public class AnimationTickHolder { public static float getPartialTicks() { Minecraft mc = Minecraft.getInstance(); - return (mc.isPaused() ? mc.pausePartialTick : mc.getFrameTime()); + return (mc.isPaused() ? ((PausedPartialTickAccessor) mc).getPausePartialTick() : mc.getFrameTime()); } } diff --git a/src/main/java/com/jozufozu/flywheel/util/RenderUtil.java b/src/main/java/com/jozufozu/flywheel/util/RenderUtil.java index 857207939..7a06724ab 100644 --- a/src/main/java/com/jozufozu/flywheel/util/RenderUtil.java +++ b/src/main/java/com/jozufozu/flywheel/util/RenderUtil.java @@ -42,21 +42,6 @@ public class RenderUtil { return Math.sqrt(lengthSqr(x, y, z)); } - public static float[] writeMatrixStack(PoseStack stack) { - return writeMatrixStack(stack.last() - .pose(), stack.last() - .normal()); - } - - // GPUs want matrices in column major order. - public static float[] writeMatrixStack(Matrix4f model, Matrix3f normal) { - return new float[]{model.m00, model.m10, model.m20, model.m30, model.m01, model.m11, model.m21, model.m31, model.m02, model.m12, model.m22, model.m32, model.m03, model.m13, model.m23, model.m33, normal.m00, normal.m10, normal.m20, normal.m01, normal.m11, normal.m21, normal.m02, normal.m12, normal.m22,}; - } - - public static float[] writeMatrix(Matrix4f model) { - return new float[]{model.m00, model.m10, model.m20, model.m30, model.m01, model.m11, model.m21, model.m31, model.m02, model.m12, model.m22, model.m32, model.m03, model.m13, model.m23, model.m33,}; - } - public static Supplier