[3.x] Add content scale stretch modes, implement integer scaling #75918
+62
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theScaleStretch
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 justif
s) 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.