Apply screen size to screen-size-independent passes (#6569)

It is needed to restore the viewport. Fixes #6500.
This commit is contained in:
Kaz Wesley 2023-05-04 14:09:00 -07:00 committed by GitHub
parent 1817da799c
commit 402c95b181
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 12 deletions

View File

@ -61,18 +61,10 @@ impl {
self.width = width;
self.height = height;
self.pixel_ratio = pixel_ratio;
let ctx = &self.context;
let vars = &self.variables;
let defs = self.pipeline.passes_clone();
let old_passes = self.passes.drain(..);
let passes = defs.into_iter().zip(old_passes).map(|(def, pass)| {
if def.is_screen_size_independent() {
pass
} else {
ComposerPass::new(ctx, vars, def, width, height, pixel_ratio)
}
}).collect_vec();
self.passes = passes;
for (pass, def) in self.passes.iter_mut().zip(defs) {
pass.resize(def, width, height, pixel_ratio);
}
}
/// Initialize all pass definitions from the [`Pipeline`].
@ -145,4 +137,24 @@ impl ComposerPass {
pub fn run(&mut self, update_status: UpdateStatus) {
self.pass.run(&self.instance, update_status);
}
/// Update the pass for a change in screen size. Depending on the pass, this may require
/// reinitialization.
pub fn resize(
&mut self,
def: Box<dyn pass::Definition>,
width: i32,
height: i32,
pixel_ratio: f32,
) {
if def.is_screen_size_independent() {
self.instance.width = width;
self.instance.height = height;
self.instance.pixel_ratio = pixel_ratio;
} else {
let ctx = self.context.clone();
let vars = mem::take(&mut self.variables);
*self = ComposerPass::new(&ctx, &vars, def, width, height, pixel_ratio);
}
}
}

View File

@ -52,7 +52,6 @@ pub struct Instance {
impl Instance {
/// Constructor
#[allow(clippy::borrowed_box)]
pub fn new(
context: &Context,
variables: &UniformScope,