Skip to content

Commit

Permalink
Add ability to merge program sets for dimensional shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbot16 committed Mar 6, 2021
1 parent ff92554 commit 5ba442a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
56 changes: 55 additions & 1 deletion src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ProgramSet {
private final ProgramSource compositeFinal;

private final ShaderPack pack;

public ProgramSet(Path root, Path inclusionRoot, ShaderProperties shaderProperties, ShaderPack pack) throws IOException {
this.packDirectives = new PackDirectives();
this.pack = pack;
Expand Down Expand Up @@ -63,6 +63,60 @@ public ProgramSet(Path root, Path inclusionRoot, ShaderProperties shaderProperti
this.compositeFinal = readProgramSource(root, inclusionRoot, "final", this, shaderProperties);
}

private ProgramSet(ProgramSet base, ProgramSet overrides) {
this.pack = base.pack;

if (this.pack != overrides.pack) {
throw new IllegalStateException();
}

// TODO: Merge this properly!
this.packDirectives = base.packDirectives;

this.gbuffersBasic = merge(base.gbuffersBasic, overrides.gbuffersBasic);
this.gbuffersBeaconBeam = merge(base.gbuffersBeaconBeam, overrides.gbuffersBeaconBeam);
this.gbuffersTextured = merge(base.gbuffersTextured, overrides.gbuffersTextured);
this.gbuffersTexturedLit = merge(base.gbuffersTexturedLit, overrides.gbuffersTexturedLit);
this.gbuffersTerrain = merge(base.gbuffersTerrain, overrides.gbuffersTerrain);
this.gbuffersDamagedBlock = merge(base.gbuffersDamagedBlock, overrides.gbuffersDamagedBlock);
this.gbuffersWater = merge(base.gbuffersWater, overrides.gbuffersWater);
this.gbuffersSkyBasic = merge(base.gbuffersSkyBasic, overrides.gbuffersSkyBasic);
this.gbuffersSkyTextured = merge(base.gbuffersSkyTextured, overrides.gbuffersSkyTextured);
this.gbuffersClouds = merge(base.gbuffersClouds, overrides.gbuffersClouds);
this.gbuffersWeather = merge(base.gbuffersWeather, overrides.gbuffersWeather);
this.gbuffersEntities = merge(base.gbuffersEntities, overrides.gbuffersEntities);
this.gbuffersEntitiesGlowing = merge(base.gbuffersEntitiesGlowing, overrides.gbuffersEntitiesGlowing);
this.gbuffersGlint = merge(base.gbuffersGlint, overrides.gbuffersGlint);
this.gbuffersEntityEyes = merge(base.gbuffersEntityEyes, overrides.gbuffersEntityEyes);
this.gbuffersBlock = merge(base.gbuffersBlock, overrides.gbuffersBlock);

this.composite = new ProgramSource[16];

for (int i = 0; i < this.composite.length; i++) {
String suffix = i == 0 ? "" : Integer.toString(i);

this.composite[i] = merge(base.composite[i], overrides.composite[i]);
}

this.compositeFinal = merge(base.compositeFinal, overrides.compositeFinal);
}

private static ProgramSource merge(ProgramSource base, ProgramSource override) {
if (override != null) {
return override;
}

return base;
}

public static ProgramSet merged(ProgramSet base, ProgramSet overrides) {
if (overrides == null) {
return base;
}

return new ProgramSet(base, overrides);
}

public Optional<ProgramSource> getGbuffersBasic() {
return gbuffersBasic.requireValid();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private static Optional<Properties> loadProperties(Path shaderPath, String name)
}

public ProgramSet getProgramSet() {
return base;
return ProgramSet.merged(base, nether);
}

public IdMap getIdMap() {
Expand Down

0 comments on commit 5ba442a

Please sign in to comment.