-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow camera viewports to be specified as a percentage of the parent viewport #5185
Conversation
@@ -340,12 +340,24 @@ impl<'a> TrackedRenderPass<'a> { | |||
/// Set the rendering viewport to the given [`Camera`](crate::camera::Viewport) [`Viewport`]. | |||
/// | |||
/// Subsequent draw calls will be projected into that viewport. | |||
pub fn set_camera_viewport(&mut self, viewport: &Viewport) { | |||
pub fn set_camera_viewport(&mut self, viewport: &Viewport, camera: &ExtractedCamera) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to change the signature of this function, because I needed camera to calculate absolute values of viewport.
Alternatives would be:
- have caller clone the viewport and calculate those values themselves (or make it a method on
Viewport
) and then pass that new "derived" viewport to this function. but then someone could forget to do that - "bake in" absolute values into viewport (i.e. only use absolutes in viewport) but tbf I'm not sure when would this have to happen (and it wouldn't be responsive)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely don't want the second option; that seems much harder to maintain and responsivity is important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing in the entire extracted camera, could you instead just pass in the physical target size as that is the only thing that is used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that works too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Suggested PR title change: "Allow camera viewports to be specified as a percentage of the parent viewport" |
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Updated the PR to use two separate enums for size and position. I'm still not fully satisfied with this solution, but it can be changed later, maybe when doing similar thing for |
PR description needs updating now :) |
let physical_size = viewport | ||
.physical_size | ||
.try_as_absolute(physical_target_size) | ||
.expect("Couldn't get camera.physical_target_size (needed for relative viewport size)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I feel like if this method takes an Option<> then it should handle it gracefully, not panic. So I guess either we need to find a way to handle this gracefully, or this shouldn’t take an Option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, I'm not sure when physical_target_size
can be None
.
I think this is the only place where it's set:
bevy/crates/bevy_render/src/camera/camera.rs
Line 424 in 9c116d5
physical_target_size: Some(target_size), |
So it looks like it's always
Some
.Maybe it shouldn't be an
Option
at all?
Also, try_as_absolute
takes an Option
because this value isn't required if the size/position is an absolute value. So requiring this to always be some value isn't great either. (Because absolute value without context is still valid)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does appear that it's always Some
as far as I can tell, since we wouldn't even extract the window if it's not. I think this can be refactored on ExtractedView
.
This appears to be stale, but I think this feature is wanted. I propose we close this an open an issue for the feature. |
Agreed. Close once the issue is up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good sans the one comment about accepting a UVec2
instead of an option.
let physical_size = viewport | ||
.physical_size | ||
.try_as_absolute(physical_target_size) | ||
.expect("Couldn't get camera.physical_target_size (needed for relative viewport size)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does appear that it's always Some
as far as I can tell, since we wouldn't even extract the window if it's not. I think this can be refactored on ExtractedView
.
Backlog cleanup: closing due to inactivity, although looks like we got pretty close here! Can be reopened via tracking issue #4960 if anyone feels like adopting. |
Objective
Solution
Changelog
Added:
ViewportSize
andViewportPosition
enumsCamera::viewport_absolute_size
function to reduce code repetitionChanged:
Viewport
's position and size to use new enumsTrackedRenderPass::set_camera_viewport
function to takeExtractedCamera
as argument (needed to calculate absolute values)