{
public void delete() {
models.invalidateAll();
- modelPool.delete();
+ if (allocator instanceof ModelPool pool) pool.delete();
}
/**
diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterialRenderer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterialRenderer.java
index 9d52ea695..a6ab47680 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterialRenderer.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterialRenderer.java
@@ -4,6 +4,7 @@ import java.util.Collection;
import java.util.function.Consumer;
import java.util.function.Supplier;
+import com.jozufozu.flywheel.backend.model.ModelPool;
import com.jozufozu.flywheel.core.shader.WorldProgram;
import com.mojang.math.Matrix4f;
@@ -28,8 +29,10 @@ public class InstancedMaterialRenderer {
// initialize all uninitialized instancers...
instancers.forEach(GPUInstancer::init);
- // ...and then flush the model arena in case anything was marked for upload
- material.modelPool.flush();
+ if (material.allocator instanceof ModelPool pool) {
+ // ...and then flush the model arena in case anything was marked for upload
+ pool.flush();
+ }
P program = this.program.get();
diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/IndexedModel.java b/src/main/java/com/jozufozu/flywheel/backend/model/IndexedModel.java
index f22818d32..02ab9606b 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/model/IndexedModel.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/model/IndexedModel.java
@@ -43,6 +43,8 @@ public class IndexedModel extends BufferedModel {
public void drawInstances(int instanceCount) {
if (!valid()) return;
+ ebo.bind();
+
GL31.glDrawElementsInstanced(primitiveMode.glEnum, ebo.elementCount, ebo.eboIndexType.getGlEnum(), 0, instanceCount);
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/ModelPool.java b/src/main/java/com/jozufozu/flywheel/backend/model/ModelPool.java
index 5a1d033f6..72f7973e2 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/model/ModelPool.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/model/ModelPool.java
@@ -120,9 +120,12 @@ public class ModelPool implements ModelAllocator {
VecBufferWriter consumer = new VecBufferWriter(buffer);
+ int vertices = 0;
for (PooledModel model : models) {
+ model.first = vertices;
model.model.buffer(consumer);
if (model.callback != null) model.callback.onAlloc(model);
+ vertices += model.getVertexCount();
}
} catch (Exception e) {
diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java
index 674f48255..1935c5406 100644
--- a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java
+++ b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java
@@ -125,80 +125,76 @@ public class ChestInstance extends TileE
private ModelPart getBaseModel() {
- switch (chestType) {
- case LEFT:
- return ModelPart.builder("chest_base_left", 64, 64)
- .sprite(renderMaterial.sprite())
- .cuboid()
- .textureOffset(0, 19)
- .start(0, 0, 1)
- .size(15, 10, 14)
- .endCuboid()
- .build();
- case RIGHT:
- return ModelPart.builder("chest_base_right", 64, 64)
- .sprite(renderMaterial.sprite())
- .cuboid()
- .textureOffset(0, 19)
- .start(1, 0, 1)
- .size(15, 10, 14)
- .endCuboid()
- .build();
- }
+ return switch (chestType) {
+ case LEFT -> ModelPart.builder("chest_base_left", 64, 64)
+ .sprite(renderMaterial.sprite())
+ .cuboid()
+ .textureOffset(0, 19)
+ .start(0, 0, 1)
+ .size(15, 10, 14)
+ .endCuboid()
+ .build();
+ case RIGHT -> ModelPart.builder("chest_base_right", 64, 64)
+ .sprite(renderMaterial.sprite())
+ .cuboid()
+ .textureOffset(0, 19)
+ .start(1, 0, 1)
+ .size(15, 10, 14)
+ .endCuboid()
+ .build();
+ default -> ModelPart.builder("chest_base", 64, 64)
+ .sprite(renderMaterial.sprite())
+ .cuboid()
+ .textureOffset(0, 19)
+ .start(1, 0, 1)
+ .end(15, 10, 15)
+ .endCuboid()
+ .build();
+ };
- return ModelPart.builder("chest_base", 64, 64)
- .sprite(renderMaterial.sprite())
- .cuboid()
- .textureOffset(0, 19)
- .start(1, 0, 1)
- .end(15, 10, 15)
- .endCuboid()
- .build();
}
private ModelPart getLidModel() {
- switch (chestType) {
- case LEFT:
- return ModelPart.builder("chest_lid_left", 64, 64)
- .sprite(renderMaterial.sprite())
- .cuboid()
- .textureOffset(0, 0)
- .start(0, 0, 1)
- .size(15, 5, 14)
- .endCuboid()
- .cuboid()
- .start(0, -2, 15)
- .size(1, 4, 1)
- .endCuboid()
- .build();
- case RIGHT:
- return ModelPart.builder("chest_lid_right", 64, 64)
- .sprite(renderMaterial.sprite())
- .cuboid()
- .textureOffset(0, 0)
- .start(1, 0, 1)
- .size(15, 5, 14)
- .endCuboid()
- .cuboid()
- .start(15, -2, 15)
- .size(1, 4, 1)
- .endCuboid()
- .build();
- }
+ return switch (chestType) {
+ case LEFT -> ModelPart.builder("chest_lid_left", 64, 64)
+ .sprite(renderMaterial.sprite())
+ .cuboid()
+ .textureOffset(0, 0)
+ .start(0, 0, 1)
+ .size(15, 5, 14)
+ .endCuboid()
+ .cuboid()
+ .start(0, -2, 15)
+ .size(1, 4, 1)
+ .endCuboid()
+ .build();
+ case RIGHT -> ModelPart.builder("chest_lid_right", 64, 64)
+ .sprite(renderMaterial.sprite())
+ .cuboid()
+ .textureOffset(0, 0)
+ .start(1, 0, 1)
+ .size(15, 5, 14)
+ .endCuboid()
+ .cuboid()
+ .start(15, -2, 15)
+ .size(1, 4, 1)
+ .endCuboid()
+ .build();
+ default -> ModelPart.builder("chest_lid", 64, 64)
+ .sprite(renderMaterial.sprite())
+ .cuboid()
+ .textureOffset(0, 0)
+ .start(1, 0, 1)
+ .size(14, 5, 14)
+ .endCuboid()
+ .cuboid()
+ .start(7, -2, 15)
+ .size(2, 4, 1)
+ .endCuboid()
+ .build();
+ };
- return ModelPart.builder("chest_lid", 64, 64)
- .sprite(renderMaterial.sprite())
- .cuboid()
- .textureOffset(0, 0)
- .start(1, 0, 1)
- .size(14, 5, 14)
- .endCuboid()
- .cuboid()
- .start(7, -2, 15)
- .size(2, 4, 1)
- .endCuboid()
- .build();
}
public static boolean isChristmas() {