example/contextlost: Bug fix: Compilie error on Go 1.14, Should use WebGL2

This commit is contained in:
Hajime Hoshi 2020-03-29 02:03:14 +09:00
parent b09fe7157b
commit 231edfbd3f

View File

@ -53,7 +53,7 @@ func loseAndRestoreContext(context js.Value) {
// Edge might not support the extension. See
// https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_lose_context
ext := context.Call("getExtension", "WEBGL_lose_context")
if ext == js.Null() {
if ext.IsNull() {
fmt.Println("Fail to force context lost. Edge might not support the extension yet.")
return
}
@ -79,11 +79,13 @@ func update(screen *ebiten.Image) error {
if inpututil.IsKeyJustPressed(ebiten.KeySpace) {
doc := js.Global().Get("document")
canvas := doc.Call("getElementsByTagName", "canvas").Index(0)
context := canvas.Call("getContext", "webgl")
if context == js.Null() {
context = canvas.Call("getContext", "experimental-webgl")
context := canvas.Call("getContext", "webgl2")
if context.IsNull() {
context = canvas.Call("getContext", "webgl")
if context.IsNull() {
context = canvas.Call("getContext", "experimental-webgl")
}
}
loseAndRestoreContext(context)
return nil
}