mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
shader: Bug fix: Comparison with constants didn't work
This commit is contained in:
parent
3eaa7dd0e1
commit
f4a72165e4
@ -78,11 +78,21 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr) ([]shaderir.Expr,
|
||||
if op == token.QUO && lhs[0].Const.Kind() == gconstant.Int && rhs[0].Const.Kind() == gconstant.Int {
|
||||
op = token.QUO_ASSIGN
|
||||
}
|
||||
v := gconstant.BinaryOp(lhs[0].Const, op, rhs[0].Const)
|
||||
t := shaderir.Type{Main: shaderir.Int}
|
||||
if v.Kind() == gconstant.Float {
|
||||
t = shaderir.Type{Main: shaderir.Float}
|
||||
var v gconstant.Value
|
||||
var t shaderir.Type
|
||||
switch op {
|
||||
case token.EQL, token.NEQ, token.LSS, token.LEQ, token.GTR, token.GEQ:
|
||||
v = gconstant.MakeBool(gconstant.Compare(lhs[0].Const, op, rhs[0].Const))
|
||||
t = shaderir.Type{Main: shaderir.Bool}
|
||||
default:
|
||||
v = gconstant.BinaryOp(lhs[0].Const, op, rhs[0].Const)
|
||||
if v.Kind() == gconstant.Float {
|
||||
t = shaderir.Type{Main: shaderir.Float}
|
||||
} else {
|
||||
t = shaderir.Type{Main: shaderir.Int}
|
||||
}
|
||||
}
|
||||
|
||||
return []shaderir.Expr{
|
||||
{
|
||||
Type: shaderir.NumberExpr,
|
||||
|
4
internal/shader/testdata/bool.expected.vs
vendored
Normal file
4
internal/shader/testdata/bool.expected.vs
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
void F0(out bool l0) {
|
||||
l0 = true;
|
||||
return;
|
||||
}
|
5
internal/shader/testdata/bool.go
vendored
Normal file
5
internal/shader/testdata/bool.go
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
package main
|
||||
|
||||
func Foo() bool {
|
||||
return 1.0 == 1.0
|
||||
}
|
Loading…
Reference in New Issue
Block a user