diff --git a/internal/shaderir/glsl.go b/internal/shaderir/glsl.go index c45722fb6..e24621c69 100644 --- a/internal/shaderir/glsl.go +++ b/internal/shaderir/glsl.go @@ -364,8 +364,7 @@ func (p *Program) glslBlock(topBlock, block *Block, level int, localVarIndex int } lines = append(lines, fmt.Sprintf("%s}", idt)) case For: - v := localVarIndex - localVarIndex++ + v := s.ForVarIndex var delta string switch s.ForDelta { case 0: diff --git a/internal/shaderir/ir_test.go b/internal/shaderir/ir_test.go index 4ac42e2a3..edd135b73 100644 --- a/internal/shaderir/ir_test.go +++ b/internal/shaderir/ir_test.go @@ -64,14 +64,15 @@ func ifStmt(cond Expr, block Block, elseBlock Block) Stmt { } } -func forStmt(init, end int, op Op, delta int, block Block) Stmt { +func forStmt(index, init, end int, op Op, delta int, block Block) Stmt { return Stmt{ - Type: For, - Blocks: []Block{block}, - ForInit: init, - ForEnd: end, - ForOp: op, - ForDelta: delta, + Type: For, + Blocks: []Block{block}, + ForVarIndex: index, + ForInit: init, + ForEnd: end, + ForOp: op, + ForDelta: delta, } } @@ -592,6 +593,7 @@ varying vec3 V0;`, Block: block( nil, forStmt( + 3, 0, 100, LessThanOp, diff --git a/internal/shaderir/program.go b/internal/shaderir/program.go index 628478b58..2a00e22b0 100644 --- a/internal/shaderir/program.go +++ b/internal/shaderir/program.go @@ -64,13 +64,14 @@ type Block struct { } type Stmt struct { - Type StmtType - Exprs []Expr - Blocks []Block - ForInit int - ForEnd int - ForOp Op - ForDelta int + Type StmtType + Exprs []Expr + Blocks []Block + ForVarIndex int + ForInit int + ForEnd int + ForOp Op + ForDelta int } type StmtType int