shaderir/glsl: Bug fix: Initialize an array

Updates #1285
This commit is contained in:
Hajime Hoshi 2020-08-09 04:56:09 +09:00
parent febdc46ad5
commit 07514a37c8
2 changed files with 21 additions and 6 deletions

View File

@ -4,14 +4,20 @@ void F0(out vec2 l0[2]);
void F1(out vec2 l0[2]); void F1(out vec2 l0[2]);
void F0(out vec2 l0[2]) { void F0(out vec2 l0[2]) {
vec2 l1[2] = vec2[2](vec2(0), vec2(0)); vec2 l1[2];
l1[0] = vec2(0);
l1[1] = vec2(0);
l0 = l1; l0 = l1;
return; return;
} }
void F1(out vec2 l0[2]) { void F1(out vec2 l0[2]) {
vec2 l1[2] = vec2[2](vec2(0), vec2(0)); vec2 l1[2];
vec2 l2[2] = vec2[2](vec2(0), vec2(0)); l1[0] = vec2(0);
l1[1] = vec2(0);
vec2 l2[2];
l2[0] = vec2(0);
l2[1] = vec2(0);
(l1)[0] = vec2(1.0); (l1)[0] = vec2(1.0);
l2 = l1; l2 = l1;
((l2)[1]).y = vec2(2.0); ((l2)[1]).y = vec2(2.0);

View File

@ -310,9 +310,18 @@ func (c *compileContext) glslBlock(p *shaderir.Program, topBlock, block *shaderi
var lines []string var lines []string
for _, t := range block.LocalVars { for _, t := range block.LocalVars {
name := fmt.Sprintf("l%d", localVarIndex)
switch t.Main {
case shaderir.Array:
lines = append(lines, fmt.Sprintf("%s%s;", idt, c.glslVarDecl(p, &t, name)))
init := c.glslVarInit(p, &t.Sub[0])
for i := 0; i < t.Length; i++ {
lines = append(lines, fmt.Sprintf("%s%s[%d] = %s;", idt, name, i, init))
}
case shaderir.None:
// The type is None e.g., when the variable is a for-loop counter. // The type is None e.g., when the variable is a for-loop counter.
if t.Main != shaderir.None { default:
lines = append(lines, fmt.Sprintf("%s%s = %s;", idt, c.glslVarDecl(p, &t, fmt.Sprintf("l%d", localVarIndex)), c.glslVarInit(p, &t))) lines = append(lines, fmt.Sprintf("%s%s = %s;", idt, c.glslVarDecl(p, &t, name), c.glslVarInit(p, &t)))
} }
localVarIndex++ localVarIndex++
} }