diff --git a/internal/graphicsdriver/opengl/context_mobile.go b/internal/graphicsdriver/opengl/context_mobile.go index 13e713607..f486b1c64 100644 --- a/internal/graphicsdriver/opengl/context_mobile.go +++ b/internal/graphicsdriver/opengl/context_mobile.go @@ -75,14 +75,6 @@ type contextImpl struct { worker mgl.Worker } -func Init() { - theContext.gl, theContext.worker = mgl.NewContext() -} - -func InitWithContext(context mgl.Context) { - theContext.gl = context -} - func (c *context) doWork(chError <-chan error, chDone <-chan struct{}) error { if c.worker == nil { panic("not reached") diff --git a/internal/graphicsdriver/opengl/driver_js.go b/internal/graphicsdriver/opengl/driver_js.go index 1c6a04ffb..91f84bb10 100644 --- a/internal/graphicsdriver/opengl/driver_js.go +++ b/internal/graphicsdriver/opengl/driver_js.go @@ -17,9 +17,9 @@ package opengl func (d *Driver) IsContextLost() bool { - return theContext.isContextLost() + return d.context.isContextLost() } func (d *Driver) RestoreContext() { - theContext.restoreContext() + d.context.restoreContext() } diff --git a/internal/graphicsdriver/opengl/driver_mobile.go b/internal/graphicsdriver/opengl/driver_mobile.go index 260c7699a..5dc354713 100644 --- a/internal/graphicsdriver/opengl/driver_mobile.go +++ b/internal/graphicsdriver/opengl/driver_mobile.go @@ -16,6 +16,18 @@ package opengl +import ( + "golang.org/x/mobile/gl" +) + func (d *Driver) DoWork(chError <-chan error, chDone <-chan struct{}) error { - return theContext.doWork(chError, chDone) + return d.context.doWork(chError, chDone) +} + +func (d *Driver) Init() { + d.context.gl, d.context.worker = gl.NewContext() +} + +func (d *Driver) InitWithContext(context gl.Context) { + d.context.gl = context } diff --git a/internal/ui/ui_mobile.go b/internal/ui/ui_mobile.go index 5a21d807d..aa1938cd5 100644 --- a/internal/ui/ui_mobile.go +++ b/internal/ui/ui_mobile.go @@ -152,9 +152,9 @@ func Run(width, height int, scale float64, title string, g GraphicsContext, main if mainloop { ctx := <-glContextCh - opengl.InitWithContext(ctx) + opengl.GetDriver().InitWithContext(ctx) } else { - opengl.Init() + opengl.GetDriver().Init() } // Force to set the screen size