mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/graphicsdriver/opengl: introduce EBITENGINE_OPENGL
replacing ebitenginewebgl1
This change inroduces a new environment variable `EBITENGINE_OPENGL` to replace the build tag `ebitenginewebgl1`.
This commit is contained in:
parent
001c344d00
commit
ec68534c73
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -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: |
|
||||
|
7
doc.go
7
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
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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
|
Loading…
Reference in New Issue
Block a user