Skip to content

Commit

Permalink
render: Ensure that the wgpu device is compatible with the window we're
Browse files Browse the repository at this point in the history
going to render to
  • Loading branch information
Dinnerbone authored and Herschel committed May 15, 2020
1 parent 1f0e695 commit 0047546
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 4 additions & 2 deletions render/wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ unsafe impl Zeroable for GPUVertex {}

impl WgpuRenderBackend<SwapChainTarget> {
pub fn for_window<W: HasRawWindowHandle>(window: &W, size: (u32, u32)) -> Result<Self, Error> {
let surface = wgpu::Surface::create(window);

let adapter = block_on(wgpu::Adapter::request(
&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::HighPerformance,
compatible_surface: None,
compatible_surface: Some(&surface),
},
wgpu::BackendBit::PRIMARY,
))
Expand All @@ -138,7 +140,7 @@ impl WgpuRenderBackend<SwapChainTarget> {
limits: wgpu::Limits::default(),
}));

let target = SwapChainTarget::new(window, size, &device);
let target = SwapChainTarget::new(surface, size, &device);
Self::new(Rc::new(device), Rc::new(queue), target)
}
}
Expand Down
8 changes: 3 additions & 5 deletions render/wgpu/src/target.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use futures::executor::block_on;
use image::buffer::ConvertBuffer;
use image::{Bgra, ImageBuffer, RgbaImage};
use raw_window_handle::HasRawWindowHandle;
use std::fmt::Debug;

pub trait RenderTargetFrame: Debug {
Expand Down Expand Up @@ -46,18 +45,17 @@ impl RenderTargetFrame for SwapChainTargetFrame {
}

impl SwapChainTarget {
pub fn new<W: HasRawWindowHandle>(window: &W, size: (u32, u32), device: &wgpu::Device) -> Self {
let window_surface = wgpu::Surface::create(window);
pub fn new(surface: wgpu::Surface, size: (u32, u32), device: &wgpu::Device) -> Self {
let swap_chain_desc = wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
format: wgpu::TextureFormat::Bgra8Unorm,
width: size.0,
height: size.1,
present_mode: wgpu::PresentMode::Mailbox,
};
let swap_chain = device.create_swap_chain(&window_surface, &swap_chain_desc);
let swap_chain = device.create_swap_chain(&surface, &swap_chain_desc);
Self {
window_surface,
window_surface: surface,
swap_chain_desc,
swap_chain,
}
Expand Down

0 comments on commit 0047546

Please sign in to comment.