Skip to content

Commit

Permalink
Apply screen size to screen-size-independent passes (#6569)
Browse files Browse the repository at this point in the history
It is needed to restore the viewport. Fixes #6500.
  • Loading branch information
kazcw authored May 4, 2023
1 parent 1817da7 commit 402c95b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
34 changes: 23 additions & 11 deletions lib/rust/ensogl/core/src/display/render/composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand Down Expand Up @@ -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);
}
}
}
1 change: 0 additions & 1 deletion lib/rust/ensogl/core/src/display/render/pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ pub struct Instance {

impl Instance {
/// Constructor
#[allow(clippy::borrowed_box)]
pub fn new(
context: &Context,
variables: &UniformScope,
Expand Down

0 comments on commit 402c95b

Please sign in to comment.