mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
graphicsdriver/metal: Optimization
This commit is contained in:
parent
2bc1475a15
commit
00e8b701c1
@ -868,16 +868,32 @@ func (i *Image) Pixels() ([]byte, error) {
|
|||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// needsToSyncBeforeReplaceRegion reports whether syncTexture is needed before calling ReplaceRegion.
|
||||||
|
//
|
||||||
|
// Before a part region is updated, the texture data needs to be loaded to CPU. Otherwise, the remaining region will
|
||||||
|
// be uninitialized (#1213).
|
||||||
|
func (i *Image) needsToSyncBeforeReplaceRegion(args []*driver.ReplacePixelsArgs) bool {
|
||||||
|
if len(args) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if len(args) > 1 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if a := args[0]; a.X == 0 && a.Y == 0 && a.Width == i.width && a.Height == i.height {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (i *Image) ReplacePixels(args []*driver.ReplacePixelsArgs) {
|
func (i *Image) ReplacePixels(args []*driver.ReplacePixelsArgs) {
|
||||||
g := i.graphics
|
g := i.graphics
|
||||||
if g.drawCalled {
|
if g.drawCalled {
|
||||||
g.flush(true, false)
|
g.flush(true, false)
|
||||||
g.drawCalled = false
|
g.drawCalled = false
|
||||||
|
if i.needsToSyncBeforeReplaceRegion(args) {
|
||||||
// When mtl.TextureUsageRenderTarget is specified, synchronizing the texture memory before replacing
|
|
||||||
// a region seems necessary (#1213).
|
|
||||||
i.syncTexture()
|
i.syncTexture()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g.t.Call(func() error {
|
g.t.Call(func() error {
|
||||||
for _, a := range args {
|
for _, a := range args {
|
||||||
|
Loading…
Reference in New Issue
Block a user