|
|
@ -80,6 +80,7 @@ public class GLSLLoader implements AssetLoader { |
|
|
|
ShaderDependencyNode node = new ShaderDependencyNode(nodeName); |
|
|
|
ShaderDependencyNode node = new ShaderDependencyNode(nodeName); |
|
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
|
|
|
|
StringBuilder sbExt = new StringBuilder(); |
|
|
|
BufferedReader bufReader = null; |
|
|
|
BufferedReader bufReader = null; |
|
|
|
try { |
|
|
|
try { |
|
|
|
bufReader = new BufferedReader(reader); |
|
|
|
bufReader = new BufferedReader(reader); |
|
|
@ -108,6 +109,8 @@ public class GLSLLoader implements AssetLoader { |
|
|
|
|
|
|
|
|
|
|
|
node.addDependency(sb.length(), dependNode); |
|
|
|
node.addDependency(sb.length(), dependNode); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else if (ln.trim().startsWith("#extension ")) { |
|
|
|
|
|
|
|
sbExt.append(ln).append('\n'); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
sb.append(ln).append('\n'); |
|
|
|
sb.append(ln).append('\n'); |
|
|
|
} |
|
|
|
} |
|
|
@ -126,6 +129,7 @@ public class GLSLLoader implements AssetLoader { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
node.setSource(sb.toString()); |
|
|
|
node.setSource(sb.toString()); |
|
|
|
|
|
|
|
node.setExtensions(sbExt.toString()); |
|
|
|
dependCache.put(nodeName, node); |
|
|
|
dependCache.put(nodeName, node); |
|
|
|
return node; |
|
|
|
return node; |
|
|
|
} |
|
|
|
} |
|
|
@ -151,19 +155,23 @@ public class GLSLLoader implements AssetLoader { |
|
|
|
throw new IOException("Circular dependency."); |
|
|
|
throw new IOException("Circular dependency."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String resolveDependencies(ShaderDependencyNode node, Set<ShaderDependencyNode> alreadyInjectedSet) { |
|
|
|
private String resolveDependencies(ShaderDependencyNode node, Set<ShaderDependencyNode> alreadyInjectedSet, StringBuilder extensions) { |
|
|
|
if (alreadyInjectedSet.contains(node)) { |
|
|
|
if (alreadyInjectedSet.contains(node)) { |
|
|
|
return "// " + node.getName() + " was already injected at the top.\n"; |
|
|
|
return "// " + node.getName() + " was already injected at the top.\n"; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
alreadyInjectedSet.add(node); |
|
|
|
alreadyInjectedSet.add(node); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!node.getExtensions().isEmpty()) { |
|
|
|
|
|
|
|
extensions.append(node.getExtensions()); |
|
|
|
|
|
|
|
} |
|
|
|
if (node.getDependencies().isEmpty()) { |
|
|
|
if (node.getDependencies().isEmpty()) { |
|
|
|
return node.getSource(); |
|
|
|
return node.getSource(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
StringBuilder sb = new StringBuilder(node.getSource()); |
|
|
|
StringBuilder sb = new StringBuilder(node.getSource()); |
|
|
|
List<String> resolvedShaderNodes = new ArrayList<String>(); |
|
|
|
List<String> resolvedShaderNodes = new ArrayList<String>(); |
|
|
|
|
|
|
|
|
|
|
|
for (ShaderDependencyNode dependencyNode : node.getDependencies()) { |
|
|
|
for (ShaderDependencyNode dependencyNode : node.getDependencies()) { |
|
|
|
resolvedShaderNodes.add( resolveDependencies(dependencyNode, alreadyInjectedSet) ); |
|
|
|
resolvedShaderNodes.add(resolveDependencies(dependencyNode, alreadyInjectedSet, extensions)); |
|
|
|
} |
|
|
|
} |
|
|
|
List<Integer> injectIndices = node.getDependencyInjectIndices(); |
|
|
|
List<Integer> injectIndices = node.getDependencyInjectIndices(); |
|
|
|
for (int i = resolvedShaderNodes.size() - 1; i >= 0; i--) { |
|
|
|
for (int i = resolvedShaderNodes.size() - 1; i >= 0; i--) { |
|
|
@ -185,9 +193,11 @@ public class GLSLLoader implements AssetLoader { |
|
|
|
return reader; |
|
|
|
return reader; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ShaderDependencyNode rootNode = loadNode(reader, "[main]"); |
|
|
|
ShaderDependencyNode rootNode = loadNode(reader, "[main]"); |
|
|
|
String code = resolveDependencies(rootNode, new HashSet<ShaderDependencyNode>()); |
|
|
|
StringBuilder extensions = new StringBuilder(); |
|
|
|
|
|
|
|
String code = resolveDependencies(rootNode, new HashSet<ShaderDependencyNode>(), extensions); |
|
|
|
|
|
|
|
extensions.append(code); |
|
|
|
dependCache.clear(); |
|
|
|
dependCache.clear(); |
|
|
|
return code; |
|
|
|
return extensions.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|