ui: Initialize GLContext at Start

This commit is contained in:
Hajime Hoshi 2016-07-23 22:17:36 +09:00
parent 5a3ea34cfc
commit 121063ee2b
3 changed files with 17 additions and 24 deletions

View File

@ -46,14 +46,6 @@ func CurrentUI() UserInterface {
var glContext *opengl.Context
func GLContext() *opengl.Context {
if glContext != nil {
return glContext
}
var err error
glContext, err = opengl.NewContext(currentUI.runOnMainThread)
if err != nil {
panic(err)
}
return glContext
}
@ -145,6 +137,13 @@ func (u *userInterface) ScreenScale() float64 {
}
func (u *userInterface) Start(width, height int, scale float64, title string) error {
// GLContext must be created before setting the screen size, which requres
// swapping buffers.
var err error
glContext, err = opengl.NewContext(currentUI.runOnMainThread)
if err != nil {
return err
}
if err := u.runOnMainThread(func() error {
m := glfw.GetPrimaryMonitor()
v := m.GetVideoMode()

View File

@ -139,14 +139,6 @@ func touchEventToTouches(e *js.Object) []touch {
var glContext *opengl.Context
func GLContext() *opengl.Context {
if glContext != nil {
return glContext
}
var err error
glContext, err = opengl.NewContext()
if err != nil {
panic(err)
}
return glContext
}
@ -301,6 +293,11 @@ func (u *userInterface) Start(width, height int, scale float64, title string) er
doc.Set("title", title)
u.setScreenSize(width, height, scale)
canvas.Call("focus")
var err error
glContext, err = opengl.NewContext()
if err != nil {
return err
}
return nil
}

View File

@ -27,14 +27,6 @@ import (
var glContext *opengl.Context
func GLContext() *opengl.Context {
if glContext != nil {
return glContext
}
var err error
glContext, err = opengl.NewContext()
if err != nil {
panic(err)
}
return glContext
}
@ -83,6 +75,11 @@ func (u *userInterface) Start(width, height int, scale float64, title string) er
u.height = height
u.scale = scale
// title is ignored?
var err error
glContext, err = opengl.NewContext()
if err != nil {
return err
}
return nil
}