Skip glass and blur work that draws nothing

Before 1.21.6 the game is only saved for glass when glass can be drawn,
and a background blur of 0 no longer runs the blur. Every version frees
the copies (and from 1.21.6 the blurs) of glass strengths no longer set,
instead of keeping one per strength ever used.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-09-28 21:57:10 +02:00
co-authored by claude
parent 2b5bcf4098
commit 254a37d757
3 changed files with 60 additions and 5 deletions
+1 -1
Submodule common updated: 524fc36bf3...7cc37b7c74
@@ -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;
@@ -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