Search in sources :

Example 1 with MutableOptionValues

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;
}
Also used : MutableOptionValues(net.coderbot.iris.shaderpack.option.values.MutableOptionValues)

Example 2 with MutableOptionValues

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;
}
Also used : MutableOptionValues(net.coderbot.iris.shaderpack.option.values.MutableOptionValues)

Example 3 with MutableOptionValues

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);
}
Also used : MutableOptionValues(net.coderbot.iris.shaderpack.option.values.MutableOptionValues) ProgramSource(net.coderbot.iris.shaderpack.ProgramSource) MutableOptionValues(net.coderbot.iris.shaderpack.option.values.MutableOptionValues) OptionValues(net.coderbot.iris.shaderpack.option.values.OptionValues) OptionAnnotatedSource(net.coderbot.iris.shaderpack.option.OptionAnnotatedSource) OptionSet(net.coderbot.iris.shaderpack.option.OptionSet) ShaderPack(net.coderbot.iris.shaderpack.ShaderPack)

Example 4 with MutableOptionValues

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));
}
Also used : MutableOptionValues(net.coderbot.iris.shaderpack.option.values.MutableOptionValues) MutableOptionValues(net.coderbot.iris.shaderpack.option.values.MutableOptionValues) OptionValues(net.coderbot.iris.shaderpack.option.values.OptionValues) OptionAnnotatedSource(net.coderbot.iris.shaderpack.option.OptionAnnotatedSource) OptionSet(net.coderbot.iris.shaderpack.option.OptionSet)

Example 5 with MutableOptionValues

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;
}
Also used : Path(java.nio.file.Path) FabricLoader(net.fabricmc.loader.api.FabricLoader) NoSuchFileException(java.nio.file.NoSuchFileException) InputConstants(com.mojang.blaze3d.platform.InputConstants) ShaderPackScreen(net.coderbot.iris.gui.screen.ShaderPackScreen) MutableOptionValues(net.coderbot.iris.shaderpack.option.values.MutableOptionValues) Level(org.apache.logging.log4j.Level) HashMap(java.util.HashMap) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) DimensionType(net.minecraft.world.level.dimension.DimensionType) ShaderpackDirectoryManager(net.coderbot.iris.shaderpack.discovery.ShaderpackDirectoryManager) InvalidPathException(java.nio.file.InvalidPathException) SodiumVersionCheck(net.coderbot.iris.compat.sodium.SodiumVersionCheck) Minecraft(net.minecraft.client.Minecraft) ChatFormatting(net.minecraft.ChatFormatting) Map(java.util.Map) OptionValues(net.coderbot.iris.shaderpack.option.values.OptionValues) IrisConfig(net.coderbot.iris.config.IrisConfig) Path(java.nio.file.Path) ModContainer(net.fabricmc.loader.api.ModContainer) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) OutputStream(java.io.OutputStream) OptionalBoolean(net.coderbot.iris.shaderpack.OptionalBoolean) ClientModInitializer(net.fabricmc.api.ClientModInitializer) OptionSet(net.coderbot.iris.shaderpack.option.OptionSet) Properties(java.util.Properties) ZipException(java.util.zip.ZipException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) Files(java.nio.file.Files) KeyBindingHelper(net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper) Throwables(com.google.common.base.Throwables) Profile(net.coderbot.iris.shaderpack.option.Profile) IOException(java.io.IOException) FileSystem(java.nio.file.FileSystem) net.coderbot.iris.pipeline(net.coderbot.iris.pipeline) ResourceKey(net.minecraft.resources.ResourceKey) GLFW(org.lwjgl.glfw.GLFW) ProgramSet(net.coderbot.iris.shaderpack.ProgramSet) ShaderPack(net.coderbot.iris.shaderpack.ShaderPack) ZipError(java.util.zip.ZipError) Logger(org.apache.logging.log4j.Logger) DimensionId(net.coderbot.iris.shaderpack.DimensionId) Optional(java.util.Optional) KeyMapping(net.minecraft.client.KeyMapping) IrisApi(net.irisshaders.iris.api.v0.IrisApi) NotNull(org.jetbrains.annotations.NotNull) LogManager(org.apache.logging.log4j.LogManager) FileSystems(java.nio.file.FileSystems) MutableOptionValues(net.coderbot.iris.shaderpack.option.values.MutableOptionValues) NoSuchFileException(java.nio.file.NoSuchFileException) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) Properties(java.util.Properties) InvalidPathException(java.nio.file.InvalidPathException) NoSuchFileException(java.nio.file.NoSuchFileException) InvalidPathException(java.nio.file.InvalidPathException) ZipException(java.util.zip.ZipException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) IOException(java.io.IOException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) HashMap(java.util.HashMap) Map(java.util.Map) ShaderPack(net.coderbot.iris.shaderpack.ShaderPack)

Aggregations

MutableOptionValues (net.coderbot.iris.shaderpack.option.values.MutableOptionValues)5 OptionSet (net.coderbot.iris.shaderpack.option.OptionSet)3 OptionValues (net.coderbot.iris.shaderpack.option.values.OptionValues)3 ShaderPack (net.coderbot.iris.shaderpack.ShaderPack)2 OptionAnnotatedSource (net.coderbot.iris.shaderpack.option.OptionAnnotatedSource)2 Throwables (com.google.common.base.Throwables)1 InputConstants (com.mojang.blaze3d.platform.InputConstants)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 FileSystem (java.nio.file.FileSystem)1 FileSystemNotFoundException (java.nio.file.FileSystemNotFoundException)1 FileSystems (java.nio.file.FileSystems)1 Files (java.nio.file.Files)1 InvalidPathException (java.nio.file.InvalidPathException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1