ebiten: bug fix: Set after Set resulted in a wrong color

Updates #2154
Updates #2176
This commit is contained in:
Hajime Hoshi 2022-07-05 01:13:06 +09:00
parent 66bf40dc84
commit 80c26e6dcc
2 changed files with 27 additions and 1 deletions

View File

@ -127,7 +127,7 @@ func (i *Image) resolveSetVerticesCacheIfNeeded() {
i.setVerticesCache = nil
srcs := [graphics.ShaderImageNum]*ui.Image{emptyImage.image}
i.image.DrawTriangles(srcs, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, i.adjustedRegion(), graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false, true)
i.image.DrawTriangles(srcs, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, i.adjustedRegion(), graphicsdriver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, false, true)
}
// Size returns the size of the image.

View File

@ -3350,3 +3350,29 @@ func TestImageTooManyDrawTriangles(t *testing.T) {
}
}
}
func TestImageSetOverSet(t *testing.T) {
img := ebiten.NewImage(1, 1)
img.Set(0, 0, color.RGBA{0xff, 0xff, 0xff, 0xff})
if got, want := img.At(0, 0), (color.RGBA{0xff, 0xff, 0xff, 0xff}); got != want {
t.Errorf("got: %v, want: %v", got, want)
}
// Apply the change by 'Set' by calling DrawImage.
dummy := ebiten.NewImage(1, 1)
img.DrawImage(dummy, nil)
if got, want := img.At(0, 0), (color.RGBA{0xff, 0xff, 0xff, 0xff}); got != want {
t.Errorf("got: %v, want: %v", got, want)
}
img.Set(0, 0, color.RGBA{0x80, 0x80, 0x80, 0x80})
if got, want := img.At(0, 0), (color.RGBA{0x80, 0x80, 0x80, 0x80}); got != want {
t.Errorf("got: %v, want: %v", got, want)
}
// Apply the change by 'Set' again.
img.DrawImage(dummy, nil)
if got, want := img.At(0, 0), (color.RGBA{0x80, 0x80, 0x80, 0x80}); got != want {
t.Errorf("got: %v, want: %v", got, want)
}
}