mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
parent
f99c979c98
commit
2da56c00c8
@ -15,16 +15,20 @@
|
|||||||
package graphicscommand
|
package graphicscommand
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/thread"
|
"github.com/hajimehoshi/ebiten/v2/internal/thread"
|
||||||
)
|
)
|
||||||
|
|
||||||
var theRenderThread thread.Thread = thread.NewNoopThread()
|
var theRenderThread thread.Thread = thread.NewNoopThread()
|
||||||
|
|
||||||
// SetRenderThread must be called from the rendering thread where e.g. OpenGL works.
|
// SetOSThreadAsRenderThread sets an OS thread as rendering thread e.g. for OpenGL.
|
||||||
//
|
func SetOSThreadAsRenderThread() {
|
||||||
// TODO: Create thread in this package instead of setting it externally.
|
theRenderThread = thread.NewOSThread()
|
||||||
func SetRenderThread(thread thread.Thread) {
|
}
|
||||||
theRenderThread = thread
|
|
||||||
|
func LoopRenderThread(ctx context.Context) {
|
||||||
|
_ = theRenderThread.Loop(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// runOnRenderThread calls f on the rendering thread.
|
// runOnRenderThread calls f on the rendering thread.
|
||||||
|
@ -35,8 +35,7 @@ func (u *UserInterface) Run(game Game, options *RunOptions) error {
|
|||||||
|
|
||||||
func (u *UserInterface) runMultiThread(game Game, options *RunOptions) error {
|
func (u *UserInterface) runMultiThread(game Game, options *RunOptions) error {
|
||||||
u.mainThread = thread.NewOSThread()
|
u.mainThread = thread.NewOSThread()
|
||||||
u.renderThread = thread.NewOSThread()
|
graphicscommand.SetOSThreadAsRenderThread()
|
||||||
graphicscommand.SetRenderThread(u.renderThread)
|
|
||||||
|
|
||||||
// Set the running state true after the main thread is set, and before initOnMainThread is called (#2742).
|
// Set the running state true after the main thread is set, and before initOnMainThread is called (#2742).
|
||||||
// TODO: As the existence of the main thread is the same as the value of `running`, this is redundant.
|
// TODO: As the existence of the main thread is the same as the value of `running`, this is redundant.
|
||||||
@ -58,7 +57,7 @@ func (u *UserInterface) runMultiThread(game Game, options *RunOptions) error {
|
|||||||
// Run the render thread.
|
// Run the render thread.
|
||||||
wg.Go(func() error {
|
wg.Go(func() error {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
_ = u.renderThread.Loop(ctx)
|
graphicscommand.LoopRenderThread(ctx)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -76,8 +75,6 @@ func (u *UserInterface) runMultiThread(game Game, options *RunOptions) error {
|
|||||||
func (u *UserInterface) runSingleThread(game Game, options *RunOptions) error {
|
func (u *UserInterface) runSingleThread(game Game, options *RunOptions) error {
|
||||||
// Initialize the main thread first so the thread is available at u.run (#809).
|
// Initialize the main thread first so the thread is available at u.run (#809).
|
||||||
u.mainThread = thread.NewNoopThread()
|
u.mainThread = thread.NewNoopThread()
|
||||||
u.renderThread = thread.NewNoopThread()
|
|
||||||
graphicscommand.SetRenderThread(u.renderThread)
|
|
||||||
|
|
||||||
u.setRunning(true)
|
u.setRunning(true)
|
||||||
defer u.setRunning(false)
|
defer u.setRunning(false)
|
||||||
|
@ -82,9 +82,6 @@ type UserInterface struct {
|
|||||||
|
|
||||||
mainThread thread.Thread
|
mainThread thread.Thread
|
||||||
|
|
||||||
// TODO: Remove this (#2714).
|
|
||||||
renderThread thread.Thread
|
|
||||||
|
|
||||||
userInterfaceImpl
|
userInterfaceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,6 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/hook"
|
"github.com/hajimehoshi/ebiten/v2/internal/hook"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/thread"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -91,7 +90,7 @@ func (u *UserInterface) Update() error {
|
|||||||
cancel()
|
cancel()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
_ = u.renderThread.Loop(ctx)
|
graphicscommand.LoopRenderThread(ctx)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,8 +272,7 @@ func (u *UserInterface) runMobile(game Game, mainloop bool, options *RunOptions)
|
|||||||
// gl.Context so that they are called on the appropriate thread.
|
// gl.Context so that they are called on the appropriate thread.
|
||||||
mgl = <-glContextCh
|
mgl = <-glContextCh
|
||||||
} else {
|
} else {
|
||||||
u.renderThread = thread.NewOSThread()
|
graphicscommand.SetOSThreadAsRenderThread()
|
||||||
graphicscommand.SetRenderThread(u.renderThread)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u.setRunning(true)
|
u.setRunning(true)
|
||||||
|
Loading…
Reference in New Issue
Block a user