listeners;
public InstancingEngine(WorldContext context, TaskEngine taskEngine) {
- this(taskEngine, context, InstancedMaterialGroup::new, false);
+ this(context, InstancedMaterialGroup::new, false);
}
public static
Builder
builder(WorldContext
context) {
return new Builder<>(context);
}
- public InstancingEngine(TaskEngine taskEngine, WorldContext
context, GroupFactory
groupFactory, boolean ignoreOriginCoordinate) {
- this.taskEngine = taskEngine;
+ public InstancingEngine(WorldContext
context, GroupFactory
groupFactory, boolean ignoreOriginCoordinate) {
this.context = context;
this.ignoreOriginCoordinate = ignoreOriginCoordinate;
@@ -82,7 +78,7 @@ public class InstancingEngine
implements Engine {
* Render every model for every material.
*/
@Override
- public void render(RenderLayerEvent event) {
+ public void render(TaskEngine taskEngine, RenderLayerEvent event) {
double camX;
double camY;
double camZ;
@@ -205,11 +201,7 @@ public class InstancingEngine
implements Engine {
}
public InstancingEngine
build() {
- return build(ImmediateExecutor.INSTANCE);
- }
-
- public InstancingEngine
build(TaskEngine taskEngine) {
- return new InstancingEngine<>(taskEngine, context, groupFactory, ignoreOriginCoordinate);
+ return new InstancingEngine<>(context, groupFactory, ignoreOriginCoordinate);
}
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileInstanceManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileInstanceManager.java
index c0b65215d..b0be524da 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileInstanceManager.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileInstanceManager.java
@@ -3,7 +3,6 @@ package com.jozufozu.flywheel.backend.instancing.tile;
import com.jozufozu.flywheel.api.MaterialManager;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
-import com.jozufozu.flywheel.backend.instancing.BatchExecutor;
import com.jozufozu.flywheel.backend.instancing.InstanceManager;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
import com.jozufozu.flywheel.backend.instancing.TaskEngine;
@@ -15,8 +14,8 @@ import net.minecraft.world.level.block.entity.BlockEntity;
public class TileInstanceManager extends InstanceManager {
- public TileInstanceManager(TaskEngine executor, MaterialManager materialManager) {
- super(executor, materialManager);
+ public TileInstanceManager(MaterialManager materialManager) {
+ super(materialManager);
}
@Override
diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/BufferBuilderHack.java b/src/main/java/com/jozufozu/flywheel/backend/model/BufferBuilderHack.java
new file mode 100644
index 000000000..ee2dd4fb8
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/backend/model/BufferBuilderHack.java
@@ -0,0 +1,16 @@
+package com.jozufozu.flywheel.backend.model;
+
+import java.nio.ByteBuffer;
+
+import com.mojang.blaze3d.vertex.BufferBuilder;
+import com.mojang.blaze3d.vertex.VertexFormat;
+
+/**
+ * Duck interface used on {@link BufferBuilder} to provide lower level access to the backing memory.
+ */
+public interface BufferBuilderHack {
+
+ void freeBuffer();
+
+ void hackBegin(ByteBuffer buffer, VertexFormat format, int vertexCount);
+}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/DirectBufferBuilder.java b/src/main/java/com/jozufozu/flywheel/backend/model/DirectBufferBuilder.java
deleted file mode 100644
index c157aed9b..000000000
--- a/src/main/java/com/jozufozu/flywheel/backend/model/DirectBufferBuilder.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.jozufozu.flywheel.backend.model;
-
-import com.mojang.blaze3d.vertex.BufferBuilder;
-
-/**
- * Duck interface used on {@link BufferBuilder} to provide lower level access to the backing memory.
- */
-public interface DirectBufferBuilder {
-
- /**
- * Create a DirectVertexConsumer from this BufferBuilder.
- *
- *
- * After this function returns, the internal state of the BufferBuilder will be as if
- * {@link BufferBuilder#endVertex()} was called vertexCount times. It is up to the callee
- * to actually populate the BufferBuilder with vertices using the returned value.
- *
- */
- DirectVertexConsumer intoDirectConsumer(int vertexCount);
-}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/DirectVertexConsumer.java b/src/main/java/com/jozufozu/flywheel/backend/model/DirectVertexConsumer.java
index 781ad8693..8446fbfcc 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/model/DirectVertexConsumer.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/model/DirectVertexConsumer.java
@@ -13,7 +13,7 @@ import com.mojang.blaze3d.vertex.VertexFormatElement;
/**
* An unsafe vertex consumer allowing for unchecked writes into a ByteBuffer.
*
- * @see DirectBufferBuilder
+ * @see BufferBuilderHack
*/
public class DirectVertexConsumer implements VertexConsumer {
public final VertexFormat format;
diff --git a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java
index bea324fd4..30e427f6b 100644
--- a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java
+++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java
@@ -1,7 +1,6 @@
package com.jozufozu.flywheel.core.crumbling;
import com.jozufozu.flywheel.api.MaterialManager;
-import com.jozufozu.flywheel.backend.instancing.ImmediateExecutor;
import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager;
import net.minecraft.core.BlockPos;
@@ -9,7 +8,7 @@ import net.minecraft.core.BlockPos;
public class CrumblingInstanceManager extends TileInstanceManager {
public CrumblingInstanceManager(MaterialManager materialManager) {
- super(ImmediateExecutor.INSTANCE, materialManager);
+ super(materialManager);
}
@Override
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 42ae86e71..4aad9a96b 100644
--- a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java
+++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java
@@ -6,6 +6,7 @@ import java.util.SortedSet;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.gl.GlTextureUnit;
+import com.jozufozu.flywheel.backend.instancing.SerialTaskEngine;
import com.jozufozu.flywheel.backend.instancing.InstanceManager;
import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine;
import com.jozufozu.flywheel.core.Contexts;
@@ -74,9 +75,9 @@ public class CrumblingRenderer {
if (_currentLayer != null) {
stage.getValue().forEach(instanceManager::add);
- instanceManager.beginFrame(info);
+ instanceManager.beginFrame(SerialTaskEngine.INSTANCE, info);
- materials.render(event);
+ materials.render(SerialTaskEngine.INSTANCE, event);
instanceManager.invalidate();
}
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/BufferBuilderMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/BufferBuilderMixin.java
index 66c29bfd4..120f552c1 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/BufferBuilderMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/mixin/BufferBuilderMixin.java
@@ -5,29 +5,34 @@ import java.nio.ByteBuffer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import org.lwjgl.system.MemoryUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
+import com.jozufozu.flywheel.backend.instancing.SuperBufferSource;
import com.jozufozu.flywheel.backend.model.DirectVertexConsumer;
-import com.jozufozu.flywheel.backend.model.DirectBufferBuilder;
+import com.jozufozu.flywheel.backend.model.BufferBuilderHack;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.blaze3d.vertex.VertexFormatElement;
@Mixin(BufferBuilder.class)
-public abstract class BufferBuilderMixin implements DirectBufferBuilder {
+public abstract class BufferBuilderMixin implements BufferBuilderHack {
@Shadow
private ByteBuffer buffer;
+ @Shadow
+ private boolean building;
+
+ @Shadow
+ public abstract void begin(VertexFormat.Mode p_166780_, VertexFormat p_166781_);
+
+ @Shadow
+ private VertexFormat.Mode mode;
+
@Shadow
private VertexFormat format;
- @Shadow
- protected abstract void ensureCapacity(int p_85723_);
-
- @Shadow
- private int vertices;
-
@Shadow
@Nullable
private VertexFormatElement currentElement;
@@ -36,24 +41,26 @@ public abstract class BufferBuilderMixin implements DirectBufferBuilder {
private int elementIndex;
@Shadow
- private int nextElementByte;
+ private int vertices;
@Override
- @Nonnull
- public DirectVertexConsumer intoDirectConsumer(int vertexCount) {
- int bytes = vertexCount * format.getVertexSize();
- // ensure we have capacity for one extra vertex, BufferBuilder does this on #endVertex
- ensureCapacity(bytes + format.getVertexSize());
+ public void freeBuffer() {
+ if (this.buffer != null) {
+ MemoryUtil.memFree(this.buffer);
+ this.buffer = null;
+ }
+ }
- DirectVertexConsumer consumer = new DirectVertexConsumer(this.buffer, this.format, vertexCount);
+ @Override
+ public void hackBegin(@Nonnull ByteBuffer buffer, @Nonnull VertexFormat format, int vertexCount) {
+ this.building = true;
+ this.mode = VertexFormat.Mode.QUADS;
- this.vertices += vertexCount;
- this.currentElement = format.getElements()
- .get(0);
+ this.buffer = buffer;
+ this.format = format;
+ this.vertices = vertexCount;
+
+ this.currentElement = this.format.getElements().get(0);
this.elementIndex = 0;
- this.nextElementByte += bytes;
- this.buffer.position(this.buffer.position() + bytes);
-
- return consumer;
}
}