diff --git a/internal/shaderir/glsl.go b/internal/shaderir/glsl.go index eeabb5e6d..9f3efcfc3 100644 --- a/internal/shaderir/glsl.go +++ b/internal/shaderir/glsl.go @@ -158,16 +158,16 @@ func (p *Program) glslBlock(b *Block, f *Func, level int, localVarIndex int) []s lines = append(lines, fmt.Sprintf("%s%s;", idt, glslExpr(&s.Exprs[0]))) case BlockStmt: lines = append(lines, idt+"{") - lines = append(lines, p.glslBlock(s.Block, f, level+1, localVarIndex)...) + lines = append(lines, p.glslBlock(&s.Blocks[0], f, level+1, localVarIndex)...) lines = append(lines, idt+"}") case Assign: lines = append(lines, fmt.Sprintf("%s%s = %s;", idt, glslExpr(&s.Exprs[0]), glslExpr(&s.Exprs[1]))) case If: lines = append(lines, fmt.Sprintf("%sif (%s) {", idt, glslExpr(&s.Exprs[0]))) - lines = append(lines, p.glslBlock(s.Block, f, level+1, localVarIndex)...) - if s.ElseBlock != nil { + lines = append(lines, p.glslBlock(&s.Blocks[0], f, level+1, localVarIndex)...) + if len(s.Blocks) > 1 { lines = append(lines, fmt.Sprintf("%s} else {", idt)) - lines = append(lines, p.glslBlock(s.ElseBlock, f, level+1, localVarIndex)...) + lines = append(lines, p.glslBlock(&s.Blocks[1], f, level+1, localVarIndex)...) } lines = append(lines, fmt.Sprintf("%s}", idt)) case For: diff --git a/internal/shaderir/ir_test.go b/internal/shaderir/ir_test.go index 9b79aea7e..dc6f0634b 100644 --- a/internal/shaderir/ir_test.go +++ b/internal/shaderir/ir_test.go @@ -27,12 +27,11 @@ func assignStmt(lhs Expr, rhs Expr) Stmt { } } -func ifStmt(cond Expr, block *Block, elseBlock *Block) Stmt { +func ifStmt(cond Expr, block Block, elseBlock Block) Stmt { return Stmt{ - Type: If, - Exprs: []Expr{cond}, - Block: block, - ElseBlock: elseBlock, + Type: If, + Exprs: []Expr{cond}, + Blocks: []Block{block, elseBlock}, } } @@ -202,10 +201,12 @@ varying vec3 V0;`, Stmts: []Stmt{ { Type: BlockStmt, - Block: &Block{ - LocalVars: []Type{ - {Main: Mat4}, - {Main: Mat4}, + Blocks: []Block{ + { + LocalVars: []Type{ + {Main: Mat4}, + {Main: Mat4}, + }, }, }, }, @@ -276,7 +277,7 @@ varying vec3 V0;`, varNameExpr(Local, 0), numericExpr(0), ), - &Block{ + Block{ Stmts: []Stmt{ assignStmt( varNameExpr(Local, 2), @@ -284,7 +285,7 @@ varying vec3 V0;`, ), }, }, - &Block{ + Block{ Stmts: []Stmt{ assignStmt( varNameExpr(Local, 2), diff --git a/internal/shaderir/program.go b/internal/shaderir/program.go index 7888c043b..4f4fc69f7 100644 --- a/internal/shaderir/program.go +++ b/internal/shaderir/program.go @@ -40,12 +40,11 @@ type Block struct { } type Stmt struct { - Type StmtType - Exprs []Expr - Block *Block - ElseBlock *Block - ForInit Expr - ForRest Expr + Type StmtType + Exprs []Expr + Blocks []Block + ForInit Expr + ForRest Expr } type StmtType int