mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
parent
c6b37e9809
commit
cb79e4eabe
@ -493,12 +493,13 @@ func (i *Image) readPixelsFromGPU(graphicsDriver graphicsdriver.Graphics) error
|
|||||||
}
|
}
|
||||||
if !r.Empty() {
|
if !r.Empty() {
|
||||||
var pix []byte
|
var pix []byte
|
||||||
if needsRestoring() && i.needsRestoring() && r == image.Rect(0, 0, i.width, i.height) {
|
if needsRestoring() && i.needsRestoring() {
|
||||||
// pixelsForRestore can be reused as basePixels was invalidated.
|
// pixelsForRestore can be reused as basePixels was invalidated.
|
||||||
if i.pixelsForRestore == nil {
|
l := 4 * r.Dx() * r.Dy()
|
||||||
i.pixelsForRestore = make([]byte, 4*r.Dx()*r.Dy())
|
if len(i.pixelsForRestore) < l {
|
||||||
|
i.pixelsForRestore = make([]byte, l)
|
||||||
}
|
}
|
||||||
pix = i.pixelsForRestore
|
pix = i.pixelsForRestore[:l]
|
||||||
} else {
|
} else {
|
||||||
pix = make([]byte, 4*r.Dx()*r.Dy())
|
pix = make([]byte, 4*r.Dx()*r.Dy())
|
||||||
}
|
}
|
||||||
@ -625,13 +626,15 @@ func (i *Image) restore(graphicsDriver graphicsdriver.Graphics) error {
|
|||||||
if len(i.drawTrianglesHistory) > 0 {
|
if len(i.drawTrianglesHistory) > 0 {
|
||||||
i.basePixels = Pixels{}
|
i.basePixels = Pixels{}
|
||||||
// As basePixels was invalidated, pixelsForRestore can be reused.
|
// As basePixels was invalidated, pixelsForRestore can be reused.
|
||||||
if i.pixelsForRestore == nil {
|
l := 4 * w * h
|
||||||
i.pixelsForRestore = make([]byte, 4*w*h)
|
if len(i.pixelsForRestore) < l {
|
||||||
|
i.pixelsForRestore = make([]byte, l)
|
||||||
}
|
}
|
||||||
if err := gimg.ReadPixels(graphicsDriver, i.pixelsForRestore, 0, 0, w, h); err != nil {
|
pix := i.pixelsForRestore[:l]
|
||||||
|
if err := gimg.ReadPixels(graphicsDriver, pix, 0, 0, w, h); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
i.basePixels.AddOrReplace(i.pixelsForRestore, 0, 0, w, h)
|
i.basePixels.AddOrReplace(pix, 0, 0, w, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
i.image = gimg
|
i.image = gimg
|
||||||
|
Loading…
Reference in New Issue
Block a user