mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-12 22:17:26 +01:00
parent
3d8d759976
commit
1c4a0ac0dc
@ -195,14 +195,14 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
t = lhst
|
t = lhst
|
||||||
case lhst.Equal(&rhst):
|
case lhst.Equal(&rhst):
|
||||||
t = lhst
|
t = lhst
|
||||||
case lhst.Main == shaderir.Float:
|
case op2 == shaderir.MatrixMul && (lhst.Main == shaderir.Float || lhst.IsVector()) && rhst.IsMatrix():
|
||||||
t = rhst
|
|
||||||
case rhst.Main == shaderir.Float:
|
|
||||||
t = lhst
|
t = lhst
|
||||||
case op2 == shaderir.MatrixMul && lhst.IsVector() && rhst.IsMatrix():
|
case op2 == shaderir.MatrixMul && lhst.IsMatrix() && (rhst.Main == shaderir.Float || rhst.IsVector()):
|
||||||
t = lhst
|
|
||||||
case op2 == shaderir.MatrixMul && lhst.IsMatrix() && rhst.IsVector():
|
|
||||||
t = rhst
|
t = rhst
|
||||||
|
case (lhst.Main == shaderir.Float || lhst.Main == shaderir.Int) && rhst.IsVector():
|
||||||
|
t = rhst
|
||||||
|
case lhst.IsVector() && (rhst.Main == shaderir.Float || rhst.Main == shaderir.Int):
|
||||||
|
t = lhst
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("shaderir: invalid expression: %s %s %s", lhst.String(), e.Op, rhst.String()))
|
panic(fmt.Sprintf("shaderir: invalid expression: %s %s %s", lhst.String(), e.Op, rhst.String()))
|
||||||
}
|
}
|
||||||
|
@ -3291,3 +3291,53 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue #2706
|
||||||
|
func TestSyntaxScalarAndVector(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
stmt string
|
||||||
|
err bool
|
||||||
|
}{
|
||||||
|
{stmt: "a := vec2(1) + 1; var b vec2 = a; _ = b", err: false},
|
||||||
|
{stmt: "a := 1 + vec2(1); var b vec2 = a; _ = b", err: false},
|
||||||
|
{stmt: "a := vec2(1); b := 1; var c vec2 = a + b; _ = c", err: true},
|
||||||
|
{stmt: "a := vec2(1); b := 1; var c vec2 = b + a; _ = c", err: true},
|
||||||
|
{stmt: "a := vec2(1) + 1.0; var b vec2 = a; _ = b", err: false},
|
||||||
|
{stmt: "a := 1.0 + vec2(1); var b vec2 = a; _ = b", err: false},
|
||||||
|
{stmt: "a := vec2(1); b := 1.0; var c vec2 = a + b; _ = c", err: false},
|
||||||
|
{stmt: "a := vec2(1); b := 1.0; var c vec2 = b + a; _ = c", err: false},
|
||||||
|
{stmt: "a := vec2(1) + 1.1; var b vec2 = a; _ = b", err: false},
|
||||||
|
{stmt: "a := 1.1 + vec2(1); var b vec2 = a; _ = b", err: false},
|
||||||
|
{stmt: "a := vec2(1); b := 1.1; var c vec2 = a + b; _ = c", err: false},
|
||||||
|
{stmt: "a := vec2(1); b := 1.1; var c vec2 = b + a; _ = c", err: false},
|
||||||
|
|
||||||
|
{stmt: "a := ivec2(1) + 1; var b ivec2 = a; _ = b", err: false},
|
||||||
|
{stmt: "a := 1 + ivec2(1); var b ivec2 = a; _ = b", err: false},
|
||||||
|
{stmt: "a := ivec2(1); b := 1; var c ivec2 = a + b; _ = c", err: false},
|
||||||
|
{stmt: "a := ivec2(1); b := 1; var c ivec2 = b + a; _ = c", err: false},
|
||||||
|
{stmt: "a := ivec2(1) + 1.0; var b ivec2 = a; _ = b", err: false},
|
||||||
|
{stmt: "a := 1.0 + ivec2(1); var b ivec2 = a; _ = b", err: false},
|
||||||
|
{stmt: "a := ivec2(1); b := 1.0; var c ivec2 = a + b; _ = c", err: true},
|
||||||
|
{stmt: "a := ivec2(1); b := 1.0; var c ivec2 = b + a; _ = c", err: true},
|
||||||
|
{stmt: "a := ivec2(1) + 1.1; var b ivec2 = a; _ = b", err: true},
|
||||||
|
{stmt: "a := 1.1 + ivec2(1); var b ivec2 = a; _ = b", err: true},
|
||||||
|
{stmt: "a := ivec2(1); b := 1.1; var c ivec2 = a + b; _ = c", err: true},
|
||||||
|
{stmt: "a := ivec2(1); b := 1.1; var c ivec2 = b + a; _ = c", err: true},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range cases {
|
||||||
|
stmt := c.stmt
|
||||||
|
src := fmt.Sprintf(`package main
|
||||||
|
|
||||||
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
|
%s
|
||||||
|
return position
|
||||||
|
}`, stmt)
|
||||||
|
_, err := compileToIR([]byte(src))
|
||||||
|
if err == nil && c.err {
|
||||||
|
t.Errorf("%s must return an error but does not", stmt)
|
||||||
|
} else if err != nil && !c.err {
|
||||||
|
t.Errorf("%s must not return nil but returned %v", stmt, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user