diff --git a/graphics.go b/graphics.go index bd52d9d1e..30dd9b865 100644 --- a/graphics.go +++ b/graphics.go @@ -66,5 +66,5 @@ type DebugInfo struct { // ReadDebugInfo writes debug info (e.g. current graphics library) into a provided struct. func ReadDebugInfo(d *DebugInfo) { - d.GraphicsLibrary = GraphicsLibrary(ui.Get().GetGraphicsLibrary()) + d.GraphicsLibrary = GraphicsLibrary(ui.Get().GraphicsLibrary()) } diff --git a/internal/graphicsdriver/directx/graphics11_windows.go b/internal/graphicsdriver/directx/graphics11_windows.go index e2002da30..8342ba562 100644 --- a/internal/graphicsdriver/directx/graphics11_windows.go +++ b/internal/graphicsdriver/directx/graphics11_windows.go @@ -472,14 +472,6 @@ func (g *graphics11) NeedsClearingScreen() bool { return true } -func (g *graphics11) IsGL() bool { - return false -} - -func (g *graphics11) IsDirectX() bool { - return true -} - func (g *graphics11) MaxImageSize() int { switch g.featureLevel { case _D3D_FEATURE_LEVEL_10_0: diff --git a/internal/graphicsdriver/directx/graphics12_windows.go b/internal/graphicsdriver/directx/graphics12_windows.go index 974059e48..f6fcd3add 100644 --- a/internal/graphicsdriver/directx/graphics12_windows.go +++ b/internal/graphicsdriver/directx/graphics12_windows.go @@ -1063,14 +1063,6 @@ func (g *graphics12) NeedsClearingScreen() bool { return true } -func (g *graphics12) IsGL() bool { - return false -} - -func (g *graphics12) IsDirectX() bool { - return true -} - func (g *graphics12) MaxImageSize() int { return _D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION } diff --git a/internal/graphicsdriver/graphics.go b/internal/graphicsdriver/graphics.go index 18750ddd1..bc8688cf9 100644 --- a/internal/graphicsdriver/graphics.go +++ b/internal/graphicsdriver/graphics.go @@ -42,8 +42,6 @@ type Graphics interface { SetVsyncEnabled(enabled bool) NeedsRestoring() bool NeedsClearingScreen() bool - IsGL() bool - IsDirectX() bool MaxImageSize() int NewShader(program *shaderir.Program) (Shader, error) diff --git a/internal/graphicsdriver/metal/graphics_darwin.go b/internal/graphicsdriver/metal/graphics_darwin.go index fd8c034d4..ef102ad98 100644 --- a/internal/graphicsdriver/metal/graphics_darwin.go +++ b/internal/graphicsdriver/metal/graphics_darwin.go @@ -686,14 +686,6 @@ func (g *Graphics) NeedsClearingScreen() bool { return false } -func (g *Graphics) IsGL() bool { - return false -} - -func (g *Graphics) IsDirectX() bool { - return false -} - func (g *Graphics) MaxImageSize() int { if g.maxImageSize != 0 { return g.maxImageSize diff --git a/internal/graphicsdriver/opengl/graphics.go b/internal/graphicsdriver/opengl/graphics.go index 6db68678d..f0e2e1eab 100644 --- a/internal/graphicsdriver/opengl/graphics.go +++ b/internal/graphicsdriver/opengl/graphics.go @@ -295,14 +295,6 @@ func (g *Graphics) NeedsClearingScreen() bool { return true } -func (g *Graphics) IsGL() bool { - return true -} - -func (g *Graphics) IsDirectX() bool { - return false -} - func (g *Graphics) MaxImageSize() int { return g.context.getMaxTextureSize() } diff --git a/internal/ui/context.go b/internal/ui/context.go index 93030dea8..1125d39f2 100644 --- a/internal/ui/context.go +++ b/internal/ui/context.go @@ -75,7 +75,7 @@ func (c *context) updateFrame(graphicsDriver graphicsdriver.Graphics, outsideWid func (c *context) forceUpdateFrame(graphicsDriver graphicsdriver.Graphics, outsideWidth, outsideHeight float64, deviceScaleFactor float64, ui *UserInterface, swapBuffersForGL func()) error { n := 1 - if graphicsDriver.IsDirectX() { + if ui.GraphicsLibrary() == GraphicsLibraryDirectX { // On DirectX, both framebuffers in the swap chain should be updated. // Or, the rendering result becomes unexpected when the window is resized. n = 2 diff --git a/internal/ui/ui.go b/internal/ui/ui.go index 702a83340..8b3ee1abe 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -173,6 +173,6 @@ func (u *UserInterface) setGraphicsLibrary(library GraphicsLibrary) { atomic.StoreInt32(&u.graphicsLibrary, int32(library)) } -func (u *UserInterface) GetGraphicsLibrary() GraphicsLibrary { +func (u *UserInterface) GraphicsLibrary() GraphicsLibrary { return GraphicsLibrary(atomic.LoadInt32(&u.graphicsLibrary)) } diff --git a/internal/ui/ui_darwin.go b/internal/ui/ui_darwin.go index 8d8bf8ffe..c7716aa58 100644 --- a/internal/ui/ui_darwin.go +++ b/internal/ui/ui_darwin.go @@ -354,7 +354,7 @@ func (u *UserInterface) setNativeFullscreen(fullscreen bool) error { } func (u *UserInterface) adjustViewSizeAfterFullscreen() error { - if u.graphicsDriver.IsGL() { + if u.GraphicsLibrary() == GraphicsLibraryOpenGL { return nil } diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 49390d021..ad85f6380 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -1137,7 +1137,7 @@ func (u *UserInterface) initOnMainThread(options *RunOptions) error { u.setGraphicsLibrary(lib) u.graphicsDriver.SetTransparent(options.ScreenTransparent) - if u.graphicsDriver.IsGL() { + if u.GraphicsLibrary() == GraphicsLibraryOpenGL { if err := u.graphicsDriver.(interface{ SetGLFWClientAPI() error }).SetGLFWClientAPI(); err != nil { return err } @@ -1427,7 +1427,7 @@ func (u *UserInterface) loopGame() (ferr error) { }() u.renderThread.Call(func() { - if u.graphicsDriver.IsGL() { + if u.GraphicsLibrary() == GraphicsLibraryOpenGL { if err := u.window.MakeContextCurrent(); err != nil { u.setError(err) return @@ -1572,7 +1572,7 @@ func (u *UserInterface) updateIconIfNeeded() error { } func (u *UserInterface) swapBuffersOnRenderThread() error { - if u.graphicsDriver.IsGL() { + if u.GraphicsLibrary() == GraphicsLibraryOpenGL { if err := u.window.SwapBuffers(); err != nil { return err } @@ -1876,7 +1876,7 @@ func (u *UserInterface) minimumWindowWidth() (int, error) { } func (u *UserInterface) updateVsyncOnRenderThread() error { - if u.graphicsDriver.IsGL() { + if u.GraphicsLibrary() == GraphicsLibraryOpenGL { // 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). diff --git a/internal/ui/ui_ios.go b/internal/ui/ui_ios.go index 2249c370d..34e9a2b33 100644 --- a/internal/ui/ui_ios.go +++ b/internal/ui/ui_ios.go @@ -77,7 +77,7 @@ func (u *UserInterface) setUIView(uiview uintptr) error { select { case err := <-u.errCh: return err - case <-u.graphicsDriverInitCh: + case <-u.graphicsLibraryInitCh: } // This function should be called only when the graphics library is Metal. @@ -91,10 +91,10 @@ func (u *UserInterface) isGL() (bool, error) { select { case err := <-u.errCh: return false, err - case <-u.graphicsDriverInitCh: + case <-u.graphicsLibraryInitCh: } - return u.graphicsDriver.IsGL(), nil + return u.GraphicsLibrary() == GraphicsLibraryOpenGL, nil } func deviceScaleFactorImpl() float64 { diff --git a/internal/ui/ui_mobile.go b/internal/ui/ui_mobile.go index 3360c477d..e234e631b 100644 --- a/internal/ui/ui_mobile.go +++ b/internal/ui/ui_mobile.go @@ -53,9 +53,9 @@ var ( func (u *UserInterface) init() error { u.userInterfaceImpl = userInterfaceImpl{ - foreground: 1, - graphicsDriverInitCh: make(chan struct{}), - errCh: make(chan error), + foreground: 1, + graphicsLibraryInitCh: make(chan struct{}), + errCh: make(chan error), // Give a default outside size so that the game can start without initializing them. outsideWidth: 640, @@ -96,8 +96,8 @@ func (u *UserInterface) Update() error { } type userInterfaceImpl struct { - graphicsDriver graphicsdriver.Graphics - graphicsDriverInitCh chan struct{} + graphicsDriver graphicsdriver.Graphics + graphicsLibraryInitCh chan struct{} outsideWidth float64 outsideHeight float64 @@ -289,7 +289,7 @@ func (u *UserInterface) run(game Game, mainloop bool, options *RunOptions) (err } u.graphicsDriver = g u.setGraphicsLibrary(lib) - close(u.graphicsDriverInitCh) + close(u.graphicsLibraryInitCh) // If gomobile-build is used, wait for the outside size fixed. if u.setGBuildSizeCh != nil {