mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
parent
baeadfb7fe
commit
82f102c422
@ -142,6 +142,7 @@ func (p *Image) ReplacePixels(pixels []uint8) {
|
||||
func (p *Image) DrawImage(img *Image, vertices []float32, colorm *affine.ColorM, mode opengl.CompositeMode) {
|
||||
theImages.resetPixelsIfDependingOn(p)
|
||||
if img.stale || img.volatile {
|
||||
// TODO: What will happen if there are images depending on p?
|
||||
p.makeStale()
|
||||
} else {
|
||||
p.appendDrawImageHistory(img, vertices, colorm, mode)
|
||||
|
@ -71,12 +71,11 @@ func vertices() []float32 {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRestoreReversedOrder(t *testing.T) {
|
||||
func TestRestoreOverrideSource(t *testing.T) {
|
||||
img0 := NewImage(1, 1, opengl.Nearest, false)
|
||||
img1 := NewImage(1, 1, opengl.Nearest, false)
|
||||
img2 := NewImage(1, 1, opengl.Nearest, false)
|
||||
img3 := NewImage(1, 1, opengl.Nearest, false)
|
||||
println(img0, img1, img2, img3)
|
||||
defer func() {
|
||||
img3.Dispose()
|
||||
img2.Dispose()
|
||||
@ -128,3 +127,47 @@ func TestRestoreReversedOrder(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRestoreRecursive(t *testing.T) {
|
||||
img0 := NewImage(1, 1, opengl.Nearest, false)
|
||||
img1 := NewImage(1, 1, opengl.Nearest, false)
|
||||
defer func() {
|
||||
img1.Dispose()
|
||||
img0.Dispose()
|
||||
}()
|
||||
clr0 := color.RGBA{0x00, 0x00, 0x01, 0xff}
|
||||
clr1 := color.RGBA{0x00, 0x00, 0x02, 0xff}
|
||||
img0.Fill(clr0)
|
||||
img1.Fill(clr1)
|
||||
img1.DrawImage(img0, vertices(), &affine.ColorM{}, opengl.CompositeModeLighter)
|
||||
img0.DrawImage(img1, vertices(), &affine.ColorM{}, opengl.CompositeModeLighter)
|
||||
if err := ResolveStalePixels(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := Restore(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
testCases := []struct {
|
||||
name string
|
||||
want color.RGBA
|
||||
got color.RGBA
|
||||
}{
|
||||
{
|
||||
"0",
|
||||
color.RGBA{0x00, 0x00, 0x04, 0xff},
|
||||
uint8SliceToColor(img0.BasePixelsForTesting()),
|
||||
},
|
||||
{
|
||||
"1",
|
||||
color.RGBA{0x00, 0x00, 0x03, 0xff},
|
||||
uint8SliceToColor(img1.BasePixelsForTesting()),
|
||||
},
|
||||
}
|
||||
for _, c := range testCases {
|
||||
if c.got != c.want {
|
||||
t.Errorf("%s: got %v, want %v", c.name, c.got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: How about volatile/screen images?
|
||||
|
Loading…
Reference in New Issue
Block a user