From 004b279e4f84f4cd03f436517abeb6853d947370 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 29 Jul 2020 22:43:49 +0900 Subject: [PATCH] shader: Add array initialization Updates #1235 --- internal/shader/testdata/array.expected.vs | 8 ++++++++ internal/shader/testdata/array.go | 5 +++++ internal/shaderir/glsl.go | 7 ++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/internal/shader/testdata/array.expected.vs b/internal/shader/testdata/array.expected.vs index 7f1e40f2c..6f15a3a04 100644 --- a/internal/shader/testdata/array.expected.vs +++ b/internal/shader/testdata/array.expected.vs @@ -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; +} diff --git a/internal/shader/testdata/array.go b/internal/shader/testdata/array.go index d095b111a..c9d411e5b 100644 --- a/internal/shader/testdata/array.go +++ b/internal/shader/testdata/array.go @@ -1,3 +1,8 @@ package main var Array [4]vec2 + +func Foo() [2]vec2 { + var x [2]vec2 + return x +} diff --git a/internal/shaderir/glsl.go b/internal/shaderir/glsl.go index b69291fa7..12ca88046 100644 --- a/internal/shaderir/glsl.go +++ b/internal/shaderir/glsl.go @@ -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: