ebiten: Add shader tests

Updates #1283
This commit is contained in:
Hajime Hoshi 2020-08-26 03:10:24 +09:00
parent 1ed2b09ba0
commit 9e678b9ecf

View File

@ -83,3 +83,34 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}
}
}
func TestShaderFunction(t *testing.T) {
const w, h = 16, 16
dst, _ := NewImage(w, h, FilterDefault)
s, err := NewShader([]byte(`package main
func clr(red float) (float, float, float, float) {
return red, 0, 0, 1
}
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
return vec4(clr(1))
}
`))
if err != nil {
t.Fatal(err)
}
dst.DrawRectShader(w, h, s, nil)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
got := dst.At(i, j).(color.RGBA)
want := color.RGBA{0xff, 0, 0, 0xff}
if got != want {
t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want)
}
}
}
}