mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
graphicsdriver/metal: Make main-thread usages more explicit
This commit is contained in:
parent
86bda42417
commit
b349efaa0a
@ -243,9 +243,12 @@ func Get() *Driver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) SetWindow(window uintptr) {
|
func (d *Driver) SetWindow(window uintptr) {
|
||||||
// Note that [NSApp mainWindow] returns nil when the window is borderless.
|
mainthread.Run(func() error {
|
||||||
// Then the window is needed to be given.
|
// Note that [NSApp mainWindow] returns nil when the window is borderless.
|
||||||
d.window = window
|
// Then the window is needed to be given.
|
||||||
|
d.window = window
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) SetVertices(vertices []float32, indices []uint16) {
|
func (d *Driver) SetVertices(vertices []float32, indices []uint16) {
|
||||||
@ -565,7 +568,10 @@ func (d *Driver) Draw(indexLen int, indexOffset int, mode graphics.CompositeMode
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) ResetSource() {
|
func (d *Driver) ResetSource() {
|
||||||
d.src = nil
|
mainthread.Run(func() error {
|
||||||
|
d.src = nil
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) SetVsyncEnabled(enabled bool) {
|
func (d *Driver) SetVsyncEnabled(enabled bool) {
|
||||||
@ -591,6 +597,7 @@ type Image struct {
|
|||||||
texture mtl.Texture
|
texture mtl.Texture
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// viewportSize must be called from the main thread.
|
||||||
func (i *Image) viewportSize() (int, int) {
|
func (i *Image) viewportSize() (int, int) {
|
||||||
if i.screen {
|
if i.screen {
|
||||||
return i.width, i.height
|
return i.width, i.height
|
||||||
@ -643,11 +650,17 @@ func (i *Image) Pixels() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) SetAsDestination() {
|
func (i *Image) SetAsDestination() {
|
||||||
i.driver.dst = i
|
mainthread.Run(func() error {
|
||||||
|
i.driver.dst = i
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) SetAsSource() {
|
func (i *Image) SetAsSource() {
|
||||||
i.driver.src = i
|
mainthread.Run(func() error {
|
||||||
|
i.driver.src = i
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
||||||
|
@ -594,10 +594,9 @@ func Run(width, height int, scale float64, title string, g GraphicsContext, main
|
|||||||
y := my + (v.Height-h)/3
|
y := my + (v.Height-h)/3
|
||||||
x, y = adjustWindowPosition(x, y)
|
x, y = adjustWindowPosition(x, y)
|
||||||
u.window.SetPos(x, y)
|
u.window.SetPos(x, y)
|
||||||
|
|
||||||
u.setWindowToDriver()
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
u.setWindowToDriver()
|
||||||
return u.loop(g)
|
return u.loop(g)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user