define the shader stage in shaders built by ShaderLoader #50

Merged
embeddedt merged 2 commits from rdh/celeritas:shader-stage-defines into stonecutter 2026-11-17 19:28:21 -05:00
2 changed files with 7 additions and 7 deletions
Showing only changes of commit c48d3834e0 - Show all commits

No files matched your search

@@ -15,6 +15,12 @@ public class ShaderConstants {
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() {
return new Builder();
}
@@ -34,13 +34,7 @@ public class ShaderLoader {
* resolve to the given source instead of the classpath.
*/
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, 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);
return new GlShader(type, name, downgradeIfNeeded(type, ShaderParser.parseShader(getShaderSource(name), sourceProvider(generatedSources), constants.with(type.stageDefine))));
}
public static Function<String, String> sourceProvider(Map<String, String> generatedSources) {
1