From 947c611bbc60331851fb6260acb3489ebc3af94f Mon Sep 17 00:00:00 2001
From: Jozufozu
Date: Tue, 10 Aug 2021 15:20:51 -0700
Subject: [PATCH] Some decoupling
- New Loader class in charge of loading and compiling everything
- ShaderSources now only loads sources
- ShaderSources is immutable now
- Resolver singleton in charge of managing name resolutions
- ProgramSpecs go through Resolver
- WorldShaderPipeline no longer needs reference to ShaderSources
---
.../jozufozu/flywheel/backend/Backend.java | 3 +-
.../com/jozufozu/flywheel/backend/Loader.java | 125 ++++++++++++++++
.../pipeline/InstancingProgramMetaData.java | 7 +-
.../backend/pipeline/WorldShaderPipeline.java | 8 +-
.../backend/source/FileResolution.java | 11 +-
.../backend/source/ISourceHolder.java | 12 ++
.../flywheel/backend/source/Resolver.java | 47 ++++++
.../backend/source/ShaderSources.java | 139 ++----------------
.../flywheel/backend/source/SourceFile.java | 2 +-
.../backend/source/error/ErrorBuilder.java | 4 +-
.../flywheel/backend/source/parse/Import.java | 10 +-
.../com/jozufozu/flywheel/core/Contexts.java | 11 +-
.../jozufozu/flywheel/core/WorldContext.java | 2 +-
.../core/shader/spec/ProgramSpec.java | 14 +-
.../{backend => util}/ResourceUtil.java | 2 +-
.../flywheel/flywheel/shaders/model.vert | 2 -
.../flywheel/flywheel/shaders/oriented.vert | 1 -
17 files changed, 235 insertions(+), 165 deletions(-)
create mode 100644 src/main/java/com/jozufozu/flywheel/backend/Loader.java
create mode 100644 src/main/java/com/jozufozu/flywheel/backend/source/ISourceHolder.java
create mode 100644 src/main/java/com/jozufozu/flywheel/backend/source/Resolver.java
rename src/main/java/com/jozufozu/flywheel/{backend => util}/ResourceUtil.java (94%)
diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java
index 880aa5e12..72a919218 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java
@@ -37,6 +37,7 @@ public class Backend {
public final Minecraft minecraft;
public ShaderSources sources;
+ public Loader loader;
public GLCapabilities capabilities;
public GlCompat compat;
@@ -55,7 +56,7 @@ public class Backend {
minecraft = Minecraft.getInstance();
if (minecraft == null) return;
- sources = new ShaderSources(this);
+ loader = new Loader(this);
OptifineHandler.init();
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/Loader.java b/src/main/java/com/jozufozu/flywheel/backend/Loader.java
new file mode 100644
index 000000000..bc69337b1
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/backend/Loader.java
@@ -0,0 +1,125 @@
+package com.jozufozu.flywheel.backend;
+
+import java.util.Collection;
+import java.util.function.Predicate;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
+import com.jozufozu.flywheel.backend.source.Resolver;
+import com.jozufozu.flywheel.backend.source.ShaderLoadingException;
+import com.jozufozu.flywheel.backend.source.ShaderSources;
+import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer;
+import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
+import com.jozufozu.flywheel.event.GatherContextEvent;
+import com.jozufozu.flywheel.util.ResourceUtil;
+import com.jozufozu.flywheel.util.StreamUtil;
+import com.mojang.datafixers.util.Pair;
+import com.mojang.serialization.DataResult;
+import com.mojang.serialization.JsonOps;
+
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.world.ClientWorld;
+import net.minecraft.resources.IReloadableResourceManager;
+import net.minecraft.resources.IResource;
+import net.minecraft.resources.IResourceManager;
+import net.minecraft.util.ResourceLocation;
+import net.minecraftforge.fml.ModLoader;
+import net.minecraftforge.resource.IResourceType;
+import net.minecraftforge.resource.ISelectiveResourceReloadListener;
+import net.minecraftforge.resource.VanillaResourceType;
+
+/**
+ * The main entity for loading shaders.
+ *
+ *
+ * This class is responsible for invoking the loading, parsing, and compilation stages.
+ *
+ */
+public class Loader implements ISelectiveResourceReloadListener {
+ public static final String PROGRAM_DIR = "flywheel/programs/";
+ private static final Gson GSON = new GsonBuilder().create();
+
+ private final Backend backend;
+ public boolean shouldCrash;
+
+
+ public Loader(Backend backend) {
+ this.backend = backend;
+
+ IResourceManager manager = backend.minecraft.getResourceManager();
+ if (manager instanceof IReloadableResourceManager) {
+ ((IReloadableResourceManager) manager).registerReloadListener(this);
+ }
+ }
+
+ public void notifyError() {
+ shouldCrash = true;
+ }
+
+ @Override
+ public void onResourceManagerReload(IResourceManager manager, Predicate predicate) {
+ if (predicate.test(VanillaResourceType.SHADERS)) {
+ backend.refresh();
+
+ if (backend.gl20()) {
+ shouldCrash = false;
+ backend._clearContexts();
+
+ Resolver.INSTANCE.invalidate();
+ ModLoader.get()
+ .postEvent(new GatherContextEvent(backend));
+
+ backend.sources = new ShaderSources(manager);
+
+ loadProgramSpecs(manager);
+
+ Resolver.INSTANCE.resolve(backend.sources);
+
+ for (IShaderContext> context : backend.allContexts()) {
+ context.load();
+ }
+
+ if (shouldCrash) {
+ throw new ShaderLoadingException("Could not load all shaders, see log for details");
+ }
+
+ Backend.log.info("Loaded all shader programs.");
+
+ ClientWorld world = Minecraft.getInstance().level;
+ if (Backend.isFlywheelWorld(world)) {
+ // TODO: looks like it might be good to have another event here
+ InstancedRenderDispatcher.loadAllInWorld(world);
+ CrumblingRenderer.reset();
+ }
+ }
+ }
+ }
+
+ private void loadProgramSpecs(IResourceManager manager) {
+ Collection programSpecs = manager.listResources(PROGRAM_DIR, s -> s.endsWith(".json"));
+
+ for (ResourceLocation location : programSpecs) {
+ try {
+ IResource file = manager.getResource(location);
+
+ String s = StreamUtil.readToString(file.getInputStream());
+
+ ResourceLocation specName = ResourceUtil.trim(location, PROGRAM_DIR, ".json");
+
+ DataResult> result = ProgramSpec.CODEC.decode(JsonOps.INSTANCE, GSON.fromJson(s, JsonElement.class));
+
+ ProgramSpec spec = result.get()
+ .orThrow()
+ .getFirst();
+
+ spec.setName(specName);
+
+ backend.register(spec);
+ } catch (Exception e) {
+ Backend.log.error(e);
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/pipeline/InstancingProgramMetaData.java b/src/main/java/com/jozufozu/flywheel/backend/pipeline/InstancingProgramMetaData.java
index 612e8989f..24e743fc3 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/pipeline/InstancingProgramMetaData.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/pipeline/InstancingProgramMetaData.java
@@ -3,6 +3,7 @@ package com.jozufozu.flywheel.backend.pipeline;
import java.util.Optional;
import com.google.common.collect.ImmutableList;
+import com.jozufozu.flywheel.backend.source.ShaderLoadingException;
import com.jozufozu.flywheel.backend.source.SourceFile;
import com.jozufozu.flywheel.backend.source.error.ErrorReporter;
import com.jozufozu.flywheel.backend.source.parse.ShaderFunction;
@@ -36,7 +37,7 @@ public class InstancingProgramMetaData {
}
if (!fragmentFunc.isPresent() || !vertexFunc.isPresent()) {
- throw new RuntimeException();
+ throw new ShaderLoadingException();
}
fragmentMain = fragmentFunc.get();
@@ -50,7 +51,7 @@ public class InstancingProgramMetaData {
if (vertexParams.size() != 2) {
ErrorReporter.generateSpanError(vertexMain.getArgs(), "instancing requires vertex function to have 2 arguments");
- throw new RuntimeException();
+ throw new ShaderLoadingException();
}
interpolantName = vertexMain.getType();
@@ -76,7 +77,7 @@ public class InstancingProgramMetaData {
}
if (!maybeVertex.isPresent() || !maybeInterpolant.isPresent() || !maybeInstance.isPresent()) {
- throw new RuntimeException();
+ throw new ShaderLoadingException();
}
interpolant = maybeInterpolant.get();
diff --git a/src/main/java/com/jozufozu/flywheel/backend/pipeline/WorldShaderPipeline.java b/src/main/java/com/jozufozu/flywheel/backend/pipeline/WorldShaderPipeline.java
index 26871b6ef..2ebf79984 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/pipeline/WorldShaderPipeline.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/pipeline/WorldShaderPipeline.java
@@ -7,7 +7,6 @@ import java.util.List;
import javax.annotation.Nullable;
import com.jozufozu.flywheel.backend.source.FileResolution;
-import com.jozufozu.flywheel.backend.source.ShaderSources;
import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
import com.jozufozu.flywheel.backend.source.SourceFile;
import com.jozufozu.flywheel.core.shader.ExtensibleGlProgram;
@@ -21,15 +20,12 @@ import net.minecraft.util.ResourceLocation;
public class WorldShaderPipeline implements IShaderPipeline
{
- private final ShaderSources sources;
-
private final ExtensibleGlProgram.Factory
factory;
private final Template> template;
private final FileResolution header;
- public WorldShaderPipeline(ShaderSources sources, ExtensibleGlProgram.Factory
factory, Template> template, FileResolution header) {
- this.sources = sources;
+ public WorldShaderPipeline(ExtensibleGlProgram.Factory
factory, Template> template, FileResolution header) {
this.factory = factory;
this.template = template;
this.header = header;
@@ -37,7 +33,7 @@ public class WorldShaderPipeline
implements IShaderPipel
public IMultiProgram
compile(ProgramSpec spec) {
- SourceFile file = sources.source(spec.source);
+ SourceFile file = spec.getSource().getFile();
return compile(spec.name, file, spec.getStates());
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/source/FileResolution.java b/src/main/java/com/jozufozu/flywheel/backend/source/FileResolution.java
index a340ff845..2e4ae7163 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/source/FileResolution.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/source/FileResolution.java
@@ -26,12 +26,10 @@ public class FileResolution {
* Spans that have references that resolved to this.
*/
private final List foundSpans = new ArrayList<>();
- private final ShaderSources parent;
private final ResourceLocation fileLoc;
private SourceFile file;
- public FileResolution(ShaderSources parent, ResourceLocation fileLoc) {
- this.parent = parent;
+ public FileResolution(ResourceLocation fileLoc) {
this.fileLoc = fileLoc;
}
@@ -52,8 +50,9 @@ public class FileResolution {
*
* @param span A span where this file is referenced.
*/
- public void addSpan(Span span) {
+ public FileResolution addSpan(Span span) {
foundSpans.add(span);
+ return this;
}
/**
@@ -63,10 +62,10 @@ public class FileResolution {
* Called after all files are loaded. If we can't find the file here, it doesn't exist.
*
*/
- void resolve() {
+ void resolve(ISourceHolder sources) {
try {
- file = this.parent.source(fileLoc);
+ file = sources.findSource(fileLoc);
} catch (RuntimeException error) {
ErrorBuilder builder = new ErrorBuilder();
builder.error(String.format("could not find source for file %s", fileLoc));
diff --git a/src/main/java/com/jozufozu/flywheel/backend/source/ISourceHolder.java b/src/main/java/com/jozufozu/flywheel/backend/source/ISourceHolder.java
new file mode 100644
index 000000000..07363f380
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/backend/source/ISourceHolder.java
@@ -0,0 +1,12 @@
+package com.jozufozu.flywheel.backend.source;
+
+import net.minecraft.util.ResourceLocation;
+
+/**
+ * A minimal source file lookup function.
+ */
+@FunctionalInterface
+public interface ISourceHolder {
+
+ SourceFile findSource(ResourceLocation name);
+}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/source/Resolver.java b/src/main/java/com/jozufozu/flywheel/backend/source/Resolver.java
new file mode 100644
index 000000000..4a7cefe65
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/backend/source/Resolver.java
@@ -0,0 +1,47 @@
+package com.jozufozu.flywheel.backend.source;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import net.minecraft.util.ResourceLocation;
+
+/**
+ * Manages deferred file resolution.
+ *
+ *
+ * Interns all referenced files in all sources, duplicating the final lookups and allowing for more dev-friendly
+ * error reporting.
+ *
+ * See {@link FileResolution} for more information.
+ *
+ */
+public class Resolver {
+
+ public static final Resolver INSTANCE = new Resolver();
+
+ private final Map resolutions = new HashMap<>();
+
+ public FileResolution findShader(ResourceLocation fileLoc) {
+ return resolutions.computeIfAbsent(fileLoc, FileResolution::new);
+ }
+
+ /**
+ * Try and resolve all referenced source files, printing errors if any aren't found.
+ */
+ public void resolve(ISourceHolder sources) {
+ for (FileResolution resolution : resolutions.values()) {
+ resolution.resolve(sources);
+ }
+ }
+
+ /**
+ * Invalidates all FileResolutions.
+ *
+ *
+ * Called on resource reload.
+ *
+ */
+ public void invalidate() {
+ resolutions.values().forEach(FileResolution::invalidate);
+ }
+}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/source/ShaderSources.java b/src/main/java/com/jozufozu/flywheel/backend/source/ShaderSources.java
index bab564af4..3039a77eb 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/source/ShaderSources.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/source/ShaderSources.java
@@ -5,126 +5,27 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import java.util.function.Predicate;
import com.google.common.collect.Lists;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
-import com.jozufozu.flywheel.backend.Backend;
-import com.jozufozu.flywheel.backend.IShaderContext;
-import com.jozufozu.flywheel.backend.ResourceUtil;
-import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
-import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer;
-import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
-import com.jozufozu.flywheel.event.GatherContextEvent;
+import com.jozufozu.flywheel.util.ResourceUtil;
import com.jozufozu.flywheel.util.StreamUtil;
-import com.mojang.datafixers.util.Pair;
-import com.mojang.serialization.DataResult;
-import com.mojang.serialization.JsonOps;
-import net.minecraft.client.Minecraft;
-import net.minecraft.client.world.ClientWorld;
-import net.minecraft.resources.IReloadableResourceManager;
import net.minecraft.resources.IResource;
import net.minecraft.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
-import net.minecraftforge.fml.ModLoader;
-import net.minecraftforge.resource.IResourceType;
-import net.minecraftforge.resource.ISelectiveResourceReloadListener;
-import net.minecraftforge.resource.VanillaResourceType;
/**
- * The main entity for loading shaders.
- *
- *
- * This class is responsible for invoking the loading, parsing, and compilation stages.
- *
+ * The main object for loading and parsing source files.
*/
-public class ShaderSources implements ISelectiveResourceReloadListener {
+public class ShaderSources implements ISourceHolder {
public static final String SHADER_DIR = "flywheel/shaders/";
- public static final String PROGRAM_DIR = "flywheel/programs/";
public static final ArrayList EXTENSIONS = Lists.newArrayList(".vert", ".vsh", ".frag", ".fsh", ".glsl");
- private static final Gson GSON = new GsonBuilder().create();
private final Map shaderSources = new HashMap<>();
- private final Map resolutions = new HashMap<>();
+ public final Index index;
- private boolean shouldCrash;
- private final Backend backend;
-
- public Index index;
-
- public ShaderSources(Backend backend) {
- this.backend = backend;
- IResourceManager manager = backend.minecraft.getResourceManager();
- if (manager instanceof IReloadableResourceManager) {
- ((IReloadableResourceManager) manager).registerReloadListener(this);
- }
- }
-
- public SourceFile source(ResourceLocation name) {
- SourceFile source = shaderSources.get(name);
-
- if (source == null) {
- throw new ShaderLoadingException(String.format("shader '%s' does not exist", name));
- }
-
- return source;
- }
-
- public FileResolution resolveFile(ResourceLocation fileLoc) {
- return resolutions.computeIfAbsent(fileLoc, l -> new FileResolution(this, l));
- }
-
- @Deprecated
- public void notifyError() {
- shouldCrash = true;
- }
-
- @Override
- public void onResourceManagerReload(IResourceManager manager, Predicate predicate) {
- if (predicate.test(VanillaResourceType.SHADERS)) {
- backend.refresh();
-
- if (backend.gl20()) {
- shouldCrash = false;
-
- backend._clearContexts();
- resolutions.values().forEach(FileResolution::invalidate);
- shaderSources.clear();
- ModLoader.get()
- .postEvent(new GatherContextEvent(backend));
-
- loadProgramSpecs(manager);
- loadShaderSources(manager);
-
- for (FileResolution resolution : resolutions.values()) {
- resolution.resolve();
- }
-
- for (IShaderContext> context : backend.allContexts()) {
- context.load();
- }
-
- if (shouldCrash) {
- throw new ShaderLoadingException("Could not load all shaders, see log for details");
- }
-
- Backend.log.info("Loaded all shader programs.");
-
- ClientWorld world = Minecraft.getInstance().level;
- if (Backend.isFlywheelWorld(world)) {
- // TODO: looks like it might be good to have another event here
- InstancedRenderDispatcher.loadAllInWorld(world);
- CrumblingRenderer.reset();
- }
- }
- }
- }
-
- private void loadShaderSources(IResourceManager manager) {
+ public ShaderSources(IResourceManager manager) {
Collection allShaders = manager.listResources(SHADER_DIR, s -> {
for (String ext : EXTENSIONS) {
if (s.endsWith(ext)) return true;
@@ -149,30 +50,14 @@ public class ShaderSources implements ISelectiveResourceReloadListener {
index = new Index(shaderSources);
}
+ @Override
+ public SourceFile findSource(ResourceLocation name) {
+ SourceFile source = shaderSources.get(name);
- private void loadProgramSpecs(IResourceManager manager) {
- Collection programSpecs = manager.listResources(PROGRAM_DIR, s -> s.endsWith(".json"));
-
- for (ResourceLocation location : programSpecs) {
- try {
- IResource file = manager.getResource(location);
-
- String s = StreamUtil.readToString(file.getInputStream());
-
- ResourceLocation specName = ResourceUtil.trim(location, PROGRAM_DIR, ".json");
-
- DataResult> result = ProgramSpec.CODEC.decode(JsonOps.INSTANCE, GSON.fromJson(s, JsonElement.class));
-
- ProgramSpec spec = result.get()
- .orThrow()
- .getFirst();
-
- spec.setName(specName);
-
- backend.register(spec);
- } catch (Exception e) {
- Backend.log.error(e);
- }
+ if (source == null) {
+ throw new ShaderLoadingException(String.format("shader '%s' does not exist", name));
}
+
+ return source;
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/source/SourceFile.java b/src/main/java/com/jozufozu/flywheel/backend/source/SourceFile.java
index c4c3d65f0..88f23d30f 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/source/SourceFile.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/source/SourceFile.java
@@ -294,7 +294,7 @@ public class SourceFile {
Span use = Span.fromMatcher(this, uses);
Span file = Span.fromMatcher(this, uses, 1);
- imports.add(new Import(parent, use, file));
+ imports.add(new Import(Resolver.INSTANCE, use, file));
elisions.add(use); // we have to trim that later
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/source/error/ErrorBuilder.java b/src/main/java/com/jozufozu/flywheel/backend/source/error/ErrorBuilder.java
index 9c01a9d19..b6669e077 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/source/error/ErrorBuilder.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/source/error/ErrorBuilder.java
@@ -1,5 +1,7 @@
package com.jozufozu.flywheel.backend.source.error;
+import javax.annotation.Nullable;
+
import com.jozufozu.flywheel.backend.source.SourceFile;
import com.jozufozu.flywheel.backend.source.span.Span;
import com.jozufozu.flywheel.util.FlwUtil;
@@ -55,7 +57,7 @@ public class ErrorBuilder {
return this;
}
- public ErrorBuilder hintIncludeFor(Span span, CharSequence msg) {
+ public ErrorBuilder hintIncludeFor(@Nullable Span span, CharSequence msg) {
if (span == null) return this;
hint("add " + span.getSourceFile().importStatement() + " " + msg)
diff --git a/src/main/java/com/jozufozu/flywheel/backend/source/parse/Import.java b/src/main/java/com/jozufozu/flywheel/backend/source/parse/Import.java
index 6df09b009..1bd886237 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/source/parse/Import.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/source/parse/Import.java
@@ -7,7 +7,7 @@ import java.util.Optional;
import javax.annotation.Nullable;
import com.jozufozu.flywheel.backend.source.FileResolution;
-import com.jozufozu.flywheel.backend.source.ShaderSources;
+import com.jozufozu.flywheel.backend.source.Resolver;
import com.jozufozu.flywheel.backend.source.error.ErrorReporter;
import com.jozufozu.flywheel.backend.source.SourceFile;
import com.jozufozu.flywheel.backend.source.span.Span;
@@ -21,15 +21,13 @@ public class Import extends AbstractShaderElement {
private final Span file;
private final FileResolution resolution;
- private final ResourceLocation fileLoc;
- public Import(ShaderSources parent, Span self, Span file) {
+ public Import(Resolver resolver, Span self, Span file) {
super(self);
this.file = file;
- fileLoc = toRL(file);
- resolution = parent.resolveFile(fileLoc);
- resolution.addSpan(file);
+ resolution = resolver.findShader(toRL(file))
+ .addSpan(file);
IMPORTS.add(this);
}
diff --git a/src/main/java/com/jozufozu/flywheel/core/Contexts.java b/src/main/java/com/jozufozu/flywheel/core/Contexts.java
index dd8e53d29..3f052ca3c 100644
--- a/src/main/java/com/jozufozu/flywheel/core/Contexts.java
+++ b/src/main/java/com/jozufozu/flywheel/core/Contexts.java
@@ -3,11 +3,12 @@ package com.jozufozu.flywheel.core;
import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.source.FileResolution;
-import com.jozufozu.flywheel.backend.ResourceUtil;
+import com.jozufozu.flywheel.util.ResourceUtil;
import com.jozufozu.flywheel.backend.SpecMetaRegistry;
import com.jozufozu.flywheel.backend.pipeline.IShaderPipeline;
import com.jozufozu.flywheel.backend.pipeline.InstancingTemplate;
import com.jozufozu.flywheel.backend.pipeline.WorldShaderPipeline;
+import com.jozufozu.flywheel.backend.source.Resolver;
import com.jozufozu.flywheel.core.crumbling.CrumblingProgram;
import com.jozufozu.flywheel.core.shader.WorldFog;
import com.jozufozu.flywheel.core.shader.WorldProgram;
@@ -34,11 +35,11 @@ public class Contexts {
SpecMetaRegistry.register(WorldFog.LINEAR);
SpecMetaRegistry.register(WorldFog.EXP2);
- FileResolution crumblingBuiltins = backend.sources.resolveFile(ResourceUtil.subPath(Names.CRUMBLING, ".glsl"));
- FileResolution worldBuiltins = backend.sources.resolveFile(ResourceUtil.subPath(Names.WORLD, ".glsl"));
+ FileResolution crumblingBuiltins = Resolver.INSTANCE.findShader(ResourceUtil.subPath(Names.CRUMBLING, ".glsl"));
+ FileResolution worldBuiltins = Resolver.INSTANCE.findShader(ResourceUtil.subPath(Names.WORLD, ".glsl"));
- IShaderPipeline crumblingPipeline = new WorldShaderPipeline<>(backend.sources, CrumblingProgram::new, InstancingTemplate.INSTANCE, crumblingBuiltins);
- IShaderPipeline worldPipeline = new WorldShaderPipeline<>(backend.sources, WorldProgram::new, InstancingTemplate.INSTANCE, worldBuiltins);
+ IShaderPipeline crumblingPipeline = new WorldShaderPipeline<>(CrumblingProgram::new, InstancingTemplate.INSTANCE, crumblingBuiltins);
+ IShaderPipeline worldPipeline = new WorldShaderPipeline<>(WorldProgram::new, InstancingTemplate.INSTANCE, worldBuiltins);
CRUMBLING = backend.register(WorldContext.builder(backend, Names.CRUMBLING).build(crumblingPipeline));
WORLD = backend.register(WorldContext.builder(backend, Names.WORLD).build(worldPipeline));
diff --git a/src/main/java/com/jozufozu/flywheel/core/WorldContext.java b/src/main/java/com/jozufozu/flywheel/core/WorldContext.java
index f7c156bea..d13d90f08 100644
--- a/src/main/java/com/jozufozu/flywheel/core/WorldContext.java
+++ b/src/main/java/com/jozufozu/flywheel/core/WorldContext.java
@@ -49,7 +49,7 @@ public class WorldContext implements IShaderContext
{
} catch (Exception e) {
Backend.log.error("Error loading program {}", spec.name);
Backend.log.error("", e);
- backend.sources.notifyError();
+ backend.loader.notifyError();
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramSpec.java b/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramSpec.java
index 03319d6bd..97553cd9d 100644
--- a/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramSpec.java
+++ b/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramSpec.java
@@ -3,6 +3,8 @@ package com.jozufozu.flywheel.core.shader.spec;
import java.util.Collections;
import java.util.List;
+import com.jozufozu.flywheel.backend.source.FileResolution;
+import com.jozufozu.flywheel.backend.source.Resolver;
import com.jozufozu.flywheel.backend.source.SourceFile;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
@@ -27,19 +29,19 @@ public class ProgramSpec {
// TODO: Block model style inheritance?
public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group(
ResourceLocation.CODEC.fieldOf("source")
- .forGetter(ProgramSpec::getSource),
+ .forGetter(ProgramSpec::getSourceLoc),
ProgramState.CODEC.listOf()
.optionalFieldOf("states", Collections.emptyList())
.forGetter(ProgramSpec::getStates))
.apply(instance, ProgramSpec::new));
public ResourceLocation name;
- public final ResourceLocation source;
+ public final FileResolution source;
public final List states;
public ProgramSpec(ResourceLocation source, List states) {
- this.source = source;
+ this.source = Resolver.INSTANCE.findShader(source);
this.states = states;
}
@@ -47,7 +49,11 @@ public class ProgramSpec {
this.name = name;
}
- public ResourceLocation getSource() {
+ public ResourceLocation getSourceLoc() {
+ return source.getFileLoc();
+ }
+
+ public FileResolution getSource() {
return source;
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/ResourceUtil.java b/src/main/java/com/jozufozu/flywheel/util/ResourceUtil.java
similarity index 94%
rename from src/main/java/com/jozufozu/flywheel/backend/ResourceUtil.java
rename to src/main/java/com/jozufozu/flywheel/util/ResourceUtil.java
index 874e429b4..e04c1cc46 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/ResourceUtil.java
+++ b/src/main/java/com/jozufozu/flywheel/util/ResourceUtil.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.backend;
+package com.jozufozu.flywheel.util;
import net.minecraft.util.ResourceLocation;
diff --git a/src/main/resources/assets/flywheel/flywheel/shaders/model.vert b/src/main/resources/assets/flywheel/flywheel/shaders/model.vert
index cbd40f7d6..603d17e54 100644
--- a/src/main/resources/assets/flywheel/flywheel/shaders/model.vert
+++ b/src/main/resources/assets/flywheel/flywheel/shaders/model.vert
@@ -1,7 +1,5 @@
#use "flywheel:core/diffuse.glsl"
-
#use "flywheel:data/modelvertex.glsl"
-
#use "flywheel:block.frag"
struct Instance {
diff --git a/src/main/resources/assets/flywheel/flywheel/shaders/oriented.vert b/src/main/resources/assets/flywheel/flywheel/shaders/oriented.vert
index 2cf8f2322..bac28858b 100644
--- a/src/main/resources/assets/flywheel/flywheel/shaders/oriented.vert
+++ b/src/main/resources/assets/flywheel/flywheel/shaders/oriented.vert
@@ -1,4 +1,3 @@
-#use "flywheel:core/matutils.glsl"
#use "flywheel:core/quaternion.glsl"
#use "flywheel:core/diffuse.glsl"