internal/graphicsdriver/opengl: refactoring: remove SetCanvas

This commit is contained in:
Hajime Hoshi 2022-11-13 15:18:44 +09:00
parent a0a5f2b301
commit 42566c6c9a
2 changed files with 10 additions and 13 deletions

View File

@ -18,11 +18,7 @@ import (
"syscall/js"
)
func (g *Graphics) init(_ any) error {
// Do nothing.
func (g *Graphics) init(canvas any) error {
g.context.canvas = canvas.(js.Value)
return nil
}
func (g *Graphics) SetCanvas(canvas js.Value) {
g.context.canvas = canvas
}

View File

@ -26,15 +26,17 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/hooks"
)
type graphicsDriverCreatorImpl struct{}
type graphicsDriverCreatorImpl struct {
canvas js.Value
}
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) {
graphics, err := g.newOpenGL()
return graphics, GraphicsLibraryOpenGL, err
}
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
return opengl.NewGraphics(nil)
func (g *graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
return opengl.NewGraphics(g.canvas)
}
func (*graphicsDriverCreatorImpl) newDirectX() (graphicsdriver.Graphics, error) {
@ -645,14 +647,13 @@ func (u *userInterfaceImpl) Run(game Game) error {
}
}
u.running = true
g, err := newGraphicsDriver(&graphicsDriverCreatorImpl{})
g, err := newGraphicsDriver(&graphicsDriverCreatorImpl{
canvas: canvas,
})
if err != nil {
return err
}
u.graphicsDriver = g
if g, ok := u.graphicsDriver.(interface{ SetCanvas(js.Value) }); ok {
g.SetCanvas(canvas)
}
return <-u.loop(game)
}