shader: Add array initialization

Updates #1235
This commit is contained in:
Hajime Hoshi 2020-07-29 22:43:49 +09:00
parent 62fbac2290
commit 004b279e4f
3 changed files with 19 additions and 1 deletions

View File

@ -1 +1,9 @@
uniform vec2[4] U0;
void F0(out vec2[2] l0);
void F0(out vec2[2] l0) {
vec2[2] l1 = vec2[2](vec2(0), vec2(0));
l0 = l1;
return;
}

View File

@ -1,3 +1,8 @@
package main
var Array [4]vec2
func Foo() [2]vec2 {
var x [2]vec2
return x
}

View File

@ -195,7 +195,12 @@ func (p *Program) glslVarInit(t *Type) string {
case None:
return "?(none)"
case Array:
panic("not implemented")
init := p.glslVarInit(&t.Sub[0])
es := make([]string, 0, t.Length)
for i := 0; i < t.Length; i++ {
es = append(es, init)
}
return fmt.Sprintf("%s[%d](%s)", t.Sub[0].Glsl(), t.Length, strings.Join(es, ", "))
case Struct:
panic("not implemented")
case Bool: