mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-15 22:43:41 +01:00
Error when missing #flwbuiltins in WorldContext
This commit is contained in:
parent
aa1a45f164
commit
05b56b9b5e
4 changed files with 17 additions and 9 deletions
|
@ -32,7 +32,7 @@ public abstract class ShaderContext<P extends GlProgram> {
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<P extends BasicProgram> extends ShaderContext<P> {
|
||||
|
||||
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<BasicProgram> INSTANCE = new WorldContext<>(new ResourceLocation("create", "std"), new FogSensitiveProgram.SpecLoader<>(BasicProgram::new));
|
||||
public static final WorldContext<CrumblingProgram> CRUMBLING = new WorldContext<>(new ResourceLocation("create", "crumbling"), new FogSensitiveProgram.SpecLoader<>(CrumblingProgram::new));
|
||||
|
@ -48,11 +50,15 @@ public class WorldContext<P extends BasicProgram> extends ShaderContext<P> {
|
|||
}
|
||||
|
||||
@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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue