From 5cfb7c9469538668f781a6e2bd4312d67205c52c Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 13 Nov 2022 14:18:20 +0900 Subject: [PATCH] internal/graphicsdriver/opengl: make context_gles.go closer to context_gl.go Updates #2451 --- internal/graphicsdriver/opengl/context_gl.go | 4 ---- .../graphicsdriver/opengl/context_gles.go | 8 +++---- internal/graphicsdriver/opengl/context_js.go | 5 ----- internal/graphicsdriver/opengl/graphics.go | 2 +- .../opengl/needsrestoring_gles.go | 21 +++++++++++++++++++ .../opengl/needsrestoring_notgles.go | 19 +++++++++++++++++ 6 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 internal/graphicsdriver/opengl/needsrestoring_gles.go create mode 100644 internal/graphicsdriver/opengl/needsrestoring_notgles.go diff --git a/internal/graphicsdriver/opengl/context_gl.go b/internal/graphicsdriver/opengl/context_gl.go index 1a3e78989..79ddf293c 100644 --- a/internal/graphicsdriver/opengl/context_gl.go +++ b/internal/graphicsdriver/opengl/context_gl.go @@ -464,10 +464,6 @@ func (c *context) flush() { gl.Flush() } -func (c *context) needsRestoring() bool { - return false -} - func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.WritePixelsArgs) { c.bindTexture(t) for _, a := range args { diff --git a/internal/graphicsdriver/opengl/context_gles.go b/internal/graphicsdriver/opengl/context_gles.go index c2d19c372..a52350eef 100644 --- a/internal/graphicsdriver/opengl/context_gles.go +++ b/internal/graphicsdriver/opengl/context_gles.go @@ -194,7 +194,9 @@ func (c *context) newRenderbuffer(width, height int) (renderbufferNative, error) renderbuffer := renderbufferNative(r) c.bindRenderbuffer(renderbuffer) - c.ctx.RenderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, int32(width), int32(height)) + // GL_STENCIL_INDEX8 might not be available with OpenGL 2.1. + // https://www.khronos.org/opengl/wiki/Image_Format + c.ctx.RenderbufferStorage(gl.RENDERBUFFER, gl.DEPTH24_STENCIL8, int32(width), int32(height)) return renderbuffer, nil } @@ -439,10 +441,6 @@ func (c *context) flush() { c.ctx.Flush() } -func (c *context) needsRestoring() bool { - return true -} - func (c *context) texSubImage2D(t textureNative, args []*graphicsdriver.WritePixelsArgs) { c.bindTexture(t) for _, a := range args { diff --git a/internal/graphicsdriver/opengl/context_js.go b/internal/graphicsdriver/opengl/context_js.go index 3079846a7..b5f654e50 100644 --- a/internal/graphicsdriver/opengl/context_js.go +++ b/internal/graphicsdriver/opengl/context_js.go @@ -570,11 +570,6 @@ func (c *context) flush() { c.gl.flush.Invoke() } -func (c *context) needsRestoring() bool { - // 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) texSubImage2D(t textureNative, args []*graphicsdriver.WritePixelsArgs) { c.bindTexture(t) for _, a := range args { diff --git a/internal/graphicsdriver/opengl/graphics.go b/internal/graphicsdriver/opengl/graphics.go index 410d9df3d..607ad7ed5 100644 --- a/internal/graphicsdriver/opengl/graphics.go +++ b/internal/graphicsdriver/opengl/graphics.go @@ -279,7 +279,7 @@ func (g *Graphics) SetFullscreen(fullscreen bool) { } func (g *Graphics) NeedsRestoring() bool { - return g.context.needsRestoring() + 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