mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
Revert "internal/restorable: use a smaller size rectangle for staleRegion"
This reverts commit e4debfd466
.
Reason: test failures on Windows: https://github.com/hajimehoshi/ebiten/actions/runs/4262488629/jobs/7418053241
This commit is contained in:
parent
e4debfd466
commit
185529f1cb
@ -17,7 +17,6 @@ package restorable
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"math"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
||||
@ -270,14 +269,7 @@ func (i *Image) BasePixelsForTesting() *Pixels {
|
||||
// makeStale makes the image stale.
|
||||
func (i *Image) makeStale(rect image.Rectangle) {
|
||||
i.stale = true
|
||||
|
||||
r := i.staleRegion
|
||||
r = r.Union(i.basePixels.Region())
|
||||
for _, d := range i.drawTrianglesHistory {
|
||||
r = r.Union(regionToRectangle(d.dstRegion))
|
||||
}
|
||||
r = r.Union(rect)
|
||||
i.staleRegion = r
|
||||
i.staleRegion = i.staleRegion.Union(i.basePixels.Region()).Union(rect)
|
||||
|
||||
i.basePixels = Pixels{}
|
||||
i.clearDrawTrianglesHistory()
|
||||
@ -346,7 +338,7 @@ func (i *Image) WritePixels(pixels []byte, x, y, width, height int) {
|
||||
|
||||
// Records for DrawTriangles cannot come before records for WritePixels.
|
||||
if len(i.drawTrianglesHistory) > 0 {
|
||||
i.makeStale(image.Rect(x, y, x+width, y+height))
|
||||
i.makeStale(image.Rect(0, 0, i.width, i.height))
|
||||
return
|
||||
}
|
||||
|
||||
@ -394,9 +386,8 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, offsets [g
|
||||
}
|
||||
}
|
||||
|
||||
// Even if the image is already stale, call makeStale to extend the stale region.
|
||||
if srcstale || !needsRestoring() || !i.needsRestoring() || i.stale {
|
||||
i.makeStale(regionToRectangle(dstRegion))
|
||||
if srcstale || !needsRestoring() || !i.needsRestoring() {
|
||||
i.makeStale(image.Rect(0, 0, i.width, i.height))
|
||||
} else {
|
||||
i.appendDrawTrianglesHistory(srcs, offsets, vertices, indices, blend, dstRegion, srcRegion, shader, uniforms, evenOdd)
|
||||
}
|
||||
@ -414,13 +405,13 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, offsets [g
|
||||
// appendDrawTrianglesHistory appends a draw-image history item to the image.
|
||||
func (i *Image) appendDrawTrianglesHistory(srcs [graphics.ShaderImageCount]*Image, offsets [graphics.ShaderImageCount - 1][2]float32, vertices []float32, indices []uint16, blend graphicsdriver.Blend, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms []uint32, evenOdd bool) {
|
||||
if i.stale || !i.needsRestoring() {
|
||||
panic("restorable: an image must not be stale or need restoring at appendDrawTrianglesHistory")
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: Would it be possible to merge draw image history items?
|
||||
const maxDrawTrianglesHistoryCount = 1024
|
||||
if len(i.drawTrianglesHistory)+1 > maxDrawTrianglesHistoryCount {
|
||||
i.makeStale(regionToRectangle(dstRegion))
|
||||
i.makeStale(image.Rect(0, 0, i.width, i.height))
|
||||
return
|
||||
}
|
||||
// All images must be resolved and not stale each after frame.
|
||||
@ -476,8 +467,7 @@ func (i *Image) makeStaleIfDependingOn(target *Image) {
|
||||
return
|
||||
}
|
||||
if i.dependsOn(target) {
|
||||
// There is no new region to make stale.
|
||||
i.makeStale(image.Rectangle{})
|
||||
i.makeStale(image.Rect(0, 0, i.width, i.height))
|
||||
}
|
||||
}
|
||||
|
||||
@ -487,21 +477,16 @@ func (i *Image) makeStaleIfDependingOnShader(shader *Shader) {
|
||||
return
|
||||
}
|
||||
if i.dependsOnShader(shader) {
|
||||
// There is no new region to make stale.
|
||||
i.makeStale(image.Rectangle{})
|
||||
i.makeStale(image.Rect(0, 0, i.width, i.height))
|
||||
}
|
||||
}
|
||||
|
||||
// readPixelsFromGPU reads the pixels from GPU and resolves the image's 'stale' state.
|
||||
func (i *Image) readPixelsFromGPU(graphicsDriver graphicsdriver.Graphics) error {
|
||||
i.basePixels = Pixels{}
|
||||
var r image.Rectangle
|
||||
if i.stale {
|
||||
r = i.staleRegion
|
||||
} else {
|
||||
for _, d := range i.drawTrianglesHistory {
|
||||
r = r.Union(regionToRectangle(d.dstRegion))
|
||||
}
|
||||
r := i.staleRegion
|
||||
if len(i.drawTrianglesHistory) > 0 {
|
||||
r = image.Rect(0, 0, i.width, i.height)
|
||||
}
|
||||
if !r.Empty() {
|
||||
var pix []byte
|
||||
@ -693,11 +678,3 @@ func (i *Image) clearDrawTrianglesHistory() {
|
||||
func (i *Image) InternalSize() (int, int) {
|
||||
return i.image.InternalSize()
|
||||
}
|
||||
|
||||
func regionToRectangle(region graphicsdriver.Region) image.Rectangle {
|
||||
return image.Rect(
|
||||
int(math.Floor(float64(region.X))),
|
||||
int(math.Floor(float64(region.Y))),
|
||||
int(math.Ceil(float64(region.X+region.Width))),
|
||||
int(math.Ceil(float64(region.Y+region.Height))))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user