Example #1
0
    static void GenerateSampler(StringBuilder sb, VeldridMemberInfo member, GenerationContext context)
    {
        if (member.Symbol is not IFieldSymbol field)
        {
            context.Report($"Resource set backing members must be fields (member {member.Symbol.ToDisplayString()} in " +
                           $"{member.Symbol.ContainingType.ToDisplayString()} was a {member.Symbol.GetType().Name})");
            return;
        }

        /* e.g.
         * public SamplerHolder Sampler
         * {
         * get => _sampler;
         * set
         * {
         *  if (_sampler == value) return;
         *  if (_sampler != null) _sampler.PropertyChanged -= PropertyDirty;
         *  _sampler = value;
         *  if (_sampler != null) _sampler.PropertyChanged += PropertyDirty;
         *  Dirty();
         * }
         * } */
        var propertyName = VeldridGenUtil.UnderscoreToTitleCase(field.Name);

        sb.AppendLine($@"        public {field.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)} {propertyName}
        {{
            get => {field.Name};
            set
            {{
                if ({field.Name} == value) 
                    return;

                if ({field.Name} != null)
                    {field.Name}.PropertyChanged -= PropertyDirty;

                {field.Name} = value;

                if ({field.Name} != null)
                    {field.Name}.PropertyChanged += PropertyDirty;
                Dirty();
            }}
        }}
");
    }
Example #2
0
    static void GenerateUniform(StringBuilder sb, VeldridMemberInfo member, GenerationContext context)
    {
        if (member.Symbol is not IFieldSymbol field)
        {
            context.Report($"Resource set backing members must be fields (member {member.Symbol.ToDisplayString()} in " +
                           $"{member.Symbol.ContainingType.ToDisplayString()} was a {member.Symbol.GetType().Name})");
            return;
        }

        /* e.g.
         * public SingleBuffer<GlobalInfo> GlobalInfo
         * {
         *  get => _globalInfo;
         *  set
         *  {
         *      if (_globalInfo == value)
         *          return;
         *      _globalInfo = value;
         *      Dirty();
         *  }
         * }*/
        var propertyName = VeldridGenUtil.UnderscoreToTitleCase(field.Name);

        sb.AppendLine($@"        public {field.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)} {propertyName}
        {{
            get => {field.Name};
            set
            {{
                if ({field.Name} == value)
                    return;
                {field.Name} = value;
                Dirty();
            }}
        }}
");
    }