mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphics: Improve clearing the offscreen performance
This commit is contained in:
parent
d1ac0e1857
commit
d0592d30e0
@ -88,7 +88,8 @@ func (c *graphicsContext) Update(afterFrameUpdate func()) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for i := 0; i < updateCount; i++ {
|
for i := 0; i < updateCount; i++ {
|
||||||
restorable.ClearVolatileImages()
|
c.offscreen.fill(0, 0, 0, 0)
|
||||||
|
|
||||||
setRunningSlowly(i < updateCount-1)
|
setRunningSlowly(i < updateCount-1)
|
||||||
if err := hooks.Run(); err != nil {
|
if err := hooks.Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -115,25 +115,6 @@ func (i *Image) makeStale() {
|
|||||||
i.stale = true
|
i.stale = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// clearIfVolatile clears the image if the image is volatile.
|
|
||||||
func (i *Image) clearIfVolatile() {
|
|
||||||
if !i.volatile {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
i.basePixels = nil
|
|
||||||
i.drawImageHistory = nil
|
|
||||||
i.stale = false
|
|
||||||
if i.image == nil {
|
|
||||||
panic("not reached")
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: ReplacePixels is bad in terms of performance. Use DrawImage if possible.
|
|
||||||
// Note that using DrawImage with *graphics.Image directly is dangerous since the image
|
|
||||||
// is never restored from context lost.
|
|
||||||
w, h := i.image.Size()
|
|
||||||
i.image.ReplacePixels(make([]byte, 4*w*h), 0, 0, w, h)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReplacePixels replaces the image pixels with the given pixels slice.
|
// ReplacePixels replaces the image pixels with the given pixels slice.
|
||||||
func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
||||||
w, h := i.image.Size()
|
w, h := i.image.Size()
|
||||||
|
@ -73,13 +73,6 @@ func Restore() error {
|
|||||||
return theImages.restore()
|
return theImages.restore()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearVolatileImages clears volatile images.
|
|
||||||
//
|
|
||||||
// ClearVolatileImages is intended to be called at the start of a frame.
|
|
||||||
func ClearVolatileImages() {
|
|
||||||
theImages.clearVolatileImages()
|
|
||||||
}
|
|
||||||
|
|
||||||
// add adds img to the images.
|
// add adds img to the images.
|
||||||
func (i *images) add(img *Image) {
|
func (i *images) add(img *Image) {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
@ -195,15 +188,6 @@ func (i *images) restore() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// clearVolatileImages clears the volatile images.
|
|
||||||
func (i *images) clearVolatileImages() {
|
|
||||||
i.m.Lock()
|
|
||||||
defer i.m.Unlock()
|
|
||||||
for img := range i.images {
|
|
||||||
img.clearIfVolatile()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// InitializeGLState initializes the GL state.
|
// InitializeGLState initializes the GL state.
|
||||||
func InitializeGLState() error {
|
func InitializeGLState() error {
|
||||||
return graphics.ResetGLState()
|
return graphics.ResetGLState()
|
||||||
|
Loading…
Reference in New Issue
Block a user