mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
internal/graphicsdriver/opengl: Give up restorign on browsers
Using restorable images is expensive as this sometimes requires to load pixels from GPU. On browsers, just reloading the application should be fine when the context lost happens. Closes #1603
This commit is contained in:
parent
38ce46328a
commit
8ff42f55a1
@ -20,7 +20,6 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"syscall/js"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (g *Game) loseAndRestoreContext() {
|
||||
@ -48,17 +47,5 @@ func (g *Game) loseAndRestoreContext() {
|
||||
|
||||
ext.Call("loseContext")
|
||||
fmt.Println("Lost the context!")
|
||||
fmt.Println("The context is automatically restored after 3 seconds.")
|
||||
g.lost = true
|
||||
|
||||
// If and only if the context is lost by loseContext, you need to call restoreContext. Note that in usual
|
||||
// case of context lost, you cannot call restoreContext but the context should be restored automatically.
|
||||
//
|
||||
// After the context is lost, update will not be called. Instead, fire the goroutine to restore the context.
|
||||
go func() {
|
||||
time.Sleep(3 * time.Second)
|
||||
ext.Call("restoreContext")
|
||||
fmt.Println("Restored the context!")
|
||||
g.lost = false
|
||||
}()
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gles"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/jsutil"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/web"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -85,7 +84,6 @@ const (
|
||||
|
||||
var (
|
||||
isWebGL2Available = !forceWebGL1 && (js.Global().Get("WebGL2RenderingContext").Truthy() || js.Global().Get("go2cpp").Truthy())
|
||||
needsRestoring = !web.IsMobileBrowser() && !js.Global().Get("go2cpp").Truthy()
|
||||
)
|
||||
|
||||
type contextImpl struct {
|
||||
@ -526,7 +524,8 @@ func (c *context) flush() {
|
||||
}
|
||||
|
||||
func (c *context) needsRestoring() bool {
|
||||
return needsRestoring
|
||||
// Though it is possible to have a logic to restore the graphics data for GPU, do not use it for performance (#1603).
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *context) canUsePBO() bool {
|
||||
|
@ -22,7 +22,6 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hooks"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -58,7 +57,6 @@ type UserInterface struct {
|
||||
cursorShape driver.CursorShape
|
||||
|
||||
sizeChanged bool
|
||||
contextLost bool
|
||||
|
||||
lastDeviceScaleFactor float64
|
||||
|
||||
@ -290,11 +288,6 @@ func (u *UserInterface) loop(context driver.UIContext) <-chan error {
|
||||
|
||||
var cf js.Func
|
||||
f := func() {
|
||||
if u.contextLost {
|
||||
requestAnimationFrame.Invoke(cf)
|
||||
return
|
||||
}
|
||||
|
||||
if err := u.update(); err != nil {
|
||||
close(reqStopAudioCh)
|
||||
<-resStopAudioCh
|
||||
@ -545,12 +538,7 @@ func setCanvasEventHandlers(v js.Value) {
|
||||
v.Call("addEventListener", "webglcontextlost", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||
e := args[0]
|
||||
e.Call("preventDefault")
|
||||
theUI.contextLost = true
|
||||
restorable.OnContextLost()
|
||||
return nil
|
||||
}))
|
||||
v.Call("addEventListener", "webglcontextrestored", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||
theUI.contextLost = false
|
||||
window.Get("location").Call("reload")
|
||||
return nil
|
||||
}))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user