mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 10:42:42 +01:00
shaderir: Refactoring
This commit is contained in:
parent
e6d78abd11
commit
4b8e745824
@ -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:
|
||||
|
@ -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),
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user