diff --git a/doc.go b/doc.go index 3525ad11e..c1cc0a75a 100644 --- a/doc.go +++ b/doc.go @@ -56,16 +56,16 @@ // // Environment variables // -// `EBITEN_SCREENSHOT_KEY` environment variable specifies the key +// `EBITENGINE_SCREENSHOT_KEY` environment variable specifies the key // to take a screenshot. For example, if you run your game with -// `EBITEN_SCREENSHOT_KEY=q`, you can take a game screen's screenshot +// `EBITENGINE_SCREENSHOT_KEY=q`, you can take a game screen's screenshot // by pressing Q key. This works only on desktops. // -// `EBITEN_INTERNAL_IMAGES_KEY` environment variable specifies the key +// `EBITENGINE_INTERNAL_IMAGES_KEY` environment variable specifies the key // to dump all the internal images. This is valid only when the build tag // 'ebitendebug' is specified. This works only on desktops. // -// `EBITEN_GRAPHICS_LIBRARY` environment variable specifies the graphics library. +// `EBITENGINE_GRAPHICS_LIBRARY` environment variable specifies the graphics library. // If the specified graphics library is not available, RunGame returns an error. // This can take one of the following value: // @@ -74,7 +74,7 @@ // "directx": DirectX. This works only on Windows. // "metal": Metal. This works only on macOS or iOS. // -// `EBITEN_DIRECTX` environment variable specifies various parameters for DirectX. +// `EBITENGINE_DIRECTX` environment variable specifies various parameters for DirectX. // You can specify multiple values separated by a comma. The default value is empty (i.e. no parameters). // // "warp": Use WARP (i.e. software rendering). diff --git a/imagedumper_desktop.go b/imagedumper_desktop.go index 031494ec6..e8bdfb858 100644 --- a/imagedumper_desktop.go +++ b/imagedumper_desktop.go @@ -98,16 +98,27 @@ type imageDumper struct { err error } +func envScreenshotKey() string { + if env := os.Getenv("EBITENGINE_SCREENSHOT_KEY"); env != "" { + return env + } + // For backward compatibility, read the EBITEN_ version. + return os.Getenv("EBITEN_SCREENSHOT_KEY") +} + +func envInternalImagesKey() string { + if env := os.Getenv("EBITENGINE_INTERNAL_IMAGES_KEY"); env != "" { + return env + } + // For backward compatibility, read the EBITEN_ version. + return os.Getenv("EBITEN_INTERNAL_IMAGES_KEY") +} + func (i *imageDumper) update() error { if i.err != nil { return i.err } - const ( - envScreenshotKey = "EBITEN_SCREENSHOT_KEY" - envInternalImagesKey = "EBITEN_INTERNAL_IMAGES_KEY" - ) - if err := i.g.Update(); err != nil { return err } @@ -116,14 +127,14 @@ func (i *imageDumper) update() error { if i.keyState == nil { i.keyState = map[Key]int{} - if keyname := os.Getenv(envScreenshotKey); keyname != "" { + if keyname := envScreenshotKey(); keyname != "" { if key, ok := keyNameToKeyCode(keyname); ok { i.hasScreenshotKey = true i.screenshotKey = key } } - if keyname := os.Getenv(envInternalImagesKey); keyname != "" { + if keyname := envInternalImagesKey(); keyname != "" { if isDebug { if key, ok := keyNameToKeyCode(keyname); ok { i.hasDumpInternalImagesKey = true diff --git a/internal/graphicsdriver/directx/graphics_windows.go b/internal/graphicsdriver/directx/graphics_windows.go index b3b577ae2..5459adbef 100644 --- a/internal/graphicsdriver/directx/graphics_windows.go +++ b/internal/graphicsdriver/directx/graphics_windows.go @@ -152,7 +152,12 @@ func (g *Graphics) initialize() (ferr error) { useWARP bool useDebugLayer bool ) - for _, t := range strings.Split(os.Getenv("EBITEN_DIRECTX"), ",") { + 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? diff --git a/internal/ui/graphics.go b/internal/ui/graphics.go index 71c771cc0..e33ea1888 100644 --- a/internal/ui/graphics.go +++ b/internal/ui/graphics.go @@ -29,9 +29,15 @@ type graphicsDriverCreator interface { } func newGraphicsDriver(creator graphicsDriverCreator) (graphicsdriver.Graphics, error) { - const envName = "EBITEN_GRAPHICS_LIBRARY" + envName := "EBITENGINE_GRAPHICS_LIBRARY" + env := os.Getenv(envName) + if env == "" { + // For backward compatibility, read the EBITEN_ version. + envName = "EBITEN_GRAPHICS_LIBRARY" + env = os.Getenv(envName) + } - switch env := os.Getenv(envName); env { + switch env { case "", "auto": g, err := creator.newAuto() if err != nil {