UNTESTED - Replace ATs

- Matrices use #store
 - Accessor for pausedPartialTick
This commit is contained in:
Jozufozu 2021-09-26 19:40:53 -07:00
parent 532e7450e9
commit 7c5e02d2e8
10 changed files with 56 additions and 54 deletions

View file

@ -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 {

View file

@ -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();

View file

@ -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();
}

View file

@ -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

View file

@ -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 {
* </p>
*/
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);
}
}

View file

@ -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();
}

View file

@ -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());
}
}

View file

@ -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<PoseStack> rotateToFace(Direction facing) {
return () -> {
PoseStack stack = new PoseStack();

View file

@ -1,31 +0,0 @@
# Don't jitter when game is paused
public net.minecraft.client.Minecraft f_91013_ #renderPartialTicksPaused
# For uploading matrices as vertex attributes.
public com.mojang.math.Matrix3f f_8134_ #a00
public com.mojang.math.Matrix3f f_8135_ #a01
public com.mojang.math.Matrix3f f_8136_ #a02
public com.mojang.math.Matrix3f f_8137_ #a10
public com.mojang.math.Matrix3f f_8138_ #a11
public com.mojang.math.Matrix3f f_8139_ #a12
public com.mojang.math.Matrix3f f_8140_ #a20
public com.mojang.math.Matrix3f f_8141_ #a21
public com.mojang.math.Matrix3f f_8142_ #a22
public com.mojang.math.Matrix4f f_27603_ #a00
public com.mojang.math.Matrix4f f_27604_ #a01
public com.mojang.math.Matrix4f f_27605_ #a02
public com.mojang.math.Matrix4f f_27606_ #a03
public com.mojang.math.Matrix4f f_27607_ #a10
public com.mojang.math.Matrix4f f_27608_ #a11
public com.mojang.math.Matrix4f f_27609_ #a12
public com.mojang.math.Matrix4f f_27610_ #a13
public com.mojang.math.Matrix4f f_27611_ #a20
public com.mojang.math.Matrix4f f_27612_ #a21
public com.mojang.math.Matrix4f f_27613_ #a22
public com.mojang.math.Matrix4f f_27614_ #a23
public com.mojang.math.Matrix4f f_27615_ #a30
public com.mojang.math.Matrix4f f_27616_ #a31
public com.mojang.math.Matrix4f f_27617_ #a32
public com.mojang.math.Matrix4f f_27618_ #a33

View file

@ -17,7 +17,8 @@
"LevelRendererAccessor",
"InstanceAddMixin",
"InstanceRemoveMixin",
"LeakChunkStorageArrayMixin"
"LeakChunkStorageArrayMixin",
"PausedPartialTickAccessor"
],
"injectors": {
"defaultRequire": 1