Something went wrong. Try again.
The Minecraft: Java Edition decompiled source code.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140package com.mojang.blaze3d.preprocessor;
import com.google.common.base.Strings;import com.google.common.collect.Lists;import java.util.ArrayList;import java.util.List;import java.util.Locale;import java.util.regex.Matcher;import java.util.regex.Pattern;import net.minecraft.client.renderer.ShaderDefines;import net.minecraft.util.FileUtil;import net.minecraft.util.StringUtil;import org.jspecify.annotations.Nullable;
public abstract class GlslPreprocessor { private static final String C_COMMENT = "/\\*(?:[^*]|\\*+[^*/])*\\*+/"; private static final String LINE_COMMENT = "//[^\\v]*"; private static final Pattern REGEX_MOJ_IMPORT = Pattern.compile( "(#(?:/\\*(?:[^*]|\\*+[^*/])*\\*+/|\\h)*moj_import(?:/\\*(?:[^*]|\\*+[^*/])*\\*+/|\\h)*(?:\"(.*)\"|<(.*)>))" ); private static final Pattern REGEX_VERSION = Pattern.compile("(#(?:/\\*(?:[^*]|\\*+[^*/])*\\*+/|\\h)*version(?:/\\*(?:[^*]|\\*+[^*/])*\\*+/|\\h)*(\\d+))\\b"); private static final Pattern REGEX_ENDS_WITH_WHITESPACE = Pattern.compile("(?:^|\\v)(?:\\s|/\\*(?:[^*]|\\*+[^*/])*\\*+/|(//[^\\v]*))*\\z");
public List<String> process(String string) { GlslPreprocessor.Context context = new GlslPreprocessor.Context(); List list = this.processImports(string, context, ""); list.set(0, this.setVersion((String)list.get(0), context.glslVersion)); return list; }
private List<String> processImports(String string, GlslPreprocessor.Context context, String string1) { int i = context.sourceId; int j = 0; String string2 = ""; ArrayList arrayList = Lists.newArrayList(); Matcher matcher = REGEX_MOJ_IMPORT.matcher(string);
while (matcher.find()) { if (!isDirectiveDisabled(string, matcher, j)) { String string3 = matcher.group(2); boolean bl = string3 != null; if (!bl) { string3 = matcher.group(3); }
if (string3 != null) { String string4 = string.substring(j, matcher.start(1)); String string5 = string1 + string3; String string6 = this.applyImport(bl, string5); if (!Strings.isNullOrEmpty(string6)) { if (!StringUtil.endsWithNewLine(string6)) { string6 = string6 + System.lineSeparator(); }
context.sourceId++; int k = context.sourceId; List list = this.processImports(string6, context, bl ? FileUtil.getFullResourcePath(string5) : ""); list.set(0, String.format(Locale.ROOT, "#line %d %d\n%s", 0, k, this.processVersions((String)list.get(0), context))); if (!StringUtil.isBlank(string4)) { arrayList.add(string4); }
arrayList.addAll(list); } else { String string8 = bl ? String.format(Locale.ROOT, "/*#moj_import \"%s\"*/", string3) : String.format(Locale.ROOT, "/*#moj_import <%s>*/", string3); arrayList.add(string2 + string4 + string8); }
int l = StringUtil.lineCount(string.substring(0, matcher.end(1))); string2 = String.format(Locale.ROOT, "#line %d %d", l, i); j = matcher.end(1); } } }
String string7 = string.substring(j); if (!StringUtil.isBlank(string7)) { arrayList.add(string2 + string7); }
return arrayList; }
private String processVersions(String string, GlslPreprocessor.Context context) { Matcher matcher = REGEX_VERSION.matcher(string); if (matcher.find() && isDirectiveEnabled(string, matcher)) { context.glslVersion = Math.max(context.glslVersion, Integer.parseInt(matcher.group(2))); return string.substring(0, matcher.start(1)) + "/*" + string.substring(matcher.start(1), matcher.end(1)) + "*/" + string.substring(matcher.end(1)); } else { return string; } }
private String setVersion(String string, int i) { Matcher matcher = REGEX_VERSION.matcher(string); return matcher.find() && isDirectiveEnabled(string, matcher) ? string.substring(0, matcher.start(2)) + Math.max(i, Integer.parseInt(matcher.group(2))) + string.substring(matcher.end(2)) : string; }
private static boolean isDirectiveEnabled(String string, Matcher matcher) { return !isDirectiveDisabled(string, matcher, 0); }
private static boolean isDirectiveDisabled(String string, Matcher matcher, int i) { int j = matcher.start() - i; if (j == 0) { return false; } else { Matcher matcher1 = REGEX_ENDS_WITH_WHITESPACE.matcher(string.substring(i, matcher.start())); if (!matcher1.find()) { return true; } else { int k = matcher1.end(1); return k == matcher.start(); } } }
@Nullable public abstract String applyImport(boolean bl, String string);
public static String injectDefines(String string, ShaderDefines shaderDefines) { if (shaderDefines.isEmpty()) { return string; } else { int i = string.indexOf(10); int j = i + 1; return string.substring(0, j) + shaderDefines.asSourceDirectives() + "#line 1 0\n" + string.substring(j); } }
static final class Context { int glslVersion; int sourceId; }}