@@ -16,6 +16,9 @@ pub struct Settings {
1616 /// [`Backend`]: crate::Backend
1717 pub present_mode : wgpu:: PresentMode ,
1818
19+ /// The internal graphics backend to use.
20+ pub internal_backend : wgpu:: BackendBit ,
21+
1922 /// The bytes of the font that will be used by default.
2023 ///
2124 /// If `None` is provided, a default system font will be chosen.
@@ -30,14 +33,52 @@ pub struct Settings {
3033 pub antialiasing : Option < Antialiasing > ,
3134}
3235
36+ impl Settings {
37+ /// Creates new [`Settings`] using environment configuration.
38+ ///
39+ /// Specifically:
40+ ///
41+ /// - The `internal_backend` can be configured using the `WGPU_BACKEND`
42+ /// environment variable. If the variable is not set, the primary backend
43+ /// will be used. The following values are allowed:
44+ /// - `vulkan`
45+ /// - `metal`
46+ /// - `dx12`
47+ /// - `dx11`
48+ /// - `gl`
49+ /// - `webgpu`
50+ pub fn from_env ( ) -> Self {
51+ Settings {
52+ internal_backend : backend_from_env ( )
53+ . unwrap_or ( wgpu:: BackendBit :: PRIMARY ) ,
54+ ..Self :: default ( )
55+ }
56+ }
57+ }
58+
3359impl Default for Settings {
3460 fn default ( ) -> Settings {
3561 Settings {
3662 format : wgpu:: TextureFormat :: Bgra8UnormSrgb ,
3763 present_mode : wgpu:: PresentMode :: Mailbox ,
64+ internal_backend : wgpu:: BackendBit :: PRIMARY ,
3865 default_font : None ,
3966 default_text_size : 20 ,
4067 antialiasing : None ,
4168 }
4269 }
4370}
71+
72+ fn backend_from_env ( ) -> Option < wgpu:: BackendBit > {
73+ std:: env:: var ( "WGPU_BACKEND" ) . ok ( ) . map ( |backend| {
74+ match backend. to_lowercase ( ) . as_str ( ) {
75+ "vulkan" => wgpu:: BackendBit :: VULKAN ,
76+ "metal" => wgpu:: BackendBit :: METAL ,
77+ "dx12" => wgpu:: BackendBit :: DX12 ,
78+ "dx11" => wgpu:: BackendBit :: DX11 ,
79+ "gl" => wgpu:: BackendBit :: GL ,
80+ "webgpu" => wgpu:: BackendBit :: BROWSER_WEBGPU ,
81+ other => panic ! ( "Unknown backend: {}" , other) ,
82+ }
83+ } )
84+ }
0 commit comments