mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
ebiten: add ReadDebugInfo
for getting debug info (only graphics libray so far) (#2222)
Closes #2177
This commit is contained in:
parent
37fe3cdabe
commit
3ac37e250f
27
graphics.go
27
graphics.go
@ -16,6 +16,7 @@ package ebiten
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
||||
)
|
||||
|
||||
// Filter represents the type of texture filter to be used when an image is maginified or minified.
|
||||
@ -82,3 +83,29 @@ const (
|
||||
// c_out = c_src * c_dst
|
||||
CompositeModeMultiply CompositeMode = CompositeMode(graphicsdriver.CompositeModeMultiply)
|
||||
)
|
||||
|
||||
// GraphicsLibrary represets graphics libraries supported by the engine.
|
||||
type GraphicsLibrary = ui.GraphicsLibrary
|
||||
|
||||
const (
|
||||
// GraphicsLibraryUnknown represents the state at which graphics library cannot be determined,
|
||||
// e.g. hasn't loaded yet or failed to initialize.
|
||||
GraphicsLibraryUnknown = ui.GraphicsLibraryUnknown
|
||||
// GraphicsLibraryOpenGL current graphics library used is OpenGL.
|
||||
GraphicsLibraryOpenGL = ui.GraphicsLibraryOpenGL
|
||||
// GraphicsLibraryDirectX current graphics library used is Microsoft DirectX.
|
||||
GraphicsLibraryDirectX = ui.GraphicsLibraryDirectX
|
||||
// GraphicsLibraryMetal current graphics library used is Apple's Metal.
|
||||
GraphicsLibraryMetal = ui.GraphicsLibraryMetal
|
||||
)
|
||||
|
||||
// DebugInfo is a struct to store debug info about the graphics.
|
||||
type DebugInfo struct {
|
||||
// GraphicsLibrary represents the graphics library currently in use.
|
||||
GraphicsLibrary GraphicsLibrary
|
||||
}
|
||||
|
||||
// ReadDebugInfo writes debug info (e.g. current graphics library) into a provided struct.
|
||||
func ReadDebugInfo(d *DebugInfo) {
|
||||
d.GraphicsLibrary = ui.GetGraphicsLibrary()
|
||||
}
|
||||
|
@ -294,6 +294,7 @@ type globalState struct {
|
||||
fpsMode_ int32
|
||||
isScreenClearedEveryFrame_ int32
|
||||
screenFilterEnabled_ int32
|
||||
graphicsLibrary_ int32
|
||||
}
|
||||
|
||||
func (g *globalState) error() error {
|
||||
@ -342,6 +343,14 @@ func (g *globalState) setScreenFilterEnabled(enabled bool) {
|
||||
atomic.StoreInt32(&g.screenFilterEnabled_, v)
|
||||
}
|
||||
|
||||
func (g *globalState) setGraphicsLibrary(library GraphicsLibrary) {
|
||||
atomic.StoreInt32(&g.graphicsLibrary_, int32(library))
|
||||
}
|
||||
|
||||
func (g *globalState) graphicsLibrary() GraphicsLibrary {
|
||||
return GraphicsLibrary(atomic.LoadInt32(&g.graphicsLibrary_))
|
||||
}
|
||||
|
||||
func FPSMode() FPSModeType {
|
||||
return theGlobalState.fpsMode()
|
||||
}
|
||||
@ -366,3 +375,7 @@ func IsScreenFilterEnabled() bool {
|
||||
func SetScreenFilterEnabled(enabled bool) {
|
||||
theGlobalState.setScreenFilterEnabled(enabled)
|
||||
}
|
||||
|
||||
func GetGraphicsLibrary() GraphicsLibrary {
|
||||
return theGlobalState.graphicsLibrary()
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
)
|
||||
|
||||
type graphicsDriverCreator interface {
|
||||
newAuto() (graphicsdriver.Graphics, error)
|
||||
newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error)
|
||||
newOpenGL() (graphicsdriver.Graphics, error)
|
||||
newDirectX() (graphicsdriver.Graphics, error)
|
||||
newMetal() (graphicsdriver.Graphics, error)
|
||||
@ -39,13 +39,14 @@ func newGraphicsDriver(creator graphicsDriverCreator) (graphicsdriver.Graphics,
|
||||
|
||||
switch env {
|
||||
case "", "auto":
|
||||
g, err := creator.newAuto()
|
||||
g, lib, err := creator.newAuto()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if g == nil {
|
||||
return nil, fmt.Errorf("ui: no graphics library is available")
|
||||
}
|
||||
theGlobalState.setGraphicsLibrary(lib)
|
||||
return g, nil
|
||||
case "opengl":
|
||||
g, err := creator.newOpenGL()
|
||||
@ -55,6 +56,7 @@ func newGraphicsDriver(creator graphicsDriverCreator) (graphicsdriver.Graphics,
|
||||
if g == nil {
|
||||
return nil, fmt.Errorf("ui: %s=%s is specified but OpenGL is not available", envName, env)
|
||||
}
|
||||
theGlobalState.setGraphicsLibrary(GraphicsLibraryOpenGL)
|
||||
return g, nil
|
||||
case "directx":
|
||||
g, err := creator.newDirectX()
|
||||
@ -64,6 +66,7 @@ func newGraphicsDriver(creator graphicsDriverCreator) (graphicsdriver.Graphics,
|
||||
if g == nil {
|
||||
return nil, fmt.Errorf("ui: %s=%s is specified but DirectX is not available.", envName, env)
|
||||
}
|
||||
theGlobalState.setGraphicsLibrary(GraphicsLibraryDirectX)
|
||||
return g, nil
|
||||
case "metal":
|
||||
g, err := creator.newMetal()
|
||||
@ -73,6 +76,7 @@ func newGraphicsDriver(creator graphicsDriverCreator) (graphicsdriver.Graphics,
|
||||
if g == nil {
|
||||
return nil, fmt.Errorf("ui: %s=%s is specified but Metal is not available", envName, env)
|
||||
}
|
||||
theGlobalState.setGraphicsLibrary(GraphicsLibraryMetal)
|
||||
return g, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("ui: an unsupported graphics library is specified: %s", env)
|
||||
|
@ -71,6 +71,15 @@ const (
|
||||
WindowResizingModeEnabled
|
||||
)
|
||||
|
||||
type GraphicsLibrary int
|
||||
|
||||
const (
|
||||
GraphicsLibraryUnknown GraphicsLibrary = iota
|
||||
GraphicsLibraryOpenGL
|
||||
GraphicsLibraryDirectX
|
||||
GraphicsLibraryMetal
|
||||
)
|
||||
|
||||
type UserInterface struct {
|
||||
userInterfaceImpl
|
||||
}
|
||||
|
@ -23,8 +23,9 @@ type graphicsDriverCreatorImpl struct {
|
||||
gomobileBuild bool
|
||||
}
|
||||
|
||||
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, error) {
|
||||
return g.newOpenGL()
|
||||
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) {
|
||||
graphics, err := g.newOpenGL()
|
||||
return graphics, GraphicsLibraryOpenGL, err
|
||||
}
|
||||
|
||||
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
|
||||
|
@ -27,8 +27,9 @@ import (
|
||||
|
||||
type graphicsDriverCreatorImpl struct{}
|
||||
|
||||
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, error) {
|
||||
return g.newOpenGL()
|
||||
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) {
|
||||
graphics, err := g.newOpenGL()
|
||||
return graphics, GraphicsLibraryOpenGL, err
|
||||
}
|
||||
|
||||
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
|
||||
|
@ -260,16 +260,16 @@ type graphicsDriverCreatorImpl struct {
|
||||
transparent bool
|
||||
}
|
||||
|
||||
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, error) {
|
||||
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) {
|
||||
m, err1 := g.newMetal()
|
||||
if err1 == nil {
|
||||
return m, nil
|
||||
return m, GraphicsLibraryMetal, nil
|
||||
}
|
||||
o, err2 := g.newOpenGL()
|
||||
if err2 == nil {
|
||||
return o, nil
|
||||
return o, GraphicsLibraryOpenGL, nil
|
||||
}
|
||||
return nil, fmt.Errorf("ui: failed to choose graphics drivers: Metal: %v, OpenGL: %v", err1, err2)
|
||||
return nil, GraphicsLibraryUnknown, fmt.Errorf("ui: failed to choose graphics drivers: Metal: %v, OpenGL: %v", err1, err2)
|
||||
}
|
||||
|
||||
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
|
||||
|
@ -35,8 +35,9 @@ type graphicsDriverCreatorImpl struct {
|
||||
transparent bool
|
||||
}
|
||||
|
||||
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, error) {
|
||||
return g.newOpenGL()
|
||||
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) {
|
||||
graphics, err := g.newOpenGL()
|
||||
return graphics, GraphicsLibraryOpenGL, err
|
||||
}
|
||||
|
||||
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
|
||||
|
@ -36,16 +36,16 @@ type graphicsDriverCreatorImpl struct {
|
||||
transparent bool
|
||||
}
|
||||
|
||||
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, error) {
|
||||
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) {
|
||||
d, err1 := g.newDirectX()
|
||||
if err1 == nil {
|
||||
return d, nil
|
||||
return d, GraphicsLibraryDirectX, nil
|
||||
}
|
||||
o, err2 := g.newOpenGL()
|
||||
if err2 == nil {
|
||||
return o, nil
|
||||
return o, GraphicsLibraryOpenGL, nil
|
||||
}
|
||||
return nil, fmt.Errorf("ui: failed to choose graphics drivers: DirectX: %v, OpenGL: %v", err1, err2)
|
||||
return nil, GraphicsLibraryUnknown, fmt.Errorf("ui: failed to choose graphics drivers: DirectX: %v, OpenGL: %v", err1, err2)
|
||||
}
|
||||
|
||||
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
|
||||
|
@ -29,16 +29,16 @@ type graphicsDriverCreatorImpl struct {
|
||||
gomobileBuild bool
|
||||
}
|
||||
|
||||
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, error) {
|
||||
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) {
|
||||
m, err1 := g.newMetal()
|
||||
if err1 == nil {
|
||||
return m, nil
|
||||
return m, GraphicsLibraryMetal, nil
|
||||
}
|
||||
o, err2 := g.newOpenGL()
|
||||
if err2 == nil {
|
||||
return o, nil
|
||||
return o, GraphicsLibraryMetal, nil
|
||||
}
|
||||
return nil, fmt.Errorf("ui: failed to choose graphics drivers: Metal: %v, OpenGL: %v", err1, err2)
|
||||
return nil, GraphicsLibraryUnknown, fmt.Errorf("ui: failed to choose graphics drivers: Metal: %v, OpenGL: %v", err1, err2)
|
||||
}
|
||||
|
||||
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
|
||||
|
@ -27,8 +27,9 @@ import (
|
||||
|
||||
type graphicsDriverCreatorImpl struct{}
|
||||
|
||||
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, error) {
|
||||
return g.newOpenGL()
|
||||
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) {
|
||||
graphics, err := g.newOpenGL()
|
||||
return graphics, GraphicsLibraryOpenGL, err
|
||||
}
|
||||
|
||||
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user