diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/GlVertexArray.java b/src/main/java/com/jozufozu/flywheel/backend/gl/GlVertexArray.java index c75e1e117..18f7bfc26 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/GlVertexArray.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/GlVertexArray.java @@ -1,5 +1,6 @@ package com.jozufozu.flywheel.backend.gl; +import com.jozufozu.flywheel.mixin.BufferUploaderAccessor; import com.jozufozu.flywheel.util.AttribUtil; import com.mojang.blaze3d.platform.GlStateManager; @@ -9,11 +10,14 @@ public class GlVertexArray extends GlObject { } public void bind() { - GlStateManager._glBindVertexArray(handle()); + int handle = handle(); + GlStateManager._glBindVertexArray(handle); + BufferUploaderAccessor.flywheel$setLastVAO(handle); } public static void unbind() { GlStateManager._glBindVertexArray(0); + BufferUploaderAccessor.flywheel$setLastVAO(0); } protected void deleteInternal(int handle) { 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 2536ba21b..8fbac95cd 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 @@ -31,12 +31,12 @@ public abstract class GlProgram extends GlObject { public void bind() { int handle = handle(); ProgramManager.glUseProgram(handle); - ShaderInstanceAccessor.setLastProgramId(handle); + ShaderInstanceAccessor.flywheel$setLastProgramId(handle); } public void unbind() { ProgramManager.glUseProgram(0); - ShaderInstanceAccessor.setLastProgramId(0); + ShaderInstanceAccessor.flywheel$setLastProgramId(0); } /** diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/SuperBufferSource.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/SuperBufferSource.java index d4b8636f5..20984c03b 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/SuperBufferSource.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/SuperBufferSource.java @@ -20,7 +20,7 @@ public class SuperBufferSource { public SuperBufferSource() { scratch = new BufferBuilder(8); - ((BufferBuilderHack) scratch).freeBuffer(); + ((BufferBuilderHack) scratch).flywheel$freeBuffer(); } public DirectVertexConsumer getBuffer(RenderType renderType, int vertexCount) { @@ -40,7 +40,7 @@ public class SuperBufferSource { if (builder.expectedVertices > 0) { RenderType type = entry.getKey(); - hack.hackBegin(builder.backingBuffer, type.format(), builder.expectedVertices); + hack.flywheel$hackBegin(builder.backingBuffer, type.format(), builder.expectedVertices); type.end(scratch, 0, 0, 0); diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/BufferBuilderHack.java b/src/main/java/com/jozufozu/flywheel/backend/model/BufferBuilderHack.java index ee2dd4fb8..2fc98cf21 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/model/BufferBuilderHack.java +++ b/src/main/java/com/jozufozu/flywheel/backend/model/BufferBuilderHack.java @@ -10,7 +10,7 @@ import com.mojang.blaze3d.vertex.VertexFormat; */ public interface BufferBuilderHack { - void freeBuffer(); + void flywheel$freeBuffer(); - void hackBegin(ByteBuffer buffer, VertexFormat format, int vertexCount); + void flywheel$hackBegin(ByteBuffer buffer, VertexFormat format, int vertexCount); } diff --git a/src/main/java/com/jozufozu/flywheel/config/FlwEngine.java b/src/main/java/com/jozufozu/flywheel/config/FlwEngine.java index 2692c63e1..f0a977224 100644 --- a/src/main/java/com/jozufozu/flywheel/config/FlwEngine.java +++ b/src/main/java/com/jozufozu/flywheel/config/FlwEngine.java @@ -6,6 +6,8 @@ import java.util.Map; import javax.annotation.Nullable; +import org.jetbrains.annotations.NotNull; + import com.jozufozu.flywheel.backend.Backend; import net.minecraft.ChatFormatting; @@ -13,12 +15,14 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.TextComponent; +import net.minecraftforge.fml.ModList; public enum FlwEngine { - OFF("off", "Off", new TextComponent("Disabled Flywheel").withStyle(ChatFormatting.RED)), - BATCHING("batching", "Parallel Batching", new TextComponent("Using Batching Engine").withStyle(ChatFormatting.GREEN)), - INSTANCING("instancing", "GL33 Instanced Arrays", new TextComponent("Using Instancing Engine").withStyle(ChatFormatting.GREEN)), + OFF("off", "Off"), + BATCHING("batching", "Parallel Batching"), + INSTANCING("instancing", "GL33 Instanced Arrays"), ; private static final Map lookup; @@ -30,14 +34,12 @@ public enum FlwEngine { } } - private final Component message; private final String shortName; private final String properName; - FlwEngine(String shortName, String properName, Component message) { + FlwEngine(String shortName, String properName) { this.shortName = shortName; this.properName = properName; - this.message = message; } public String getProperName() { @@ -55,13 +57,33 @@ public enum FlwEngine { if (type != null) { FlwConfig.get().client.engine.set(type); - player.displayClientMessage(type.message, false); + Component message = getMessage(type); + + player.displayClientMessage(message, false); Backend.reloadWorldRenderers(); } else { - player.displayClientMessage(FlwConfig.get().getEngine().message, false); + player.displayClientMessage(getMessage(FlwConfig.get().getEngine()), false); } } + private static Component getMessage(@NotNull FlwEngine type) { + return switch (type) { + case OFF -> new TextComponent("Disabled Flywheel").withStyle(ChatFormatting.RED); + case INSTANCING -> new TextComponent("Using Instancing Engine").withStyle(ChatFormatting.GREEN); + case BATCHING -> { + MutableComponent msg = new TextComponent("Using Batching Engine").withStyle(ChatFormatting.GREEN); + + if (ModList.get() + .isLoaded("create")) { + // FIXME: batching engine contraption lighting issues + msg.append(new TextComponent("\nWARNING: May cause issues with Create Contraptions").withStyle(ChatFormatting.RED)); + } + + yield msg; + } + }; + } + @Nullable public static FlwEngine decode(FriendlyByteBuf buffer) { byte b = buffer.readByte(); diff --git a/src/main/java/com/jozufozu/flywheel/core/crumbling/AtlasInfo.java b/src/main/java/com/jozufozu/flywheel/core/crumbling/AtlasInfo.java index a21ba81b8..1289a3db9 100644 --- a/src/main/java/com/jozufozu/flywheel/core/crumbling/AtlasInfo.java +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/AtlasInfo.java @@ -40,7 +40,7 @@ public class AtlasInfo { * FOR USE IN MIXIN */ public static void _setAtlasData(ResourceLocation atlas, SheetDataAccessor accessor) { - sheetData.put(atlas, new SheetSize(accessor.getWidth(), accessor.getHeight())); + sheetData.put(atlas, new SheetSize(accessor.flywheel$getWidth(), accessor.flywheel$getHeight())); } public record SheetSize(int width, int height) { diff --git a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java index 4aad9a96b..056790864 100644 --- a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java @@ -96,7 +96,7 @@ public class CrumblingRenderer { Int2ObjectMap> breakingEntities = new Int2ObjectArrayMap<>(); - for (Long2ObjectMap.Entry> entry : ((LevelRendererAccessor) Minecraft.getInstance().levelRenderer).getDestructionProgress() + for (Long2ObjectMap.Entry> entry : ((LevelRendererAccessor) Minecraft.getInstance().levelRenderer).flywheel$getDestructionProgress() .long2ObjectEntrySet()) { BlockPos breakingPos = BlockPos.of(entry.getLongKey()); diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelWriterUnsafe.java b/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelWriterUnsafe.java index 6fac04507..354751f4e 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelWriterUnsafe.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelWriterUnsafe.java @@ -3,7 +3,7 @@ package com.jozufozu.flywheel.core.materials.model; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.core.materials.BasicWriterUnsafe; -import com.jozufozu.flywheel.util.WriteUnsafe; +import com.jozufozu.flywheel.util.MatrixWrite; public class ModelWriterUnsafe extends BasicWriterUnsafe { @@ -16,7 +16,7 @@ public class ModelWriterUnsafe extends BasicWriterUnsafe { super.writeInternal(d); long ptr = writePointer + 6; - ((WriteUnsafe) (Object) d.model).writeUnsafe(ptr); - ((WriteUnsafe) (Object) d.normal).writeUnsafe(ptr + 4 * 16); + ((MatrixWrite) (Object) d.model).flywheel$writeUnsafe(ptr); + ((MatrixWrite) (Object) d.normal).flywheel$writeUnsafe(ptr + 4 * 16); } } diff --git a/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java b/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java index f0d84bf31..9aacbe054 100644 --- a/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java +++ b/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java @@ -72,6 +72,6 @@ public class RenderLayerEvent extends Event { @Override public String toString() { - return "RenderLayerEvent{" + "world=" + world + ", type=" + type + ", stack=" + stack + ", viewProjection=" + viewProjection + ", buffers=" + buffers + ", camX=" + camX + ", camY=" + camY + ", camZ=" + camZ + ", layer=" + layer + '}'; + return "RenderLayerEvent[" + layer + "][" + "world=" + world + ", type=" + type + ", stack=" + stack + ", viewProjection=" + viewProjection + ", buffers=" + buffers + ", camX=" + camX + ", camY=" + camY + ", camZ=" + camZ + ']'; } } diff --git a/src/main/java/com/jozufozu/flywheel/mixin/BufferBuilderMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/BufferBuilderMixin.java index 120f552c1..a105affa3 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/BufferBuilderMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/BufferBuilderMixin.java @@ -44,7 +44,7 @@ public abstract class BufferBuilderMixin implements BufferBuilderHack { private int vertices; @Override - public void freeBuffer() { + public void flywheel$freeBuffer() { if (this.buffer != null) { MemoryUtil.memFree(this.buffer); this.buffer = null; @@ -52,7 +52,7 @@ public abstract class BufferBuilderMixin implements BufferBuilderHack { } @Override - public void hackBegin(@Nonnull ByteBuffer buffer, @Nonnull VertexFormat format, int vertexCount) { + public void flywheel$hackBegin(@Nonnull ByteBuffer buffer, @Nonnull VertexFormat format, int vertexCount) { this.building = true; this.mode = VertexFormat.Mode.QUADS; diff --git a/src/main/java/com/jozufozu/flywheel/mixin/BufferUploaderAccessor.java b/src/main/java/com/jozufozu/flywheel/mixin/BufferUploaderAccessor.java new file mode 100644 index 000000000..8ee045d05 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/mixin/BufferUploaderAccessor.java @@ -0,0 +1,16 @@ +package com.jozufozu.flywheel.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import com.mojang.blaze3d.vertex.BufferUploader; + +import net.minecraft.client.renderer.ShaderInstance; + +@Mixin(BufferUploader.class) +public interface BufferUploaderAccessor { + @Accessor("lastVertexArrayObject") + static void flywheel$setLastVAO(int id) { + throw new AssertionError(); + } +} diff --git a/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererAccessor.java b/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererAccessor.java index e348cebbe..f306c68cb 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererAccessor.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererAccessor.java @@ -11,6 +11,6 @@ import net.minecraft.server.level.BlockDestructionProgress; @Mixin(LevelRenderer.class) public interface LevelRendererAccessor { - @Accessor - Long2ObjectMap> getDestructionProgress(); + @Accessor("destructionProgress") + Long2ObjectMap> flywheel$getDestructionProgress(); } diff --git a/src/main/java/com/jozufozu/flywheel/mixin/ShaderInstanceAccessor.java b/src/main/java/com/jozufozu/flywheel/mixin/ShaderInstanceAccessor.java index ca5743441..6f7538a4d 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/ShaderInstanceAccessor.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/ShaderInstanceAccessor.java @@ -8,7 +8,7 @@ import net.minecraft.client.renderer.ShaderInstance; @Mixin(ShaderInstance.class) public interface ShaderInstanceAccessor { @Accessor("lastProgramId") - static void setLastProgramId(int id) { + static void flywheel$setLastProgramId(int id) { throw new AssertionError(); } } diff --git a/src/main/java/com/jozufozu/flywheel/mixin/atlas/SheetDataAccessor.java b/src/main/java/com/jozufozu/flywheel/mixin/atlas/SheetDataAccessor.java index 8ab5bc643..a1914724b 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/atlas/SheetDataAccessor.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/atlas/SheetDataAccessor.java @@ -9,9 +9,9 @@ import net.minecraft.client.renderer.texture.TextureAtlas; public interface SheetDataAccessor { @Accessor("width") - int getWidth(); + int flywheel$getWidth(); @Accessor("height") - int getHeight(); + int flywheel$getHeight(); } diff --git a/src/main/java/com/jozufozu/flywheel/mixin/matrix/Matrix3fMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/matrix/Matrix3fMixin.java index fc7dd333c..2967eb43a 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/matrix/Matrix3fMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/matrix/Matrix3fMixin.java @@ -5,8 +5,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; -import com.jozufozu.flywheel.util.WriteSafe; -import com.jozufozu.flywheel.util.WriteUnsafe; +import com.jozufozu.flywheel.util.MatrixWrite; import com.mojang.math.Matrix3f; import net.minecraftforge.api.distmarker.Dist; @@ -14,7 +13,7 @@ import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) @Mixin(Matrix3f.class) -public abstract class Matrix3fMixin implements WriteUnsafe, WriteSafe { +public abstract class Matrix3fMixin implements MatrixWrite { @Shadow protected float m00; @Shadow protected float m01; @@ -27,7 +26,7 @@ public abstract class Matrix3fMixin implements WriteUnsafe, WriteSafe { @Shadow protected float m22; @Override - public void writeUnsafe(long ptr) { + public void flywheel$writeUnsafe(long ptr) { MemoryUtil.memPutFloat(ptr, m00); MemoryUtil.memPutFloat(ptr + 4, m10); MemoryUtil.memPutFloat(ptr + 8, m20); @@ -40,7 +39,7 @@ public abstract class Matrix3fMixin implements WriteUnsafe, WriteSafe { } @Override - public void write(VecBuffer buffer) { + public void flywheel$write(VecBuffer buffer) { buffer.putFloat(m00); buffer.putFloat(m10); buffer.putFloat(m20); diff --git a/src/main/java/com/jozufozu/flywheel/mixin/matrix/Matrix4fMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/matrix/Matrix4fMixin.java index 8d98d502e..e512a8899 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/matrix/Matrix4fMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/matrix/Matrix4fMixin.java @@ -5,8 +5,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; -import com.jozufozu.flywheel.util.WriteSafe; -import com.jozufozu.flywheel.util.WriteUnsafe; +import com.jozufozu.flywheel.util.MatrixWrite; import com.mojang.math.Matrix4f; import net.minecraftforge.api.distmarker.Dist; @@ -14,7 +13,7 @@ import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) @Mixin(Matrix4f.class) -public abstract class Matrix4fMixin implements WriteUnsafe, WriteSafe { +public abstract class Matrix4fMixin implements MatrixWrite { @Shadow protected float m00; @Shadow protected float m01; @@ -34,7 +33,7 @@ public abstract class Matrix4fMixin implements WriteUnsafe, WriteSafe { @Shadow protected float m33; @Override - public void writeUnsafe(long ptr) { + public void flywheel$writeUnsafe(long ptr) { MemoryUtil.memPutFloat(ptr, m00); MemoryUtil.memPutFloat(ptr + 4, m10); MemoryUtil.memPutFloat(ptr + 8, m20); @@ -54,7 +53,7 @@ public abstract class Matrix4fMixin implements WriteUnsafe, WriteSafe { } @Override - public void write(VecBuffer buf) { + public void flywheel$write(VecBuffer buf) { buf.putFloat(m00); buf.putFloat(m10); buf.putFloat(m20); diff --git a/src/main/java/com/jozufozu/flywheel/util/MatrixWrite.java b/src/main/java/com/jozufozu/flywheel/util/MatrixWrite.java new file mode 100644 index 000000000..0619d0793 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/util/MatrixWrite.java @@ -0,0 +1,17 @@ +package com.jozufozu.flywheel.util; + +import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; + +/** + * @see com.jozufozu.flywheel.mixin.matrix.Matrix3fMixin + * @see com.jozufozu.flywheel.mixin.matrix.Matrix4fMixin + */ +public interface MatrixWrite { + + /** + * Write the contents of this object into sequential memory starting at the given address. + */ + void flywheel$writeUnsafe(long ptr); + + void flywheel$write(VecBuffer buf); +} diff --git a/src/main/java/com/jozufozu/flywheel/util/WriteSafe.java b/src/main/java/com/jozufozu/flywheel/util/WriteSafe.java deleted file mode 100644 index 0fdc7f128..000000000 --- a/src/main/java/com/jozufozu/flywheel/util/WriteSafe.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.jozufozu.flywheel.util; - -import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; - -public interface WriteSafe { - void write(VecBuffer buf); -} diff --git a/src/main/java/com/jozufozu/flywheel/util/WriteUnsafe.java b/src/main/java/com/jozufozu/flywheel/util/WriteUnsafe.java deleted file mode 100644 index 1b4b6e985..000000000 --- a/src/main/java/com/jozufozu/flywheel/util/WriteUnsafe.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.jozufozu.flywheel.util; - -public interface WriteUnsafe { - - /** - * Write the contents of this object into sequential memory starting at the given address. - */ - void writeUnsafe(long ptr); -} diff --git a/src/main/resources/flywheel.mixins.json b/src/main/resources/flywheel.mixins.json index c2e308cef..9113d4962 100644 --- a/src/main/resources/flywheel.mixins.json +++ b/src/main/resources/flywheel.mixins.json @@ -6,6 +6,7 @@ "refmap": "flywheel.refmap.json", "client": [ "BufferBuilderMixin", + "BufferUploaderAccessor", "CancelEntityRenderMixin", "ChunkRebuildHooksMixin", "FixFabulousDepthMixin",