mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
internal/graphicsdriver/opengl: refactoring: remove SetCanvas
This commit is contained in:
parent
a0a5f2b301
commit
42566c6c9a
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user