diff --git a/src/main/java/net/vulkanmod/config/Config.java b/src/main/java/net/vulkanmod/config/Config.java index f3de4c4979..2aa08beac9 100644 --- a/src/main/java/net/vulkanmod/config/Config.java +++ b/src/main/java/net/vulkanmod/config/Config.java @@ -19,6 +19,7 @@ public class Config { public int advCulling = 2; public boolean indirectDraw = false; public boolean uniqueOpaqueLayer = false; + public boolean enableCutouts = true; public boolean entityCulling = true; private static Path path; diff --git a/src/main/java/net/vulkanmod/config/Options.java b/src/main/java/net/vulkanmod/config/Options.java index 45421ece91..998f58e008 100644 --- a/src/main/java/net/vulkanmod/config/Options.java +++ b/src/main/java/net/vulkanmod/config/Options.java @@ -155,6 +155,9 @@ public static Option[] getGraphicsOpts() { .setTooltip(Component.nullToEmpty(""" Improves performance by using a unique render layer for opaque terrain rendering. It changes distant grass aspect and may cause unexpected texture behaviour""")), + new SwitchOption("enableCutouts", + value -> config.enableCutouts = value, + () -> config.enableCutouts), new CyclingOption<>("Mipmap Levels", new Integer[]{0, 1, 2, 3, 4}, value -> Component.nullToEmpty(value.toString()), diff --git a/src/main/java/net/vulkanmod/render/chunk/DrawBuffers.java b/src/main/java/net/vulkanmod/render/chunk/DrawBuffers.java index e86ba26b4f..61755b03b9 100644 --- a/src/main/java/net/vulkanmod/render/chunk/DrawBuffers.java +++ b/src/main/java/net/vulkanmod/render/chunk/DrawBuffers.java @@ -15,7 +15,8 @@ import java.nio.ByteBuffer; import java.util.EnumMap; -import static net.vulkanmod.render.vertex.TerrainRenderType.*; +import static net.vulkanmod.render.vertex.TerrainRenderType.TRANSLUCENT; +import static net.vulkanmod.render.vertex.TerrainRenderType.getActiveLayers; import static org.lwjgl.vulkan.VK10.*; public class DrawBuffers { @@ -42,8 +43,8 @@ public DrawBuffers(int index, Vector3i origin) { } public void allocateBuffers() { - getActiveLayers().forEach(t -> areaBufferTypes.put(t, new AreaBuffer(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, t.initialSize, VERTEX_SIZE))); - this.indexBuffer = new AreaBuffer(VK_BUFFER_USAGE_INDEX_BUFFER_BIT, 1000000, INDEX_SIZE); +// getActiveLayers().forEach(t -> areaBufferTypes.put(t, new AreaBuffer(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, t.initialSize, VERTEX_SIZE))); +// this.indexBuffer = new AreaBuffer(VK_BUFFER_USAGE_INDEX_BUFFER_BIT, 1000000, INDEX_SIZE); this.allocated = true; } @@ -54,7 +55,7 @@ public DrawParameters upload(int xOffset, int yOffset, int zOffset, UploadBuffer drawParameters.baseInstance = encodeSectionOffset(xOffset, yOffset, zOffset); if(!buffer.indexOnly) { - getAreaBuffer(r).upload(buffer.getVertexBuffer(), drawParameters.vertexBufferSegment); + getAreaBufferCheckedAlloc(r).upload(buffer.getVertexBuffer(), drawParameters.vertexBufferSegment); // drawParameters.vertexOffset = drawParameters.vertexBufferSegment.getOffset() / VERTEX_SIZE; vertexOffset = drawParameters.vertexBufferSegment.getOffset() / VERTEX_SIZE; @@ -84,10 +85,22 @@ public DrawParameters upload(int xOffset, int yOffset, int zOffset, UploadBuffer return drawParameters; } + private AreaBuffer getAreaBufferCheckedAlloc(TerrainRenderType r) { + if(!this.areaBufferTypes.containsKey(r)) + { + if(r==TRANSLUCENT) this.indexBuffer=new AreaBuffer(VK_BUFFER_USAGE_INDEX_BUFFER_BIT, r.initialSize, INDEX_SIZE); + this.areaBufferTypes.put(r, new AreaBuffer(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, r.initialSize, VERTEX_SIZE)); + } + return this.areaBufferTypes.get(r); + } private AreaBuffer getAreaBuffer(TerrainRenderType r) { return this.areaBufferTypes.get(r); } + private boolean hasRenderType(TerrainRenderType r) { + return this.areaBufferTypes.containsKey(r); + } + private static int encodeSectionOffset(int xOffset, int yOffset, int zOffset) { final int xOffset1 = (xOffset & 127); final int zOffset1 = (zOffset & 127); @@ -224,7 +237,7 @@ private static void fakeIndirectCmd(VkCommandBuffer commandBuffer, IndirectBuffe } public void buildDrawBatchesDirect(TerrainRenderType terrainRenderType, double camX, double camY, double camZ) { - + if(!this.hasRenderType(terrainRenderType)) return; boolean isTranslucent = terrainRenderType == TRANSLUCENT; VkCommandBuffer commandBuffer = Renderer.getCommandBuffer(); @@ -251,7 +264,8 @@ public void releaseBuffers() { return; this.areaBufferTypes.values().forEach(AreaBuffer::freeBuffer); - this.indexBuffer.freeBuffer(); + if(this.areaBufferTypes.containsKey(TRANSLUCENT)) this.indexBuffer.freeBuffer(); + this.areaBufferTypes.clear(); this.indexBuffer = null; @@ -293,7 +307,7 @@ public void reset(ChunkArea chunkArea, TerrainRenderType r) { this.vertexOffset = 0; int segmentOffset = this.vertexBufferSegment.getOffset(); - if(chunkArea != null && chunkArea.drawBuffers.isAllocated() && segmentOffset != -1) { + if(chunkArea != null && chunkArea.drawBuffers.hasRenderType(r) && segmentOffset != -1) { // this.chunkArea.drawBuffers.vertexBuffer.setSegmentFree(segmentOffset); chunkArea.drawBuffers.getAreaBuffer(r).setSegmentFree(this.vertexBufferSegment); if(r==TRANSLUCENT||this.indexBufferSegment!=null) chunkArea.drawBuffers.indexBuffer.setSegmentFree(this.indexBufferSegment); diff --git a/src/main/java/net/vulkanmod/render/chunk/WorldRenderer.java b/src/main/java/net/vulkanmod/render/chunk/WorldRenderer.java index 7943f2c8df..2422add1f3 100644 --- a/src/main/java/net/vulkanmod/render/chunk/WorldRenderer.java +++ b/src/main/java/net/vulkanmod/render/chunk/WorldRenderer.java @@ -594,7 +594,7 @@ else if(terrainRenderType.equals(TRANSLUCENT)) p.push("draw batches"); final int currentFrame = Renderer.getCurrentFrame(); - if((Initializer.CONFIG.uniqueOpaqueLayer ? COMPACT_RENDER_TYPES : SEMI_COMPACT_RENDER_TYPES).contains(terrainRenderType)) { + if ((!Initializer.CONFIG.enableCutouts | Initializer.CONFIG.uniqueOpaqueLayer ? COMPACT_RENDER_TYPES : SEMI_COMPACT_RENDER_TYPES).contains(terrainRenderType)) { Renderer.getInstance().bindGraphicsPipeline(terrainShader); diff --git a/src/main/java/net/vulkanmod/render/chunk/build/TaskDispatcher.java b/src/main/java/net/vulkanmod/render/chunk/build/TaskDispatcher.java index d62d0cb09a..823d67c9c3 100644 --- a/src/main/java/net/vulkanmod/render/chunk/build/TaskDispatcher.java +++ b/src/main/java/net/vulkanmod/render/chunk/build/TaskDispatcher.java @@ -9,6 +9,7 @@ import javax.annotation.Nullable; import java.util.EnumMap; +import java.util.EnumSet; import java.util.Queue; public class TaskDispatcher {