diff --git a/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java b/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java index c72614242..65344a93d 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java +++ b/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java @@ -32,7 +32,7 @@ public abstract class ShaderContext

{ Backend.log.debug("Loaded program {}", programSpec.name); } - public String preProcess(ShaderLoader loader, String shaderSrc, ShaderType type) { + public String preProcess(ShaderLoader loader, ShaderType type, ResourceLocation shader, String shaderSrc) { return shaderSrc; } diff --git a/src/main/java/com/jozufozu/flywheel/backend/ShaderLoader.java b/src/main/java/com/jozufozu/flywheel/backend/ShaderLoader.java index fc357957e..bb1ed25c0 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/ShaderLoader.java +++ b/src/main/java/com/jozufozu/flywheel/backend/ShaderLoader.java @@ -127,7 +127,7 @@ public class ShaderLoader { public GlShader loadShader(ShaderContext ctx, ResourceLocation name, ShaderType type, ShaderConstants defines) { String source = shaderSource.get(name); - source = ctx.preProcess(this, source, type); + source = ctx.preProcess(this, type, name, source); source = processIncludes(source, name); if (defines != null) diff --git a/src/main/java/com/jozufozu/flywheel/backend/core/WorldContext.java b/src/main/java/com/jozufozu/flywheel/backend/core/WorldContext.java index 3febc5b2b..54797de14 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/core/WorldContext.java +++ b/src/main/java/com/jozufozu/flywheel/backend/core/WorldContext.java @@ -2,6 +2,7 @@ package com.jozufozu.flywheel.backend.core; import java.util.EnumMap; import java.util.Map; +import java.util.regex.Matcher; import java.util.regex.Pattern; import com.jozufozu.flywheel.backend.Backend; @@ -18,7 +19,8 @@ import net.minecraft.util.ResourceLocation; public class WorldContext

extends ShaderContext

{ - private static final Pattern builtinPattern = Pattern.compile("#flwbuiltins"); + private static final String declaration = "#flwbuiltins"; + private static final Pattern builtinPattern = Pattern.compile(declaration); public static final WorldContext INSTANCE = new WorldContext<>(new ResourceLocation("create", "std"), new FogSensitiveProgram.SpecLoader<>(BasicProgram::new)); public static final WorldContext CRUMBLING = new WorldContext<>(new ResourceLocation("create", "crumbling"), new FogSensitiveProgram.SpecLoader<>(CrumblingProgram::new)); @@ -48,11 +50,15 @@ public class WorldContext

extends ShaderContext

{ } @Override - public String preProcess(ShaderLoader loader, String shaderSrc, ShaderType type) { + public String preProcess(ShaderLoader loader, ShaderType type, ResourceLocation shader, String shaderSrc) { String builtinSrc = loader.getShaderSource(builtins.get(type)); - return builtinPattern.matcher(shaderSrc) - .replaceFirst(builtinSrc); + Matcher matcher = builtinPattern.matcher(shaderSrc); + + if (matcher.find()) + return matcher.replaceFirst(builtinSrc); + + throw new RuntimeException(String.format("%s shader '%s' is missing %s, cannot use in World Context", type.name, shader, declaration)); } @Override diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/ShaderType.java b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/ShaderType.java index 8f6ec6801..2ac5a3721 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/ShaderType.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/ShaderType.java @@ -3,13 +3,15 @@ package com.jozufozu.flywheel.backend.gl.shader; import org.lwjgl.opengl.GL20; public enum ShaderType { - VERTEX(GL20.GL_VERTEX_SHADER), - FRAGMENT(GL20.GL_FRAGMENT_SHADER), + VERTEX("vertex", GL20.GL_VERTEX_SHADER), + FRAGMENT("fragment", GL20.GL_FRAGMENT_SHADER), ; + public final String name; public final int glEnum; - ShaderType(int glEnum) { + ShaderType(String name, int glEnum) { + this.name = name; this.glEnum = glEnum; } }