@Override public String toString() { final StringBuilder builder = new StringBuilder(leftVariable.toString()); if (!leftSwizzling.isEmpty()) { builder.append('.').append(leftSwizzling); } builder.append(" = "); if (rightVariable != null) { builder.append(rightVariable.getType()) .append(' ') .append(rightVariable.getNameSpace()) .append('.') .append(rightVariable.getName()); if (!rightSwizzling.isEmpty()) { builder.append('.').append(rightSwizzling); } } else if (rightExpression != null) { builder.append(rightExpression); } if (condition != null && !condition.isEmpty()) { builder.append(" : ").append(condition); } return builder.toString(); }
/** * declare and assign the global position in the vertex shader. * @param info the shader generation info * @param source the shader source being generated */ protected void declareGlobalPosition(ShaderGenerationInfo info, StringBuilder source) { if(inPosTmp.getType().equals(info.getVertexGlobal().getType())){ declareVariable(source, info.getVertexGlobal(), "inPosition"); }else{ declareVariable(source, info.getVertexGlobal(), "vec4(inPosition,1.0)"); } } }
/** * 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); } }
/** * 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; }
source.append(var.getType()); source.append(" "); if (appendNameSpace) {
/** * 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); } }
/** * 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); }
/** * Searches a variable in the given list and updates its type and namespace. * * @param var the variable to update. * @param list the variables list. * @return true if the variable has been found and updated. */ protected boolean updateVariableFromList(ShaderNodeVariable var, List<ShaderNodeVariable> list) { for (ShaderNodeVariable shaderNodeVariable : list) { if (shaderNodeVariable.getName().equals(var.getName())) { var.setType(shaderNodeVariable.getType()); var.setMultiplicity(shaderNodeVariable.getMultiplicity()); var.setNameSpace(shaderNode.getName()); return true; } } return false; }
if (var.getType().startsWith("sampler")) { continue; final ShaderNodeVariable variable = new ShaderNodeVariable(var.getType(), shaderNode.getName(), var.getName(), var.getMultiplicity()); if (rightVariable != null && isWorldOrMaterialParam(rightVariable) && rightVariable.getType().startsWith("sampler")) { nodeSource = replace(nodeSource, leftVariable, rightVariable.getPrefix() + rightVariable.getName()); } else { if (leftVariable.getType().startsWith("sampler")) { throw new IllegalArgumentException("a Sampler must be a uniform"); ShaderNodeVariable v = new ShaderNodeVariable(var.getType(), shaderNode.getName(), var.getName(), var.getMultiplicity()); if (!declaredInputs.contains(shaderNode.getName() + "_" + var.getName())) { if (!isVarying(info, v)) {
private void assertEqualsVariables(ShaderNodeVariable v1, ShaderNodeVariable v2) { assertEquals(v1.getName(), v2.getName()); assertEquals(v1.getNameSpace(), v2.getNameSpace()); assertEquals(v1.getMultiplicity(), v2.getMultiplicity()); assertEquals(v1.getType(), v2.getType()); assertEquals(v1.getCondition(), v2.getCondition()); }
} else if (left.getType().startsWith("sampler") && (right == null || !right.getNameSpace().equals(ShaderGenerator.NAME_SPACE_MAT_PARAM))) { throw new MatParseException("Samplers can only be assigned to MatParams", statement); right.setType(var.getType()); right.setMultiplicity(var.getMultiplicity());
@Override public String toString() { return "\n{" + leftVariable.toString() + (leftSwizzling.length() > 0 ? ("." + leftSwizzling) : "") + " = " + rightVariable.getType() + " " + rightVariable.getNameSpace() + "." + rightVariable.getName() + (rightSwizzling.length() > 0 ? ("." + rightSwizzling) : "") + " : " + condition + "}"; }
/** * declare and assign the global position in the vertex shader. * @param info the shader generation info * @param source the shader source being generated */ protected void declareGlobalPosition(ShaderGenerationInfo info, StringBuilder source) { if(inPosTmp.getType().equals(info.getVertexGlobal().getType())){ declareVariable(source, info.getVertexGlobal(), "inPosition"); }else{ declareVariable(source, info.getVertexGlobal(), "vec4(inPosition,1.0)"); } } }
/** * 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); } }
/** * 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); }
/** * search a variable in the given list and updates its type and namespace * * @param var the variable to update * @param list the variables list * @return true if the variable has been found and updated */ protected boolean updateVariableFromList(ShaderNodeVariable var, List<ShaderNodeVariable> list) { for (ShaderNodeVariable shaderNodeVariable : list) { if (shaderNodeVariable.getName().equals(var.getName())) { var.setType(shaderNodeVariable.getType()); var.setMultiplicity(shaderNodeVariable.getMultiplicity()); var.setNameSpace(shaderNode.getName()); return true; } } return false; }