diff --git a/internal/restorable/image.go b/internal/restorable/image.go index ef7c8703a..7a8511dc5 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -121,6 +121,7 @@ type Image struct { // staleRegions indicates the regions to restore. // staleRegions is valid only when stale is true. + // staleRegions is not used when alwaysReadPixelsFromGPU() returns true. staleRegions []image.Rectangle imageType ImageType @@ -261,6 +262,11 @@ func (i *Image) BasePixelsForTesting() *Pixels { func (i *Image) makeStale(rect image.Rectangle) { i.stale = true + // If ReadPixels always reads pixels from GPU, staleRegions are never used. + if alwaysReadPixelsFromGPU() { + return + } + i.staleRegions = i.appendRegionsForDrawTriangles(i.staleRegions) if !rect.Empty() { i.staleRegions = append(i.staleRegions, rect) @@ -402,6 +408,9 @@ func (i *Image) appendDrawTrianglesHistory(srcs [graphics.ShaderImageCount]*Imag if i.stale || !i.needsRestoring() { panic("restorable: an image must not be stale or need restoring at appendDrawTrianglesHistory") } + if alwaysReadPixelsFromGPU() { + panic("restorable: appendDrawTrianglesHistory must not be called when alwaysReadPixelsFromGPU() returns true") + } // TODO: Would it be possible to merge draw image history items? const maxDrawTrianglesHistoryCount = 1024