shaderir: Add Stmt.ForVarIndex

Updates #1230
This commit is contained in:
Hajime Hoshi 2020-07-12 21:53:18 +09:00
parent 4a8bd688a9
commit 291d69500b
3 changed files with 18 additions and 16 deletions

View File

@ -364,8 +364,7 @@ func (p *Program) glslBlock(topBlock, block *Block, level int, localVarIndex int
} }
lines = append(lines, fmt.Sprintf("%s}", idt)) lines = append(lines, fmt.Sprintf("%s}", idt))
case For: case For:
v := localVarIndex v := s.ForVarIndex
localVarIndex++
var delta string var delta string
switch s.ForDelta { switch s.ForDelta {
case 0: case 0:

View File

@ -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{ return Stmt{
Type: For, Type: For,
Blocks: []Block{block}, Blocks: []Block{block},
ForInit: init, ForVarIndex: index,
ForEnd: end, ForInit: init,
ForOp: op, ForEnd: end,
ForDelta: delta, ForOp: op,
ForDelta: delta,
} }
} }
@ -592,6 +593,7 @@ varying vec3 V0;`,
Block: block( Block: block(
nil, nil,
forStmt( forStmt(
3,
0, 0,
100, 100,
LessThanOp, LessThanOp,

View File

@ -64,13 +64,14 @@ type Block struct {
} }
type Stmt struct { type Stmt struct {
Type StmtType Type StmtType
Exprs []Expr Exprs []Expr
Blocks []Block Blocks []Block
ForInit int ForVarIndex int
ForEnd int ForInit int
ForOp Op ForEnd int
ForDelta int ForOp Op
ForDelta int
} }
type StmtType int type StmtType int