/** * Check if a mapping is valid by checking the types and swizzle of both of * the variables * * @param mapping the mapping * @return true if this mapping is valid */ public static boolean typesMatch(VariableMapping mapping) { String leftType = mapping.getLeftVariable().getType(); String rightType = mapping.getRightVariable().getType(); String leftSwizzling = mapping.getLeftSwizzling(); String rightSwizzling = mapping.getRightSwizzling(); //types match : no error if (leftType.equals(rightType) && leftSwizzling.length() == rightSwizzling.length()) { return true; } if (isSwizzlable(leftType) && isSwizzlable(rightType)) { if (getCardinality(leftType, leftSwizzling) == getCardinality(rightType, rightSwizzling)) { return true; } } return false; }
/** * 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 if a mapping is valid by checking the types and swizzle of both of * the variables * * @param mapping the mapping * @return true if this mapping is valid */ public static boolean typesMatch(VariableMapping mapping) { String leftType = mapping.getLeftVariable().getType(); String rightType = mapping.getRightVariable().getType(); String leftSwizzling = mapping.getLeftSwizzling(); String rightSwizzling = mapping.getRightSwizzling(); //types match : no error if (leftType.equals(rightType) && leftSwizzling.length() == rightSwizzling.length()) { return true; } if (isSwizzlable(leftType) && isSwizzlable(rightType)) { if (getCardinality(leftType, leftSwizzling) == getCardinality(rightType, rightSwizzling)) { return true; } } return false; }
/** * 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); }