/** * return the cardinality of a type and a swizzle example : vec4 cardinality * is 4 float cardinality is 1 vec4.xyz cardinality is 3. sampler2D * cardinality is 0 * * @param type the glsl type * @param swizzling the swizzling of a variable * @return the cardinality */ public static int getCardinality(String type, String swizzling) { int card = 0; if (isSwizzlable(type)) { if (type.equals("float")) { card = 1; if (swizzling.length() != 0) { card = 0; } } else { card = Integer.parseInt(type.replaceAll(".*vec", "")); if (swizzling.length() > 0) { card = swizzling.length(); } } } return card; }
/** * 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; }
/** * return the cardinality of a type and a swizzle example : vec4 cardinality * is 4 float cardinality is 1 vec4.xyz cardinality is 3. sampler2D * cardinality is 0 * * @param type the glsl type * @param swizzling the swizzling of a variable * @return the cardinality */ public static int getCardinality(String type, String swizzling) { int card = 0; if (isSwizzlable(type)) { if (type.equals("float")) { card = 1; if (swizzling.length() != 0) { card = 0; } } else { card = Integer.parseInt(type.replaceAll(".*vec", "")); if (swizzling.length() > 0) { card = swizzling.length(); } } } return card; }
/** * 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; }