mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
internal/graphicsdriver/directx: refactoring
This commit is contained in:
parent
902d7244eb
commit
0b46d2b799
@ -18,8 +18,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
@ -122,58 +120,22 @@ type graphics12 struct {
|
|||||||
pipelineStates
|
pipelineStates
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphics12) initialize() (ferr error) {
|
func newGraphics12(useWARP bool, useDebugLayer bool, featureLevel _D3D_FEATURE_LEVEL) (*graphics12, error) {
|
||||||
var (
|
g := &graphics12{}
|
||||||
useWARP bool
|
|
||||||
useDebugLayer bool
|
|
||||||
)
|
|
||||||
env := os.Getenv("EBITENGINE_DIRECTX")
|
|
||||||
if env == "" {
|
|
||||||
// For backward compatibility, read the EBITEN_ version.
|
|
||||||
env = os.Getenv("EBITEN_DIRECTX")
|
|
||||||
}
|
|
||||||
for _, t := range strings.Split(env, ",") {
|
|
||||||
switch strings.TrimSpace(t) {
|
|
||||||
case "warp":
|
|
||||||
// TODO: Is WARP available on Xbox?
|
|
||||||
useWARP = true
|
|
||||||
case "debug":
|
|
||||||
useDebugLayer = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Specify the 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize not only a device but also other members like a fence.
|
// Initialize not only a device but also other members like a fence.
|
||||||
// Even if initializing a device succeeds, initializing a fence might fail (#2142).
|
// Even if initializing a device succeeds, initializing a fence might fail (#2142).
|
||||||
|
|
||||||
if microsoftgdk.IsXbox() {
|
if microsoftgdk.IsXbox() {
|
||||||
if err := g.initializeXbox(useWARP, useDebugLayer); err != nil {
|
if err := g.initializeXbox(useWARP, useDebugLayer); err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := g.initializeDesktop(useWARP, useDebugLayer, featureLevel); err != nil {
|
if err := g.initializeDesktop(useWARP, useDebugLayer, featureLevel); err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return g, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphics12) initializeDesktop(useWARP bool, useDebugLayer bool, featureLevel _D3D_FEATURE_LEVEL) (ferr error) {
|
func (g *graphics12) initializeDesktop(useWARP bool, useDebugLayer bool, featureLevel _D3D_FEATURE_LEVEL) (ferr error) {
|
||||||
|
@ -15,15 +15,55 @@
|
|||||||
package directx
|
package directx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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) {
|
||||||
|
var (
|
||||||
|
useWARP bool
|
||||||
|
useDebugLayer bool
|
||||||
|
)
|
||||||
|
env := os.Getenv("EBITENGINE_DIRECTX")
|
||||||
|
if env == "" {
|
||||||
|
// For backward compatibility, read the EBITEN_ version.
|
||||||
|
env = os.Getenv("EBITEN_DIRECTX")
|
||||||
|
}
|
||||||
|
for _, t := range strings.Split(env, ",") {
|
||||||
|
switch strings.TrimSpace(t) {
|
||||||
|
case "warp":
|
||||||
|
// TODO: Is WARP available on Xbox?
|
||||||
|
useWARP = true
|
||||||
|
case "debug":
|
||||||
|
useDebugLayer = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Specify the 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Implement a new graphics for DirectX 11 (#2613).
|
// TODO: Implement a new graphics for DirectX 11 (#2613).
|
||||||
g := &graphics12{}
|
g, err := newGraphics12(useWARP, useDebugLayer, featureLevel)
|
||||||
if err := g.initialize(); err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return g, nil
|
return g, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user