diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index c870e723c..fccfb3305 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -27,8 +27,8 @@ import ( "time" "github.com/hajimehoshi/ebiten/internal/devicescale" - "github.com/hajimehoshi/ebiten/internal/driver" "github.com/hajimehoshi/ebiten/internal/glfw" + "github.com/hajimehoshi/ebiten/internal/graphicsdriver" "github.com/hajimehoshi/ebiten/internal/hooks" "github.com/hajimehoshi/ebiten/internal/input" "github.com/hajimehoshi/ebiten/internal/mainthread" @@ -65,6 +65,8 @@ type userInterface struct { reqWidth int reqHeight int + driver graphicsdriver.GraphicsDriver + m sync.Mutex } @@ -575,10 +577,12 @@ func DeviceScaleFactor() float64 { return f } -func Run(width, height int, scale float64, title string, g GraphicsContext, mainloop bool) error { +func Run(width, height int, scale float64, title string, g GraphicsContext, mainloop bool, driver graphicsdriver.GraphicsDriver) error { u := currentUI _ = mainthread.Run(func() error { - if driver.Graphics().IsGL() { + u.driver = driver + + if driver.IsGL() { glfw.WindowHint(glfw.ContextVersionMajor, 2) glfw.WindowHint(glfw.ContextVersionMinor, 1) } else { @@ -605,7 +609,7 @@ func Run(width, height int, scale float64, title string, g GraphicsContext, main } u.window = window - if driver.Graphics().IsGL() { + if driver.IsGL() { u.window.MakeContextCurrent() } @@ -680,7 +684,7 @@ func Run(width, height int, scale float64, title string, g GraphicsContext, main w = u.nativeWindow() return nil }) - driver.Graphics().SetWindow(w) + driver.SetWindow(w) return u.loop(g) } @@ -835,7 +839,7 @@ func (u *userInterface) loop(g GraphicsContext) error { // swapBuffers must be called from the main thread. func (u *userInterface) swapBuffers() { - if driver.Graphics().IsGL() { + if u.driver.IsGL() { u.window.SwapBuffers() } } @@ -933,7 +937,7 @@ func (u *userInterface) forceSetScreenSize(width, height int, scale float64, ful u.window.SetTitle(u.title) } - if driver.Graphics().IsGL() { + if u.driver.IsGL() { // SwapInterval is affected by the current monitor of the window. // This needs to be called at least after SetMonitor. // Without SwapInterval after SetMonitor, vsynch doesn't work (#375). @@ -947,7 +951,7 @@ func (u *userInterface) forceSetScreenSize(width, height int, scale float64, ful glfw.SwapInterval(0) } } - driver.Graphics().SetVsyncEnabled(vsync) + u.driver.SetVsyncEnabled(vsync) u.toChangeSize = true } diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index 666076f49..2faf67cea 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -25,6 +25,7 @@ import ( "github.com/gopherjs/gopherwasm/js" "github.com/hajimehoshi/ebiten/internal/devicescale" + "github.com/hajimehoshi/ebiten/internal/graphicsdriver" "github.com/hajimehoshi/ebiten/internal/hooks" "github.com/hajimehoshi/ebiten/internal/input" ) @@ -372,7 +373,7 @@ func Loop(ch <-chan error) error { return <-ch } -func Run(width, height int, scale float64, title string, g GraphicsContext, mainloop bool) error { +func Run(width, height int, scale float64, title string, g GraphicsContext, mainloop bool, driver graphicsdriver.GraphicsDriver) error { u := currentUI document.Set("title", title) u.setScreenSize(width, height, scale, u.fullscreen) diff --git a/internal/ui/ui_mobile.go b/internal/ui/ui_mobile.go index 454b8a2f8..3d720b038 100644 --- a/internal/ui/ui_mobile.go +++ b/internal/ui/ui_mobile.go @@ -31,6 +31,7 @@ import ( "golang.org/x/mobile/gl" "github.com/hajimehoshi/ebiten/internal/devicescale" + "github.com/hajimehoshi/ebiten/internal/graphicsdriver" "github.com/hajimehoshi/ebiten/internal/graphicsdriver/opengl" "github.com/hajimehoshi/ebiten/internal/hooks" "github.com/hajimehoshi/ebiten/internal/input" @@ -141,7 +142,7 @@ func appMain(a app.App) { } } -func Run(width, height int, scale float64, title string, g GraphicsContext, mainloop bool) error { +func Run(width, height int, scale float64, title string, g GraphicsContext, mainloop bool, driver graphicsdriver.GraphicsDriver) error { u := currentUI u.m.Lock() diff --git a/run.go b/run.go index eb7dee811..313d34828 100644 --- a/run.go +++ b/run.go @@ -19,6 +19,7 @@ import ( "sync/atomic" "github.com/hajimehoshi/ebiten/internal/clock" + "github.com/hajimehoshi/ebiten/internal/driver" "github.com/hajimehoshi/ebiten/internal/ui" "github.com/hajimehoshi/ebiten/internal/web" ) @@ -96,7 +97,7 @@ func run(width, height int, scale float64, title string, g *graphicsContext, mai if !web.IsGopherJS() { defer atomic.StoreInt32(&isRunning, 0) } - if err := ui.Run(width, height, scale, title, g, mainloop); err != nil { + if err := ui.Run(width, height, scale, title, g, mainloop, driver.Graphics()); err != nil { if err == ui.RegularTermination { return nil }