From 8cc6fa82fdbd8ea3269e4f273b0ee1b994eb974f Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 17 Nov 2022 12:43:10 +0900 Subject: [PATCH] internal/graphicsdriver/opengl: remove fnIsContextLost As restoring from context lost doesn't happen on browsers, isContextLost doesn't have to be called. --- internal/graphicsdriver/graphics.go | 5 ----- internal/graphicsdriver/opengl/context_js.go | 5 ----- internal/graphicsdriver/opengl/graphics_js.go | 1 - internal/restorable/images.go | 6 +----- 4 files changed, 1 insertion(+), 16 deletions(-) diff --git a/internal/graphicsdriver/graphics.go b/internal/graphicsdriver/graphics.go index 91013e6fe..d9afc6b2c 100644 --- a/internal/graphicsdriver/graphics.go +++ b/internal/graphicsdriver/graphics.go @@ -15,8 +15,6 @@ package graphicsdriver import ( - "errors" - "github.com/hajimehoshi/ebiten/v2/internal/graphics" "github.com/hajimehoshi/ebiten/v2/internal/shaderir" ) @@ -60,9 +58,6 @@ type Graphics interface { DrawTriangles(dst ImageID, srcs [graphics.ShaderImageCount]ImageID, shader ShaderID, dstRegions []DstRegion, indexOffset int, blend Blend, uniforms [][]uint32, evenOdd bool) error } -// GraphicsNotReady represents that the graphics driver is not ready for recovering from the context lost. -var GraphicsNotReady = errors.New("graphics not ready") - type Image interface { ID() ImageID Dispose() diff --git a/internal/graphicsdriver/opengl/context_js.go b/internal/graphicsdriver/opengl/context_js.go index a0f83c313..f395720d1 100644 --- a/internal/graphicsdriver/opengl/context_js.go +++ b/internal/graphicsdriver/opengl/context_js.go @@ -48,8 +48,6 @@ type contextImpl struct { ctx gl.Context canvas js.Value webGL2 bool - - fnIsContextLost js.Value } func (c *context) reset() error { @@ -60,9 +58,6 @@ func (c *context) reset() error { c.lastViewportHeight = 0 c.lastBlend = graphicsdriver.Blend{} - if c.fnIsContextLost.Invoke().Bool() { - return graphicsdriver.GraphicsNotReady - } c.ctx.Enable(gl.BLEND) c.ctx.Enable(gl.SCISSOR_TEST) c.blend(graphicsdriver.BlendSourceOver) diff --git a/internal/graphicsdriver/opengl/graphics_js.go b/internal/graphicsdriver/opengl/graphics_js.go index 91a3960c5..1a34cbec2 100644 --- a/internal/graphicsdriver/opengl/graphics_js.go +++ b/internal/graphicsdriver/opengl/graphics_js.go @@ -62,7 +62,6 @@ func NewGraphics(canvas js.Value) (graphicsdriver.Graphics, error) { g.context.canvas = canvas g.context.ctx = ctx g.context.webGL2 = webGL2 - g.context.fnIsContextLost = glContext.Get("isContextLost").Call("bind", glContext) if !webGL2 { glContext.Call("getExtension", "OES_standard_derivatives") diff --git a/internal/restorable/images.go b/internal/restorable/images.go index 34d681de7..53f747ba5 100644 --- a/internal/restorable/images.go +++ b/internal/restorable/images.go @@ -109,11 +109,7 @@ func RestoreIfNeeded(graphicsDriver graphicsdriver.Graphics) error { } } - err := graphicscommand.ResetGraphicsDriverState(graphicsDriver) - if err == graphicsdriver.GraphicsNotReady { - return nil - } - if err != nil { + if err := graphicscommand.ResetGraphicsDriverState(graphicsDriver); err != nil { return err } return theImages.restore(graphicsDriver)