Skip to content
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

Fix viewport scaling at intermediate resolutions #102741

Merged
merged 1 commit into from
Mar 6, 2025

Conversation

KerekesDavid
Copy link
Contributor

@KerekesDavid KerekesDavid commented Feb 12, 2025

Fixes #102656: viewport scale is wrong at resolutions that are not integer multiples of content_scale_factor.

This is done by allowing size_2d_override to be Size2 instead of Size2i. This change is propagated to keep the exposed SubViewport consistent with the underlying implementation not propagated to SubViewport to keep compatibility for now.

Note:
I see the output of Viewport::get_visible_rect() get treated as a Rect2i in some places, even though it returns a Rect2. Before this change, this might have been accidentally correct, since it was generated from either size or size_2d_override, which were both Size2i. It might need a second look to make sure it still works correctly, because I'm not exactly sure what all these code fragments do.

@KerekesDavid KerekesDavid requested review from a team as code owners February 12, 2025 00:31
@AThousandShips AThousandShips added bug topic:rendering topic:gui cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release labels Feb 12, 2025
@AThousandShips AThousandShips added this to the 4.4 milestone Feb 12, 2025
@AThousandShips AThousandShips added breaks compat and removed cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release labels Feb 12, 2025
@AThousandShips AThousandShips modified the milestones: 4.4, 4.5 Feb 12, 2025
@KerekesDavid KerekesDavid force-pushed the fix-viewport-scale branch 2 times, most recently from f63973d to 33b2360 Compare February 12, 2025 17:58
@KerekesDavid
Copy link
Contributor Author

KerekesDavid commented Feb 12, 2025

Pushed a change that does not expose this to SubViewport to avoid the compatibility warnings. (As a side note, these do not pop up in my local tests for some reason, how would I fix this?)

If someone could point me towards some resources on what kind of compatibility are we talking about here, and what is the usual philosophy that the dev team follows, that would be super appreciated. (Is it compatibility for users between versions? Is it API/ABI compatibility?)

@AThousandShips
Copy link
Member

AThousandShips commented Feb 12, 2025

The compatibility notes doesn't occur locally because it's a dedicated check, but this breaks compatibility because the type changes, and that can't be done trivially

You would probably need to register compatibility methods, see here for instructions

If this can be done in a way that doesn't break compatibility it should, if unavoidable it can be evaluated

@KerekesDavid
Copy link
Contributor Author

KerekesDavid commented Feb 12, 2025

One last try, forgot to revert the property registration itself to Vector2i.

@AThousandShips
Copy link
Member

The methods will still be registered with the changed type I think, so that will still break compatibility unless the bound methods also don't use Vector2

@KerekesDavid
Copy link
Contributor Author

Bound methods should all be Vector2i, only the internals are working with Vector2.

@AThousandShips AThousandShips added cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release and removed breaks compat labels Feb 12, 2025
@AThousandShips AThousandShips modified the milestones: 4.5, 4.4 Feb 12, 2025
@KerekesDavid KerekesDavid changed the title Fix wrong viewport scaling at intermediate resolutions Fix viewport scaling at intermediate resolutions Feb 12, 2025
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally on macOS, it works as expected. There's no more jitter in the MRP when resizing the window from any of its corners.

I think the rationale makes sense, and keeping the exposed property as-is to keep compatibility.

@akien-mga akien-mga modified the milestones: 4.4, 4.5 Feb 13, 2025
@akien-mga akien-mga added the cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release label Feb 13, 2025
@KerekesDavid
Copy link
Contributor Author

KerekesDavid commented Feb 18, 2025

I think this one is only waiting for a last review from the core team and a merge now :)

@akien-mga
Copy link
Member

We're in release freeze for 4.4 and only merging regression fixes now, so this will first be merged for 4.5 after 4.4-stable is released. It's already queued for merge in 4.5-dev1.

Copy link
Contributor

@OhiraKyou OhiraKyou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set up a dev environment and tested the changes locally. I found that only two of the changes (plus a function signature header update) needed to be included to fix the MRP. So, my reversion suggestions are based on the assumption that this would be merged as a fix for the jitter, with any additional work being pushed to an optional future PR.

Minimum necessary changes:

  • In Window::_update_viewport_size, final_size_override must be a Size2
    • This is because it is divided by the content_scale_factor on lines 1155 and 1236, resulting in float values that need to be preserved.
  • In Viewport::_set_size, p_size_2d_override must be a Size2 (with the redundant Size2 conversion removed).
    • This is because Window passes in final_size_override on line 1257.

In other words, the math on Window's final_size_override is what results in float values. Everywhere else, 2D size overrides are only given integer values. So, changing them to floats doesn't do anything without additional work.

Edit: Actually, as discussed later, because p_size_2d_override is saved to the Viewport's size_2d_override in Viewport::_set_size, the value will be out of sync with the calculated stretch_transform if size_2d_override is not also a Size2.

Fixes viewport scale being wrong at resolutions that are not
integer multiples of content_scale_factor.

This is done by allowing size_2d_override to be Size2 instead of
Size2i. This change is not propagated to the exposed SubViewport
to keep compatibility for now.
@Repiteo Repiteo merged commit 490854e into godotengine:master Mar 6, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Mar 6, 2025

Thanks! Congratulations on your first merged contribution! 🎉

@KerekesDavid
Copy link
Contributor Author

Thanks! Congratulations on your first merged contribution! 🎉

Thanks, happy to help! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release topic:gui topic:rendering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Window content_scale_factor causes jitter in Control size
6 participants