mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +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])))
|
lines = append(lines, fmt.Sprintf("%s%s;", idt, glslExpr(&s.Exprs[0])))
|
||||||
case BlockStmt:
|
case BlockStmt:
|
||||||
lines = append(lines, idt+"{")
|
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+"}")
|
lines = append(lines, idt+"}")
|
||||||
case Assign:
|
case Assign:
|
||||||
lines = append(lines, fmt.Sprintf("%s%s = %s;", idt, glslExpr(&s.Exprs[0]), glslExpr(&s.Exprs[1])))
|
lines = append(lines, fmt.Sprintf("%s%s = %s;", idt, glslExpr(&s.Exprs[0]), glslExpr(&s.Exprs[1])))
|
||||||
case If:
|
case If:
|
||||||
lines = append(lines, fmt.Sprintf("%sif (%s) {", idt, glslExpr(&s.Exprs[0])))
|
lines = append(lines, fmt.Sprintf("%sif (%s) {", idt, glslExpr(&s.Exprs[0])))
|
||||||
lines = append(lines, p.glslBlock(s.Block, f, level+1, localVarIndex)...)
|
lines = append(lines, p.glslBlock(&s.Blocks[0], f, level+1, localVarIndex)...)
|
||||||
if s.ElseBlock != nil {
|
if len(s.Blocks) > 1 {
|
||||||
lines = append(lines, fmt.Sprintf("%s} else {", idt))
|
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))
|
lines = append(lines, fmt.Sprintf("%s}", idt))
|
||||||
case For:
|
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{
|
return Stmt{
|
||||||
Type: If,
|
Type: If,
|
||||||
Exprs: []Expr{cond},
|
Exprs: []Expr{cond},
|
||||||
Block: block,
|
Blocks: []Block{block, elseBlock},
|
||||||
ElseBlock: elseBlock,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,10 +201,12 @@ varying vec3 V0;`,
|
|||||||
Stmts: []Stmt{
|
Stmts: []Stmt{
|
||||||
{
|
{
|
||||||
Type: BlockStmt,
|
Type: BlockStmt,
|
||||||
Block: &Block{
|
Blocks: []Block{
|
||||||
LocalVars: []Type{
|
{
|
||||||
{Main: Mat4},
|
LocalVars: []Type{
|
||||||
{Main: Mat4},
|
{Main: Mat4},
|
||||||
|
{Main: Mat4},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -276,7 +277,7 @@ varying vec3 V0;`,
|
|||||||
varNameExpr(Local, 0),
|
varNameExpr(Local, 0),
|
||||||
numericExpr(0),
|
numericExpr(0),
|
||||||
),
|
),
|
||||||
&Block{
|
Block{
|
||||||
Stmts: []Stmt{
|
Stmts: []Stmt{
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 2),
|
varNameExpr(Local, 2),
|
||||||
@ -284,7 +285,7 @@ varying vec3 V0;`,
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
&Block{
|
Block{
|
||||||
Stmts: []Stmt{
|
Stmts: []Stmt{
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 2),
|
varNameExpr(Local, 2),
|
||||||
|
@ -40,12 +40,11 @@ type Block struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Stmt struct {
|
type Stmt struct {
|
||||||
Type StmtType
|
Type StmtType
|
||||||
Exprs []Expr
|
Exprs []Expr
|
||||||
Block *Block
|
Blocks []Block
|
||||||
ElseBlock *Block
|
ForInit Expr
|
||||||
ForInit Expr
|
ForRest Expr
|
||||||
ForRest Expr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type StmtType int
|
type StmtType int
|
||||||
|
Loading…
Reference in New Issue
Block a user