Skip to content

Commit

Permalink
Add from_size() to get a default SurfaceConfiguration, simplify t…
Browse files Browse the repository at this point in the history
…he use of users
  • Loading branch information
jinleili committed Sep 19, 2022
1 parent 6f2c393 commit 627fdf8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ SurfaceConfiguration {
- Address Clippy 0.1.63 complaints. By @jimblandy in [#2977](https://github.com/gfx-rs/wgpu/pull/2977)
- Don't use `PhantomData` for `IdentityManager`'s `Input` type. By @jimblandy in [#2972](https://github.com/gfx-rs/wgpu/pull/2972)
- Changed Naga variant in ShaderSource to `Cow<'static, Module>`, to allow loading global variables by @daxpedda in [#2903](https://github.com/gfx-rs/wgpu/pull/2903)
- Add `from_size()` to get a default `SurfaceConfiguration`, simplify the use of users. By @jinleili in [#3034](https://github.com/gfx-rs/wgpu/pull/3034)

#### Metal
- Extract the generic code into `get_metal_layer` by @jinleili in [#2826](https://github.com/gfx-rs/wgpu/pull/2826)
Expand Down
15 changes: 15 additions & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3122,6 +3122,21 @@ pub struct SurfaceConfiguration {
pub alpha_mode: CompositeAlphaMode,
}

impl SurfaceConfiguration {
/// Get a default `SurfaceConfiguration` from width and height
#[allow(dead_code)]
pub fn from_size(width: u32, height: u32) -> Self {
Self {
usage: crate::TextureUsages::RENDER_ATTACHMENT,
format: TextureFormat::Bgra8UnormSrgb,
width,
height,
present_mode: PresentMode::AutoVsync,
alpha_mode: CompositeAlphaMode::Auto,
}
}
}

/// Status of the recieved surface image.
#[repr(C)]
#[derive(Debug)]
Expand Down
9 changes: 1 addition & 8 deletions wgpu/examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,7 @@ fn start<E: Example>(
}: Setup,
) {
let spawner = Spawner::new();
let mut config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
alpha_mode: surface.get_supported_alpha_modes(&adapter)[0],
};
let mut config = wgpu::SurfaceConfiguration::from_size(size.width, size.height);
surface.configure(&device, &config);

log::info!("Initializing the example...");
Expand Down

0 comments on commit 627fdf8

Please sign in to comment.