From 27bff45d7a765c64163b1b5b2eaa8130c4c9182d Mon Sep 17 00:00:00 2001 From: Sakura Ryoko Date: Sun, 11 Aug 2024 13:35:30 -0400 Subject: [PATCH] recycle VBO for Light Level Overlays whenever the count "goes down" . --- gradle.properties | 2 +- .../renderer/OverlayRendererLightLevel.java | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/gradle.properties b/gradle.properties index f01434991..7aacbbe6f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ author = masa mod_file_name = minihud-fabric # Current mod version -mod_version = 0.31.999-sakura.22 +mod_version = 0.31.999-sakura.23 # Required malilib version malilib_version = 0.20.0 diff --git a/src/main/java/fi/dy/masa/minihud/renderer/OverlayRendererLightLevel.java b/src/main/java/fi/dy/masa/minihud/renderer/OverlayRendererLightLevel.java index c37107976..0de81c826 100644 --- a/src/main/java/fi/dy/masa/minihud/renderer/OverlayRendererLightLevel.java +++ b/src/main/java/fi/dy/masa/minihud/renderer/OverlayRendererLightLevel.java @@ -111,6 +111,13 @@ public void update(Vec3d cameraPos, Entity entity, MinecraftClient mc) this.allocateGlResources(); this.wasEmpty = false; } + else if (lastSize - this.lightInfos.size() > 0) + { + // A bit extreme, but this gets rid of the VBO when the count goes down; so there are no more 'Ghost' renders. + // I believe this happens whenever we use STATIC VBO buffers. + this.deleteGlResources(); + this.allocateGlResources(); + } RenderObjectBase renderQuads = this.renderObjects.get(0); RenderObjectBase renderLines = this.renderObjects.get(1); @@ -129,8 +136,8 @@ public void update(Vec3d cameraPos, Entity entity, MinecraftClient mc) this.wasEmpty = true; } - //long pre = System.nanoTime(); - //System.out.printf("LL markers: %d, time: %.3f s\n", this.lightInfos.size(), (double) (System.nanoTime() - pre) / 1000000000D); + long pre = System.nanoTime(); + System.out.printf("LL markers: %d, time: %.3f s\n", this.lightInfos.size(), (double) (System.nanoTime() - pre) / 1000000000D); this.lastUpdatePos = pos; this.lastDirection = entity.getHorizontalFacing(); @@ -488,7 +495,7 @@ private boolean updateLightLevels(World world, BlockPos center) } } - return this.lightInfos.isEmpty() == false && this.lightInfos.size() > 0; + return this.lightInfos.isEmpty() == false; } private boolean canSpawnAtWrapper(int x, int y, int z, Chunk chunk, World world, boolean skipBlockCheck) @@ -573,10 +580,10 @@ else if (state.isIn(BlockTags.PREVENT_MOB_SPAWNING_INSIDE)) public static class LightLevelInfo { - public final long pos; - public final byte block; - public final byte sky; - public final float y; + public long pos; + public byte block; + public byte sky; + public float y; public LightLevelInfo(long pos, float y, int block, int sky) {