mellinoe / ShaderGen

Proof-of-concept library for generating HLSL, GLSL, and Metal shader code from C#,
MIT License
497 stars 56 forks source link

[Enhancement] Support constructor invocation on structs #72

Open thargy opened 6 years ago

thargy commented 6 years ago

For example:

    public struct SimpleConstructedStruct
    {
        public readonly float OutFloat;

        public SimpleConstructedStruct(float outFloat)
        {
            OutFloat = outFloat;
        }
    }

...
    SimpleConstructedStruct s = new SimpleConstructedStruct(1.0f);

Should become:

    struct SimpleConstructedStruct
    {
        float OutFloat;
    };

    SimpleConstructedStruct_0_ctor(float outFloat)
    {
        SimpleConsructedStruct this;
        this.OutFloat = outFloat;
        return this;
    }

...
    SimpleConstructedStruct s = SimpleConstructedStruct_0_ctor(1.0);
mellinoe commented 6 years ago

This would be fantastic -- it would also be fantastic if "readonly struct" works. Shaders shouldn't care about it, so we'd just need to make sure that it's ignored in whatever way is needed.