internal IEnumerable <ASLShaderVariable> GetOutputs() { foreach (var field in _shader.Fields) { if (field.HasCustomAttributes) { var attrs = field.CustomAttributes.Where(a => a.AttributeType.IsOut() && !a.AttributeType.IsBuiltIn()); if (attrs.Count() > 0) { var attr = attrs.First(); var type = GLSL.ToGLSL(field.FieldType); var isArray = field.FieldType.IsArray; var arrayAttr = field.CustomAttributes.Where(a => a.AttributeType.Is <ArraySizeAttribute>()); var arraySize = (isArray && arrayAttr.Count() > 0 && arrayAttr.First().HasConstructorArguments) ? arrayAttr.First().ConstructorArguments.First().Value.ToString() : string.Empty; var name = field.Name; var commentAttr = field.CustomAttributes.Where(a => a.AttributeType.Is <CommentAttribute>()); var u_comment = (commentAttr.Count() > 0 && commentAttr.First().HasConstructorArguments) ? commentAttr.First().ConstructorArguments.First().Value.ToString() : string.Empty; var d_comment = DebugMode ? field.DeclaringType.FullName + "." + field.Name : string.Empty; var layoutAttr = (this is FragmentShader) ? field.CustomAttributes.Where(a => a.AttributeType.Is <FragmentShader.LayoutAttribute>()) : ((this is GeometryShader) ? field.CustomAttributes.Where(a => a.AttributeType.Is <GeometryShader.LayoutAttribute>()) : null); var layout = (layoutAttr != null && layoutAttr.Count() > 0) ? layoutAttr.First() : null; yield return(new ASLShaderVariable(type, isArray, arraySize, name, u_comment, d_comment, attr.AttributeType, layout)); } } } }
public static string ToGLSLParamType(ParameterDefinition p) { var t = GLSL.ToGLSL(p.ParameterType.Resolve()); if (p.ParameterType.IsByReference) { return((p.IsOut ? "out " : "inout ") + t); } return(t); }
internal static string GetSignature(MethodDefinition m) { var arraySize = string.Empty; if (m.ReturnType.IsArray && m.MethodReturnType.HasCustomAttributes) { var attr = m.MethodReturnType.CustomAttributes.Where(a => a.AttributeType.Is <ArraySizeAttribute>()).First(); arraySize = attr.ConstructorArguments.First().Value.ToString(); } return(GLSL.ToGLSL(m.ReturnType) + (m.ReturnType.IsArray ? "[" + arraySize + "]" : string.Empty) + " " + m.Name + "(" + GetParameterString(m) + ")"); }
internal IEnumerable <ASLShaderStruct> GetStructures() { foreach (var structure in _shader.NestedTypes) { var isInterfaceBlock = structure.HasCustomAttributes && structure.HasAttribute <InterfaceBlockAttribute>(); TypeReference interfaceBlockType = null; if (isInterfaceBlock) { var attrs = structure.CustomAttributes.Where(a => a.AttributeType.IsIn() || a.AttributeType.IsOut() || a.AttributeType.IsUniform()); if (attrs.Count() == 0) { throw new ASLException("ASL Error: An interface block have to have a qualifier which can be in, out or uniform."); } if (attrs.Count() > 1) { throw new ASLException("ASL Error: An interface block have to have only one qualifier, which can be in, out or uniform."); } interfaceBlockType = attrs.First().AttributeType; } List <ASLShaderVariable> fields = new List <ASLShaderVariable>(); foreach (var field in structure.Fields) { var type = GLSL.ToGLSL(field.FieldType); var isArray = field.FieldType.IsArray; var arrayAttr = field.CustomAttributes.Where(a => a.AttributeType.Is <ArraySizeAttribute>()); var arraySize = (isArray && arrayAttr.Count() > 0 && arrayAttr.First().HasConstructorArguments) ? arrayAttr.First().ConstructorArguments.First().Value.ToString() : string.Empty; var name = field.Name; var commentAttr = field.CustomAttributes.Where(a => a.AttributeType.Is <CommentAttribute>()); var u_comment = (commentAttr.Count() > 0 && commentAttr.First().HasConstructorArguments) ? commentAttr.First().ConstructorArguments.First().Value.ToString() : string.Empty; var d_comment = DebugMode ? field.DeclaringType.FullName + "." + field.Name : string.Empty; TypeReference attrType = null; if (isInterfaceBlock) { var attrs = field.CustomAttributes.Where(a => a.AttributeType.IsIn() || a.AttributeType.IsOut() || a.AttributeType.IsUniform()); if (attrs.Count() > 1) { throw new ASLException("ASL Error: An interface block member have to have only one qualifier, which can be in, out or uniform, according to the interface block qualifier."); } if (attrs.Count() > 0) { if ((interfaceBlockType.IsIn() && (attrs.First().AttributeType.IsOut() || attrs.First().AttributeType.IsUniform())) || (interfaceBlockType.IsUniform() && (attrs.First().AttributeType.IsOut() || attrs.First().AttributeType.IsIn())) || (interfaceBlockType.IsOut() && (attrs.First().AttributeType.IsIn() || attrs.First().AttributeType.IsUniform()))) { throw new ASLException("ASL Error: An interface block member have to have (if he has one) a similar qualifier than the interface block."); } attrType = attrs.First().AttributeType; } } var varLayoutAttr = (this is VertexShader) ? field.CustomAttributes.Where(a => a.AttributeType.Is <VertexShader.LayoutAttribute>()) : ((this is FragmentShader) ? field.CustomAttributes.Where(a => a.AttributeType.Is <FragmentShader.LayoutAttribute>()) : ((this is GeometryShader) ? field.CustomAttributes.Where(a => a.AttributeType.Is <GeometryShader.LayoutAttribute>()) : null)); var varLayout = (varLayoutAttr != null && varLayoutAttr.Count() > 0) ? varLayoutAttr.First() : null; fields.Add(new ASLShaderVariable(type, isArray, arraySize, name, u_comment, d_comment, attrType, varLayout)); } var layoutAttr = (this is VertexShader) ? structure.CustomAttributes.Where(a => a.AttributeType.Is <VertexShader.LayoutAttribute>()) : ((this is FragmentShader) ? structure.CustomAttributes.Where(a => a.AttributeType.Is <FragmentShader.LayoutAttribute>()) : ((this is GeometryShader) ? structure.CustomAttributes.Where(a => a.AttributeType.Is <GeometryShader.LayoutAttribute>()) : null)); var layout = (layoutAttr != null && layoutAttr.Count() > 0) ? layoutAttr.First() : null; yield return(new ASLShaderStruct(structure.Name, isInterfaceBlock, interfaceBlockType, fields, layout)); } }
public override StringBuilder VisitMemberType(MemberType memberType, int data) { return(new StringBuilder(GLSL.ToGLSL(memberType.Annotation <TypeReference>()))); }
public static void ValidateType(TypeReference t) { GLSL.ToGLSL(t); // throws if t is not valid }