From f04d9d6925227babc5d65d8fe9dc3fe7c56d2655 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 25 Feb 2023 23:24:09 +0900 Subject: [PATCH] internal/restoring: avoid using staleRegions when alwaysReadPixelsFromGPU is true Updates #2582 --- internal/restorable/image.go | 9 +++++++++ 1 file changed, 9 insertions(+) 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