mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
opengl: Prepare Context Losing for JavaScript (#217)
This commit is contained in:
parent
9453f9e7b5
commit
328ef85606
@ -26,9 +26,10 @@ import (
|
||||
var canvas *js.Object
|
||||
|
||||
type userInterface struct {
|
||||
scale float64
|
||||
deviceScale float64
|
||||
sizeChanged bool
|
||||
scale float64
|
||||
deviceScale float64
|
||||
sizeChanged bool
|
||||
contextRestored chan struct{}
|
||||
}
|
||||
|
||||
var currentUI = &userInterface{
|
||||
@ -80,6 +81,9 @@ func (u *userInterface) ActualScreenScale() float64 {
|
||||
}
|
||||
|
||||
func (u *userInterface) Update() (interface{}, error) {
|
||||
if u.contextRestored != nil {
|
||||
<-u.contextRestored
|
||||
}
|
||||
currentInput.updateGamepads()
|
||||
if u.sizeChanged {
|
||||
u.sizeChanged = false
|
||||
@ -229,6 +233,15 @@ func initialize() (*opengl.Context, error) {
|
||||
// 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()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user