diff --git a/internal/graphicsdriver/opengl/gl/default_android.go b/internal/graphicsdriver/opengl/gl/default_android.go index 5090a6ca9..5e6232615 100644 --- a/internal/graphicsdriver/opengl/gl/default_android.go +++ b/internal/graphicsdriver/opengl/gl/default_android.go @@ -41,10 +41,6 @@ func (defaultContext) Init() error { return nil } -func (defaultContext) IsES() bool { - return true -} - func (defaultContext) ActiveTexture(texture uint32) { C.glActiveTexture(C.GLenum(texture)) } diff --git a/internal/graphicsdriver/opengl/gl/default_notpurego.go b/internal/graphicsdriver/opengl/gl/default_notpurego.go index 563e1f923..67305030d 100644 --- a/internal/graphicsdriver/opengl/gl/default_notpurego.go +++ b/internal/graphicsdriver/opengl/gl/default_notpurego.go @@ -406,10 +406,6 @@ func boolToInt(b bool) int { return 0 } -func (c *defaultContext) IsES() bool { - return isES -} - func (c *defaultContext) ActiveTexture(texture uint32) { C.glowActiveTexture(c.gpActiveTexture, (C.GLenum)(texture)) } diff --git a/internal/graphicsdriver/opengl/gl/default_purego.go b/internal/graphicsdriver/opengl/gl/default_purego.go index f6b02befc..1e08bb49f 100644 --- a/internal/graphicsdriver/opengl/gl/default_purego.go +++ b/internal/graphicsdriver/opengl/gl/default_purego.go @@ -107,10 +107,6 @@ func boolToInt(b bool) int { return 0 } -func (c *defaultContext) IsES() bool { - return isES -} - func (c *defaultContext) ActiveTexture(texture uint32) { purego.SyscallN(c.gpActiveTexture, uintptr(texture)) } diff --git a/internal/graphicsdriver/opengl/gl/gomobile.go b/internal/graphicsdriver/opengl/gl/gomobile.go index 45a597a2d..ce9db5d4a 100644 --- a/internal/graphicsdriver/opengl/gl/gomobile.go +++ b/internal/graphicsdriver/opengl/gl/gomobile.go @@ -39,10 +39,6 @@ func (g *gomobileContext) Init() error { return nil } -func (g *gomobileContext) IsES() bool { - return true -} - func (g *gomobileContext) ActiveTexture(texture uint32) { g.ctx.ActiveTexture(gl.Enum(texture)) } diff --git a/internal/graphicsdriver/opengl/gl/interface.go b/internal/graphicsdriver/opengl/gl/interface.go index e5a011f07..82ca63a7a 100644 --- a/internal/graphicsdriver/opengl/gl/interface.go +++ b/internal/graphicsdriver/opengl/gl/interface.go @@ -20,7 +20,6 @@ package gl // See https://pkg.go.dev/golang.org/x/mobile/gl#Context type Context interface { Init() error - IsES() bool ActiveTexture(texture uint32) AttachShader(program uint32, shader uint32) diff --git a/internal/graphicsdriver/opengl/gl/procaddr_darwin.go b/internal/graphicsdriver/opengl/gl/procaddr_darwin.go index dd9b18fff..cf88e94d5 100644 --- a/internal/graphicsdriver/opengl/gl/procaddr_darwin.go +++ b/internal/graphicsdriver/opengl/gl/procaddr_darwin.go @@ -18,15 +18,11 @@ import ( "github.com/ebitengine/purego" ) -var ( - opengl uintptr - isES bool -) +var opengl uintptr func init() { opengl = purego.Dlopen("/System/Library/Frameworks/OpenGLES.framework/Versions/Current/OpenGLES", purego.RTLD_GLOBAL) if opengl != 0 { - isES = true return } opengl = purego.Dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", purego.RTLD_GLOBAL) diff --git a/internal/graphicsdriver/opengl/gl/procaddr_gl.go b/internal/graphicsdriver/opengl/gl/procaddr_gl.go index fe341ee59..36edc228f 100644 --- a/internal/graphicsdriver/opengl/gl/procaddr_gl.go +++ b/internal/graphicsdriver/opengl/gl/procaddr_gl.go @@ -28,8 +28,6 @@ import "C" import "unsafe" -var isES = false - func getProcAddress(namea string) unsafe.Pointer { cname := C.CString(namea) defer C.free(unsafe.Pointer(cname)) diff --git a/internal/graphicsdriver/opengl/gl/procaddr_gles.go b/internal/graphicsdriver/opengl/gl/procaddr_gles.go index 79ca45434..8a0dec9e6 100644 --- a/internal/graphicsdriver/opengl/gl/procaddr_gles.go +++ b/internal/graphicsdriver/opengl/gl/procaddr_gles.go @@ -35,8 +35,6 @@ import ( "unsafe" ) -var isES = true - func getProcAddress(namea string) unsafe.Pointer { const ext = "EXT" if strings.HasSuffix(namea, ext) { diff --git a/internal/graphicsdriver/opengl/gl/procaddr_nintendosdk.go b/internal/graphicsdriver/opengl/gl/procaddr_nintendosdk.go index cb2c26786..84babbded 100644 --- a/internal/graphicsdriver/opengl/gl/procaddr_nintendosdk.go +++ b/internal/graphicsdriver/opengl/gl/procaddr_nintendosdk.go @@ -28,8 +28,6 @@ import "C" import "unsafe" -var isES = false - func getProcAddress(namea string) unsafe.Pointer { cname := C.CString(namea) defer C.free(unsafe.Pointer(cname)) diff --git a/internal/graphicsdriver/opengl/gl/procaddr_windows.go b/internal/graphicsdriver/opengl/gl/procaddr_windows.go index 68bc9b9d9..e0a946d5b 100644 --- a/internal/graphicsdriver/opengl/gl/procaddr_windows.go +++ b/internal/graphicsdriver/opengl/gl/procaddr_windows.go @@ -24,7 +24,6 @@ import ( var ( opengl32 = windows.NewLazySystemDLL("opengl32") procWglGetProcAddress = opengl32.NewProc("wglGetProcAddress") - isES = false ) func getProcAddress(namea string) uintptr { diff --git a/internal/graphicsdriver/opengl/graphics.go b/internal/graphicsdriver/opengl/graphics.go index a98c140d1..e9dddb310 100644 --- a/internal/graphicsdriver/opengl/graphics.go +++ b/internal/graphicsdriver/opengl/graphics.go @@ -16,7 +16,6 @@ package opengl import ( "fmt" - "runtime" "github.com/hajimehoshi/ebiten/v2/internal/graphics" "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver" @@ -266,11 +265,7 @@ func (g *Graphics) SetFullscreen(fullscreen bool) { } func (g *Graphics) NeedsRestoring() bool { - // Though it is possible to have a logic to restore the graphics data for GPU, do not use it for performance (#1603). - if runtime.GOOS == "js" { - return false - } - return g.context.ctx.IsES() + return needsRestoring } func (g *Graphics) NeedsClearingScreen() bool { diff --git a/internal/graphicsdriver/opengl/needsrestoring_gles.go b/internal/graphicsdriver/opengl/needsrestoring_gles.go new file mode 100644 index 000000000..0d0f5523c --- /dev/null +++ b/internal/graphicsdriver/opengl/needsrestoring_gles.go @@ -0,0 +1,21 @@ +// Copyright 2022 The Ebitengine 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 && !opengles + +package opengl + +// Though it is possible to have a logic to restore the graphics data for GPU, do not use it for performance (#1603). + +const needsRestoring = false diff --git a/internal/graphicsdriver/opengl/needsrestoring_notgles.go b/internal/graphicsdriver/opengl/needsrestoring_notgles.go new file mode 100644 index 000000000..5399d7a61 --- /dev/null +++ b/internal/graphicsdriver/opengl/needsrestoring_notgles.go @@ -0,0 +1,19 @@ +// Copyright 2022 The Ebitengine 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 || opengles + +package opengl + +const needsRestoring = true