mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 11:48:55 +01:00
parent
529dddda53
commit
ec59e9b9ae
@ -27,7 +27,8 @@ type Image struct {
|
|||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
|
|
||||||
pendingPixels []byte
|
pixels []byte
|
||||||
|
needsToResolvePixels bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func BeginFrame() error {
|
func BeginFrame() error {
|
||||||
@ -83,18 +84,19 @@ func NewScreenFramebufferImage(width, height int) *Image {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) invalidatePendingPixels() {
|
func (i *Image) invalidatePendingPixels() {
|
||||||
i.pendingPixels = nil
|
i.pixels = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) resolvePendingPixels(keepPendingPixels bool) {
|
func (i *Image) resolvePendingPixels(keepPendingPixels bool) {
|
||||||
if i.pendingPixels == nil {
|
if !i.needsToResolvePixels {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
i.img.ReplacePixels(i.pendingPixels)
|
i.img.ReplacePixels(i.pixels)
|
||||||
if !keepPendingPixels {
|
if !keepPendingPixels {
|
||||||
i.pendingPixels = nil
|
i.pixels = nil
|
||||||
}
|
}
|
||||||
|
i.needsToResolvePixels = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) MarkDisposed() {
|
func (i *Image) MarkDisposed() {
|
||||||
@ -138,7 +140,7 @@ func (i *Image) Set(x, y int, r, g, b, a byte) {
|
|||||||
|
|
||||||
func (img *Image) set(x, y int, r, g, b, a byte) {
|
func (img *Image) set(x, y int, r, g, b, a byte) {
|
||||||
w, h := img.width, img.height
|
w, h := img.width, img.height
|
||||||
if img.pendingPixels == nil {
|
if img.pixels == nil {
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
idx := 0
|
idx := 0
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
@ -151,12 +153,13 @@ func (img *Image) set(x, y int, r, g, b, a byte) {
|
|||||||
idx++
|
idx++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
img.pendingPixels = pix
|
img.pixels = pix
|
||||||
}
|
}
|
||||||
img.pendingPixels[4*(x+y*w)] = r
|
img.pixels[4*(x+y*w)] = r
|
||||||
img.pendingPixels[4*(x+y*w)+1] = g
|
img.pixels[4*(x+y*w)+1] = g
|
||||||
img.pendingPixels[4*(x+y*w)+2] = b
|
img.pixels[4*(x+y*w)+2] = b
|
||||||
img.pendingPixels[4*(x+y*w)+3] = a
|
img.pixels[4*(x+y*w)+3] = a
|
||||||
|
img.needsToResolvePixels = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) Dump(name string) error {
|
func (i *Image) Dump(name string) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user