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

Force unstretched integer scaling to be precise #93796

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

alvinhochun
Copy link
Contributor

@alvinhochun alvinhochun commented Jun 30, 2024

Both viewport size and 2D size override are limited to integer for now, therefore having a window size that is not divisible by the scale factor may cause scaling artifacts.

We can prevent this by shrinking the usable window viewport down to the nearest size that is fully divisible by the scale factor. Only apply this for integer scale factors, as this is mostly useless for fractional scale factors.

(In theory scale factors like 1.5 could also benefit from this kind of rounding, but this will require changing viewport size to accept floating point sizes to be really useful.)


Fixes #79726

Unresolved defects with OpenGL rendering:

  • With OpenGL rendering, the viewport sticks to the bottom of the window instead of the top, causing unpleasant jiggling when resizing the window..
  • With OpenGL rendering (again), the viewport is not cleared, so sometimes you can see leftover or garbage pixels on the edges when the shrinkage is being applied.

I think both of the above should be corrected in

void RasterizerGLES3::_blit_render_target_to_screen(RID p_render_target, DisplayServer::WindowID p_screen, const Rect2 &p_screen_rect, uint32_t p_layer, bool p_first) {
but I don't see how I can get the actual GL viewport size there... I would appreciate some help.

Both viewport size and 2D size override are limited to integer for now,
therefore having a window size that is not divisible by the scale factor
may cause scaling artifacts.

We can prevent this by shrinking the usable window viewport down to the
nearest size that is fully divisible by the scale factor. Only apply
this for integer scale factors, as this is mostly useless for fractional
scale factors.

(In theory scale factors like 1.5 could also benefit from this kind of
rounding, but this will require changing viewport size to accept
floating point sizes to be really useful.)
@alvinhochun alvinhochun requested a review from a team as a code owner June 30, 2024 22:12
@alvinhochun alvinhochun marked this pull request as draft June 30, 2024 22:12
@adamscott adamscott modified the milestone: 4.4 Jun 30, 2024
@adamscott adamscott self-assigned this Jun 30, 2024
@alvinhochun
Copy link
Contributor Author

alvinhochun commented Jul 1, 2024

I found a way to fixed the OpenGL defects, at least on Windows. Not sure if calling window_get_size is the best way of doing it though, and I don't know if this breaks any other platforms.

Edit: Looking again, probably should make it so that the viewport size is explicitly passed from window.

@alvinhochun alvinhochun marked this pull request as ready for review July 1, 2024 08:15
@alvinhochun alvinhochun requested a review from a team as a code owner July 1, 2024 08:15
@AThousandShips AThousandShips modified the milestones: 4.3, 4.4 Jul 1, 2024
@alvinhochun alvinhochun marked this pull request as draft July 1, 2024 13:55
@alvinhochun alvinhochun marked this pull request as ready for review July 1, 2024 17:50
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.

Scaling artifacts when viewport is scaled up and texture filtering is disabled
3 participants