internal/graphicslibrary: refactoring: remove IsGL and IsDirectX

This commit is contained in:
Hajime Hoshi 2023-10-15 17:21:56 +09:00
parent 48054ec9c8
commit 8274b32301
12 changed files with 17 additions and 51 deletions

View File

@ -66,5 +66,5 @@ type DebugInfo struct {
// ReadDebugInfo writes debug info (e.g. current graphics library) into a provided struct. // ReadDebugInfo writes debug info (e.g. current graphics library) into a provided struct.
func ReadDebugInfo(d *DebugInfo) { func ReadDebugInfo(d *DebugInfo) {
d.GraphicsLibrary = GraphicsLibrary(ui.Get().GetGraphicsLibrary()) d.GraphicsLibrary = GraphicsLibrary(ui.Get().GraphicsLibrary())
} }

View File

@ -472,14 +472,6 @@ func (g *graphics11) NeedsClearingScreen() bool {
return true return true
} }
func (g *graphics11) IsGL() bool {
return false
}
func (g *graphics11) IsDirectX() bool {
return true
}
func (g *graphics11) MaxImageSize() int { func (g *graphics11) MaxImageSize() int {
switch g.featureLevel { switch g.featureLevel {
case _D3D_FEATURE_LEVEL_10_0: case _D3D_FEATURE_LEVEL_10_0:

View File

@ -1063,14 +1063,6 @@ func (g *graphics12) NeedsClearingScreen() bool {
return true return true
} }
func (g *graphics12) IsGL() bool {
return false
}
func (g *graphics12) IsDirectX() bool {
return true
}
func (g *graphics12) MaxImageSize() int { func (g *graphics12) MaxImageSize() int {
return _D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION return _D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION
} }

View File

@ -42,8 +42,6 @@ type Graphics interface {
SetVsyncEnabled(enabled bool) SetVsyncEnabled(enabled bool)
NeedsRestoring() bool NeedsRestoring() bool
NeedsClearingScreen() bool NeedsClearingScreen() bool
IsGL() bool
IsDirectX() bool
MaxImageSize() int MaxImageSize() int
NewShader(program *shaderir.Program) (Shader, error) NewShader(program *shaderir.Program) (Shader, error)

View File

@ -686,14 +686,6 @@ func (g *Graphics) NeedsClearingScreen() bool {
return false return false
} }
func (g *Graphics) IsGL() bool {
return false
}
func (g *Graphics) IsDirectX() bool {
return false
}
func (g *Graphics) MaxImageSize() int { func (g *Graphics) MaxImageSize() int {
if g.maxImageSize != 0 { if g.maxImageSize != 0 {
return g.maxImageSize return g.maxImageSize

View File

@ -295,14 +295,6 @@ func (g *Graphics) NeedsClearingScreen() bool {
return true return true
} }
func (g *Graphics) IsGL() bool {
return true
}
func (g *Graphics) IsDirectX() bool {
return false
}
func (g *Graphics) MaxImageSize() int { func (g *Graphics) MaxImageSize() int {
return g.context.getMaxTextureSize() return g.context.getMaxTextureSize()
} }

View File

@ -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 { func (c *context) forceUpdateFrame(graphicsDriver graphicsdriver.Graphics, outsideWidth, outsideHeight float64, deviceScaleFactor float64, ui *UserInterface, swapBuffersForGL func()) error {
n := 1 n := 1
if graphicsDriver.IsDirectX() { if ui.GraphicsLibrary() == GraphicsLibraryDirectX {
// On DirectX, both framebuffers in the swap chain should be updated. // On DirectX, both framebuffers in the swap chain should be updated.
// Or, the rendering result becomes unexpected when the window is resized. // Or, the rendering result becomes unexpected when the window is resized.
n = 2 n = 2

View File

@ -173,6 +173,6 @@ func (u *UserInterface) setGraphicsLibrary(library GraphicsLibrary) {
atomic.StoreInt32(&u.graphicsLibrary, int32(library)) atomic.StoreInt32(&u.graphicsLibrary, int32(library))
} }
func (u *UserInterface) GetGraphicsLibrary() GraphicsLibrary { func (u *UserInterface) GraphicsLibrary() GraphicsLibrary {
return GraphicsLibrary(atomic.LoadInt32(&u.graphicsLibrary)) return GraphicsLibrary(atomic.LoadInt32(&u.graphicsLibrary))
} }

View File

@ -354,7 +354,7 @@ func (u *UserInterface) setNativeFullscreen(fullscreen bool) error {
} }
func (u *UserInterface) adjustViewSizeAfterFullscreen() error { func (u *UserInterface) adjustViewSizeAfterFullscreen() error {
if u.graphicsDriver.IsGL() { if u.GraphicsLibrary() == GraphicsLibraryOpenGL {
return nil return nil
} }

View File

@ -1137,7 +1137,7 @@ func (u *UserInterface) initOnMainThread(options *RunOptions) error {
u.setGraphicsLibrary(lib) u.setGraphicsLibrary(lib)
u.graphicsDriver.SetTransparent(options.ScreenTransparent) u.graphicsDriver.SetTransparent(options.ScreenTransparent)
if u.graphicsDriver.IsGL() { if u.GraphicsLibrary() == GraphicsLibraryOpenGL {
if err := u.graphicsDriver.(interface{ SetGLFWClientAPI() error }).SetGLFWClientAPI(); err != nil { if err := u.graphicsDriver.(interface{ SetGLFWClientAPI() error }).SetGLFWClientAPI(); err != nil {
return err return err
} }
@ -1427,7 +1427,7 @@ func (u *UserInterface) loopGame() (ferr error) {
}() }()
u.renderThread.Call(func() { u.renderThread.Call(func() {
if u.graphicsDriver.IsGL() { if u.GraphicsLibrary() == GraphicsLibraryOpenGL {
if err := u.window.MakeContextCurrent(); err != nil { if err := u.window.MakeContextCurrent(); err != nil {
u.setError(err) u.setError(err)
return return
@ -1572,7 +1572,7 @@ func (u *UserInterface) updateIconIfNeeded() error {
} }
func (u *UserInterface) swapBuffersOnRenderThread() error { func (u *UserInterface) swapBuffersOnRenderThread() error {
if u.graphicsDriver.IsGL() { if u.GraphicsLibrary() == GraphicsLibraryOpenGL {
if err := u.window.SwapBuffers(); err != nil { if err := u.window.SwapBuffers(); err != nil {
return err return err
} }
@ -1876,7 +1876,7 @@ func (u *UserInterface) minimumWindowWidth() (int, error) {
} }
func (u *UserInterface) updateVsyncOnRenderThread() error { func (u *UserInterface) updateVsyncOnRenderThread() error {
if u.graphicsDriver.IsGL() { if u.GraphicsLibrary() == GraphicsLibraryOpenGL {
// SwapInterval is affected by the current monitor of the window. // SwapInterval is affected by the current monitor of the window.
// This needs to be called at least after SetMonitor. // This needs to be called at least after SetMonitor.
// Without SwapInterval after SetMonitor, vsynch doesn't work (#375). // Without SwapInterval after SetMonitor, vsynch doesn't work (#375).

View File

@ -77,7 +77,7 @@ func (u *UserInterface) setUIView(uiview uintptr) error {
select { select {
case err := <-u.errCh: case err := <-u.errCh:
return err return err
case <-u.graphicsDriverInitCh: case <-u.graphicsLibraryInitCh:
} }
// This function should be called only when the graphics library is Metal. // This function should be called only when the graphics library is Metal.
@ -91,10 +91,10 @@ func (u *UserInterface) isGL() (bool, error) {
select { select {
case err := <-u.errCh: case err := <-u.errCh:
return false, err return false, err
case <-u.graphicsDriverInitCh: case <-u.graphicsLibraryInitCh:
} }
return u.graphicsDriver.IsGL(), nil return u.GraphicsLibrary() == GraphicsLibraryOpenGL, nil
} }
func deviceScaleFactorImpl() float64 { func deviceScaleFactorImpl() float64 {

View File

@ -53,9 +53,9 @@ var (
func (u *UserInterface) init() error { func (u *UserInterface) init() error {
u.userInterfaceImpl = userInterfaceImpl{ u.userInterfaceImpl = userInterfaceImpl{
foreground: 1, foreground: 1,
graphicsDriverInitCh: make(chan struct{}), graphicsLibraryInitCh: make(chan struct{}),
errCh: make(chan error), errCh: make(chan error),
// Give a default outside size so that the game can start without initializing them. // Give a default outside size so that the game can start without initializing them.
outsideWidth: 640, outsideWidth: 640,
@ -96,8 +96,8 @@ func (u *UserInterface) Update() error {
} }
type userInterfaceImpl struct { type userInterfaceImpl struct {
graphicsDriver graphicsdriver.Graphics graphicsDriver graphicsdriver.Graphics
graphicsDriverInitCh chan struct{} graphicsLibraryInitCh chan struct{}
outsideWidth float64 outsideWidth float64
outsideHeight float64 outsideHeight float64
@ -289,7 +289,7 @@ func (u *UserInterface) run(game Game, mainloop bool, options *RunOptions) (err
} }
u.graphicsDriver = g u.graphicsDriver = g
u.setGraphicsLibrary(lib) u.setGraphicsLibrary(lib)
close(u.graphicsDriverInitCh) close(u.graphicsLibraryInitCh)
// If gomobile-build is used, wait for the outside size fixed. // If gomobile-build is used, wait for the outside size fixed.
if u.setGBuildSizeCh != nil { if u.setGBuildSizeCh != nil {