shaderir: Add more tests

This commit is contained in:
Hajime Hoshi 2020-05-14 00:46:36 +09:00
parent 3d7c102472
commit c75a35fd64
2 changed files with 50 additions and 4 deletions

View File

@ -99,8 +99,25 @@ func (p *Program) glslFunc(f *Func) []string {
argsstr = strings.Join(args, ", ") argsstr = strings.Join(args, ", ")
} }
return []string{ var lines []string
fmt.Sprintf(`void %s(%s) {`, f.Name, argsstr), lines = append(lines, fmt.Sprintf("void %s(%s) {", f.Name, argsstr))
`}`, lines = append(lines, p.glslBlock(&f.Block, f, 0)...)
lines = append(lines, "}")
return lines
} }
func (p *Program) glslBlock(b *Block, f *Func, level int) []string {
idt := strings.Repeat("\t", level+1)
var lines []string
var idx int
if level == 0 {
idx = len(f.InParams) + len(f.InOutParams) + len(f.OutParams)
}
for _, t := range b.LocalVars {
lines = append(lines, fmt.Sprintf("%s%s;", idt, p.glslVarDecl(&t, fmt.Sprintf("l%d", idx))))
idx++
}
return lines
} }

View File

@ -122,6 +122,35 @@ varying vec3 V0;`,
}, },
}, },
Glsl: `void F0(in float l0, in vec2 l1, in vec4 l2, inout mat2 l3, out mat4 l4) { Glsl: `void F0(in float l0, in vec2 l1, in vec4 l2, inout mat2 l3, out mat4 l4) {
}`,
},
{
Name: "FuncLocals",
Program: Program{
Funcs: []Func{
{
Name: "F0",
InParams: []Type{
{Main: Float},
},
InOutParams: []Type{
{Main: Float},
},
OutParams: []Type{
{Main: Float},
},
Block: Block{
LocalVars: []Type{
{Main: Mat4},
{Main: Mat4},
},
},
},
},
},
Glsl: `void F0(in float l0, inout float l1, out float l2) {
mat4 l3;
mat4 l4;
}`, }`,
}, },
} }