mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-12 22:17:26 +01:00
restorable: Bug fix: Reading pixels from a volatile image might fail
Fixes #793
This commit is contained in:
parent
837571d05c
commit
158f4fb3ed
@ -241,7 +241,7 @@ func (i *Image) DrawImage(img *Image, vertices []float32, indices []uint16, colo
|
|||||||
}
|
}
|
||||||
theImages.makeStaleIfDependingOn(i)
|
theImages.makeStaleIfDependingOn(i)
|
||||||
|
|
||||||
if img.stale || img.volatile || i.screen || !IsRestoringEnabled() {
|
if img.stale || img.volatile || i.screen || !IsRestoringEnabled() || i.volatile {
|
||||||
i.makeStale()
|
i.makeStale()
|
||||||
} else {
|
} else {
|
||||||
i.appendDrawImageHistory(img, vertices, indices, colorm, mode, filter, address)
|
i.appendDrawImageHistory(img, vertices, indices, colorm, mode, filter, address)
|
||||||
@ -274,7 +274,7 @@ func (i *Image) appendDrawImageHistory(image *Image, vertices []float32, indices
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) readPixelsFromGPUIfNeeded() {
|
func (i *Image) readPixelsFromGPUIfNeeded() {
|
||||||
if i.basePixels == nil || i.drawImageHistory != nil || i.stale {
|
if i.basePixels == nil || len(i.drawImageHistory) > 0 || i.stale {
|
||||||
graphicscommand.FlushCommands()
|
graphicscommand.FlushCommands()
|
||||||
i.readPixelsFromGPU()
|
i.readPixelsFromGPU()
|
||||||
i.drawImageHistory = nil
|
i.drawImageHistory = nil
|
||||||
|
@ -652,3 +652,27 @@ func TestReplacePixelsOnly(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: How about volatile/screen images?
|
// TODO: How about volatile/screen images?
|
||||||
|
|
||||||
|
// Issue #793
|
||||||
|
func TestReadPixelsFromVolatileImage(t *testing.T) {
|
||||||
|
const w, h = 16, 16
|
||||||
|
dst := NewImage(w, h, true)
|
||||||
|
src := NewImage(w, h, false)
|
||||||
|
|
||||||
|
// First, make sure that dst has pixels
|
||||||
|
dst.ReplacePixels(make([]byte, 4*w*h), 0, 0, w, h)
|
||||||
|
|
||||||
|
// Second, draw src to dst. If the implementation is correct, drawImageHistory is created.
|
||||||
|
fill(src, 0xff, 0xff, 0xff, 0xff)
|
||||||
|
vs := graphics.QuadVertices(w, h, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||||
|
is := graphics.QuadIndices()
|
||||||
|
dst.DrawImage(src, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
|
||||||
|
|
||||||
|
// Read the pixels. If the implementation is correct, dst tries to read its pixels from GPU due to
|
||||||
|
// drawImageHistory items.
|
||||||
|
want := byte(0xff)
|
||||||
|
got, _, _, _ := dst.At(0, 0)
|
||||||
|
if got != want {
|
||||||
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user