Fix compatible_surface overrides when RequestAdapterOptions is provided (#85)

- This will use the default `compatible_surface` from `SurfaceTexture` when `RequestAdapterOptions` is configured without `compatible_surface`.
This commit is contained in:
Jay Oster 2020-06-05 02:20:17 -07:00 committed by GitHub
parent 4991d2cddc
commit 7779d682cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -557,13 +557,18 @@ impl<'req> PixelsBuilder<'req> {
/// Returns an error when a [`wgpu::Adapter`] cannot be found. /// Returns an error when a [`wgpu::Adapter`] cannot be found.
pub fn build(self) -> Result<Pixels, Error> { pub fn build(self) -> Result<Pixels, Error> {
// TODO: Use `options.pixel_aspect_ratio` to stretch the scaled texture // TODO: Use `options.pixel_aspect_ratio` to stretch the scaled texture
let compatible_surface = Some(&self.surface_texture.surface);
let adapter = pollster::block_on(wgpu::Adapter::request( let adapter = pollster::block_on(wgpu::Adapter::request(
&self &self.request_adapter_options.map_or_else(
.request_adapter_options || wgpu::RequestAdapterOptions {
.unwrap_or(wgpu::RequestAdapterOptions { compatible_surface,
compatible_surface: Some(&self.surface_texture.surface),
power_preference: wgpu::PowerPreference::Default, power_preference: wgpu::PowerPreference::Default,
}), },
|rao| wgpu::RequestAdapterOptions {
compatible_surface: rao.compatible_surface.or(compatible_surface),
power_preference: rao.power_preference,
},
),
self.backend, self.backend,
)) ))
.ok_or(Error::AdapterNotFound)?; .ok_or(Error::AdapterNotFound)?;