diff --git a/init.go b/init.go index 3a55254ac..b783bcc48 100644 --- a/init.go +++ b/init.go @@ -20,5 +20,5 @@ import ( ) func init() { - graphicscommand.SetGraphicsDriver(ui.Get().Graphics()) + graphicscommand.SetGraphicsDriver(ui.Graphics()) } diff --git a/internal/ui/graphics_darwin.go b/internal/ui/graphics_darwin.go index e082201c6..f58e81a79 100644 --- a/internal/ui/graphics_darwin.go +++ b/internal/ui/graphics_darwin.go @@ -64,6 +64,6 @@ func init() { graphics = opengl.Get() } -func (*UserInterface) Graphics() driver.Graphics { +func Graphics() driver.Graphics { return graphics } diff --git a/internal/ui/graphics_ios.go b/internal/ui/graphics_ios.go index ca40b74fd..9adced660 100644 --- a/internal/ui/graphics_ios.go +++ b/internal/ui/graphics_ios.go @@ -27,7 +27,7 @@ import ( "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/mtl" ) -func (*UserInterface) Graphics() driver.Graphics { +func Graphics() driver.Graphics { if _, err := mtl.CreateSystemDefaultDevice(); err != nil { panic(fmt.Sprintf("mobile: mtl.CreateSystemDefaultDevice failed on iOS: %v", err)) } diff --git a/internal/ui/graphics_opengl.go b/internal/ui/graphics_opengl.go index 662545d2f..ce2cd16d9 100644 --- a/internal/ui/graphics_opengl.go +++ b/internal/ui/graphics_opengl.go @@ -22,6 +22,6 @@ import ( "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl" ) -func (*UserInterface) Graphics() driver.Graphics { +func Graphics() driver.Graphics { return opengl.Get() } diff --git a/internal/ui/ui_darwin.go b/internal/ui/ui_darwin.go index a7889b187..af031f591 100644 --- a/internal/ui/ui_darwin.go +++ b/internal/ui/ui_darwin.go @@ -195,7 +195,7 @@ func (u *UserInterface) setNativeFullscreen(fullscreen bool) { } func (u *UserInterface) adjustViewSize() { - if u.Graphics().IsGL() { + if Graphics().IsGL() { return } C.adjustViewSize(C.uintptr_t(u.window.GetCocoaWindow())) diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 3b274f809..bb44f976f 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -700,7 +700,7 @@ func (u *UserInterface) createWindow() error { // Ensure to consume this callback. u.waitForFramebufferSizeCallback(u.window, nil) - if u.Graphics().IsGL() { + if Graphics().IsGL() { u.window.MakeContextCurrent() } @@ -735,7 +735,7 @@ func (u *UserInterface) registerWindowSetSizeCallback() { if err := u.runOnAnotherThreadFromMainThread(func() error { // Disable Vsync temporarily. On macOS, getting a next frame can get stuck (#1740). - u.Graphics().SetVsyncEnabled(false) + Graphics().SetVsyncEnabled(false) var outsideWidth, outsideHeight float64 @@ -752,7 +752,7 @@ func (u *UserInterface) registerWindowSetSizeCallback() { if err := u.context.ForceUpdateFrame(); err != nil { return err } - if u.Graphics().IsGL() { + if Graphics().IsGL() { u.t.Call(func() { u.swapBuffers() }) @@ -852,7 +852,7 @@ event: } func (u *UserInterface) init() error { - if u.Graphics().IsGL() { + if Graphics().IsGL() { glfw.WindowHint(glfw.ClientAPI, glfw.OpenGLAPI) glfw.WindowHint(glfw.ContextVersionMajor, 2) glfw.WindowHint(glfw.ContextVersionMinor, 1) @@ -873,7 +873,7 @@ func (u *UserInterface) init() error { transparent = glfw.True } glfw.WindowHint(glfw.TransparentFramebuffer, transparent) - u.Graphics().SetTransparent(u.isInitScreenTransparent()) + Graphics().SetTransparent(u.isInitScreenTransparent()) resizable := glfw.False if u.isInitWindowResizable() { @@ -931,7 +931,7 @@ func (u *UserInterface) init() error { u.window.SetTitle(u.title) u.window.Show() - if g, ok := u.Graphics().(interface{ SetWindow(uintptr) }); ok { + if g, ok := Graphics().(interface{ SetWindow(uintptr) }); ok { g.SetWindow(u.nativeWindow()) } @@ -1109,7 +1109,7 @@ func (u *UserInterface) loop() error { // swapBuffers also checks IsGL, so this condition is redundant. // However, (*thread).Call is not good for performance due to channels. // Let's avoid this whenever possible (#1367). - if u.Graphics().IsGL() { + if Graphics().IsGL() { u.t.Call(u.swapBuffers) } @@ -1131,7 +1131,7 @@ func (u *UserInterface) loop() error { // swapBuffers must be called from the main thread. func (u *UserInterface) swapBuffers() { - if u.Graphics().IsGL() { + if Graphics().IsGL() { u.window.SwapBuffers() } } @@ -1186,7 +1186,7 @@ func (u *UserInterface) adjustWindowSizeBasedOnSizeLimitsInDIP(width, height int func (u *UserInterface) setWindowSizeInDIP(width, height int, fullscreen bool) { width, height = u.adjustWindowSizeBasedOnSizeLimitsInDIP(width, height) - u.Graphics().SetFullscreen(fullscreen) + Graphics().SetFullscreen(fullscreen) scale := u.deviceScaleFactor(u.currentMonitor()) if u.windowWidthInDIP == width && u.windowHeightInDIP == height && u.isFullscreen() == fullscreen && u.lastDeviceScaleFactor == scale { @@ -1226,7 +1226,7 @@ func (u *UserInterface) setWindowSizeInDIP(width, height int, fullscreen bool) { u.windowHeightInDIP = height if windowRecreated { - if g, ok := u.Graphics().(interface{ SetWindow(uintptr) }); ok { + if g, ok := Graphics().(interface{ SetWindow(uintptr) }); ok { g.SetWindow(u.nativeWindow()) } } @@ -1249,7 +1249,7 @@ func (u *UserInterface) setWindowSizeInDIPImpl(width, height int, fullscreen boo // Swapping buffer is necesary to prevent the image lag (#1004). // TODO: This might not work when vsync is disabled. - if u.Graphics().IsGL() { + if Graphics().IsGL() { glfw.PollEvents() u.swapBuffers() } @@ -1269,7 +1269,7 @@ func (u *UserInterface) setWindowSizeInDIPImpl(width, height int, fullscreen boo if u.isNativeFullscreenAvailable() && u.isNativeFullscreen() { u.setNativeFullscreen(false) } else if !u.isNativeFullscreenAvailable() && u.window.GetMonitor() != nil { - if u.Graphics().IsGL() { + if Graphics().IsGL() { // When OpenGL is used, swapping buffer is enough to solve the image-lag // issue (#1004). Rather, recreating window destroys GPU resources. // TODO: This might not work when vsync is disabled. @@ -1326,7 +1326,7 @@ func (u *UserInterface) setWindowSizeInDIPImpl(width, height int, fullscreen boo // updateVsync must be called on the main thread. func (u *UserInterface) updateVsync() { - if u.Graphics().IsGL() { + if Graphics().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). @@ -1340,7 +1340,7 @@ func (u *UserInterface) updateVsync() { glfw.SwapInterval(0) } } - u.Graphics().SetVsyncEnabled(u.fpsMode == FPSModeVsyncOn) + Graphics().SetVsyncEnabled(u.fpsMode == FPSModeVsyncOn) } // initialMonitor returns the initial monitor to show the window. diff --git a/internal/ui/ui_mobile.go b/internal/ui/ui_mobile.go index 77af63119..fda44e979 100644 --- a/internal/ui/ui_mobile.go +++ b/internal/ui/ui_mobile.go @@ -279,7 +279,7 @@ func (u *UserInterface) run(context Context, mainloop bool) (err error) { // When mainloop is true, gomobile-build is used. In this case, GL functions must be called via // gl.Context so that they are called on the appropriate thread. ctx := <-glContextCh - u.Graphics().(*opengl.Graphics).SetGomobileGLContext(ctx) + Graphics().(*opengl.Graphics).SetGomobileGLContext(ctx) } else { u.t = thread.NewOSThread() graphicscommand.SetMainThread(u.t) diff --git a/uicontext.go b/uicontext.go index 4525cacfd..8677d2520 100644 --- a/uicontext.go +++ b/uicontext.go @@ -200,7 +200,7 @@ func (c *uiContext) updateFrameImpl(updateCount int) error { } c.game.Draw(c.offscreen) - if ui.Get().Graphics().NeedsClearingScreen() { + if ui.Graphics().NeedsClearingScreen() { // This clear is needed for fullscreen mode or some mobile platforms (#622). c.screen.Clear() } @@ -208,7 +208,7 @@ func (c *uiContext) updateFrameImpl(updateCount int) error { op := &DrawImageOptions{} s := c.screenScale(ui.Get().DeviceScaleFactor()) - switch vd := ui.Get().Graphics().FramebufferYDirection(); vd { + switch vd := ui.Graphics().FramebufferYDirection(); vd { case driver.Upward: op.GeoM.Scale(s, -s) _, h := c.offscreen.Size()