mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
internal/shader: refactoring
This commit is contained in:
parent
dc1df824a5
commit
5aecd6762c
@ -1202,39 +1202,31 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
}
|
||||
|
||||
func TestSyntaxAtan(t *testing.T) {
|
||||
// `atan` takes 1 argument.
|
||||
if _, err := compileToIR([]byte(`package main
|
||||
cases := []struct {
|
||||
stmt string
|
||||
err bool
|
||||
}{
|
||||
// `atan` takes 1 argument.
|
||||
{stmt: "_ = atan(vec4(0))", err: false},
|
||||
{stmt: "_ = atan(vec4(0), vec4(0))", err: true},
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
return atan(vec4(0))
|
||||
}
|
||||
`)); err != nil {
|
||||
t.Error(err)
|
||||
// `atan2` takes 2 arguments.
|
||||
{stmt: "_ = atan2(vec4(0))", err: true},
|
||||
{stmt: "_ = atan2(vec4(0), vec4(0))", err: false},
|
||||
}
|
||||
if _, err := compileToIR([]byte(`package main
|
||||
|
||||
for _, c := range cases {
|
||||
_, err := compileToIR([]byte(fmt.Sprintf(`package main
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
return atan(vec4(0), vec4(0))
|
||||
}
|
||||
`)); err == nil {
|
||||
t.Errorf("error must be non-nil but was nil")
|
||||
}
|
||||
// `atan2` takes 2 arguments.
|
||||
if _, err := compileToIR([]byte(`package main
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
return atan2(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 {
|
||||
return atan2(vec4(0), vec4(0))
|
||||
}
|
||||
`)); err != nil {
|
||||
t.Error(err)
|
||||
%s
|
||||
return position
|
||||
}`, c.stmt)))
|
||||
if err == nil && c.err {
|
||||
t.Errorf("%s must return an error but does not", c.stmt)
|
||||
} else if err != nil && !c.err {
|
||||
t.Errorf("%s must not return nil but returned %v", c.stmt, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user