-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ported WgpuOptions to bevy_render2 (#3282)
# Objective The new renderer does not support any options yet for wgpu. These are needed for example for rendering wireframes (see #3193). ## Solution I've ported WgpuOptions to bevy_render2. The defaults match the defaults that were used before this PR (meaning, some specific options when target_arch = wasm32). Additionally, I removed `Auto` from WgpuBackends and added `Primary`. The default will use primary or GL based on the target_arch.
- Loading branch information
Showing
2 changed files
with
49 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::borrow::Cow; | ||
|
||
pub use wgpu::{Backends, Features, Limits, PowerPreference}; | ||
|
||
#[derive(Clone)] | ||
pub struct WgpuOptions { | ||
pub device_label: Option<Cow<'static, str>>, | ||
pub backends: Backends, | ||
pub power_preference: PowerPreference, | ||
pub features: Features, | ||
pub limits: Limits, | ||
} | ||
|
||
impl Default for WgpuOptions { | ||
fn default() -> Self { | ||
let default_backends = if cfg!(target_arch = "wasm32") { | ||
Backends::GL | ||
} else { | ||
Backends::PRIMARY | ||
}; | ||
|
||
let backends = wgpu::util::backend_bits_from_env().unwrap_or(default_backends); | ||
|
||
let limits = if cfg!(target_arch = "wasm32") { | ||
wgpu::Limits::downlevel_webgl2_defaults() | ||
} else { | ||
wgpu::Limits::default() | ||
}; | ||
|
||
Self { | ||
device_label: Default::default(), | ||
backends, | ||
power_preference: PowerPreference::HighPerformance, | ||
features: wgpu::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES, | ||
limits, | ||
} | ||
} | ||
} |