mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
internal/buffered: update pixels instead of dotsBuffer when possible
This commit is contained in:
parent
26e2748732
commit
3cbc1870bf
@ -120,8 +120,20 @@ func (i *Image) WritePixels(pix []byte, region image.Rectangle) {
|
||||
}
|
||||
|
||||
// Writing one pixel is a special case.
|
||||
// Do not discard the cached pixels in this case, especially for (image/draw).Image.
|
||||
// Do not write pixels in GPU especially for (image/draw).Image.
|
||||
if region.Dx() == 1 && region.Dy() == 1 {
|
||||
// If i.pixels exists, update this instead of adding an entry to dotsBuffer.
|
||||
if i.pixels != nil {
|
||||
idx := 4 * (region.Min.Y*i.width + region.Min.X)
|
||||
i.pixels[idx] = pix[0]
|
||||
i.pixels[idx+1] = pix[1]
|
||||
i.pixels[idx+2] = pix[2]
|
||||
i.pixels[idx+3] = pix[3]
|
||||
i.pixelsUnsynced = true
|
||||
delete(i.dotsBuffer, region.Min)
|
||||
return
|
||||
}
|
||||
|
||||
if i.dotsBuffer == nil {
|
||||
i.dotsBuffer = map[image.Point][4]byte{}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user