mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-04 15:04:28 +01:00
internal/buffered: refactoring
This commit is contained in:
parent
14c327c89b
commit
ea81d4abf4
@ -138,16 +138,25 @@ func (i *Image) MarkDisposed() {
|
|||||||
i.img.MarkDisposed()
|
i.img.MarkDisposed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *Image) ensurePixels(graphicsDriver graphicsdriver.Graphics) error {
|
||||||
|
if i.pixels != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
pix, err := i.img.Pixels(graphicsDriver)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
i.pixels = pix
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (img *Image) At(graphicsDriver graphicsdriver.Graphics, x, y int) (r, g, b, a byte, err error) {
|
func (img *Image) At(graphicsDriver graphicsdriver.Graphics, x, y int) (r, g, b, a byte, err error) {
|
||||||
checkDelayedCommandsFlushed("At")
|
checkDelayedCommandsFlushed("At")
|
||||||
|
|
||||||
if img.pixels == nil {
|
if err := img.ensurePixels(graphicsDriver); err != nil {
|
||||||
pix, err := img.img.Pixels(graphicsDriver)
|
|
||||||
if err != nil {
|
|
||||||
return 0, 0, 0, 0, err
|
return 0, 0, 0, 0, err
|
||||||
}
|
}
|
||||||
img.pixels = pix
|
|
||||||
}
|
|
||||||
|
|
||||||
idx := 4 * (y*img.width + x)
|
idx := 4 * (y*img.width + x)
|
||||||
return img.pixels[idx], img.pixels[idx+1], img.pixels[idx+2], img.pixels[idx+3], nil
|
return img.pixels[idx], img.pixels[idx+1], img.pixels[idx+2], img.pixels[idx+3], nil
|
||||||
@ -199,13 +208,10 @@ func (i *Image) ReplacePartialPixels(graphicsDriver graphicsdriver.Graphics, pix
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if i.pixels == nil {
|
if err := i.ensurePixels(graphicsDriver); err != nil {
|
||||||
pix, err := i.img.Pixels(graphicsDriver)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
i.pixels = pix
|
|
||||||
}
|
|
||||||
i.replacePendingPixels(pix, x, y, width, height)
|
i.replacePendingPixels(pix, x, y, width, height)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user