Skip to content

Commit

Permalink
Add expected values count to ManagedUniform
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Aug 15, 2023
1 parent 7d7ec5a commit ce809ca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package ladysnake.satin.api.managed.uniform;

import ladysnake.satin.impl.ManagedUniform;
import org.apiguardian.api.API;
import org.joml.Matrix4f;

Expand All @@ -43,7 +42,5 @@ public interface UniformMat4 {
* @apiNote {@link #set(Matrix4f)} should generally be preferred due to its inherent type safety
*/
@API(status = MAINTAINED, since = "1.15.0")
default void setFromArray(float[] values) {
((ManagedUniform) this).setFromArray(values, 16);
}
void setFromArray(float[] values);
}
13 changes: 10 additions & 3 deletions src/main/java/ladysnake/satin/impl/ManagedUniform.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ public final class ManagedUniform extends ManagedUniformBase implements

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

private final int count;

private GlUniform[] targets = NO_TARGETS;
private int i0, i1, i2, i3;
private float f0, f1, f2, f3;
private boolean firstUpload = true;

public ManagedUniform(String name) {
public ManagedUniform(String name, int count) {
super(name);
this.count = count;
}

@Override
Expand All @@ -60,6 +63,9 @@ public boolean findUniformTargets(List<PostEffectPass> shaders) {
GlUniform uniform = shader.getProgram().getUniformByName(this.name);

if (uniform != null) {
if (uniform.getCount() != this.count) {
throw new IllegalStateException("Mismatched number of values, expected " + this.count + " but JSON definition declares " + uniform.getCount());
}
list.add(uniform);
}
}
Expand Down Expand Up @@ -258,8 +264,9 @@ public void set(Matrix4f value) {
}
}

public void setFromArray(float[] values, int count) {
if (count != values.length) {
@Override
public void setFromArray(float[] values) {
if (this.count != values.length) {
throw new IllegalArgumentException("Mismatched values size, expected " + count + " but got " + values.length);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,47 +128,47 @@ protected <U extends ManagedUniformBase> U manageUniform(Map<String, U> uniformM

@Override
public Uniform1i findUniform1i(String uniformName) {
return manageUniform(this.managedUniforms, ManagedUniform::new, uniformName, "uniform");
return manageUniform(this.managedUniforms, name -> new ManagedUniform(name, 1), uniformName, "uniform");
}

@Override
public Uniform2i findUniform2i(String uniformName) {
return manageUniform(this.managedUniforms, ManagedUniform::new, uniformName, "uniform");
return manageUniform(this.managedUniforms, name -> new ManagedUniform(name, 2), uniformName, "uniform");
}

@Override
public Uniform3i findUniform3i(String uniformName) {
return manageUniform(this.managedUniforms, ManagedUniform::new, uniformName, "uniform");
return manageUniform(this.managedUniforms, name -> new ManagedUniform(name, 3), uniformName, "uniform");
}

@Override
public Uniform4i findUniform4i(String uniformName) {
return manageUniform(this.managedUniforms, ManagedUniform::new, uniformName, "uniform");
return manageUniform(this.managedUniforms, name -> new ManagedUniform(name, 4), uniformName, "uniform");
}

@Override
public Uniform1f findUniform1f(String uniformName) {
return manageUniform(this.managedUniforms, ManagedUniform::new, uniformName, "uniform");
return manageUniform(this.managedUniforms, name -> new ManagedUniform(name, 1), uniformName, "uniform");
}

@Override
public Uniform2f findUniform2f(String uniformName) {
return manageUniform(this.managedUniforms, ManagedUniform::new, uniformName, "uniform");
return manageUniform(this.managedUniforms, name -> new ManagedUniform(name, 2), uniformName, "uniform");
}

@Override
public Uniform3f findUniform3f(String uniformName) {
return manageUniform(this.managedUniforms, ManagedUniform::new, uniformName, "uniform");
return manageUniform(this.managedUniforms, name -> new ManagedUniform(name, 3), uniformName, "uniform");
}

@Override
public Uniform4f findUniform4f(String uniformName) {
return manageUniform(this.managedUniforms, ManagedUniform::new, uniformName, "uniform");
return manageUniform(this.managedUniforms, name -> new ManagedUniform(name, 4), uniformName, "uniform");
}

@Override
public UniformMat4 findUniformMat4(String uniformName) {
return manageUniform(this.managedUniforms, ManagedUniform::new, uniformName, "uniform");
return manageUniform(this.managedUniforms, name -> new ManagedUniform(name, 16), uniformName, "uniform");
}

@API(status = INTERNAL)
Expand Down

0 comments on commit ce809ca

Please sign in to comment.