Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_default_configure to simplify user creation of SurfaceConfiguration #3034

Merged
merged 1 commit into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Bottom level categories:
- Implement `Hash` for `DepthStencilState` and `DepthBiasState`
- Add the `"wgsl"` feature, to enable WGSL shaders in `wgpu-core` and `wgpu`. Enabled by default in `wgpu`. By @daxpedda in [#2890](https://github.com/gfx-rs/wgpu/pull/2890).
- Implement `Clone` for `ShaderSource` and `ShaderModuleDescriptor` in `wgpu`. By @daxpedda in [#3086](https://github.com/gfx-rs/wgpu/pull/3086).
- Add `get_default_config` for `Surface` to simplify user creation of `SurfaceConfiguration`. By @jinleili in [#3034](https://github.com/gfx-rs/wgpu/pull/3034)

#### GLES

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 = surface.get_default_config(&adapter, size.width, size.height);
surface.configure(&device, &config);

log::info!("Initializing the example...");
Expand Down
17 changes: 17 additions & 0 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3713,6 +3713,23 @@ impl Surface {
Context::surface_get_supported_alpha_modes(&*self.context, &self.id, &adapter.id)
}

/// Return a default `SurfaceConfiguration` from width and height to use for the [`Surface`] with this adapter.
pub fn get_default_config(
&self,
adapter: &Adapter,
width: u32,
height: u32,
) -> wgt::SurfaceConfiguration {
wgt::SurfaceConfiguration {
usage: wgt::TextureUsages::RENDER_ATTACHMENT,
format: self.get_supported_formats(adapter)[0],
width,
height,
present_mode: self.get_supported_present_modes(adapter)[0],
alpha_mode: wgt::CompositeAlphaMode::Auto,
}
}

/// Initializes [`Surface`] for presentation.
///
/// # Panics
Expand Down