Recreate RenderTarget while preserving RenderPass
This commit is contained in:
parent
500fea420c
commit
f5b0f76173
1 changed files with 46 additions and 21 deletions
|
@ -12,13 +12,12 @@ use super::{
|
|||
|
||||
use cgmath::ortho;
|
||||
|
||||
use std::slice;
|
||||
use std::sync::Weak;
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, AtomicU32, Ordering::SeqCst},
|
||||
Arc, Mutex, RwLock,
|
||||
};
|
||||
use std::{collections::HashMap, ptr};
|
||||
use std::{ops::Deref, sync::Weak};
|
||||
|
||||
use paste::paste;
|
||||
|
||||
|
@ -1159,25 +1158,35 @@ impl GuiHandler {
|
|||
device: &Arc<Device>,
|
||||
target_images: &TargetMode<Vec<Arc<Image>>>,
|
||||
) -> Result<TargetMode<RwLock<RenderTarget>>> {
|
||||
let create = |target_images: &Vec<Arc<Image>>| -> Result<RenderTarget> {
|
||||
RenderTarget::builder()
|
||||
.add_sub_pass(
|
||||
SubPass::builder(target_images[0].width(), target_images[0].height())
|
||||
.set_prepared_targets(target_images, 0, [0.0, 0.0, 0.0, 0.0], false)
|
||||
.build(device)?,
|
||||
)
|
||||
.build(device)
|
||||
};
|
||||
|
||||
Ok(match target_images {
|
||||
TargetMode::Mono(images) => TargetMode::Mono(RwLock::new(create(images)?)),
|
||||
TargetMode::Mono(images) => TargetMode::Mono(RwLock::new(Self::create_render_target(
|
||||
device, images, None,
|
||||
)?)),
|
||||
TargetMode::Stereo(left_images, right_images) => TargetMode::Stereo(
|
||||
RwLock::new(create(left_images)?),
|
||||
RwLock::new(create(right_images)?),
|
||||
RwLock::new(Self::create_render_target(device, left_images, None)?),
|
||||
RwLock::new(Self::create_render_target(device, right_images, None)?),
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
fn create_render_target(
|
||||
device: &Arc<Device>,
|
||||
target_images: &Vec<Arc<Image>>,
|
||||
old_render_target: Option<&RenderTarget>,
|
||||
) -> Result<RenderTarget> {
|
||||
let mut builder = RenderTarget::builder().add_sub_pass(
|
||||
SubPass::builder(target_images[0].width(), target_images[0].height())
|
||||
.set_prepared_targets(target_images, 0, [0.0, 0.0, 0.0, 0.0], false)
|
||||
.build(device)?,
|
||||
);
|
||||
|
||||
if let Some(render_target) = old_render_target {
|
||||
builder = builder.preserve_old_render_pass(render_target);
|
||||
}
|
||||
|
||||
builder.build(device)
|
||||
}
|
||||
|
||||
fn create_command_buffers(
|
||||
device: &Arc<Device>,
|
||||
queue: &Arc<Mutex<Queue>>,
|
||||
|
@ -1529,13 +1538,29 @@ impl GuiHandler {
|
|||
}
|
||||
|
||||
pub fn resize(&self, width: u32, height: u32) -> Result<()> {
|
||||
todo!();
|
||||
match (self.context.images(), &self.render_targets) {
|
||||
(TargetMode::Mono(images), TargetMode::Mono(render_target)) => {
|
||||
let mut rt_lock = render_target.write().unwrap();
|
||||
|
||||
// *self.framebuffers.lock().unwrap() = Self::create_framebuffers(
|
||||
// self.context.device(),
|
||||
// &self.context.images(),
|
||||
// &self.render_pass,
|
||||
// )?;
|
||||
*rt_lock = Self::create_render_target(&self.device, &images, Some(&*rt_lock))?;
|
||||
}
|
||||
(
|
||||
TargetMode::Stereo(left_images, right_images),
|
||||
TargetMode::Stereo(left_render_target, right_render_target),
|
||||
) => {
|
||||
let mut left_rt_lock = left_render_target.write().unwrap();
|
||||
|
||||
*left_rt_lock =
|
||||
Self::create_render_target(&self.device, &left_images, Some(&*left_rt_lock))?;
|
||||
|
||||
let mut right_rt_lock = right_render_target.write().unwrap();
|
||||
|
||||
*right_rt_lock =
|
||||
Self::create_render_target(&self.device, &right_images, Some(&*right_rt_lock))?;
|
||||
}
|
||||
|
||||
_ => unreachable!("unsupported case!"),
|
||||
}
|
||||
|
||||
self.needs_update.store(true, SeqCst);
|
||||
*self.ortho.write().unwrap() = ortho(0.0, width as f32, 0.0, height as f32, -1.0, 1.0);
|
||||
|
|
Loading…
Reference in a new issue