diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fb3a03490..c5e576412 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -129,7 +129,7 @@ jobs: if: ${{ !startsWith(matrix.os, 'windows-') && !startsWith(matrix.go, '1.15.') && !startsWith(matrix.go, '1.16.') }} run: | env GOOS=js GOARCH=wasm go test -tags=example ${{ !startsWith(matrix.go, '1.15.') && !startsWith(matrix.go, '1.16.') && '-shuffle=on' || '' }} -v ./... - env GOOS=js GOARCH=wasm go test -tags=example,ebitenginewebgl1 ${{ !startsWith(matrix.go, '1.15.') && !startsWith(matrix.go, '1.16.') && '-shuffle=on' || '' }} -v ./... + env GOOS=js GOARCH=wasm EBITENGINE_OPENGL=webgl1 go test -tags=example ${{ !startsWith(matrix.go, '1.15.') && !startsWith(matrix.go, '1.16.') && '-shuffle=on' || '' }} -v ./... - name: Install ebitenmobile run: | diff --git a/doc.go b/doc.go index 8a458d044..646745c80 100644 --- a/doc.go +++ b/doc.go @@ -81,13 +81,16 @@ // "warp": Use WARP (i.e. software rendering). // "debug": Use a debug layer. // +// `EBITENGINE_OPENGL` environment variable specifies various parameters for OpenGL. +// You can specify multiple values separated by a comma. The default value is empty (i.e. no parameters). +// +// "webgl1": Use WebGL 1. This is valid only on browsers. +// // # Build tags // // `ebitenginedebug` outputs a log of graphics commands. This is useful to know what happens in Ebitengine. In general, the // number of graphics commands affects the performance of your game. // -// `ebitenginewebgl1` forces to use WebGL 1 on browsers. -// // `ebitenginesinglethread` disables Ebitengine's thread safety to unlock maximum performance. If you use this you will have // to manage threads yourself. Functions like IsKeyPressed will no longer be concurrent-safe with this build tag. // They must be called from the main thread or the same goroutine as the given game's callback functions like Update diff --git a/internal/graphicsdriver/opengl/context_js.go b/internal/graphicsdriver/opengl/context_js.go index c256d6520..ab0fb8dcf 100644 --- a/internal/graphicsdriver/opengl/context_js.go +++ b/internal/graphicsdriver/opengl/context_js.go @@ -17,6 +17,8 @@ package opengl import ( "errors" "fmt" + "os" + "strings" "syscall/js" "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver" @@ -95,9 +97,16 @@ const ( webGLVersion2 ) -var ( - webGL2MightBeAvailable = !forceWebGL1 && (js.Global().Get("WebGL2RenderingContext").Truthy()) -) +func webGL2MightBeAvailable() bool { + env := os.Getenv("EBITENGINE_OPENGL") + for _, t := range strings.Split(env, ",") { + switch strings.TrimSpace(t) { + case "webgl1": + return false + } + } + return js.Global().Get("WebGL2RenderingContext").Truthy() +} func uint8ArrayToSlice(value js.Value, length int) []byte { if l := value.Get("byteLength").Int(); length > l { @@ -131,7 +140,7 @@ func (c *context) initGL() error { attr.Set("premultipliedAlpha", true) attr.Set("stencil", true) - if webGL2MightBeAvailable { + if webGL2MightBeAvailable() { gl = canvas.Call("getContext", "webgl2", attr) if gl.Truthy() { c.webGLVersion = webGLVersion2 diff --git a/internal/graphicsdriver/opengl/context_notwebgl1.go b/internal/graphicsdriver/opengl/context_notwebgl1.go deleted file mode 100644 index e128bda37..000000000 --- a/internal/graphicsdriver/opengl/context_notwebgl1.go +++ /dev/null @@ -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 !ebitenginewebgl1 && !ebitenwebgl1 -// +build !ebitenginewebgl1,!ebitenwebgl1 - -package opengl - -const forceWebGL1 = false diff --git a/internal/graphicsdriver/opengl/context_webgl1.go b/internal/graphicsdriver/opengl/context_webgl1.go deleted file mode 100644 index 5135c6840..000000000 --- a/internal/graphicsdriver/opengl/context_webgl1.go +++ /dev/null @@ -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 ebitenginewebgl1 || ebitenwebgl1 -// +build ebitenginewebgl1 ebitenwebgl1 - -package opengl - -const forceWebGL1 = true