mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
restorable: Bug fix: Make limit to the number of draw-image command history (#349)
This commit is contained in:
parent
e8b155fefe
commit
d94e9c9d86
2
image.go
2
image.go
@ -72,7 +72,7 @@ func (i *images) resolveStalePixels(context *opengl.Context) error {
|
|||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
i.lastChecked = nil
|
i.lastChecked = nil
|
||||||
for img := range i.images {
|
for img := range i.images {
|
||||||
if err := img.ReadPixelsFromVRAMIfStale(context); err != nil {
|
if err := img.ResolveStalePixels(context); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,8 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const drawImageHistoryMax = 100
|
||||||
|
|
||||||
type drawImageHistoryItem struct {
|
type drawImageHistoryItem struct {
|
||||||
image *Image
|
image *Image
|
||||||
vertices []float32
|
vertices []float32
|
||||||
@ -129,6 +131,10 @@ func (p *Image) appendDrawImageHistory(image *Image, vertices []float32, colorm
|
|||||||
if p.stale {
|
if p.stale {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if len(p.drawImageHistory)+1 > drawImageHistoryMax {
|
||||||
|
p.makeStale()
|
||||||
|
return
|
||||||
|
}
|
||||||
// All images must be resolved and not stale each after frame.
|
// All images must be resolved and not stale each after frame.
|
||||||
// So we don't have to care if image is stale or not here.
|
// So we don't have to care if image is stale or not here.
|
||||||
item := &drawImageHistoryItem{
|
item := &drawImageHistoryItem{
|
||||||
@ -164,7 +170,6 @@ func (p *Image) MakeStaleIfDependingOn(target *Image) {
|
|||||||
if p.stale {
|
if p.stale {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// TODO: Performance is bad when drawImageHistory is too many.
|
|
||||||
for _, c := range p.drawImageHistory {
|
for _, c := range p.drawImageHistory {
|
||||||
if c.image == target {
|
if c.image == target {
|
||||||
p.makeStale()
|
p.makeStale()
|
||||||
@ -185,7 +190,7 @@ func (p *Image) readPixelsFromVRAM(image *graphics.Image, context *opengl.Contex
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Image) ReadPixelsFromVRAMIfStale(context *opengl.Context) error {
|
func (p *Image) ResolveStalePixels(context *opengl.Context) error {
|
||||||
if p.volatile {
|
if p.volatile {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -199,7 +204,7 @@ func (p *Image) HasDependency() bool {
|
|||||||
if p.stale {
|
if p.stale {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return p.drawImageHistory != nil
|
return len(p.drawImageHistory) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore restores *graphics.Image from the pixels using its state.
|
// Restore restores *graphics.Image from the pixels using its state.
|
||||||
|
Loading…
Reference in New Issue
Block a user