mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +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) {
|
func TestSyntaxAtan(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
stmt string
|
||||||
|
err bool
|
||||||
|
}{
|
||||||
// `atan` takes 1 argument.
|
// `atan` takes 1 argument.
|
||||||
if _, err := compileToIR([]byte(`package main
|
{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)
|
|
||||||
}
|
|
||||||
if _, err := compileToIR([]byte(`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.
|
// `atan2` takes 2 arguments.
|
||||||
if _, err := compileToIR([]byte(`package main
|
{stmt: "_ = atan2(vec4(0))", err: true},
|
||||||
|
{stmt: "_ = atan2(vec4(0), vec4(0))", err: false},
|
||||||
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
|
|
||||||
|
for _, c := range cases {
|
||||||
|
_, err := compileToIR([]byte(fmt.Sprintf(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
return atan2(vec4(0), vec4(0))
|
%s
|
||||||
}
|
return position
|
||||||
`)); err != nil {
|
}`, c.stmt)))
|
||||||
t.Error(err)
|
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