use of net.coderbot.iris.shaderpack.option.values.MutableOptionValues in project Iris by IrisShaders.
the class OptionMenuOptionElement method getPendingOptionValues.
/**
* @return an {@link OptionValues} that also contains values currently
* pending application.
*/
public OptionValues getPendingOptionValues() {
MutableOptionValues values = getAppliedOptionValues().mutableCopy();
values.addAll(Iris.getShaderPackOptionQueue());
return values;
}
use of net.coderbot.iris.shaderpack.option.values.MutableOptionValues in project Iris by IrisShaders.
the class OptionMenuProfileElement method getPendingOptionValues.
/**
* @return an {@link OptionValues} that also contains values currently
* pending application.
*/
public OptionValues getPendingOptionValues() {
MutableOptionValues values = packAppliedValues.mutableCopy();
values.addAll(Iris.getShaderPackOptionQueue());
return values;
}
use of net.coderbot.iris.shaderpack.option.values.MutableOptionValues in project Iris by IrisShaders.
the class OptionApplyTest method testOptions.
// @Test
// TODO: Re-enable this once we can load shader packs in tests without referencing OpenGL / LWJGL / Minecraft.
void testOptions() {
ShaderPack shaderPack;
// ensure that we can actually load the shader pack
try {
shaderPack = new ShaderPack(IrisTests.getTestShaderPackPath("options"));
} catch (Exception e) {
Assertions.fail("Couldn't load test shader pack options", e);
return;
}
ProgramSource basic = shaderPack.getProgramSet(DimensionId.OVERWORLD).getGbuffersBasic().orElseThrow(RuntimeException::new);
String basicVsh = basic.getVertexSource().orElseThrow(RuntimeException::new);
String basicFsh = basic.getFragmentSource().orElseThrow(RuntimeException::new);
OptionAnnotatedSource basicVshAnnotated = new OptionAnnotatedSource(basicVsh);
OptionAnnotatedSource basicFshAnnotated = new OptionAnnotatedSource(basicFsh);
// TODO: Separate includes will need more complex boolean define reference behavior
OptionSet basicVshSet = basicVshAnnotated.getOptionSet(AbsolutePackPath.fromAbsolutePath("/basic.vsh"), basicVshAnnotated.getBooleanDefineReferences().keySet());
OptionSet basicFshSet = basicFshAnnotated.getOptionSet(AbsolutePackPath.fromAbsolutePath("/basic.fsh"), basicFshAnnotated.getBooleanDefineReferences().keySet());
OptionSet.Builder setBuilder = OptionSet.builder();
setBuilder.addAll(basicVshSet);
setBuilder.addAll(basicFshSet);
OptionSet options = setBuilder.build();
Map<String, String> changes = ImmutableMap.of("SHADOWS", "false", "ambientOcclusionLevel", "0.0", "shadowDistance", "64", "ANNOYING_STUFF", "true", "GODRAYS", "16");
OptionValues values = new MutableOptionValues(options, changes);
System.out.println(basicVshAnnotated.apply(values));
System.out.println(basicFshAnnotated.apply(values));
System.out.println(options);
}
use of net.coderbot.iris.shaderpack.option.values.MutableOptionValues in project Iris by IrisShaders.
the class OptionApplyTest method testTrivial.
private void testTrivial(String base, ImmutableMap<String, String> changes, String expected) {
OptionAnnotatedSource source = new OptionAnnotatedSource(base);
OptionSet options = source.getOptionSet(AbsolutePackPath.fromAbsolutePath("/<hardcoded>"), source.getBooleanDefineReferences().keySet());
OptionValues values = new MutableOptionValues(options, changes);
Assertions.assertEquals(expected, source.apply(values));
}
use of net.coderbot.iris.shaderpack.option.values.MutableOptionValues in project Iris by IrisShaders.
the class Iris method loadExternalShaderpack.
private static boolean loadExternalShaderpack(String name) {
Path shaderPackRoot;
Path shaderPackConfigTxt;
try {
shaderPackRoot = getShaderpacksDirectory().resolve(name);
shaderPackConfigTxt = getShaderpacksDirectory().resolve(name + ".txt");
} catch (InvalidPathException e) {
logger.error("Failed to load the shaderpack \"{}\" because it contains invalid characters in its path", name);
return false;
}
Path shaderPackPath;
if (shaderPackRoot.toString().endsWith(".zip")) {
Optional<Path> optionalPath;
try {
optionalPath = loadExternalZipShaderpack(shaderPackRoot);
} catch (FileSystemNotFoundException | NoSuchFileException e) {
logger.error("Failed to load the shaderpack \"{}\" because it does not exist in your shaderpacks folder!", name);
return false;
} catch (ZipException e) {
logger.error("The shaderpack \"{}\" appears to be corrupted, please try downloading it again!", name);
return false;
} catch (IOException e) {
logger.error("Failed to load the shaderpack \"{}\"!", name);
logger.error("", e);
return false;
}
if (optionalPath.isPresent()) {
shaderPackPath = optionalPath.get();
} else {
logger.error("Could not load the shaderpack \"{}\" because it appears to lack a \"shaders\" directory", name);
return false;
}
} else {
if (!Files.exists(shaderPackRoot)) {
logger.error("Failed to load the shaderpack \"{}\" because it does not exist!", name);
return false;
}
// If it's a folder-based shaderpack, just use the shaders subdirectory
shaderPackPath = shaderPackRoot.resolve("shaders");
}
if (!Files.exists(shaderPackPath)) {
logger.error("Could not load the shaderpack \"{}\" because it appears to lack a \"shaders\" directory", name);
return false;
}
Map<String, String> changedConfigs = tryReadConfigProperties(shaderPackConfigTxt).map(properties -> (Map<String, String>) (Map) properties).orElse(new HashMap<>());
changedConfigs.putAll(shaderPackOptionQueue);
clearShaderPackOptionQueue();
if (resetShaderPackOptions) {
changedConfigs.clear();
}
resetShaderPackOptions = false;
try {
currentPack = new ShaderPack(shaderPackPath, changedConfigs);
MutableOptionValues changedConfigsValues = currentPack.getShaderPackOptions().getOptionValues().mutableCopy();
// Store changed values from those currently in use by the shader pack
Properties configsToSave = new Properties();
changedConfigsValues.getBooleanValues().forEach((k, v) -> configsToSave.setProperty(k, Boolean.toString(v)));
changedConfigsValues.getStringValues().forEach(configsToSave::setProperty);
tryUpdateConfigPropertiesFile(shaderPackConfigTxt, configsToSave);
} catch (Exception e) {
logger.error("Failed to load the shaderpack \"{}\"!", name);
logger.error("", e);
return false;
}
currentPackName = name;
logger.info("Using shaderpack: " + name);
return true;
}
Aggregations