Skip to content

Commit

Permalink
fix egui-wgpu callback viewport size check (#3759) (#3778)
Browse files Browse the repository at this point in the history
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to add commits to your PR.
* Remember to run `cargo fmt` and `cargo cranky`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

Closes #3759
  • Loading branch information
msparkles committed Jan 8, 2024
1 parent 0e7bf6d commit b087f58
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions crates/egui-wgpu/src/renderer.rs
Expand Up @@ -450,39 +450,35 @@ impl Renderer {
continue;
};

if callback.rect.is_positive() {
let info = PaintCallbackInfo {
viewport: callback.rect,
clip_rect: *clip_rect,
pixels_per_point,
screen_size_px: size_in_pixels,
};

let viewport_px = info.viewport_in_pixels();
if viewport_px.width_px > 0 && viewport_px.height_px > 0 {
crate::profile_scope!("callback");

needs_reset = true;

let info = PaintCallbackInfo {
viewport: callback.rect,
clip_rect: *clip_rect,
pixels_per_point,
screen_size_px: size_in_pixels,
};

{
// We're setting a default viewport for the render pass as a
// courtesy for the user, so that they don't have to think about
// it in the simple case where they just want to fill the whole
// paint area.
//
// The user still has the possibility of setting their own custom
// viewport during the paint callback, effectively overriding this
// one.

let viewport_px = info.viewport_in_pixels();

render_pass.set_viewport(
viewport_px.left_px as f32,
viewport_px.top_px as f32,
viewport_px.width_px as f32,
viewport_px.height_px as f32,
0.0,
1.0,
);
}
// We're setting a default viewport for the render pass as a
// courtesy for the user, so that they don't have to think about
// it in the simple case where they just want to fill the whole
// paint area.
//
// The user still has the possibility of setting their own custom
// viewport during the paint callback, effectively overriding this
// one.
render_pass.set_viewport(
viewport_px.left_px as f32,
viewport_px.top_px as f32,
viewport_px.width_px as f32,
viewport_px.height_px as f32,
0.0,
1.0,
);

cbfn.0.paint(info, render_pass, &self.callback_resources);
}
Expand Down

0 comments on commit b087f58

Please sign in to comment.