Skip to content

Commit

Permalink
Allow sampler bindings to run custom behavior after they get bound
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbot16 committed Jun 26, 2021
1 parent 9e742d3 commit 6290d0c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public boolean hasSampler(String name) {
}

@Override
public boolean addDynamicSampler(IntSupplier sampler, String... names) {
return samplers.addDynamicSampler(sampler, names);
public boolean addDynamicSampler(IntSupplier sampler, Runnable postBind, String... names) {
return samplers.addDynamicSampler(sampler, postBind, names);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public boolean hasSampler(String name) {
* @return false if this sampler is not active, true if at least one of the names referred to an active sampler
*/
@Override
public boolean addDynamicSampler(IntSupplier sampler, String... names) {
public boolean addDynamicSampler(IntSupplier sampler, Runnable postBind, String... names) {
boolean used = false;

for (String name : names) {
Expand Down Expand Up @@ -139,7 +139,7 @@ public boolean addDynamicSampler(IntSupplier sampler, String... names) {
return false;
}

samplers.add(new SamplerBinding(nextUnit, sampler));
samplers.add(new SamplerBinding(nextUnit, sampler, postBind));

remainingUnits -= 1;
nextUnit += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
public class SamplerBinding {
private final int textureUnit;
private final IntSupplier texture;
private final Runnable postBind;

public SamplerBinding(int textureUnit, IntSupplier texture) {
public SamplerBinding(int textureUnit, IntSupplier texture, Runnable postBind) {
this.textureUnit = textureUnit;
this.texture = texture;
this.postBind = postBind;
}

public void update() {
RenderSystem.activeTexture(GL20C.GL_TEXTURE0 + textureUnit);
RenderSystem.bindTexture(texture.getAsInt());
this.postBind.run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
public interface SamplerHolder {
void addExternalSampler(int textureUnit, String... names);
boolean hasSampler(String name);
boolean addDynamicSampler(IntSupplier sampler, String... names);
boolean addDynamicSampler(IntSupplier sampler, Runnable postBind, String... names);

default boolean addDynamicSampler(IntSupplier sampler, String... names) {
return addDynamicSampler(sampler, () -> {}, names);
}
}

0 comments on commit 6290d0c

Please sign in to comment.