diff --git a/internal/shader/shader.go b/internal/shader/shader.go index 68fdf53c1..912f4e6cc 100644 --- a/internal/shader/shader.go +++ b/internal/shader/shader.go @@ -38,11 +38,9 @@ type constant struct { type function struct { name string - args []variable - rets []variable + in []string + out []string block *block - - ir shaderir.Func } type compileState struct { @@ -208,42 +206,44 @@ func (cs *compileState) parseFunc(d *ast.FuncDecl, block *block) function { return function{} } - var args []variable + var in []string + var inT []shaderir.Type for _, f := range d.Type.Params.List { t := cs.parseType(f.Type) for _, n := range f.Names { - args = append(args, variable{ - name: n.Name, - typ: t, - }) + in = append(in, n.Name) + inT = append(inT, t.ir) } } - var rets []variable + var out []string + var outT []shaderir.Type if d.Type.Results != nil { for _, f := range d.Type.Results.List { t := cs.parseType(f.Type) if len(f.Names) == 0 { - rets = append(rets, variable{ - name: "", - typ: t, - }) + out = append(out, "") + outT = append(outT, t.ir) } else { for _, n := range f.Names { - rets = append(rets, variable{ - name: n.Name, - typ: t, - }) + out = append(out, n.Name) + outT = append(outT, t.ir) } } } } + cs.ir.Funcs = append(cs.ir.Funcs, shaderir.Func{ + Index: len(cs.ir.Funcs), + InParams: inT, + OutParams: outT, + }) + return function{ name: d.Name.Name, - args: args, - rets: rets, - //body: cs.parseBlock(block, d.Body), + in: in, + out: out, + //block: cs.parseBlock(block, d.Body), } } diff --git a/internal/shader/shader_test.go b/internal/shader/shader_test.go index 5588696f3..323d32d42 100644 --- a/internal/shader/shader_test.go +++ b/internal/shader/shader_test.go @@ -40,6 +40,17 @@ uniform vec4 U1;`, FS: `uniform vec2 U0; uniform vec4 U1;`, }, + { + Name: "func", + Src: `package main + +func Foo(foo vec2) vec4 { +}`, + VS: `void F0(in vec2 l0, out vec4 l1) { +}`, + FS: `void F0(in vec2 l0, out vec4 l1) { +}`, + }, } for _, tc := range tests { s, err := Compile([]byte(tc.Src))