mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
opengl: Prepare Context Losing for JavaScript (#217)
This commit is contained in:
parent
9453f9e7b5
commit
328ef85606
@ -29,6 +29,7 @@ type userInterface struct {
|
|||||||
scale float64
|
scale float64
|
||||||
deviceScale float64
|
deviceScale float64
|
||||||
sizeChanged bool
|
sizeChanged bool
|
||||||
|
contextRestored chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentUI = &userInterface{
|
var currentUI = &userInterface{
|
||||||
@ -80,6 +81,9 @@ func (u *userInterface) ActualScreenScale() float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterface) Update() (interface{}, error) {
|
func (u *userInterface) Update() (interface{}, error) {
|
||||||
|
if u.contextRestored != nil {
|
||||||
|
<-u.contextRestored
|
||||||
|
}
|
||||||
currentInput.updateGamepads()
|
currentInput.updateGamepads()
|
||||||
if u.sizeChanged {
|
if u.sizeChanged {
|
||||||
u.sizeChanged = false
|
u.sizeChanged = false
|
||||||
@ -229,6 +233,15 @@ func initialize() (*opengl.Context, error) {
|
|||||||
// Do nothing.
|
// Do nothing.
|
||||||
})
|
})
|
||||||
|
|
||||||
|
canvas.Call("addEventListener", "webglcontextlost", func(e *js.Object) {
|
||||||
|
e.Call("preventDefault")
|
||||||
|
currentUI.contextRestored = make(chan struct{})
|
||||||
|
})
|
||||||
|
canvas.Call("addEventListener", "webglcontextrestored", func(e *js.Object) {
|
||||||
|
close(currentUI.contextRestored)
|
||||||
|
currentUI.contextRestored = nil
|
||||||
|
})
|
||||||
|
|
||||||
c, err := opengl.NewContext()
|
c, err := opengl.NewContext()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user