mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
internal/graphicsdriver/directx: integrate EBITENGINE_DIRECTX and EBITENGINE_DIRECTX_FEATURE_LEVEL
This commit is contained in:
parent
129956d8f0
commit
0449126c5b
16
doc.go
16
doc.go
@ -80,15 +80,17 @@
|
|||||||
//
|
//
|
||||||
// "debug": Use a debug layer.
|
// "debug": Use a debug layer.
|
||||||
// "warp": Use WARP (i.e. software rendering).
|
// "warp": Use WARP (i.e. software rendering).
|
||||||
// "version=11": Use DirectX 11 (default).
|
// "version=VERSION": Specify a DirectX version (e.g. 11).
|
||||||
// "version=12": Use DirectX 12.
|
// "featurelevel=FEATURE_LEVEL": Specify a feature level (e.g. 11_0). This is for DirectX 12.
|
||||||
//
|
//
|
||||||
// The options "version=..." are exclusive and if multiples are specified, the lastly specified value is adopted.
|
// The options taking arguments are exclusive, and if multiples are specified, the lastly specified value is adopted.
|
||||||
// On Xbox, the version options are ignored and DirectX 12 is always adopted.
|
|
||||||
//
|
//
|
||||||
// `EBITENGINE_DIRECTX_FEATURE_LEVEL` environment variable specifies DirectX feature level.
|
// The possible values for the option "version" are "11" and "12".
|
||||||
// The possible values are "11_0", "11_1", "12_0", "12_1", and "12_2".
|
// If the version is not specified, the default version 11 is adopted.
|
||||||
// The default value is "11_0".
|
// On Xbox, the "version" option is ignored and DirectX 12 is always adopted.
|
||||||
|
//
|
||||||
|
// The option "featurelevel" is valid only for DirectX 12.
|
||||||
|
// The possible values are "11_0", "11_1", "12_0", "12_1", and "12_2". The default value is "11_0".
|
||||||
//
|
//
|
||||||
// `EBITENGINE_OPENGL` environment variable specifies various parameters for OpenGL.
|
// `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).
|
// You can specify multiple values separated by a comma. The default value is empty (i.e. no parameters).
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
@ -52,6 +53,23 @@ func pow2(x uint32) uint32 {
|
|||||||
return p2
|
return p2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseFeatureLevel(str string) (_D3D_FEATURE_LEVEL, bool) {
|
||||||
|
switch str {
|
||||||
|
case "11_0":
|
||||||
|
return _D3D_FEATURE_LEVEL_11_0, true
|
||||||
|
case "11_1":
|
||||||
|
return _D3D_FEATURE_LEVEL_11_1, true
|
||||||
|
case "12_0":
|
||||||
|
return _D3D_FEATURE_LEVEL_12_0, true
|
||||||
|
case "12_1":
|
||||||
|
return _D3D_FEATURE_LEVEL_12_1, true
|
||||||
|
case "12_2":
|
||||||
|
return _D3D_FEATURE_LEVEL_12_2, true
|
||||||
|
default:
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewGraphics creates an implementation of graphicsdriver.Graphics for DirectX.
|
// NewGraphics creates an implementation of graphicsdriver.Graphics for DirectX.
|
||||||
// The returned graphics value is nil iff the error is not nil.
|
// The returned graphics value is nil iff the error is not nil.
|
||||||
func NewGraphics() (graphicsdriver.Graphics, error) {
|
func NewGraphics() (graphicsdriver.Graphics, error) {
|
||||||
@ -59,22 +77,43 @@ func NewGraphics() (graphicsdriver.Graphics, error) {
|
|||||||
var useDebugLayer bool
|
var useDebugLayer bool
|
||||||
version := 11
|
version := 11
|
||||||
|
|
||||||
|
// Specify the feature level 11 by default.
|
||||||
|
// Some old cards don't work well with the default feature level (#2447, #2486).
|
||||||
|
featureLevel := _D3D_FEATURE_LEVEL_11_0
|
||||||
|
|
||||||
|
// Parse a special environment variable for backward compatibility.
|
||||||
|
if env := os.Getenv("EBITENGINE_DIRECTX_FEATURE_LEVEL"); env != "" {
|
||||||
|
if fl, ok := parseFeatureLevel(env); ok {
|
||||||
|
featureLevel = fl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
env := os.Getenv("EBITENGINE_DIRECTX")
|
env := os.Getenv("EBITENGINE_DIRECTX")
|
||||||
if env == "" {
|
if env == "" {
|
||||||
// For backward compatibility, read the EBITEN_ version.
|
// For backward compatibility, read the EBITEN_ version.
|
||||||
env = os.Getenv("EBITEN_DIRECTX")
|
env = os.Getenv("EBITEN_DIRECTX")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, t := range strings.Split(env, ",") {
|
for _, t := range strings.Split(env, ",") {
|
||||||
switch strings.TrimSpace(t) {
|
t := strings.TrimSpace(t)
|
||||||
case "warp":
|
switch {
|
||||||
|
case t == "warp":
|
||||||
// TODO: Is WARP available on Xbox?
|
// TODO: Is WARP available on Xbox?
|
||||||
useWARP = true
|
useWARP = true
|
||||||
case "debug":
|
case t == "debug":
|
||||||
useDebugLayer = true
|
useDebugLayer = true
|
||||||
case "version=11":
|
case strings.HasPrefix(t, "version="):
|
||||||
version = 11
|
v, err := strconv.Atoi(t[len("version="):])
|
||||||
case "version=12":
|
if err != nil {
|
||||||
version = 12
|
continue
|
||||||
|
}
|
||||||
|
version = v
|
||||||
|
case strings.HasPrefix(t, "featurelevel="):
|
||||||
|
fl, ok := parseFeatureLevel(t[len("featurelevel="):])
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
featureLevel = fl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,24 +130,6 @@ func NewGraphics() (graphicsdriver.Graphics, error) {
|
|||||||
}
|
}
|
||||||
return g, nil
|
return g, nil
|
||||||
case 12:
|
case 12:
|
||||||
// Specify the feature level 11 by default.
|
|
||||||
// Some old cards don't work well with the default feature level (#2447, #2486).
|
|
||||||
var featureLevel _D3D_FEATURE_LEVEL = _D3D_FEATURE_LEVEL_11_0
|
|
||||||
if env := os.Getenv("EBITENGINE_DIRECTX_FEATURE_LEVEL"); env != "" {
|
|
||||||
switch env {
|
|
||||||
case "11_0":
|
|
||||||
featureLevel = _D3D_FEATURE_LEVEL_11_0
|
|
||||||
case "11_1":
|
|
||||||
featureLevel = _D3D_FEATURE_LEVEL_11_1
|
|
||||||
case "12_0":
|
|
||||||
featureLevel = _D3D_FEATURE_LEVEL_12_0
|
|
||||||
case "12_1":
|
|
||||||
featureLevel = _D3D_FEATURE_LEVEL_12_1
|
|
||||||
case "12_2":
|
|
||||||
featureLevel = _D3D_FEATURE_LEVEL_12_2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g, err := newGraphics12(useWARP, useDebugLayer, featureLevel)
|
g, err := newGraphics12(useWARP, useDebugLayer, featureLevel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user