mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
shaderir: Avoid duplications of local variable names
This commit is contained in:
parent
32a88b3b03
commit
1ed004ae05
@ -101,23 +101,19 @@ func (p *Program) glslFunc(f *Func) []string {
|
||||
|
||||
var lines []string
|
||||
lines = append(lines, fmt.Sprintf("void %s(%s) {", f.Name, argsstr))
|
||||
lines = append(lines, p.glslBlock(&f.Block, f, 0)...)
|
||||
lines = append(lines, p.glslBlock(&f.Block, f, 0, idx)...)
|
||||
lines = append(lines, "}")
|
||||
|
||||
return lines
|
||||
}
|
||||
|
||||
func (p *Program) glslBlock(b *Block, f *Func, level int) []string {
|
||||
func (p *Program) glslBlock(b *Block, f *Func, level int, localVarIndex int) []string {
|
||||
idt := strings.Repeat("\t", level+1)
|
||||
|
||||
var lines []string
|
||||
var idx int
|
||||
if level == 0 {
|
||||
idx = len(f.InParams) + len(f.InOutParams) + len(f.OutParams)
|
||||
}
|
||||
for _, t := range b.LocalVars {
|
||||
lines = append(lines, fmt.Sprintf("%s%s;", idt, p.glslVarDecl(&t, fmt.Sprintf("l%d", idx))))
|
||||
idx++
|
||||
lines = append(lines, fmt.Sprintf("%s%s;", idt, p.glslVarDecl(&t, fmt.Sprintf("l%d", localVarIndex))))
|
||||
localVarIndex++
|
||||
}
|
||||
|
||||
var glslExpr func(e *Expr) string
|
||||
@ -149,7 +145,7 @@ func (p *Program) glslBlock(b *Block, f *Func, level int) []string {
|
||||
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)...)
|
||||
lines = append(lines, p.glslBlock(s.Block, 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])))
|
||||
|
@ -151,6 +151,50 @@ varying vec3 V0;`,
|
||||
Glsl: `void F0(in float l0, inout float l1, out float l2) {
|
||||
mat4 l3;
|
||||
mat4 l4;
|
||||
}`,
|
||||
},
|
||||
{
|
||||
Name: "FuncBlocks",
|
||||
Program: Program{
|
||||
Funcs: []Func{
|
||||
{
|
||||
Name: "F0",
|
||||
InParams: []Type{
|
||||
{Main: Float},
|
||||
},
|
||||
InOutParams: []Type{
|
||||
{Main: Float},
|
||||
},
|
||||
OutParams: []Type{
|
||||
{Main: Float},
|
||||
},
|
||||
Block: Block{
|
||||
LocalVars: []Type{
|
||||
{Main: Mat4},
|
||||
{Main: Mat4},
|
||||
},
|
||||
Stmts: []Stmt{
|
||||
{
|
||||
Type: BlockStmt,
|
||||
Block: &Block{
|
||||
LocalVars: []Type{
|
||||
{Main: Mat4},
|
||||
{Main: Mat4},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Glsl: `void F0(in float l0, inout float l1, out float l2) {
|
||||
mat4 l3;
|
||||
mat4 l4;
|
||||
{
|
||||
mat4 l5;
|
||||
mat4 l6;
|
||||
}
|
||||
}`,
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user