/** * returns the shaderpath index according to the version of the generator. * This allow to select the higher version of the shader that the generator * can handle * * @param shaderNode the shaderNode being processed * @param type the shaderType * @return the index of the shader path in ShaderNodeDefinition shadersPath * list * @throws NumberFormatException */ protected int findShaderIndexFromVersion(ShaderNode shaderNode, ShaderType type) throws NumberFormatException { int index = 0; List<String> lang = shaderNode.getDefinition().getShadersLanguage(); int genVersion = Integer.parseInt(getLanguageAndVersion(type).substring(4)); int curVersion = 0; for (int i = 0; i < lang.size(); i++) { int version = Integer.parseInt(lang.get(i).substring(4)); if (version > curVersion && version <= genVersion) { curVersion = version; index = i; } } return index; } }
/** * Generate vertex and fragment shaders for the given technique * * @return a Shader program */ public Shader generateShader(String definesSourceCode) { if (techniqueDef == null) { throw new UnsupportedOperationException("The shaderGenerator was not " + "properly initialized, call " + "initialize(TechniqueDef) before any generation"); } String techniqueName = techniqueDef.getName(); ShaderGenerationInfo info = techniqueDef.getShaderGenerationInfo(); Shader shader = new Shader(); for (ShaderType type : ShaderType.values()) { String extension = type.getExtension(); String language = getLanguageAndVersion(type); String shaderSourceCode = buildShader(techniqueDef.getShaderNodes(), info, type); if (shaderSourceCode != null) { String shaderSourceAssetName = techniqueName + "." + extension; shader.addSource(type, shaderSourceAssetName, shaderSourceCode, definesSourceCode, language); } } techniqueDef = null; return shader; }
/** * returns the shaderpath index according to the version of the generator. * This allow to select the higher version of the shader that the generator * can handle * * @param shaderNode the shaderNode being processed * @param type the shaderType * @return the index of the shader path in ShaderNodeDefinition shadersPath * list * @throws NumberFormatException */ protected int findShaderIndexFromVersion(ShaderNode shaderNode, ShaderType type) throws NumberFormatException { int index = 0; List<String> lang = shaderNode.getDefinition().getShadersLanguage(); int genVersion = Integer.parseInt(getLanguageAndVersion(type).substring(4)); int curVersion = 0; for (int i = 0; i < lang.size(); i++) { int version = Integer.parseInt(lang.get(i).substring(4)); if (version > curVersion && version <= genVersion) { curVersion = version; index = i; } } return index; } }
/** * Generate vertex and fragment shaders for the given technique * * @return a Shader program */ public Shader generateShader(String definesSourceCode) { if (techniqueDef == null) { throw new UnsupportedOperationException("The shaderGenerator was not " + "properly initialized, call " + "initialize(TechniqueDef) before any generation"); } String techniqueName = techniqueDef.getName(); ShaderGenerationInfo info = techniqueDef.getShaderGenerationInfo(); Shader shader = new Shader(); for (ShaderType type : ShaderType.values()) { String extension = type.getExtension(); String language = getLanguageAndVersion(type); String shaderSourceCode = buildShader(techniqueDef.getShaderNodes(), info, type); if (shaderSourceCode != null) { String shaderSourceAssetName = techniqueName + "." + extension; shader.addSource(type, shaderSourceAssetName, shaderSourceCode, definesSourceCode, language); } } techniqueDef = null; return shader; }