diff --git a/common b/common index 524fc36..7cc37b7 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 524fc36bf333f37796516e267e5e8de8d5030f7e +Subproject commit 7cc37b7c7455caea920981f982823af16810898a diff --git a/src/main/java/org/saturnclient/impl/ui/GlassRenderer.java b/src/main/java/org/saturnclient/impl/ui/GlassRenderer.java index f552152..37da9f3 100644 --- a/src/main/java/org/saturnclient/impl/ui/GlassRenderer.java +++ b/src/main/java/org/saturnclient/impl/ui/GlassRenderer.java @@ -28,6 +28,7 @@ import com.mojang.blaze3d.textures.FilterMode; import com.mojang.blaze3d.textures.GpuTextureView; import com.mojang.serialization.JsonOps; +import org.saturnclient.config.Config; import org.saturnclient.saturnclient.SaturnClient; import net.minecraft.client.gl.Framebuffer; @@ -86,6 +87,7 @@ public final class GlassRenderer { processor.render(backdrop, POOL); } POOL.decrementLifespan(); + release(blur); } // The mask, then the copy blurred by blur, as the glass pipeline samples them @@ -97,6 +99,28 @@ public final class GlassRenderer { //return TextureSetup.of(mask.getGlTextureView(), backdrop); } + // Frees the copies and blurs of strengths that are no longer set, besides kept + private static void release(int kept) { + BACKDROPS.entrySet().removeIf(entry -> { + boolean unused = entry.getKey() != kept && !isSet(entry.getKey()); + if (unused) { + entry.getValue().delete(); + } + return unused; + }); + BLURS.entrySet().removeIf(entry -> { + boolean unused = entry.getKey() != kept && !isSet(entry.getKey()); + if (unused && entry.getValue() != null) { + entry.getValue().close(); + } + return unused; + }); + } + + private static boolean isSet(int blur) { + return blur == Config.menuBlur.value || blur == Config.widgetBlur.value; + } + private static PostEffectProcessor getBlur(int blur) { if (!BLURS.containsKey(blur)) { BLURS.put(blur, loadBlur(blur)); @@ -141,6 +165,7 @@ import com.mojang.blaze3d.pipeline.RenderPipeline; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.textures.FilterMode; +import org.saturnclient.config.Config; import org.saturnclient.saturnclient.SaturnClient; import net.minecraft.client.gl.Framebuffer; @@ -191,6 +216,7 @@ public final class GlassRenderer { processor.render(backdrop, POOL, pass -> pass.setUniform("Radius", (float) blur)); } POOL.decrementLifespan(); + release(blur); } // Draws glass through mask with the copy blurred by blur @@ -206,6 +232,18 @@ public final class GlassRenderer { .build(false))); } + // Frees the copies of strengths that are no longer set, besides kept + private static void release(int kept) { + BACKDROPS.entrySet().removeIf(entry -> { + boolean unused = entry.getKey() != kept && entry.getKey() != Config.menuBlur.value + && entry.getKey() != Config.widgetBlur.value; + if (unused) { + entry.getValue().delete(); + } + return unused; + }); + } + // Copies from into to, made or resized to match private static SimpleFramebuffer copy(Framebuffer from, SimpleFramebuffer to, String name) { int width = from.textureWidth; @@ -233,6 +271,7 @@ import org.lwjgl.opengl.GL30; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; +import org.saturnclient.config.Config; import org.saturnclient.saturnclient.SaturnClient; import net.minecraft.client.gl.Defines; @@ -284,6 +323,7 @@ public final class GlassRenderer { processor.render(backdrop, POOL); } POOL.decrementLifespan(); + release(blur); SaturnClient.client.getFramebuffer().beginWrite(false); } @@ -302,6 +342,18 @@ public final class GlassRenderer { .build(false))); } + // Frees the copies of strengths that are no longer set, besides kept + private static void release(int kept) { + BACKDROPS.entrySet().removeIf(entry -> { + boolean unused = entry.getKey() != kept && entry.getKey() != Config.menuBlur.value + && entry.getKey() != Config.widgetBlur.value; + if (unused) { + entry.getValue().delete(); + } + return unused; + }); + } + // Copies from into to, made or resized to match private static SimpleFramebuffer copy(Framebuffer from, SimpleFramebuffer to) { int width = from.textureWidth; diff --git a/src/main/java/org/saturnclient/impl/ui/SaturnScreenFabric.java b/src/main/java/org/saturnclient/impl/ui/SaturnScreenFabric.java index 7f17d03..908ad91 100644 --- a/src/main/java/org/saturnclient/impl/ui/SaturnScreenFabric.java +++ b/src/main/java/org/saturnclient/impl/ui/SaturnScreenFabric.java @@ -3,6 +3,7 @@ package org.saturnclient.impl.ui; import java.time.Duration; import java.time.Instant; +import org.saturnclient.config.Config; import org.saturnclient.ui.RenderScope; import org.saturnclient.ui.SaturnScreen; import org.saturnclient.ui.SaturnScreen.ScreenProvider; @@ -98,15 +99,17 @@ public class SaturnScreenFabric extends Screen implements ScreenProvider { } // Glass is blurred from the game as it is before this screen blurs it. - context.draw(); - GlassRenderer.saveBackground(); + if (Config.usesGlass()) { + context.draw(); + GlassRenderer.saveBackground(); + } - PostEffectProcessor postEffectProcessor = this.client.getShaderLoader().loadPostEffect( + float radius = screen.getBackgroundBlur(); + PostEffectProcessor postEffectProcessor = radius < 1 ? null : this.client.getShaderLoader().loadPostEffect( Identifier.ofVanilla("blur"), DefaultFramebufferSet.MAIN_ONLY); if (postEffectProcessor != null) { - float radius = screen.getBackgroundBlur(); //? if >=1.21.5 postEffectProcessor.render(this.client.getFramebuffer(), this.pool, pass -> pass.setUniform("Radius", radius)); //? if <1.21.5