ebiten: Add TestShaderFillWithDrawTriangles

This commit is contained in:
Hajime Hoshi 2020-09-20 00:49:57 +09:00
parent 85a6ef2ea6
commit 7bd8fad738

View File

@ -84,6 +84,79 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}
}
func TestShaderFillWithDrawTriangles(t *testing.T) {
const w, h = 16, 16
dst, _ := NewImage(w, h, FilterDefault)
s, err := NewShader([]byte(`package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
return vec4(1, 0, 0, 1)
}
`))
if err != nil {
t.Fatal(err)
}
src, _ := NewImage(w/2, h/2, FilterDefault)
op := &DrawTrianglesOptions{}
op.Shader = s
vs := []Vertex{
{
DstX: 0,
DstY: 0,
SrcX: 0,
SrcY: 0,
ColorR: 1,
ColorG: 1,
ColorB: 1,
ColorA: 1,
},
{
DstX: w,
DstY: 0,
SrcX: w / 2,
SrcY: 0,
ColorR: 1,
ColorG: 1,
ColorB: 1,
ColorA: 1,
},
{
DstX: 0,
DstY: h,
SrcX: 0,
SrcY: h / 2,
ColorR: 1,
ColorG: 1,
ColorB: 1,
ColorA: 1,
},
{
DstX: w,
DstY: h,
SrcX: w / 2,
SrcY: h / 2,
ColorR: 1,
ColorG: 1,
ColorB: 1,
ColorA: 1,
},
}
is := []uint16{0, 1, 2, 1, 2, 3}
dst.DrawTriangles(vs, is, src, op)
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)
}
}
}
}
func TestShaderFunction(t *testing.T) {
const w, h = 16, 16