shader: Treat if's 'init' part correctly

Updates #1230
This commit is contained in:
Hajime Hoshi 2020-07-05 03:29:34 +09:00
parent f3651e23e4
commit ce4732a7dc
3 changed files with 39 additions and 1 deletions

View File

@ -111,7 +111,22 @@ func (cs *compileState) parseStmt(block *block, stmt ast.Stmt, inParams []variab
return nil, false
}
case *ast.IfStmt:
// TODO: Parse stmt.Init
if stmt.Init != nil {
init := stmt.Init
stmt.Init = nil
b, ok := cs.parseBlock(block, []ast.Stmt{init, stmt}, nil, nil)
if !ok {
return nil, false
}
stmts = append(stmts, shaderir.Stmt{
Type: shaderir.BlockStmt,
Blocks: []shaderir.Block{
b.ir,
},
})
return stmts, true
}
exprs, ts, ss, ok := cs.parseExpr(block, stmt.Cond)
if !ok {

View File

@ -0,0 +1,14 @@
void F0(out vec2 l0) {
vec2 l1 = vec2(0);
l1 = vec2(0.0);
{
vec2 l2 = vec2(0);
l2 = vec2(1.0);
if (((l2).x) == (1.0)) {
l0 = l2;
return;
}
}
l0 = l1;
return;
}

9
internal/shader/testdata/if_init.go vendored Normal file
View File

@ -0,0 +1,9 @@
package main
func Foo() vec2 {
v := vec2(0)
if v := vec2(1); v.x == 1 {
return v
}
return v
}