Search in sources :

Example 11 with VariableMapping

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;
}
Also used : MatParam(com.jme3.material.MatParam) ShaderNodeVariable(com.jme3.shader.ShaderNodeVariable)

Aggregations

VariableMapping (com.jme3.shader.VariableMapping)6 ShaderNodeVariable (com.jme3.shader.ShaderNodeVariable)5 AssetNotFoundException (com.jme3.asset.AssetNotFoundException)2 MatParam (com.jme3.material.MatParam)2 ShaderNode (com.jme3.shader.ShaderNode)2 IOException (java.io.IOException)2 InputCapsule (com.jme3.export.InputCapsule)1 OutputCapsule (com.jme3.export.OutputCapsule)1 ConditionParser (com.jme3.material.plugins.ConditionParser)1 ShaderNodeDefinition (com.jme3.shader.ShaderNodeDefinition)1 UniformBinding (com.jme3.shader.UniformBinding)1 Statement (com.jme3.util.blockparser.Statement)1