mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
internal/restorable: refactoring: add Image.needsRestoring
This commit is contained in:
parent
9f729cf5c3
commit
6b212d7642
@ -270,6 +270,10 @@ func (i *Image) ClearPixels(x, y, width, height int) {
|
|||||||
i.ReplacePixels(nil, nil, x, y, width, height)
|
i.ReplacePixels(nil, nil, x, y, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *Image) needsRestoring() bool {
|
||||||
|
return i.imageType == ImageTypeRegular
|
||||||
|
}
|
||||||
|
|
||||||
// ReplacePixels replaces the image pixels with the given pixels slice.
|
// ReplacePixels replaces the image pixels with the given pixels slice.
|
||||||
//
|
//
|
||||||
// The specified region must not be overlapped with other regions by ReplacePixels.
|
// The specified region must not be overlapped with other regions by ReplacePixels.
|
||||||
@ -295,7 +299,7 @@ func (i *Image) ReplacePixels(pixels []byte, mask []byte, x, y, width, height in
|
|||||||
i.image.ReplacePixels(make([]byte, 4*width*height), nil, x, y, width, height)
|
i.image.ReplacePixels(make([]byte, 4*width*height), nil, x, y, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !NeedsRestoring() || i.imageType == ImageTypeScreen || i.imageType == ImageTypeVolatile {
|
if !NeedsRestoring() || !i.needsRestoring() {
|
||||||
i.makeStale()
|
i.makeStale()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -369,7 +373,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, offsets [gra
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if srcstale || i.imageType == ImageTypeScreen || !NeedsRestoring() || i.imageType == ImageTypeVolatile {
|
if srcstale || !NeedsRestoring() || !i.needsRestoring() {
|
||||||
i.makeStale()
|
i.makeStale()
|
||||||
} else {
|
} else {
|
||||||
i.appendDrawTrianglesHistory(srcs, offsets, vertices, indices, colorm, mode, filter, address, dstRegion, srcRegion, shader, uniforms, evenOdd)
|
i.appendDrawTrianglesHistory(srcs, offsets, vertices, indices, colorm, mode, filter, address, dstRegion, srcRegion, shader, uniforms, evenOdd)
|
||||||
@ -394,9 +398,10 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, offsets [gra
|
|||||||
|
|
||||||
// appendDrawTrianglesHistory appends a draw-image history item to the image.
|
// appendDrawTrianglesHistory appends a draw-image history item to the image.
|
||||||
func (i *Image) appendDrawTrianglesHistory(srcs [graphics.ShaderImageNum]*Image, offsets [graphics.ShaderImageNum - 1][2]float32, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms [][]float32, evenOdd bool) {
|
func (i *Image) appendDrawTrianglesHistory(srcs [graphics.ShaderImageNum]*Image, offsets [graphics.ShaderImageNum - 1][2]float32, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms [][]float32, evenOdd bool) {
|
||||||
if i.stale || i.imageType == ImageTypeVolatile || i.imageType == ImageTypeScreen {
|
if i.stale || !i.needsRestoring() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Would it be possible to merge draw image history items?
|
// TODO: Would it be possible to merge draw image history items?
|
||||||
const maxDrawTrianglesHistoryNum = 1024
|
const maxDrawTrianglesHistoryNum = 1024
|
||||||
if len(i.drawTrianglesHistory)+1 > maxDrawTrianglesHistoryNum {
|
if len(i.drawTrianglesHistory)+1 > maxDrawTrianglesHistoryNum {
|
||||||
@ -496,11 +501,7 @@ func (i *Image) resolveStale(graphicsDriver graphicsdriver.Graphics) error {
|
|||||||
if !NeedsRestoring() {
|
if !NeedsRestoring() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if !i.needsRestoring() {
|
||||||
if i.imageType == ImageTypeVolatile {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if i.imageType == ImageTypeScreen {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if !i.stale {
|
if !i.stale {
|
||||||
|
Loading…
Reference in New Issue
Block a user