Skip to content

Commit

Permalink
Slightly optimize uniform loading methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Aug 6, 2023
1 parent 6747143 commit 2b88ee7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
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.21
fabric_version=0.84.0+1.20.1

# Mod Properties
mod_version = 1.14.0
mod_version = 1.15.0-SNAPSHOT
owners = Ladysnake
maven_group = org.ladysnake
archives_base_name = satin
Expand Down
34 changes: 24 additions & 10 deletions src/main/java/ladysnake/satin/impl/ManagedUniform.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@
import org.joml.Vector3f;
import org.joml.Vector4f;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public final class ManagedUniform extends ManagedUniformBase implements
Uniform1i, Uniform2i, Uniform3i, Uniform4i,
Uniform1f, Uniform2f, Uniform3f, Uniform4f,
UniformMat4 {

private GlUniform[] targets = new GlUniform[0];
private static final GlUniform[] NO_TARGETS = new GlUniform[0];

private GlUniform[] targets = NO_TARGETS;
private int i0, i1, i2, i3;
private float f0, f1, f2, f3;
private boolean firstUpload = true;
Expand All @@ -53,13 +55,23 @@ public ManagedUniform(String name) {

@Override
public boolean findUniformTargets(List<PostEffectPass> shaders) {
this.targets = shaders.stream()
.map(PostEffectPass::getProgram)
.map(s -> s.getUniformByName(this.name))
.filter(Objects::nonNull)
.toArray(GlUniform[]::new);
this.syncCurrentValues();
return this.targets.length > 0;
List<GlUniform> list = new ArrayList<>();
for (PostEffectPass shader : shaders) {
GlUniform uniform = shader.getProgram().getUniformByName(this.name);

if (uniform != null) {
list.add(uniform);
}
}

if (list.size() > 0) {
this.targets = list.toArray(new GlUniform[0]);
this.syncCurrentValues();
return true;
} else {
this.targets = NO_TARGETS;
return false;
}
}

@Override
Expand All @@ -69,8 +81,10 @@ public boolean findUniformTarget(ShaderProgram shader) {
this.targets = new GlUniform[] {uniform};
this.syncCurrentValues();
return true;
} else {
this.targets = NO_TARGETS;
return false;
}
return false;
}

private void syncCurrentValues() {
Expand Down

0 comments on commit 2b88ee7

Please sign in to comment.