diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java | 4 | ||||
-rw-r--r-- | src/main/java/makamys/lodmod/renderer/LODRenderer.java | 13 |
2 files changed, 13 insertions, 4 deletions
diff --git a/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java b/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java index 791f24d..02b130f 100644 --- a/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java +++ b/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java @@ -144,7 +144,7 @@ abstract class MixinWorldRenderer implements IWorldRenderer { @Inject(method = "setDontDraw", at = @At(value = "HEAD")) private void preSetDontDraw(CallbackInfo ci) { if(LODMod.isActive()) { - LODMod.renderer.onWorldRendererChanged(WorldRenderer.class.cast(this), false); + LODMod.renderer.onWorldRendererChanged(WorldRenderer.class.cast(this), LODRenderer.WorldRendererChange.DELETED); } } @@ -170,7 +170,7 @@ abstract class MixinWorldRenderer implements IWorldRenderer { private void notifyIfDrawnStatusChanged() { boolean drawn = isDrawn(); if(LODMod.isActive() && drawn != savedDrawnStatus) { - LODMod.renderer.onWorldRendererChanged(WorldRenderer.class.cast(this), drawn); + LODMod.renderer.onWorldRendererChanged(WorldRenderer.class.cast(this), drawn ? LODRenderer.WorldRendererChange.VISIBLE : LODRenderer.WorldRendererChange.INVISIBLE); } } diff --git a/src/main/java/makamys/lodmod/renderer/LODRenderer.java b/src/main/java/makamys/lodmod/renderer/LODRenderer.java index 7dac491..3da4603 100644 --- a/src/main/java/makamys/lodmod/renderer/LODRenderer.java +++ b/src/main/java/makamys/lodmod/renderer/LODRenderer.java @@ -448,13 +448,16 @@ public class LODRenderer { ChunkMesh.usedRAM = 0; } - public void onWorldRendererChanged(WorldRenderer wr, boolean visible) { + public void onWorldRendererChanged(WorldRenderer wr, WorldRendererChange change) { int x = Math.floorDiv(wr.posX, 16); int y = Math.floorDiv(wr.posY, 16); int z = Math.floorDiv(wr.posZ, 16); LODChunk lodChunk = getLODChunk(x, z); - lodChunk.hidden[y] = LODMod.hideUnderVanillaChunks ? visible : !visible; + lodChunk.hidden[y] = change != WorldRendererChange.VISIBLE; + if(change == WorldRendererChange.DELETED) { + removeMesh(lodChunk.chunkMeshes[y]); + } lodChunkChanged(lodChunk); } @@ -578,6 +581,8 @@ public class LODRenderer { } public void removeMesh(Mesh mesh) { + if(mesh == null) return; + mem.deleteMeshFromGPU(mesh); sentMeshes[mesh.pass].remove(mesh); setMeshVisible(mesh, false); @@ -707,4 +712,8 @@ public class LODRenderer { } } + + public static enum WorldRendererChange { + VISIBLE, INVISIBLE, DELETED + } }
\ No newline at end of file |