Skip to content

Commit

Permalink
Fix managed sampler uniforms breaking on reload
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jun 6, 2023
1 parent 2264247 commit 08251c9
Show file tree
Hide file tree
Showing 84 changed files with 137 additions and 122 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
------------------------------------------------------
Version 1.10.1
------------------------------------------------------
**Fixes**
- Fixed managed sampler uniforms losing data upon resource reloading

------------------------------------------------------
Version 1.10.0
------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ loader_version=0.14.11
fabric_version=0.68.1+1.19.3

# Mod Properties
mod_version = 1.10.0
mod_version = 1.10.1
owners = Ladysnake
maven_group = io.github.ladysnake
archives_base_name = satin
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/ladysnake/satin/Satin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -20,11 +20,7 @@
import ladysnake.satin.api.event.ResolutionChangeCallback;
import ladysnake.satin.impl.ReloadableShaderEffectManager;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.resource.ResourceType;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apiguardian.api.API;
Expand All @@ -48,8 +44,6 @@ public static boolean areShadersDisabled() {
@Override
public void onInitializeClient() {
ResolutionChangeCallback.EVENT.register(ReloadableShaderEffectManager.INSTANCE);
// Subscribe the shader manager to MinecraftClient's resource manager to reload shaders like normal assets.
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(ReloadableShaderEffectManager.INSTANCE);
if (FabricLoader.getInstance().isModLoaded("optifabric")) {
LOGGER.warn("[Satin] Optifine present in the instance, custom entity post process shaders will not work");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ladysnake/satin/api/event/package-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ladysnake/satin/api/util/GlMatrices.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ladysnake/satin/api/util/ShaderLoader.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ladysnake/satin/api/util/ShaderPrograms.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ladysnake/satin/api/util/package-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ladysnake/satin/impl/FramebufferWrapper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/ladysnake/satin/impl/ManagedSamplerUniformBase.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -30,10 +30,10 @@
import java.util.function.IntSupplier;

/**
* Mojank working in divergent branches for half a century, {@link net.minecraft.client.render.Shader}
* is a copy of an old implementation of {@link net.minecraft.client.gl.JsonEffectGlShader}.
* The latter has since been updated to have the {@link net.minecraft.client.gl.JsonEffectGlShader#bindSampler(String, IntSupplier)}
* while the former still uses {@link net.minecraft.client.render.Shader#addSampler(String, Object)}.
* Mojank working in divergent branches for half a century, {@link net.minecraft.client.gl.ShaderProgram}
* is a copy of an old implementation of {@link net.minecraft.client.gl.JsonEffectShaderProgram}.
* The latter has since been updated to have the {@link net.minecraft.client.gl.JsonEffectShaderProgram#bindSampler(String, IntSupplier)}
* while the former still uses {@link net.minecraft.client.gl.ShaderProgram#addSampler(String, Object)}.
*
* <p>So we need to deal with both those extremely similar implementations
*/
Expand All @@ -60,6 +60,7 @@ public boolean findUniformTargets(List<PostEffectPass> shaders) {
}
this.targets = targets.toArray(new SamplerAccess[0]);
this.locations = rawTargets.toArray(new int[0]);
this.syncCurrentValues();
return this.targets.length > 0;
}

Expand All @@ -76,11 +77,22 @@ private boolean findUniformTarget(SamplerAccess access) {
if (access.satin$hasSampler(this.name)) {
this.targets = new SamplerAccess[] {access};
this.locations = new int[] {getSamplerLoc(access)};
this.syncCurrentValues();
return true;
}
return false;
}

private void syncCurrentValues() {
Object value = this.cachedValue;
if (value != null) { // after the first upload
this.cachedValue = null;
this.set(value);
}
}

protected abstract void set(Object value);

@Override
public void setDirect(int activeTexture) {
int length = this.locations.length;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Satin
* Copyright (C) 2019-2022 Ladysnake
* Copyright (C) 2019-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -41,7 +41,8 @@ public void set(int textureName) {
this.set((Object)textureName);
}

private void set(Object value) {
@Override
protected void set(Object value) {
SamplerAccess[] targets = this.targets;
if (targets.length > 0 && this.cachedValue != value) {
for (SamplerAccess target : targets) {
Expand Down
Loading

0 comments on commit 08251c9

Please sign in to comment.