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

[3.x] Add content scale stretch modes, implement integer scaling #75918

Draft
wants to merge 1 commit into
base: 3.x
Choose a base branch
from

Conversation

Riteo
Copy link
Contributor

@Riteo Riteo commented Apr 11, 2023

Supersedes (and based on) #63206
Improves godotengine/godot-demo-projects#898
3.x version of #75784

Implements a new display/window/stretch/stretch project setting and the ScaleStretch enum, controlling the way the game scales the content while stretching it.

This is different from the stretch mode as this defines what rules to apply when deciding how much to stretch, instead of governing how.

Integer scaling is achieved (after aspect expansion) by "lying" to the stretching code about the window's size, telling it that it's always an integer multiple of the viewport so that it only gets stretched to an integer factor.

This approach works with all stretch and aspect modes and doesn't require handling for each, only requiring to "loosen up" some self-excluding conditions (in other words, replacing some else ifs with just ifs) regarding viewport offset and margin calculation (black bars).

Notes:

  • Perhaps even worse than Add content scale stretch modes, implement integer scaling #75784, I really don't like the name and it clashes even more with 3.x naming. I'm not sure on how to name it. Perhaps I could name the enum StretchScale? Again, no idea.

  • 3.x has this huge method (set_screen_stretch) which sets up everything else regarding screen stretching. I implemented another method (set_scale_stretch) to not break API compatibility.

  • This has only been lightly tested on my NVIDIA/X11 desktop, as I mostly use 4.x and Wayland on my laptop, which is only supported there. That said, the code is almost identical to its 4.x counterpart and the porting job was trivial, having just to compensate for a bunch of 3.x-isms. I'm thus pretty sure that this should work as well as Add content scale stretch modes, implement integer scaling #75784.

Implements a new `display/window/stretch/stretch` project setting and
the `ScaleStretch` enum, controlling the way the game scales the content
while stretching it.

This is different from the stretch mode as this defines what rules to
apply when deciding _how much_ to stretch, instead of governing _how_.

Integer scaling is achieved (after aspect expansion) by "lying" to the
stretching code about the window's size, telling it that it's always an
integer multiple of the viewport so that it only gets stretched to an
integer factor.

This approach works with all stretch and aspect modes and doesn't
require handling for each, only requiring to "loosen up" some
self-excluding conditions (in other words, replacing some `else if`s
with just `if`s) regarding viewport offset and margin calculation (black
bars).

Co-Authored-By: Hugo Locurcio <hugo.locurcio@hugo.pro>
@Riteo Riteo requested review from a team as code owners April 11, 2023 02:56
@Riteo
Copy link
Contributor Author

Riteo commented Apr 11, 2023

Ugh, 3.x doesn't have a content scale factor but a "shrink" property. I'll have to port it properly. Marking as draft.

@Calinou
Copy link
Member

Calinou commented Apr 11, 2023

Ugh, 3.x doesn't have a content scale factor but a "shrink" property. I'll have to port it properly. Marking as draft.

The goal was originally to have a content scale factor in 3.4, but we decided to merge both into the existing shrink property for backwards compatibility. (Content scale factor is essentially 1.0 / shrink.)

@Riteo
Copy link
Contributor Author

Riteo commented Apr 11, 2023

@Calinou I see, so it shouldn't take much to port the scale flooring to it.

Thinking about it, would it be a good idea to touch that value at all? If the user sets a shrink/CSF of 0.6, they would probably expect a non even-result in the first place, but that would be still stretched by an integer factor.

@Riteo Riteo modified the milestones: 3.6, 3.x Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants