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 469dda9 commit 5d118fa
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
15 changes: 15 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
------------------------------------------------------
Version 1.12.1
------------------------------------------------------
**Changes**
- Optimized shader loading (should now be faster)

**Fixes**
- Fixed managed sampler uniforms losing data upon resource reloading (Ported fix from v1.10.1 to MC 1.19.4)

------------------------------------------------------
Version 1.12.0
------------------------------------------------------
Expand All @@ -12,6 +21,12 @@ Version 1.11.0
------------------------------------------------------
Updated to MC 1.19.4

------------------------------------------------------
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.17
fabric_version=0.76.0+1.19.4

# Mod Properties
mod_version = 1.12.0
mod_version = 1.12.1
owners = Ladysnake
maven_group = io.github.ladysnake
archives_base_name = satin
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/ladysnake/satin/impl/ManagedSamplerUniformBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public void set(int textureName) {
set(() -> textureName);
}

@Override
protected void set(Object value) {
this.set((IntSupplier) value);
}

@Override
public void set(IntSupplier value) {
SamplerAccess[] targets = this.targets;
Expand Down

0 comments on commit 5d118fa

Please sign in to comment.