mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
restorable: Merge draw image history items if possible (#379)
This commit is contained in:
parent
979836d0f5
commit
565a28ff04
@ -32,6 +32,19 @@ type drawImageHistoryItem struct {
|
||||
mode opengl.CompositeMode
|
||||
}
|
||||
|
||||
func (d *drawImageHistoryItem) canMerge(image *Image, colorm *affine.ColorM, mode opengl.CompositeMode) bool {
|
||||
if d.image != image {
|
||||
return false
|
||||
}
|
||||
if !d.colorm.Equals(colorm) {
|
||||
return false
|
||||
}
|
||||
if d.mode != mode {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Image represents an image that can be restored when GL context is lost.
|
||||
type Image struct {
|
||||
image *graphics.Image
|
||||
@ -154,9 +167,16 @@ func (p *Image) DrawImage(img *Image, vertices []float32, colorm *affine.ColorM,
|
||||
}
|
||||
|
||||
func (p *Image) appendDrawImageHistory(image *Image, vertices []float32, colorm *affine.ColorM, mode opengl.CompositeMode) {
|
||||
if p.stale {
|
||||
if p.stale || p.volatile {
|
||||
return
|
||||
}
|
||||
if len(p.drawImageHistory) > 0 {
|
||||
last := p.drawImageHistory[len(p.drawImageHistory)-1]
|
||||
if last.canMerge(image, colorm, mode) {
|
||||
last.vertices = append(last.vertices, vertices...)
|
||||
return
|
||||
}
|
||||
}
|
||||
const maxDrawImageHistoryNum = 100
|
||||
if len(p.drawImageHistory)+1 > maxDrawImageHistoryNum {
|
||||
p.makeStale()
|
||||
|
Loading…
Reference in New Issue
Block a user