From 8614599c5c9ad3ed53a528ce09d4fe5483990a0d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 28 May 2017 00:49:01 +0900 Subject: [PATCH] graphics: Don't call IsTexture on browsers --- graphicscontext.go | 13 +------------ graphicscontext_js.go | 25 +++++++++++++++++++++++++ graphicscontext_notjs.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 graphicscontext_js.go create mode 100644 graphicscontext_notjs.go diff --git a/graphicscontext.go b/graphicscontext.go index ac2e9eca0..317afbc91 100644 --- a/graphicscontext.go +++ b/graphicscontext.go @@ -37,7 +37,7 @@ type graphicsContext struct { screen *Image screenScale float64 initialized int32 - invalidated bool + invalidated bool // browser only } func (c *graphicsContext) GLContext() *opengl.Context { @@ -100,17 +100,6 @@ func (c *graphicsContext) SetSize(screenWidth, screenHeight int, screenScale flo return nil } -func (c *graphicsContext) needsRestoring(context *opengl.Context) (bool, error) { - if c.invalidated { - return true, nil - } - // FlushCommands is required because c.offscreen.impl might not have an actual texture. - if err := graphics.FlushCommands(context); err != nil { - return false, err - } - return c.offscreen.restorable.IsInvalidated(context), nil -} - func (c *graphicsContext) initializeIfNeeded(context *opengl.Context) error { if atomic.LoadInt32(&c.initialized) == 0 { if err := graphics.Reset(context); err != nil { diff --git a/graphicscontext_js.go b/graphicscontext_js.go new file mode 100644 index 000000000..a8e4b1188 --- /dev/null +++ b/graphicscontext_js.go @@ -0,0 +1,25 @@ +// Copyright 2017 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. + +// +build js + +package ebiten + +import ( + "github.com/hajimehoshi/ebiten/internal/opengl" +) + +func (c *graphicsContext) needsRestoring(context *opengl.Context) (bool, error) { + return c.invalidated, nil +} diff --git a/graphicscontext_notjs.go b/graphicscontext_notjs.go new file mode 100644 index 000000000..ef921cfc3 --- /dev/null +++ b/graphicscontext_notjs.go @@ -0,0 +1,30 @@ +// Copyright 2017 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. + +// +build !js + +package ebiten + +import ( + "github.com/hajimehoshi/ebiten/internal/graphics" + "github.com/hajimehoshi/ebiten/internal/opengl" +) + +func (c *graphicsContext) needsRestoring(context *opengl.Context) (bool, error) { + // FlushCommands is required because c.offscreen.impl might not have an actual texture. + if err := graphics.FlushCommands(context); err != nil { + return false, err + } + return c.offscreen.restorable.IsInvalidated(context), nil +}