public ShaderGeneratorResult GenerateShader() { if (result != null) { return(result); } CollectStructure(shaderType, shader); WriteTopLevelStructure(); result = new ShaderGeneratorResult(stringWriter.ToString()); GetEntryPoints(result, shaderType, GetBindingFlagsForType(shaderType)); ShaderAttribute?shaderAttribute = EntryPointAttributes.OfType <ShaderAttribute>().FirstOrDefault(); if (shaderAttribute != null && action != null && !action.Method.IsDefined(typeof(ShaderMemberAttribute))) { result.EntryPoints[shaderAttribute.Name] = AnonymousMethodEntryPointName; } return(result); }
public ShaderGeneratorResult GenerateShader() { if (result != null) { return(result); } var allMemberInfos = shaderType.GetMembersInTypeHierarchyInOrder(GetBindingFlagsForType(shaderType)); var memberInfos = allMemberInfos.Where(m => !(m is MethodInfo)); // Collecting stage foreach (MemberInfo memberInfo in memberInfos) { Type?memberType = memberInfo.GetMemberType(shader); if (memberType != null) { CollectStructure(memberType, memberInfo.GetMemberValue(shader)); } } CollectStructure(shaderType, shader); // Writing stage foreach (ShaderTypeDefinition type in collectedTypes) { WriteStructure(type.Type, type.Instance); } foreach (MemberInfo memberInfo in memberInfos) { Type?memberType = memberInfo.GetMemberType(shader); ShaderMemberAttribute?resourceType = memberInfo.GetResourceAttribute(memberType); if (memberType != null && resourceType != null) { WriteResource(memberInfo.Name, memberType, resourceType); } } foreach (Type type in shaderType.GetBaseTypes().Reverse()) { WriteStructure(type, shader); } foreach (MethodInfo methodInfo in shaderType.GetMethods(GetBindingFlagsForType(shaderType)) .Where(m => m.IsDefined(typeof(ShaderMemberAttribute))) .OrderBy(m => m.GetCustomAttribute <ShaderMemberAttribute>()?.Order)) { WriteMethod(methodInfo, null, null, true); } if (action != null && !action.Method.IsDefined(typeof(ShaderMemberAttribute))) { WriteMethod(action.Method, EntryPointAttributes, AnonymousMethodEntryPointName, true); } stringWriter.GetStringBuilder().TrimEnd(); writer.WriteLine(); result = new ShaderGeneratorResult(stringWriter.ToString()); GetEntryPoints(result, shaderType, GetBindingFlagsForType(shaderType)); ShaderAttribute?shaderAttribute = EntryPointAttributes.OfType <ShaderAttribute>().FirstOrDefault(); if (shaderAttribute != null && action != null && !action.Method.IsDefined(typeof(ShaderMemberAttribute))) { result.EntryPoints[shaderAttribute.Name] = AnonymousMethodEntryPointName; } return(result); }