define the shader stage in shaders built by ShaderLoader #50
No files matched your search
@@ -15,6 +15,12 @@ public class ShaderConstants {
|
|||||||
return this.defines;
|
return this.defines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ShaderConstants with(String name) {
|
||||||
|
List<String> defines = new ArrayList<>(this.defines);
|
||||||
|
defines.add("#define " + name);
|
||||||
|
return new ShaderConstants(Collections.unmodifiableList(defines));
|
||||||
|
}
|
||||||
|
|
||||||
public static ShaderConstants.Builder builder() {
|
public static ShaderConstants.Builder builder() {
|
||||||
return new Builder();
|
return new Builder();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,13 +34,7 @@ public class ShaderLoader {
|
|||||||
* resolve to the given source instead of the classpath.
|
* resolve to the given source instead of the classpath.
|
||||||
*/
|
*/
|
||||||
public static GlShader loadShader(ShaderType type, String name, ShaderConstants constants, Map<String, String> generatedSources) {
|
public static GlShader loadShader(ShaderType type, String name, ShaderConstants constants, Map<String, String> generatedSources) {
|
||||||
String source = ShaderParser.parseShader(getShaderSource(name), sourceProvider(generatedSources), constants);
|
return new GlShader(type, name, downgradeIfNeeded(type, ShaderParser.parseShader(getShaderSource(name), sourceProvider(generatedSources), constants.with(type.stageDefine))));
|
||||||
return new GlShader(type, name, downgradeIfNeeded(type, defineStage(type, source)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String defineStage(ShaderType type, String source) {
|
|
||||||
int lineEnd = source.indexOf('\n') + 1;
|
|
||||||
return source.substring(0, lineEnd) + "#define " + type.stageDefine + "\n" + source.substring(lineEnd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Function<String, String> sourceProvider(Map<String, String> generatedSources) {
|
public static Function<String, String> sourceProvider(Map<String, String> generatedSources) {
|
||||||
|
|||||||
Reference in new issue
Block a user