material: warn / ignore fixed function techniques

This commit is contained in:
Kirill Vainer 2016-04-10 12:16:35 -04:00
parent b6729c46d4
commit 8bd5b59a0e
3 changed files with 33 additions and 9 deletions

View File

@ -134,13 +134,12 @@ public class TechniqueDef implements Savable {
* <p> * <p>
* Used internally by the J3M/J3MD loader. * Used internally by the J3M/J3MD loader.
* *
* @param name The name of the technique, should be set to <code>null</code> * @param name The name of the technique
* for default techniques.
*/ */
public TechniqueDef(String name, int sortId){ public TechniqueDef(String name, int sortId){
this(); this();
this.sortId = sortId; this.sortId = sortId;
this.name = name == null ? TechniqueDef.DEFAULT_TECHNIQUE_NAME : name; this.name = name;
} }
/** /**

View File

@ -591,17 +591,18 @@ public class J3MLoader implements AssetLoader {
isUseNodes = false; isUseNodes = false;
String[] split = techStat.getLine().split(whitespacePattern); String[] split = techStat.getLine().split(whitespacePattern);
String name;
if (split.length == 1) { if (split.length == 1) {
String techniqueUniqueName = materialDef.getAssetName() + "@Default"; name = TechniqueDef.DEFAULT_TECHNIQUE_NAME;
technique = new TechniqueDef(null, techniqueUniqueName.hashCode());
} else if (split.length == 2) { } else if (split.length == 2) {
String techName = split[1]; name = split[1];
String techniqueUniqueName = materialDef.getAssetName() + "@" + techName;
technique = new TechniqueDef(techName, techniqueUniqueName.hashCode());
} else { } else {
throw new IOException("Technique statement syntax incorrect"); throw new IOException("Technique statement syntax incorrect");
} }
String techniqueUniqueName = materialDef.getAssetName() + "@" + name;
technique = new TechniqueDef(name, techniqueUniqueName.hashCode());
for (Statement statement : techStat.getContents()){ for (Statement statement : techStat.getContents()){
readTechniqueStatement(statement); readTechniqueStatement(statement);
} }
@ -619,6 +620,15 @@ public class J3MLoader implements AssetLoader {
if (shaderNames.containsKey(Shader.ShaderType.Vertex) && shaderNames.containsKey(Shader.ShaderType.Fragment)) { if (shaderNames.containsKey(Shader.ShaderType.Vertex) && shaderNames.containsKey(Shader.ShaderType.Fragment)) {
technique.setShaderFile(shaderNames, shaderLanguages); technique.setShaderFile(shaderNames, shaderLanguages);
} else {
technique = null;
shaderLanguages.clear();
shaderNames.clear();
presetDefines.clear();
logger.log(Level.WARNING, "Fixed function technique was ignored");
logger.log(Level.WARNING, "Fixed function technique ''{0}'' was ignored for material {1}",
new Object[]{name, key});
return;
} }
technique.setShaderPrologue(createShaderPrologue(presetDefines)); technique.setShaderPrologue(createShaderPrologue(presetDefines));

View File

@ -55,6 +55,21 @@ public class J3MLoaderTest {
j3MLoader = new J3MLoader(); j3MLoader = new J3MLoader();
} }
@Test
public void noDefaultTechnique_shouldBeSupported() throws IOException {
when(assetInfo.openStream()).thenReturn(J3MLoader.class.getResourceAsStream("/no-default-technique.j3md"));
MaterialDef def = (MaterialDef) j3MLoader.load(assetInfo);
assertEquals(1, def.getTechniqueDefs("Test").size());
}
@Test
public void fixedPipelineTechnique_shouldBeIgnored() throws IOException {
when(assetInfo.openStream()).thenReturn(J3MLoader.class.getResourceAsStream("/no-shader-specified.j3md"));
MaterialDef def = (MaterialDef) j3MLoader.load(assetInfo);
assertEquals(null, def.getTechniqueDefs("A"));
assertEquals(1, def.getTechniqueDefs("B").size());
}
@Test @Test
public void multipleSameNamedTechniques_shouldBeSupported() throws IOException { public void multipleSameNamedTechniques_shouldBeSupported() throws IOException {
when(assetInfo.openStream()).thenReturn(J3MLoader.class.getResourceAsStream("/same-name-technique.j3md")); when(assetInfo.openStream()).thenReturn(J3MLoader.class.getResourceAsStream("/same-name-technique.j3md"));