mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 13:07:26 +01:00
ui: Initialize GLContext at Start
This commit is contained in:
parent
5a3ea34cfc
commit
121063ee2b
@ -46,14 +46,6 @@ func CurrentUI() UserInterface {
|
|||||||
var glContext *opengl.Context
|
var glContext *opengl.Context
|
||||||
|
|
||||||
func 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
|
return glContext
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,6 +137,13 @@ func (u *userInterface) ScreenScale() float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterface) Start(width, height int, scale float64, title string) error {
|
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 {
|
if err := u.runOnMainThread(func() error {
|
||||||
m := glfw.GetPrimaryMonitor()
|
m := glfw.GetPrimaryMonitor()
|
||||||
v := m.GetVideoMode()
|
v := m.GetVideoMode()
|
||||||
|
@ -139,14 +139,6 @@ func touchEventToTouches(e *js.Object) []touch {
|
|||||||
var glContext *opengl.Context
|
var glContext *opengl.Context
|
||||||
|
|
||||||
func 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
|
return glContext
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,6 +293,11 @@ func (u *userInterface) Start(width, height int, scale float64, title string) er
|
|||||||
doc.Set("title", title)
|
doc.Set("title", title)
|
||||||
u.setScreenSize(width, height, scale)
|
u.setScreenSize(width, height, scale)
|
||||||
canvas.Call("focus")
|
canvas.Call("focus")
|
||||||
|
var err error
|
||||||
|
glContext, err = opengl.NewContext()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,14 +27,6 @@ import (
|
|||||||
var glContext *opengl.Context
|
var glContext *opengl.Context
|
||||||
|
|
||||||
func 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
|
return glContext
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,6 +75,11 @@ func (u *userInterface) Start(width, height int, scale float64, title string) er
|
|||||||
u.height = height
|
u.height = height
|
||||||
u.scale = scale
|
u.scale = scale
|
||||||
// title is ignored?
|
// title is ignored?
|
||||||
|
var err error
|
||||||
|
glContext, err = opengl.NewContext()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user