Skip to content

Commit

Permalink
Fix uniform caching for core shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jul 4, 2021
1 parent 0f13363 commit 86e022e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 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.6.1
------------------------------------------------------
**Fixes**
- Fixed uniforms for core shaders still being reset after resource reloading

------------------------------------------------------
Version 1.6.0
------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ loader_version=0.11.6
fabric_version=0.36.0+1.17

# Mod Properties
mod_version = 1.6.0
mod_version = 1.6.1
owners = Ladysnake
maven_group = io.github.ladysnake
archives_base_name = satin
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/ladysnake/satin/impl/ManagedUniform.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,34 @@ public boolean findUniformTargets(List<PostProcessShader> shaders) {
.map(s -> s.getUniformByName(this.name))
.filter(Objects::nonNull)
.toArray(GlUniform[]::new);
if (!this.firstUpload) {
this.uploadCurrentValues();
}
this.syncCurrentValues();
return this.targets.length > 0;
}

private void uploadCurrentValues() {
for (GlUniform target : this.targets) {
if (target.getIntData() != null) {
target.setForDataType(i0, i1, i2, i3);
} else {
assert target.getFloatData() != null;
target.setForDataType(f0, f1, f2, f3);
}
}
}

@Override
public boolean findUniformTarget(Shader shader) {
GlUniform uniform = shader.getUniform(this.name);
if (uniform != null) {
this.targets = new GlUniform[] {uniform};
this.syncCurrentValues();
return true;
}
return false;
}

private void syncCurrentValues() {
if (!this.firstUpload) {
for (GlUniform target : this.targets) {
if (target.getIntData() != null) {
target.setForDataType(i0, i1, i2, i3);
} else {
assert target.getFloatData() != null;
target.setForDataType(f0, f1, f2, f3);
}
}
}
}

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

0 comments on commit 86e022e

Please sign in to comment.