shaderir: Bug fix: Wrong implementation of isValidSwizzling

This commit is contained in:
Hajime Hoshi 2020-05-17 02:25:37 +09:00
parent 7e274050a3
commit e1d0800f19

View File

@ -37,18 +37,21 @@ func isValidSwizzling(s string) bool {
return false return false
} }
} }
return true
case strings.IndexByte(rgba, s[0]) >= 0: case strings.IndexByte(rgba, s[0]) >= 0:
for _, c := range s { for _, c := range s {
if strings.IndexRune(rgba, c) == -1 { if strings.IndexRune(rgba, c) == -1 {
return false return false
} }
} }
return true
case strings.IndexByte(strq, s[0]) >= 0: case strings.IndexByte(strq, s[0]) >= 0:
for _, c := range s { for _, c := range s {
if strings.IndexRune(strq, c) == -1 { if strings.IndexRune(strq, c) == -1 {
return false return false
} }
} }
return true
} }
return false return false
} }
@ -225,7 +228,7 @@ func (p *Program) glslBlock(b *Block, level int, localVarIndex int) []string {
case BuiltinFuncExpr: case BuiltinFuncExpr:
return string(e.BuiltinFunc) return string(e.BuiltinFunc)
case SwizzlingExpr: case SwizzlingExpr:
if isValidSwizzling(e.Swizzling) { if !isValidSwizzling(e.Swizzling) {
return fmt.Sprintf("?(unexpected swizzling: %s)", e.Swizzling) return fmt.Sprintf("?(unexpected swizzling: %s)", e.Swizzling)
} }
return e.Swizzling return e.Swizzling