mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/buffered: simplify the API
This commit is contained in:
parent
5c3f8915d1
commit
c316aaae72
9
image.go
9
image.go
@ -741,7 +741,7 @@ func (i *Image) Set(x, y int, clr color.Color) {
|
||||
}
|
||||
|
||||
r, g, b, a := clr.RGBA()
|
||||
i.image.ReplacePartialPixels([]byte{byte(r >> 8), byte(g >> 8), byte(b >> 8), byte(a >> 8)}, x, y, 1, 1)
|
||||
i.image.ReplacePixels([]byte{byte(r >> 8), byte(g >> 8), byte(b >> 8), byte(a >> 8)}, x, y, 1, 1)
|
||||
}
|
||||
|
||||
// Dispose disposes the image data.
|
||||
@ -783,16 +783,11 @@ func (i *Image) ReplacePixels(pixels []byte) {
|
||||
return
|
||||
}
|
||||
|
||||
if !i.isSubImage() {
|
||||
i.image.ReplacePixels(pixels)
|
||||
return
|
||||
}
|
||||
|
||||
r := i.Bounds()
|
||||
// Do not need to copy pixels here.
|
||||
// * In internal/mipmap, pixels are copied when necessary.
|
||||
// * In internal/atlas, pixels are copied to make its paddings.
|
||||
i.image.ReplacePartialPixels(pixels, r.Min.X, r.Min.Y, r.Dx(), r.Dy())
|
||||
i.image.ReplacePixels(pixels, r.Min.X, r.Min.Y, r.Dx(), r.Dy())
|
||||
}
|
||||
|
||||
// NewImage returns an empty image.
|
||||
|
@ -174,9 +174,8 @@ func (i *Image) DumpScreenshot(graphicsDriver graphicsdriver.Graphics, name stri
|
||||
}
|
||||
|
||||
// ReplacePixels replaces the pixels at the specified region.
|
||||
// This call is not accumulated and send one draw call to replace pixels.
|
||||
func (i *Image) ReplacePixels(pix []byte) {
|
||||
if l := 4 * i.width * i.height; len(pix) != l {
|
||||
func (i *Image) ReplacePixels(pix []byte, x, y, width, height int) {
|
||||
if l := 4 * width * height; len(pix) != l {
|
||||
panic(fmt.Sprintf("buffered: len(pix) was %d but must be %d", len(pix), l))
|
||||
}
|
||||
|
||||
@ -184,35 +183,21 @@ func (i *Image) ReplacePixels(pix []byte) {
|
||||
copied := make([]byte, len(pix))
|
||||
copy(copied, pix)
|
||||
if tryAddDelayedCommand(func() error {
|
||||
i.ReplacePixels(copied)
|
||||
i.ReplacePixels(copied, x, y, width, height)
|
||||
return nil
|
||||
}) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
i.invalidatePendingPixels()
|
||||
|
||||
i.img.ReplacePixels(pix, nil)
|
||||
}
|
||||
|
||||
// ReplacePartial replaces the pixel at the specified partial region.
|
||||
// This call might be accumulated and send one draw call to replace pixels for the accumulated calls.
|
||||
func (i *Image) ReplacePartialPixels(pix []byte, x, y, width, height int) {
|
||||
if l := 4 * width * height; len(pix) != l {
|
||||
panic(fmt.Sprintf("buffered: len(pix) was %d but must be %d", len(pix), l))
|
||||
if x == 0 && y == 0 && width == i.width && height == i.height {
|
||||
i.invalidatePendingPixels()
|
||||
i.img.ReplacePixels(pix, nil)
|
||||
return
|
||||
}
|
||||
|
||||
if maybeCanAddDelayedCommand() {
|
||||
if tryAddDelayedCommand(func() error {
|
||||
copied := make([]byte, len(pix))
|
||||
copy(copied, pix)
|
||||
i.ReplacePartialPixels(copied, x, y, width, height)
|
||||
return nil
|
||||
}) {
|
||||
return
|
||||
}
|
||||
}
|
||||
// TODO: If width/height is big enough, ReplacePixels can be called instead of replacePendingPixels.
|
||||
// Check if this is efficient.
|
||||
|
||||
i.replacePendingPixels(pix, x, y, width, height)
|
||||
}
|
||||
|
@ -71,13 +71,8 @@ func (m *Mipmap) DumpScreenshot(graphicsDriver graphicsdriver.Graphics, name str
|
||||
return m.orig.DumpScreenshot(graphicsDriver, name, blackbg)
|
||||
}
|
||||
|
||||
func (m *Mipmap) ReplacePixels(pix []byte) {
|
||||
m.orig.ReplacePixels(pix)
|
||||
m.disposeMipmaps()
|
||||
}
|
||||
|
||||
func (m *Mipmap) ReplacePartialPixels(pix []byte, x, y, width, height int) {
|
||||
m.orig.ReplacePartialPixels(pix, x, y, width, height)
|
||||
func (m *Mipmap) ReplacePixels(pix []byte, x, y, width, height int) {
|
||||
m.orig.ReplacePixels(pix, x, y, width, height)
|
||||
m.disposeMipmaps()
|
||||
}
|
||||
|
||||
|
@ -68,12 +68,8 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []f
|
||||
i.mipmap.DrawTriangles(srcMipmaps, vertices, indices, colorm, mode, filter, address, dstRegion, srcRegion, subimageOffsets, s, uniforms, evenOdd, canSkipMipmap)
|
||||
}
|
||||
|
||||
func (i *Image) ReplacePixels(pix []byte) {
|
||||
i.mipmap.ReplacePixels(pix)
|
||||
}
|
||||
|
||||
func (i *Image) ReplacePartialPixels(pix []byte, x, y, width, height int) {
|
||||
i.mipmap.ReplacePartialPixels(pix, x, y, width, height)
|
||||
func (i *Image) ReplacePixels(pix []byte, x, y, width, height int) {
|
||||
i.mipmap.ReplacePixels(pix, x, y, width, height)
|
||||
}
|
||||
|
||||
func (i *Image) At(x, y int) (r, g, b, a byte) {
|
||||
|
Loading…
Reference in New Issue
Block a user