mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
internal/shader: bug fix: operators between vec/mat and float should work
Closes #1963
This commit is contained in:
parent
f5edc189e6
commit
4940159e5b
@ -108,6 +108,13 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
||||
cs.addError(stmt.Pos(), fmt.Sprintf("invalid operation: mismatched types %s and %s", lts[0].String(), rts[0].String()))
|
||||
return nil, false
|
||||
}
|
||||
case shaderir.Vec2, shaderir.Vec3, shaderir.Vec4, shaderir.Mat2, shaderir.Mat3, shaderir.Mat4:
|
||||
if rts[0].Main == shaderir.Float || rhs[0].Const != nil {
|
||||
// ok
|
||||
} else {
|
||||
cs.addError(stmt.Pos(), fmt.Sprintf("invalid operation: mismatched types %s and %s", lts[0].String(), rts[0].String()))
|
||||
return nil, false
|
||||
}
|
||||
default:
|
||||
cs.addError(stmt.Pos(), fmt.Sprintf("invalid operation: mismatched types %s and %s", lts[0].String(), rts[0].String()))
|
||||
return nil, false
|
||||
|
@ -1459,3 +1459,46 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
t.Errorf("error must be non-nil but was nil")
|
||||
}
|
||||
}
|
||||
|
||||
// Issue #1963
|
||||
func TestShaderOperatorVecAndNumber(t *testing.T) {
|
||||
if _, err := ebiten.NewShader([]byte(`package main
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
a := vec2(1)
|
||||
a += 2
|
||||
return a.xxyy
|
||||
}`)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if _, err := ebiten.NewShader([]byte(`package main
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
a := vec2(1)
|
||||
a += 2.1
|
||||
return a.xxyy
|
||||
}`)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if _, err := ebiten.NewShader([]byte(`package main
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
a := vec2(1)
|
||||
a %= 2
|
||||
return a.xxyy
|
||||
}`)); err == nil {
|
||||
t.Errorf("error must be non-nil but was nil")
|
||||
}
|
||||
|
||||
if _, err := ebiten.NewShader([]byte(`package main
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
a := vec2(1)
|
||||
a %= 2.1
|
||||
return a.xxyy
|
||||
}`)); err == nil {
|
||||
t.Errorf("error must be non-nil but was nil")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user