only create wgpu swap chain when surface is ready
This commit is contained in:
parent
26ff878469
commit
ed9eb88835
@ -6,7 +6,7 @@ fn main() {
|
|||||||
.setup_world(setup)
|
.setup_world(setup)
|
||||||
.add_system(build_move_system())
|
.add_system(build_move_system())
|
||||||
.add_default_diagnostics()
|
.add_default_diagnostics()
|
||||||
.print_diagnostics(std::time::Duration::from_secs_f64(1.0))
|
.print_diagnostics()
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,31 +346,36 @@ impl WgpuRenderer {
|
|||||||
|
|
||||||
impl Renderer for WgpuRenderer {
|
impl Renderer for WgpuRenderer {
|
||||||
fn resize(&mut self, world: &mut World, resources: &mut Resources) {
|
fn resize(&mut self, world: &mut World, resources: &mut Resources) {
|
||||||
self.encoder = Some(
|
if let Some(surface) = self.surface.as_ref() {
|
||||||
self.device
|
self.encoder = Some(
|
||||||
|
self.device
|
||||||
|
.borrow()
|
||||||
|
.create_command_encoder(&wgpu::CommandEncoderDescriptor { todo: 0 }),
|
||||||
|
);
|
||||||
|
let swap_chain_descriptor: wgpu::SwapChainDescriptor = {
|
||||||
|
let window: &Window = &resources.get::<Window>().unwrap();
|
||||||
|
window.into()
|
||||||
|
};
|
||||||
|
|
||||||
|
let swap_chain = self
|
||||||
|
.device
|
||||||
.borrow()
|
.borrow()
|
||||||
.create_command_encoder(&wgpu::CommandEncoderDescriptor { todo: 0 }),
|
.create_swap_chain(surface, &swap_chain_descriptor);
|
||||||
);
|
|
||||||
let swap_chain_descriptor: wgpu::SwapChainDescriptor = {
|
|
||||||
let window: &Window = &resources.get::<Window>().unwrap();
|
|
||||||
window.into()
|
|
||||||
};
|
|
||||||
|
|
||||||
let swap_chain = self
|
// WgpuRenderer can't own swap_chain without creating lifetime ergonomics issues, so lets just store it in World.
|
||||||
.device
|
resources.insert(swap_chain);
|
||||||
.borrow()
|
let mut render_graph = resources.get_mut::<RenderGraph>().unwrap();
|
||||||
.create_swap_chain(self.surface.as_ref().unwrap(), &swap_chain_descriptor);
|
for resource_provider in render_graph.resource_providers.iter_mut() {
|
||||||
|
resource_provider.resize(self, world, resources, swap_chain_descriptor.width, swap_chain_descriptor.height);
|
||||||
|
}
|
||||||
|
|
||||||
// WgpuRenderer can't own swap_chain without creating lifetime ergonomics issues, so lets just store it in World.
|
// consume current encoder
|
||||||
resources.insert(swap_chain);
|
let command_buffer = self.encoder.take().unwrap().finish();
|
||||||
let mut render_graph = resources.get_mut::<RenderGraph>().unwrap();
|
self.queue.submit(&[command_buffer]);
|
||||||
for resource_provider in render_graph.resource_providers.iter_mut() {
|
} else {
|
||||||
resource_provider.resize(self, world, resources, swap_chain_descriptor.width, swap_chain_descriptor.height);
|
// TODO: remove this warning if this case is not a problem
|
||||||
|
println!("warning: attempted to resize renderer before surface was ready");
|
||||||
}
|
}
|
||||||
|
|
||||||
// consume current encoder
|
|
||||||
let command_buffer = self.encoder.take().unwrap().finish();
|
|
||||||
self.queue.submit(&[command_buffer]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, world: &mut World, resources: &mut Resources) {
|
fn update(&mut self, world: &mut World, resources: &mut Resources) {
|
||||||
|
Loading…
Reference in New Issue
Block a user