mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
internal/restorable: simplify canDetectContextLostExplicitly
This constant was set with some wrong assumptions: 1. On Android, recovering was needed. 2. On iOS, OpenGL ES was used when a. The architecture was 386 or amd64 == an emulator is used b. The build tag ebitengl was not specified c. gomobile-build was used 3. On browsers, recovering was needed. 1., 2b, and 2c are correct. 2a. is not correct: Now emulators are available on all the architectures with both Metal and OpenGL. 3. is not correct: Ebiten no longer recovers the contest lost. Now, Ebiten can detect a context lost explicitly when 1. On Android 2. On iOS and on gomobile-build (When gomobile-build is used, OpenGL should always be used) Based on this fact, this change changes the constant to a variable, and fixes the logic to set the variable.
This commit is contained in:
parent
85daef7436
commit
151dfffad6
@ -1,20 +0,0 @@
|
||||
// Copyright 2020 The Ebiten Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build android || (ios && ebitengl)
|
||||
// +build android ios,ebitengl
|
||||
|
||||
package restorable
|
||||
|
||||
const canDetectContextLostExplicitly = true
|
@ -1,18 +0,0 @@
|
||||
// Copyright 2020 The Ebiten Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package restorable
|
||||
|
||||
// canDetectContextLostExplicitly reports whether the context lost can be detected by handlers in an explicit way.
|
||||
const canDetectContextLostExplicitly = true
|
@ -1,22 +0,0 @@
|
||||
// Copyright 2020 The Ebiten Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build !android && !js && (!ios || !ebitengl)
|
||||
// +build !android
|
||||
// +build !js
|
||||
// +build !ios !ebitengl
|
||||
|
||||
package restorable
|
||||
|
||||
const canDetectContextLostExplicitly = false
|
@ -17,6 +17,7 @@ package restorable
|
||||
import (
|
||||
"image"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/debug"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
||||
@ -292,8 +293,11 @@ func MaxImageSize(graphicsDriver graphicsdriver.Graphics) int {
|
||||
|
||||
// OnContextLost is called when the context lost is detected in an explicit way.
|
||||
func OnContextLost() {
|
||||
if !canDetectContextLostExplicitly {
|
||||
panic("restorable: OnContextLost cannot be called in this environment")
|
||||
}
|
||||
canDetectContextLostExplicitly = true
|
||||
theImages.contextLost = true
|
||||
}
|
||||
|
||||
// canDetectContextLostExplicitly reports whether Ebiten can detect a context lost in an explicit way.
|
||||
// On Android, a context lost can be detected via GLSurfaceView.Renderer.onSurfaceCreated.
|
||||
// On iOS w/ OpenGL ES, this can be detected only when gomobile-build is used.
|
||||
var canDetectContextLostExplicitly = runtime.GOOS == "android"
|
||||
|
Loading…
Reference in New Issue
Block a user