Remove remaining std::mem::replace usages in examples (#1006)

This commit is contained in:
Lucas Kent 2018-08-04 22:38:57 +10:00 committed by Pierre Krieger
parent b0832072fc
commit 257994c7e8
3 changed files with 8 additions and 13 deletions

View File

@ -171,8 +171,8 @@ fn main() {
Err(err) => panic!("{:?}", err) Err(err) => panic!("{:?}", err)
}; };
std::mem::replace(&mut swapchain, new_swapchain); swapchain = new_swapchain;
std::mem::replace(&mut images, new_images); images = new_images;
framebuffers = None; framebuffers = None;
@ -186,12 +186,11 @@ fn main() {
} }
if framebuffers.is_none() { if framebuffers.is_none() {
let new_framebuffers = Some(images.iter().map(|image| { framebuffers = Some(images.iter().map(|image| {
Arc::new(vulkano::framebuffer::Framebuffer::start(renderpass.clone()) Arc::new(vulkano::framebuffer::Framebuffer::start(renderpass.clone())
.add(image.clone()).unwrap() .add(image.clone()).unwrap()
.build().unwrap()) .build().unwrap())
}).collect::<Vec<_>>()); }).collect::<Vec<_>>());
std::mem::replace(&mut framebuffers, new_framebuffers);
} }
let (image_num, future) = match vulkano::swapchain::acquire_next_image(swapchain.clone(), let (image_num, future) = match vulkano::swapchain::acquire_next_image(swapchain.clone(),

View File

@ -168,8 +168,7 @@ fn main() {
swapchain = new_swapchain; swapchain = new_swapchain;
images = new_images; images = new_images;
let new_depth_buffer = vulkano::image::attachment::AttachmentImage::transient(device.clone(), dimensions, vulkano::format::D16Unorm).unwrap(); depth_buffer = vulkano::image::attachment::AttachmentImage::transient(device.clone(), dimensions, vulkano::format::D16Unorm).unwrap();
std::mem::replace(&mut depth_buffer, new_depth_buffer);
framebuffers = None; framebuffers = None;
@ -185,13 +184,12 @@ fn main() {
} }
if framebuffers.is_none() { if framebuffers.is_none() {
let new_framebuffers = Some(images.iter().map(|image| { framebuffers = Some(images.iter().map(|image| {
Arc::new(vulkano::framebuffer::Framebuffer::start(renderpass.clone()) Arc::new(vulkano::framebuffer::Framebuffer::start(renderpass.clone())
.add(image.clone()).unwrap() .add(image.clone()).unwrap()
.add(depth_buffer.clone()).unwrap() .add(depth_buffer.clone()).unwrap()
.build().unwrap()) .build().unwrap())
}).collect::<Vec<_>>()); }).collect::<Vec<_>>());
std::mem::replace(&mut framebuffers, new_framebuffers);
} }
let uniform_buffer_subbuffer = { let uniform_buffer_subbuffer = {

View File

@ -57,7 +57,6 @@ use vulkano::sync::now;
use vulkano::sync::GpuFuture; use vulkano::sync::GpuFuture;
use std::sync::Arc; use std::sync::Arc;
use std::mem;
fn main() { fn main() {
// The first step of any vulkan program is to create an instance. // The first step of any vulkan program is to create an instance.
@ -364,8 +363,8 @@ void main() {
Err(err) => panic!("{:?}", err) Err(err) => panic!("{:?}", err)
}; };
mem::replace(&mut swapchain, new_swapchain); swapchain = new_swapchain;
mem::replace(&mut images, new_images); images = new_images;
framebuffers = None; framebuffers = None;
@ -381,12 +380,11 @@ void main() {
// Because framebuffers contains an Arc on the old swapchain, we need to // Because framebuffers contains an Arc on the old swapchain, we need to
// recreate framebuffers as well. // recreate framebuffers as well.
if framebuffers.is_none() { if framebuffers.is_none() {
let new_framebuffers = Some(images.iter().map(|image| { framebuffers = Some(images.iter().map(|image| {
Arc::new(Framebuffer::start(render_pass.clone()) Arc::new(Framebuffer::start(render_pass.clone())
.add(image.clone()).unwrap() .add(image.clone()).unwrap()
.build().unwrap()) .build().unwrap())
}).collect::<Vec<_>>()); }).collect::<Vec<_>>());
mem::replace(&mut framebuffers, new_framebuffers);
} }
// Before we can draw on the output, we have to *acquire* an image from the swapchain. If // Before we can draw on the output, we have to *acquire* an image from the swapchain. If