mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
shader: Refactoring: Simplify calculation of LocalVarIndexOffset
This commit is contained in:
parent
41d4fc288b
commit
0a0401e217
@ -695,27 +695,11 @@ func (cs *compileState) parseBlock(outer *block, fname string, stmts []ast.Stmt,
|
||||
}
|
||||
|
||||
var offset int
|
||||
switch {
|
||||
case outer.outer == nil && fname == cs.vertexEntry:
|
||||
offset = 0
|
||||
case outer.outer == nil && fname == cs.fragmentEntry:
|
||||
offset = 0
|
||||
case outer.outer == nil:
|
||||
offset = len(inParams) + len(outParams)
|
||||
default:
|
||||
for b := outer; b != nil; b = b.outer {
|
||||
offset += len(b.vars)
|
||||
}
|
||||
if fname == cs.vertexEntry {
|
||||
offset -= len(cs.ir.Attributes)
|
||||
offset-- // position
|
||||
offset -= len(cs.ir.Varyings)
|
||||
}
|
||||
if fname == cs.fragmentEntry {
|
||||
offset-- // position
|
||||
offset -= len(cs.ir.Varyings)
|
||||
offset-- // color
|
||||
}
|
||||
for b := outer; b != nil; b = b.outer {
|
||||
offset += len(b.vars)
|
||||
}
|
||||
if outer == &cs.global {
|
||||
offset += len(inParams) + len(outParams)
|
||||
}
|
||||
|
||||
block := &block{
|
||||
|
@ -346,8 +346,8 @@ func (c *compileContext) glslBlock(p *shaderir.Program, topBlock, block *shaderi
|
||||
idt := strings.Repeat("\t", level+1)
|
||||
|
||||
var lines []string
|
||||
for i, t := range block.LocalVars {
|
||||
name := fmt.Sprintf("l%d", block.LocalVarIndexOffset+i)
|
||||
for i := range block.LocalVars {
|
||||
name, t := localVariable(p, topBlock, block, block.LocalVarIndexOffset+i)
|
||||
switch t.Main {
|
||||
case shaderir.Array:
|
||||
lines = append(lines, fmt.Sprintf("%s%s;", idt, c.glslVarDecl(p, &t, name)))
|
||||
|
@ -321,8 +321,9 @@ func (c *compileContext) metalBlock(p *shaderir.Program, topBlock, block *shader
|
||||
var lines []string
|
||||
for i, t := range block.LocalVars {
|
||||
// The type is None e.g., when the variable is a for-loop counter.
|
||||
name := localVariableName(p, topBlock, block.LocalVarIndexOffset+i)
|
||||
if t.Main != shaderir.None {
|
||||
lines = append(lines, fmt.Sprintf("%s%s = %s;", idt, c.metalVarDecl(p, &t, fmt.Sprintf("l%d", block.LocalVarIndexOffset+i), false, false), c.metalVarInit(p, &t)))
|
||||
lines = append(lines, fmt.Sprintf("%s%s = %s;", idt, c.metalVarDecl(p, &t, name, false, false), c.metalVarInit(p, &t)))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user