mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
internal/ui: refactoring
This commit is contained in:
parent
a89aaa0756
commit
a16a03c9db
@ -28,7 +28,7 @@ type graphicsDriverCreator interface {
|
|||||||
newMetal() (graphicsdriver.Graphics, error)
|
newMetal() (graphicsdriver.Graphics, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newGraphicsDriver(creator graphicsDriverCreator, graphicsLibrary GraphicsLibrary) (graphicsdriver.Graphics, error) {
|
func newGraphicsDriver(creator graphicsDriverCreator, graphicsLibrary GraphicsLibrary) (graphicsdriver.Graphics, GraphicsLibrary, error) {
|
||||||
if graphicsLibrary == GraphicsLibraryAuto {
|
if graphicsLibrary == GraphicsLibraryAuto {
|
||||||
envName := "EBITENGINE_GRAPHICS_LIBRARY"
|
envName := "EBITENGINE_GRAPHICS_LIBRARY"
|
||||||
env := os.Getenv(envName)
|
env := os.Getenv(envName)
|
||||||
@ -48,7 +48,7 @@ func newGraphicsDriver(creator graphicsDriverCreator, graphicsLibrary GraphicsLi
|
|||||||
case "metal":
|
case "metal":
|
||||||
graphicsLibrary = GraphicsLibraryMetal
|
graphicsLibrary = GraphicsLibraryMetal
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("ui: an unsupported graphics library is specified by the environment variable: %s", env)
|
return nil, 0, fmt.Errorf("ui: an unsupported graphics library is specified by the environment variable: %s", env)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,45 +56,41 @@ func newGraphicsDriver(creator graphicsDriverCreator, graphicsLibrary GraphicsLi
|
|||||||
case GraphicsLibraryAuto:
|
case GraphicsLibraryAuto:
|
||||||
g, lib, err := creator.newAuto()
|
g, lib, err := creator.newAuto()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
if g == nil {
|
if g == nil {
|
||||||
return nil, fmt.Errorf("ui: no graphics library is available")
|
return nil, 0, fmt.Errorf("ui: no graphics library is available")
|
||||||
}
|
}
|
||||||
theGlobalState.setGraphicsLibrary(lib)
|
return g, lib, nil
|
||||||
return g, nil
|
|
||||||
case GraphicsLibraryOpenGL:
|
case GraphicsLibraryOpenGL:
|
||||||
g, err := creator.newOpenGL()
|
g, err := creator.newOpenGL()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
if g == nil {
|
if g == nil {
|
||||||
return nil, fmt.Errorf("ui: %s is specified but OpenGL is not available", graphicsLibrary)
|
return nil, 0, fmt.Errorf("ui: %s is specified but OpenGL is not available", graphicsLibrary)
|
||||||
}
|
}
|
||||||
theGlobalState.setGraphicsLibrary(GraphicsLibraryOpenGL)
|
return g, GraphicsLibraryOpenGL, nil
|
||||||
return g, nil
|
|
||||||
case GraphicsLibraryDirectX:
|
case GraphicsLibraryDirectX:
|
||||||
g, err := creator.newDirectX()
|
g, err := creator.newDirectX()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
if g == nil {
|
if g == nil {
|
||||||
return nil, fmt.Errorf("ui: %s is specified but DirectX is not available.", graphicsLibrary)
|
return nil, 0, fmt.Errorf("ui: %s is specified but DirectX is not available.", graphicsLibrary)
|
||||||
}
|
}
|
||||||
theGlobalState.setGraphicsLibrary(GraphicsLibraryDirectX)
|
return g, GraphicsLibraryDirectX, nil
|
||||||
return g, nil
|
|
||||||
case GraphicsLibraryMetal:
|
case GraphicsLibraryMetal:
|
||||||
g, err := creator.newMetal()
|
g, err := creator.newMetal()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
if g == nil {
|
if g == nil {
|
||||||
return nil, fmt.Errorf("ui: %s is specified but Metal is not available", graphicsLibrary)
|
return nil, 0, fmt.Errorf("ui: %s is specified but Metal is not available", graphicsLibrary)
|
||||||
}
|
}
|
||||||
theGlobalState.setGraphicsLibrary(GraphicsLibraryMetal)
|
return g, GraphicsLibraryMetal, nil
|
||||||
return g, nil
|
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("ui: an unsupported graphics library is specified: %d", graphicsLibrary)
|
return nil, 0, fmt.Errorf("ui: an unsupported graphics library is specified: %d", graphicsLibrary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1127,13 +1127,14 @@ func (u *UserInterface) initOnMainThread(options *RunOptions) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
g, err := newGraphicsDriver(&graphicsDriverCreatorImpl{
|
g, lib, err := newGraphicsDriver(&graphicsDriverCreatorImpl{
|
||||||
transparent: options.ScreenTransparent,
|
transparent: options.ScreenTransparent,
|
||||||
}, options.GraphicsLibrary)
|
}, options.GraphicsLibrary)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
u.graphicsDriver = g
|
u.graphicsDriver = g
|
||||||
|
theGlobalState.setGraphicsLibrary(lib)
|
||||||
u.graphicsDriver.SetTransparent(options.ScreenTransparent)
|
u.graphicsDriver.SetTransparent(options.ScreenTransparent)
|
||||||
|
|
||||||
if u.graphicsDriver.IsGL() {
|
if u.graphicsDriver.IsGL() {
|
||||||
|
@ -748,13 +748,14 @@ func (u *UserInterface) Run(game Game, options *RunOptions) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
u.running = true
|
u.running = true
|
||||||
g, err := newGraphicsDriver(&graphicsDriverCreatorImpl{
|
g, lib, err := newGraphicsDriver(&graphicsDriverCreatorImpl{
|
||||||
canvas: canvas,
|
canvas: canvas,
|
||||||
}, options.GraphicsLibrary)
|
}, options.GraphicsLibrary)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
u.graphicsDriver = g
|
u.graphicsDriver = g
|
||||||
|
theGlobalState.setGraphicsLibrary(lib)
|
||||||
|
|
||||||
if bodyStyle := document.Get("body").Get("style"); options.ScreenTransparent {
|
if bodyStyle := document.Get("body").Get("style"); options.ScreenTransparent {
|
||||||
bodyStyle.Set("backgroundColor", "transparent")
|
bodyStyle.Set("backgroundColor", "transparent")
|
||||||
|
@ -281,13 +281,14 @@ func (u *UserInterface) run(game Game, mainloop bool, options *RunOptions) (err
|
|||||||
graphicscommand.SetRenderThread(u.renderThread)
|
graphicscommand.SetRenderThread(u.renderThread)
|
||||||
}
|
}
|
||||||
|
|
||||||
g, err := newGraphicsDriver(&graphicsDriverCreatorImpl{
|
g, lib, err := newGraphicsDriver(&graphicsDriverCreatorImpl{
|
||||||
gomobileContext: mgl,
|
gomobileContext: mgl,
|
||||||
}, options.GraphicsLibrary)
|
}, options.GraphicsLibrary)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
u.graphicsDriver = g
|
u.graphicsDriver = g
|
||||||
|
theGlobalState.setGraphicsLibrary(lib)
|
||||||
close(u.graphicsDriverInitCh)
|
close(u.graphicsDriverInitCh)
|
||||||
|
|
||||||
// If gomobile-build is used, wait for the outside size fixed.
|
// If gomobile-build is used, wait for the outside size fixed.
|
||||||
|
@ -80,11 +80,12 @@ func (u *UserInterface) init() error {
|
|||||||
|
|
||||||
func (u *UserInterface) Run(game Game, options *RunOptions) error {
|
func (u *UserInterface) Run(game Game, options *RunOptions) error {
|
||||||
u.context = newContext(game)
|
u.context = newContext(game)
|
||||||
g, err := newGraphicsDriver(&graphicsDriverCreatorImpl{}, options.GraphicsLibrary)
|
g, lib, err := newGraphicsDriver(&graphicsDriverCreatorImpl{}, options.GraphicsLibrary)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
u.graphicsDriver = g
|
u.graphicsDriver = g
|
||||||
|
theGlobalState.setGraphicsLibrary(lib)
|
||||||
|
|
||||||
n := C.ebitengine_Initialize()
|
n := C.ebitengine_Initialize()
|
||||||
if err := u.egl.init(n); err != nil {
|
if err := u.egl.init(n); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user