use of com.jme3.shader.VariableMapping in project jmonkeyengine by jMonkeyEngine.
the class ShaderNodeLoaderDelegate method updateRightFromUniforms.
/**
* updates the right variable of the given mapping from a MatParam (a
* WorldParam) it checks if the uniform hasn't already been loaded, add it
* to the maps if not.
*
* @param param the MatParam
* @param mapping the mapping
* @param map the map of uniforms to search into
* @return true if the param was added to the map
*/
public boolean updateRightFromUniforms(MatParam param, VariableMapping mapping, Map<String, DeclaredVariable> map, Statement statement) throws MatParseException {
ShaderNodeVariable right = mapping.getRightVariable();
DeclaredVariable dv = map.get(param.getPrefixedName());
if (dv == null) {
right.setType(param.getVarType().getGlslType());
right.setName(param.getPrefixedName());
if (mapping.getLeftVariable().getMultiplicity() != null) {
if (!param.getVarType().name().endsWith("Array")) {
throw new MatParseException(param.getName() + " is not of Array type", statement);
}
String multiplicity = mapping.getLeftVariable().getMultiplicity();
try {
Integer.parseInt(multiplicity);
} catch (NumberFormatException nfe) {
//multiplicity is not an int attempting to find for a material parameter.
MatParam mp = findMatParam(multiplicity);
if (mp != null) {
addDefine(multiplicity, VarType.Int);
multiplicity = multiplicity.toUpperCase();
} else {
throw new MatParseException("Wrong multiplicity for variable" + mapping.getLeftVariable().getName() + ". " + multiplicity + " should be an int or a declared material parameter.", statement);
}
}
right.setMultiplicity(multiplicity);
}
dv = new DeclaredVariable(right);
map.put(right.getName(), dv);
dv.addNode(shaderNode);
mapping.setRightVariable(right);
return true;
}
dv.addNode(shaderNode);
mapping.setRightVariable(dv.var);
return false;
}
Aggregations