Search in sources :

Example 1 with OptionValues

use of net.coderbot.iris.shaderpack.option.values.OptionValues in project Iris by IrisShaders.

the class ProfileElementWidget method init.

@Override
public void init(ShaderPackScreen screen, NavigationController navigation) {
    super.init(screen, navigation);
    this.setLabel(PROFILE_LABEL);
    ProfileSet profiles = this.element.profiles;
    OptionSet options = this.element.options;
    OptionValues pendingValues = this.element.getPendingOptionValues();
    ProfileSet.ProfileResult result = profiles.scan(options, pendingValues);
    this.next = result.next;
    this.previous = result.previous;
    Optional<String> profileName = result.current.map(p -> p.name);
    this.profileLabel = profileName.map(name -> GuiUtil.translateOrDefault(new TextComponent(name), "profile." + name)).orElse(PROFILE_CUSTOM);
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) ProfileSet(net.coderbot.iris.shaderpack.option.ProfileSet) OptionValues(net.coderbot.iris.shaderpack.option.values.OptionValues) OptionSet(net.coderbot.iris.shaderpack.option.OptionSet)

Example 2 with OptionValues

use of net.coderbot.iris.shaderpack.option.values.OptionValues 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 3 with OptionValues

use of net.coderbot.iris.shaderpack.option.values.OptionValues 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 4 with OptionValues

use of net.coderbot.iris.shaderpack.option.values.OptionValues in project Iris by IrisShaders.

the class Iris method queueDefaultShaderPackOptionValues.

// Used in favor of resetShaderPackOptions as the aforementioned requires the pack to be reloaded
public static void queueDefaultShaderPackOptionValues() {
    clearShaderPackOptionQueue();
    getCurrentPack().ifPresent(pack -> {
        OptionSet options = pack.getShaderPackOptions().getOptionSet();
        OptionValues values = pack.getShaderPackOptions().getOptionValues();
        options.getStringOptions().forEach((key, mOpt) -> {
            if (values.getStringValue(key).isPresent()) {
                getShaderPackOptionQueue().put(key, mOpt.getOption().getDefaultValue());
            }
        });
        options.getBooleanOptions().forEach((key, mOpt) -> {
            if (values.getBooleanValue(key) != OptionalBoolean.DEFAULT) {
                getShaderPackOptionQueue().put(key, Boolean.toString(mOpt.getOption().getDefaultValue()));
            }
        });
    });
}
Also used : MutableOptionValues(net.coderbot.iris.shaderpack.option.values.MutableOptionValues) OptionValues(net.coderbot.iris.shaderpack.option.values.OptionValues) OptionSet(net.coderbot.iris.shaderpack.option.OptionSet)

Example 5 with OptionValues

use of net.coderbot.iris.shaderpack.option.values.OptionValues in project Iris by IrisShaders.

the class OptionAnnotatedSource method edit.

private String edit(OptionValues values, int index, String existing) {
    // See if it's a boolean option
    BooleanOption booleanOption = booleanOptions.get(index);
    if (booleanOption != null) {
        OptionalBoolean value = values.getBooleanValue(booleanOption.getName());
        if (booleanOption.getType() == OptionType.DEFINE) {
            return setBooleanDefineValue(existing, value, booleanOption.getDefaultValue());
        } else if (booleanOption.getType() == OptionType.CONST) {
            if (value != OptionalBoolean.DEFAULT) {
                // Value will never be default here, but we're using orElse just to get a normal boolean out of it.
                return editConst(existing, Boolean.toString(booleanOption.getDefaultValue()), Boolean.toString(value.orElse(booleanOption.getDefaultValue())));
            } else {
                return existing;
            }
        } else {
            throw new AssertionError("Unknown option type " + booleanOption.getType());
        }
    }
    StringOption stringOption = stringOptions.get(index);
    if (stringOption != null) {
        return values.getStringValue(stringOption.getName()).map(value -> {
            if (stringOption.getType() == OptionType.DEFINE) {
                return "#define " + stringOption.getName() + " " + value + " // OptionAnnotatedSource: Changed option";
            } else if (stringOption.getType() == OptionType.CONST) {
                return editConst(existing, stringOption.getDefaultValue(), value);
            } else {
                throw new AssertionError("Unknown option type " + stringOption.getType());
            }
        }).orElse(existing);
    }
    return existing;
}
Also used : OptionalBoolean(net.coderbot.iris.shaderpack.OptionalBoolean) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AbsolutePackPath(net.coderbot.iris.shaderpack.include.AbsolutePackPath) Set(java.util.Set) HashMap(java.util.HashMap) ParsedString(net.coderbot.iris.shaderpack.parsing.ParsedString) IntList(it.unimi.dsi.fastutil.ints.IntList) Matcher(java.util.regex.Matcher) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) OptionValues(net.coderbot.iris.shaderpack.option.values.OptionValues) Pattern(java.util.regex.Pattern) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) LineTransform(net.coderbot.iris.shaderpack.transform.line.LineTransform) OptionalBoolean(net.coderbot.iris.shaderpack.OptionalBoolean)

Aggregations

OptionValues (net.coderbot.iris.shaderpack.option.values.OptionValues)5 OptionSet (net.coderbot.iris.shaderpack.option.OptionSet)4 MutableOptionValues (net.coderbot.iris.shaderpack.option.values.MutableOptionValues)3 OptionAnnotatedSource (net.coderbot.iris.shaderpack.option.OptionAnnotatedSource)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 IntList (it.unimi.dsi.fastutil.ints.IntList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 OptionalBoolean (net.coderbot.iris.shaderpack.OptionalBoolean)1 ProgramSource (net.coderbot.iris.shaderpack.ProgramSource)1 ShaderPack (net.coderbot.iris.shaderpack.ShaderPack)1 AbsolutePackPath (net.coderbot.iris.shaderpack.include.AbsolutePackPath)1 ProfileSet (net.coderbot.iris.shaderpack.option.ProfileSet)1 ParsedString (net.coderbot.iris.shaderpack.parsing.ParsedString)1