mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 11:48:55 +01:00
internal/shader: ban the operator div on a matrix
The operator div on a matrix doesn't work on Metal.
This commit is contained in:
parent
2e5b4954f3
commit
84c680c6ed
@ -182,6 +182,10 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr, markLocalVariable
|
|||||||
}
|
}
|
||||||
t = lhst
|
t = lhst
|
||||||
case lhst.Equal(&rhst):
|
case lhst.Equal(&rhst):
|
||||||
|
if op == shaderir.Div && (rhst.Main == shaderir.Mat2 || rhst.Main == shaderir.Mat3 || rhst.Main == shaderir.Mat4) {
|
||||||
|
cs.addError(e.Pos(), fmt.Sprintf("invalid operation: operator %s not defined on %s", e.Op, rhst.String()))
|
||||||
|
return nil, nil, nil, false
|
||||||
|
}
|
||||||
t = lhst
|
t = lhst
|
||||||
case lhst.Main == shaderir.Float:
|
case lhst.Main == shaderir.Float:
|
||||||
switch rhst.Main {
|
switch rhst.Main {
|
||||||
|
@ -94,7 +94,12 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if lts[0].Main != rts[0].Main {
|
if lts[0].Main == rts[0].Main {
|
||||||
|
if op == shaderir.Div && (rts[0].Main == shaderir.Mat2 || rts[0].Main == shaderir.Mat3 || rts[0].Main == shaderir.Mat4) {
|
||||||
|
cs.addError(stmt.Pos(), fmt.Sprintf("invalid operation: operator / not defined on %s", rts[0].String()))
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
switch lts[0].Main {
|
switch lts[0].Main {
|
||||||
case shaderir.Int:
|
case shaderir.Int:
|
||||||
if !cs.forceToInt(stmt, &rhs[0]) {
|
if !cs.forceToInt(stmt, &rhs[0]) {
|
||||||
|
@ -1594,6 +1594,7 @@ func TestShaderOperatorMultiply(t *testing.T) {
|
|||||||
{stmt: "a := mat2(1) * vec3(2); _ = a", err: true},
|
{stmt: "a := mat2(1) * vec3(2); _ = a", err: true},
|
||||||
{stmt: "a := mat2(1) * vec4(2); _ = a", err: true},
|
{stmt: "a := mat2(1) * vec4(2); _ = a", err: true},
|
||||||
{stmt: "a := mat2(1) * mat2(2); _ = a", err: false},
|
{stmt: "a := mat2(1) * mat2(2); _ = a", err: false},
|
||||||
|
{stmt: "a := mat2(1) / mat2(2); _ = a", err: true},
|
||||||
{stmt: "a := mat2(1) * mat3(2); _ = a", err: true},
|
{stmt: "a := mat2(1) * mat3(2); _ = a", err: true},
|
||||||
{stmt: "a := mat2(1) * mat4(2); _ = a", err: true},
|
{stmt: "a := mat2(1) * mat4(2); _ = a", err: true},
|
||||||
}
|
}
|
||||||
@ -1641,6 +1642,7 @@ func TestShaderOperatorMultiplyAssign(t *testing.T) {
|
|||||||
{stmt: "a := vec2(1); a *= vec4(2)", err: true},
|
{stmt: "a := vec2(1); a *= vec4(2)", err: true},
|
||||||
{stmt: "a := vec2(1); a *= mat2(2)", err: false},
|
{stmt: "a := vec2(1); a *= mat2(2)", err: false},
|
||||||
{stmt: "a := vec2(1); a += mat2(2)", err: true},
|
{stmt: "a := vec2(1); a += mat2(2)", err: true},
|
||||||
|
{stmt: "a := vec2(1); a /= mat2(2)", err: true},
|
||||||
{stmt: "a := vec2(1); a *= mat3(2)", err: true},
|
{stmt: "a := vec2(1); a *= mat3(2)", err: true},
|
||||||
{stmt: "a := vec2(1); a *= mat4(2)", err: true},
|
{stmt: "a := vec2(1); a *= mat4(2)", err: true},
|
||||||
{stmt: "a := mat2(1); a *= 2", err: false},
|
{stmt: "a := mat2(1); a *= 2", err: false},
|
||||||
@ -1656,6 +1658,7 @@ func TestShaderOperatorMultiplyAssign(t *testing.T) {
|
|||||||
{stmt: "a := mat2(1); a *= vec4(2)", err: true},
|
{stmt: "a := mat2(1); a *= vec4(2)", err: true},
|
||||||
{stmt: "a := mat2(1); a *= mat2(2)", err: false},
|
{stmt: "a := mat2(1); a *= mat2(2)", err: false},
|
||||||
{stmt: "a := mat2(1); a += mat2(2)", err: false},
|
{stmt: "a := mat2(1); a += mat2(2)", err: false},
|
||||||
|
{stmt: "a := mat2(1); a /= mat2(2)", err: true},
|
||||||
{stmt: "a := mat2(1); a *= mat3(2)", err: true},
|
{stmt: "a := mat2(1); a *= mat3(2)", err: true},
|
||||||
{stmt: "a := mat2(1); a *= mat4(2)", err: true},
|
{stmt: "a := mat2(1); a *= mat4(2)", err: true},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user