Skip to content

Commit

Permalink
feat: added backends option to the window descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
ElhamAryanpur committed May 17, 2023
1 parent 641e4d6 commit 9e86772
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ pub struct WindowDescriptor {
pub resizable: bool,
/// Define how much power should the app ask for
pub power_preference: crate::PowerPreference,
/// The backend to use for the draw
pub backends: crate::Backends,
}
impl std::default::Default for WindowDescriptor {
/// Will quickly create a window with default settings
Expand All @@ -250,6 +252,7 @@ impl std::default::Default for WindowDescriptor {
decorations: true,
resizable: true,
power_preference: crate::PowerPreference::LowPower,
backends: crate::Backends::all(),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/header/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub use bytemuck::Pod;
/// Zeroable trait for custom uniform buffer structure
pub use bytemuck::Zeroable;

/// Backends
pub use wgpu::Backends;
/// Encoder from wgpu
pub use wgpu::CommandEncoder;
pub use wgpu::LoadOp;
Expand Down Expand Up @@ -62,4 +64,3 @@ pub use winit::window::Window;
pub use winit_input_helper::WinitInputHelper as InputHelper;

pub const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float;

6 changes: 5 additions & 1 deletion src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ impl Renderer {
pub(crate) async fn new(
window: &Window,
power_preference: crate::PowerPreference,
backends: crate::Backends,
) -> anyhow::Result<Self> {
let size = window.inner_size();

// The instance is a handle to our GPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::default());
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends,
..Default::default()
});

#[cfg(not(feature = "android"))]
let surface = Some(unsafe { instance.create_surface(window) }.unwrap());
Expand Down
7 changes: 5 additions & 2 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ impl Engine {
let window = Window::new(&event_loop).unwrap();

// The renderer init on current window
let mut renderer =
futures::executor::block_on(Renderer::new(&window, settings.power_preference))?;
let mut renderer = futures::executor::block_on(Renderer::new(
&window,
settings.power_preference,
settings.backends,
))?;

let camera = Camera::new(window.inner_size(), &mut renderer)?;

Expand Down

0 comments on commit 9e86772

Please sign in to comment.