replacements
This commit is contained in:
@@ -69,6 +69,7 @@ public class Shader extends TrackedObject {
|
|||||||
J make(Builder<J> builder, int program);
|
J make(Builder<J> builder, int program);
|
||||||
}
|
}
|
||||||
final Map<String, String> defines = new HashMap<>();
|
final Map<String, String> defines = new HashMap<>();
|
||||||
|
final Map<String, String> replacements = new LinkedHashMap<>();
|
||||||
private final Map<ShaderType, String> sources = new HashMap<>();
|
private final Map<ShaderType, String> sources = new HashMap<>();
|
||||||
private final IShaderProcessor processor;
|
private final IShaderProcessor processor;
|
||||||
private final IShaderObjectConstructor<T> constructor;
|
private final IShaderObjectConstructor<T> constructor;
|
||||||
@@ -109,11 +110,21 @@ public class Shader extends TrackedObject {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder<T> define(String name, float value) {
|
||||||
|
this.defines.put(name, Float.toString(value)+"f");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Builder<T> define(String name, String value) {
|
public Builder<T> define(String name, String value) {
|
||||||
this.defines.put(name, value);
|
this.defines.put(name, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder<T> replace(String value, String replacement) {
|
||||||
|
this.defines.put(value, replacement);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Builder<T> add(ShaderType type, String id) {
|
public Builder<T> add(ShaderType type, String id) {
|
||||||
this.addSource(type, ShaderLoader.parse(id));
|
this.addSource(type, ShaderLoader.parse(id));
|
||||||
return this;
|
return this;
|
||||||
@@ -139,6 +150,10 @@ public class Shader extends TrackedObject {
|
|||||||
defs
|
defs
|
||||||
+ src.substring(src.indexOf('\n')+1);
|
+ src.substring(src.indexOf('\n')+1);
|
||||||
|
|
||||||
|
for (var replacement : this.replacements.entrySet()) {
|
||||||
|
src = src.replaceAll(replacement.getKey(), replacement.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
shaders[i++] = createShader(entry.getKey(), src);
|
shaders[i++] = createShader(entry.getKey(), src);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user