mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/shader: bug fix: wrong assignment rule for booleans
This commit is contained in:
parent
87be157b23
commit
6dcd2ff11c
@ -773,8 +773,15 @@ func canAssign(re *shaderir.Expr, lt *shaderir.Type, rt *shaderir.Type) bool {
|
||||
if lt.Equal(rt) {
|
||||
return true
|
||||
}
|
||||
if re.Type == shaderir.NumberExpr && (lt.Main == shaderir.Float || lt.Main == shaderir.Int || lt.Main == shaderir.Bool) {
|
||||
return true
|
||||
if re.Type == shaderir.NumberExpr {
|
||||
switch lt.Main {
|
||||
case shaderir.Bool:
|
||||
return re.Const.Kind() == gconstant.Bool
|
||||
case shaderir.Int:
|
||||
return canTruncateToInteger(re.Const)
|
||||
case shaderir.Float:
|
||||
return gconstant.ToFloat(re.Const).Kind() != gconstant.Unknown
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -444,7 +444,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
return true
|
||||
}
|
||||
`)); err != nil {
|
||||
t.Errorf("error must be nil but was non-nil")
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -928,6 +928,39 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
}`)); err == nil {
|
||||
t.Errorf("error must be non-nil but was nil")
|
||||
}
|
||||
|
||||
if _, err := compileToIR([]byte(`package main
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
var x float = true
|
||||
_ = x
|
||||
return vec4(0)
|
||||
}
|
||||
`)); err == nil {
|
||||
t.Errorf("error must be non-nil but was nil")
|
||||
}
|
||||
|
||||
if _, err := compileToIR([]byte(`package main
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
var x bool = true
|
||||
_ = x
|
||||
return vec4(0)
|
||||
}
|
||||
`)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if _, err := compileToIR([]byte(`package main
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
var x int = 1.0
|
||||
_ = x
|
||||
return vec4(0)
|
||||
}
|
||||
`)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Issue #1963
|
||||
|
Loading…
Reference in New Issue
Block a user