private void assertEqualsVariableMapping(VariableMapping im1, VariableMapping im2) { assertEquals(im1.getCondition(), im2.getCondition()); assertEquals(im1.getLeftSwizzling(), im2.getLeftSwizzling()); assertEquals(im1.getRightSwizzling(), im2.getRightSwizzling()); assertEqualsVariables(im1.getRightVariable(), im2.getRightVariable()); assertEqualsVariables(im1.getLeftVariable(), im2.getLeftVariable()); }
VariableMapping mapping = new VariableMapping(); String[] cond = statement.getLine().split(":"); String[] vars = cond[0].split("="); mapping.setLeftVariable(variables[0]); mapping.setLeftSwizzling(swizzle[0] != null ? swizzle[0] : ""); mapping.setRightExpression(rightExpression); } else { mapping.setRightVariable(variables[1]); mapping.setRightSwizzling(swizzle[1] != null ? swizzle[1] : ""); mapping.setCondition(conditionParser.getFormattedExpression());
@Override public ShaderNode clone() throws CloneNotSupportedException { ShaderNode clone = (ShaderNode) super.clone(); // No need to clone the definition. clone.definition = definition; clone.inputMapping = new ArrayList<>(); for (VariableMapping variableMapping : inputMapping) { clone.inputMapping.add(variableMapping.clone()); } clone.outputMapping = new ArrayList<>(); for (VariableMapping variableMapping : outputMapping) { clone.outputMapping.add(variableMapping.clone()); } return clone; } }
/** * Updates the type of the right variable of a mapping from the type of the * left variable. * * @param mapping the mapping to consider. */ protected void updateRightTypeFromLeftType(VariableMapping mapping) { String type = mapping.getLeftVariable().getType(); int card = ShaderUtils.getCardinality(type, mapping.getRightSwizzling()); if (card > 0) { if (card == 1) { type = "float"; } else { type = "vec" + card; } } mapping.getRightVariable().setType(type); }
/** * check the types of a mapping, left type must match right type take the * swizzle into account * * @param mapping the mapping * @param statement1 the statement being read * @throws MatParseException */ protected void checkTypes(VariableMapping mapping, Statement statement1) throws MatParseException { if (!ShaderUtils.typesMatch(mapping)) { String ls = mapping.getLeftSwizzling().length() == 0 ? "" : "." + mapping.getLeftSwizzling(); String rs = mapping.getRightSwizzling().length() == 0 ? "" : "." + mapping.getRightSwizzling(); throw new MatParseException("Type mismatch, cannot convert " + mapping.getRightVariable().getType() + rs + " to " + mapping.getLeftVariable().getType() + ls, statement1); } if (!ShaderUtils.multiplicityMatch(mapping)) { String type1 = mapping.getLeftVariable().getType() + "[" + mapping.getLeftVariable().getMultiplicity() + "]"; String type2 = mapping.getRightVariable().getType() + "[" + mapping.getRightVariable().getMultiplicity() + "]"; throw new MatParseException("Type mismatch, cannot convert " + type1 + " to " + type2, statement1); } }
/** * Check if a mapping is valid by checking the multiplicity of both of * the variables if they are arrays * * @param mapping the mapping * @return true if this mapping is valid */ public static boolean multiplicityMatch(VariableMapping mapping) { String leftMult = mapping.getLeftVariable().getMultiplicity(); String rightMult = mapping.getRightVariable().getMultiplicity(); if(leftMult == null){ if(rightMult != null){ return false; } }else{ if(rightMult == null){ return false; }else{ if(!leftMult.equalsIgnoreCase(rightMult)){ return false; } } } return true; }
Statement statement) throws MatParseException { final ShaderNodeVariable left = mapping.getLeftVariable(); final ShaderNodeVariable right = mapping.getRightVariable(); map.put(right.getName(), dv); dv.addNode(shaderNode); mapping.setRightVariable(right); return true; mapping.setRightVariable(dv.var);
final ShaderNodeVariable left = mapping.getLeftVariable(); final ShaderNodeVariable right = mapping.getRightVariable(); final String expression = mapping.getRightExpression(); throw new MatParseException("Cannot have an attribute as input in a fragment shader" + right.getName(), statement); updateVarFromAttributes(mapping.getRightVariable(), mapping); storeAttribute(mapping.getRightVariable()); } else if (right.getNameSpace().equals(ShaderGenerator.NAME_SPACE_MAT_PARAM)) { if (updateRightFromUniforms(param, mapping, vertexDeclaredUniforms, statement)) { updateMaterialTextureType(statement, mapping, left, param); storeVertexUniform(mapping.getRightVariable()); storeFragmentUniform(mapping.getRightVariable()); storeVertexUniform(mapping.getRightVariable()); storeFragmentUniform(mapping.getRightVariable()); right.setMultiplicity(var.getMultiplicity()); mapping.setRightVariable(right); storeVaryings(node, mapping.getRightVariable());
for (String param : params) { for (VariableMapping map : shaderNode.getInputMapping()) { if ((map.getLeftVariable().getName()).equals(param)) { if (map.getCondition() != null) { l = l.replaceAll(param, map.getCondition()); match = true;
/** * Updates the material texture type of the variable mapping. * * @param statement the statement. * @param mapping the variable mapping. * @param left the left variable. * @param param the material parameter. * @throws MatParseException if the texture type isn't valid. */ private void updateMaterialTextureType(final Statement statement, final VariableMapping mapping, final ShaderNodeVariable left, final MatParam param) throws MatParseException { if (!mapping.getRightVariable().getType().contains("|")) { return; } final String type = fixSamplerType(left.getType(), mapping.getRightVariable().getType()); if (type != null) { mapping.getRightVariable().setType(type); } else { throw new MatParseException(param.getVarType().toString() + " can only be matched to one of " + param.getVarType().getGlslType().replaceAll("\\|", ",") + " found " + left.getType(), statement); } }
/** * updates the right variable of the given mapping from a UniformBinding (a * WorldParam) it checks if the uniform hasn't already been loaded, add it * to the maps if not. * * @param param the WorldParam UniformBinding * @param mapping the mapping * @param map the map of uniforms to search into * @return true if the param was added to the map */ protected boolean updateRightFromUniforms(UniformBinding param, VariableMapping mapping, Map<String, DeclaredVariable> map) { ShaderNodeVariable right = mapping.getRightVariable(); String name = param.toString(); DeclaredVariable dv = map.get(name); if (dv == null) { right.setType(param.getGlslType()); right.setName(name); right.setPrefix("g_"); 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; }
final ShaderNodeVariable leftVariable = variableMapping.getLeftVariable(); if (leftVariable.getName().equals(variable.getName())) { leftVariable.setShaderOutput(true);
final ShaderNodeVariable left = mapping.getLeftVariable(); final ShaderNodeVariable right = mapping.getRightVariable();
/** * updates the type of the right variable of a mapping from the type of the * left variable * * @param mapping the mapping to consider */ protected void updateRightTypeFromLeftType(VariableMapping mapping) { String type = mapping.getLeftVariable().getType(); int card = ShaderUtils.getCardinality(type, mapping.getRightSwizzling()); if (card > 0) { if (card == 1) { type = "float"; } else { type = "vec" + card; } } mapping.getRightVariable().setType(type); }
ShaderNodeVariable right = mapping.getRightVariable(); DeclaredVariable dv = map.get(param.getName()); if (dv == null) { right.setName(param.getName()); right.setPrefix("m_"); 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); mapping.getLeftVariable().setMultiplicity(multiplicity); mapping.getLeftVariable().setCondition(mergeConditions(mapping.getLeftVariable().getCondition(), "defined(" + multiplicity + ")", "||")); } else { throw new MatParseException("Wrong multiplicity for variable" + mapping.getLeftVariable().getName() + ". " + multiplicity + " should be an int or a declared material parameter.", statement); right.setCondition(mapping.getLeftVariable().getCondition()); mapping.setRightVariable(right); return true; mapping.setRightVariable(dv.var); return false;
for (String param : params) { for (VariableMapping map : shaderNode.getInputMapping()) { if ((map.getLeftVariable().getName()).equals(param)) { if (map.getCondition() != null) { l = l.replaceAll(param, map.getCondition()); match = true;
final ShaderNodeVariable rightVariable = mapping.getRightVariable(); if (rightVariable != null) { unusedNodes.remove(rightVariable.getNameSpace());
/** * updates the right variable of the given mapping from a UniformBinding (a * WorldParam) it checks if the uniform hasn't already been loaded, add it * to the maps if not. * * @param param the WorldParam UniformBinding * @param mapping the mapping * @param map the map of uniforms to search into * @return true if the param was added to the map */ protected boolean updateRightFromUniforms(UniformBinding param, VariableMapping mapping, Map<String, DeclaredVariable> map) { ShaderNodeVariable right = mapping.getRightVariable(); String name = param.toString(); DeclaredVariable dv = map.get(name); if (dv == null) { right.setType(param.getGlslType()); right.setName(name); right.setPrefix("g_"); 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; }
final ShaderNodeVariable leftVariable = variableMapping.getLeftVariable(); if (leftVariable.getName().equals(variable.getName())) { leftVariable.setShaderOutput(true);
final ShaderNodeVariable rightVariable = mapping.getRightVariable(); final ShaderNodeVariable leftVariable = mapping.getLeftVariable();