From 80c26e6dcce9d9a28cd6dd347a9d75b0cab5d60e Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 5 Jul 2022 01:13:06 +0900 Subject: [PATCH] ebiten: bug fix: Set after Set resulted in a wrong color Updates #2154 Updates #2176 --- image.go | 2 +- image_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/image.go b/image.go index 6c34cc35e..256034d24 100644 --- a/image.go +++ b/image.go @@ -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. diff --git a/image_test.go b/image_test.go index 7483a8fbf..e57b680fa 100644 --- a/image_test.go +++ b/image_test.go @@ -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) + } +}