mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
parent
f99c979c98
commit
2da56c00c8
@ -15,16 +15,20 @@
|
||||
package graphicscommand
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/thread"
|
||||
)
|
||||
|
||||
var theRenderThread thread.Thread = thread.NewNoopThread()
|
||||
|
||||
// SetRenderThread must be called from the rendering thread where e.g. OpenGL works.
|
||||
//
|
||||
// TODO: Create thread in this package instead of setting it externally.
|
||||
func SetRenderThread(thread thread.Thread) {
|
||||
theRenderThread = thread
|
||||
// SetOSThreadAsRenderThread sets an OS thread as rendering thread e.g. for OpenGL.
|
||||
func SetOSThreadAsRenderThread() {
|
||||
theRenderThread = thread.NewOSThread()
|
||||
}
|
||||
|
||||
func LoopRenderThread(ctx context.Context) {
|
||||
_ = theRenderThread.Loop(ctx)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
u.mainThread = thread.NewOSThread()
|
||||
u.renderThread = thread.NewOSThread()
|
||||
graphicscommand.SetRenderThread(u.renderThread)
|
||||
graphicscommand.SetOSThreadAsRenderThread()
|
||||
|
||||
// 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.
|
||||
@ -58,7 +57,7 @@ func (u *UserInterface) runMultiThread(game Game, options *RunOptions) error {
|
||||
// Run the render thread.
|
||||
wg.Go(func() error {
|
||||
defer cancel()
|
||||
_ = u.renderThread.Loop(ctx)
|
||||
graphicscommand.LoopRenderThread(ctx)
|
||||
return nil
|
||||
})
|
||||
|
||||
@ -76,8 +75,6 @@ func (u *UserInterface) runMultiThread(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).
|
||||
u.mainThread = thread.NewNoopThread()
|
||||
u.renderThread = thread.NewNoopThread()
|
||||
graphicscommand.SetRenderThread(u.renderThread)
|
||||
|
||||
u.setRunning(true)
|
||||
defer u.setRunning(false)
|
||||
|
@ -82,9 +82,6 @@ type UserInterface struct {
|
||||
|
||||
mainThread thread.Thread
|
||||
|
||||
// TODO: Remove this (#2714).
|
||||
renderThread thread.Thread
|
||||
|
||||
userInterfaceImpl
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,6 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hook"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/thread"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -91,7 +90,7 @@ func (u *UserInterface) Update() error {
|
||||
cancel()
|
||||
}()
|
||||
|
||||
_ = u.renderThread.Loop(ctx)
|
||||
graphicscommand.LoopRenderThread(ctx)
|
||||
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.
|
||||
mgl = <-glContextCh
|
||||
} else {
|
||||
u.renderThread = thread.NewOSThread()
|
||||
graphicscommand.SetRenderThread(u.renderThread)
|
||||
graphicscommand.SetOSThreadAsRenderThread()
|
||||
}
|
||||
|
||||
u.setRunning(true)
|
||||
|
Loading…
Reference in New Issue
Block a user