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

Resizing SubViewportContainer with stretch enabled changes render resolution of child SubViewport #62041

Open
lapspider45 opened this issue Jun 14, 2022 · 10 comments

Comments

@lapspider45
Copy link

lapspider45 commented Jun 14, 2022

Godot version

v4.0.alpha9.official.fc18891db

System information

Linux

Issue description

When resizing a SubViewportContainer with stretch enabled, the size of the child SubViewport is changed to the size of the container.
What this does is to undo all the "stretching", since the resolution of the viewport is now the same as the displayed resolution. This is unexpected of a property named stretch, if this were intentional a more fitting name would be auto_resize.
This problem was present in Godot 3 as well, but it wasn't hard to write something like this to preserve the size of the viewport:

func _on_Viewport_size_changed(): # connected to signal "resized" in Viewport
	if size == correct_size:
		return
	size = correct_size

But in newer alpha versions Godot 4, this workaround stopped working consistently, especially inside nested containers. So this is what I resorted to:

func workaround_hack():
	for i in 3: # with one iteration, this fails up to 50% of the time 
		await get_tree().process_frame
		$SubViewport.size = correct_size

This is very inelegant, and I don't see how SubViewportContainer messing with viewport sizes would be intended behavior in the first place.

Steps to reproduce

  • Create a SubViewport inside a SubViewportContainer
  • enable stretch on SubViewportContainer
  • add icon.png or an image of your choice to the SubViewport, and set viewport size to the image dimensions
  • the texture should "stretch" and fill the entire parent container's size, just like a TextureRect set to STRETCH_SCALE
  • resize the container
  • instead of staying stretched to fit the container, the image is no longer scaled, unless you use a "workaround"
  • the above also caused the size of the SubViewport to change

Minimal reproduction project

MRP_SubViewportContainer.zip

  1. Open main.tscn in editor
  2. Resize the root Control
  3. Notice both the viewport and icon.png changing size
@Calinou
Copy link
Member

Calinou commented Jun 14, 2022

@lapspider45 Please upload a minimal reproduction project to make this easier to troubleshoot.

@lapspider45
Copy link
Author

Done.

@Rindbee
Copy link
Contributor

Rindbee commented Jul 10, 2022

In my opinion, SubViewport seems to be a pipe. Render a 2D/3D scene to a 2D texture. And SubViewportContainer is an adapter that converts SubViewport to Control.

In this way, the size property is the sampling resolution of the source, and size_2d_override is the resolution of the render target. Currently, size_2d_override only seems to work in get_visible_rect. size does the work that size_2d_override should.

This is just my guess, maybe I'm wrong.

@TisFoolish
Copy link

I can confirm that this still happens with Beta 10

@TisFoolish
Copy link

The workarounds also don't work anymore. The data of the subviewports size property properly changes, but the SVPs don't properly fill the viewport

@DieStockEnte
Copy link

Still happens in Godot v4.1.1 stable.
As a workaround I set in the SubViewportContainer the "stretch_shrink" property to 2, to half the render resolution of the child SubViewport. This isn't ideal, because my display resolution is 1280x720, so the SubViewport will be 640x360 and I need another resolution...

@djpeach
Copy link

djpeach commented Aug 2, 2023

I can't reproduce this. Downloaded the minimal project, resized the subviewportContainer, and the icon does not stretch.

sbc stretch demo

@lapspider45
Copy link
Author

@djpeach it looks to me like you are reproducing the issue. Right now there is no sensible way to scale a SubViewport, since SubViewportContainer enforces a 1:1 pixel ratio in all cases

@YuriSizov YuriSizov modified the milestones: 4.2, 4.x Nov 15, 2023
@Stalker2106x
Copy link

Stalker2106x commented Nov 22, 2023

I am actually reproducing that as well on 4.1.3
A subviewport cannot have resolution stretch as a window can get.

Still happens in Godot v4.1.1 stable. As a workaround I set in the SubViewportContainer the "stretch_shrink" property to 2, to half the render resolution of the child SubViewport. This isn't ideal, because my display resolution is 1280x720, so the SubViewport will be 640x360 and I need another resolution...

This indeed resize the actual Subviewport from origin resolution, but then requires unticking scale parameter to apply.
And this workaround being integer based, any resolution between 1 and 2 are unavailable.

EDIT: Setting the original resolution on Subviewport "size_2d_override", and target resolution on its "size" makes the viewport actually respect its resolution and scale to. Which works for me 🎉

@Rindbee
Copy link
Contributor

Rindbee commented Nov 23, 2023

EDIT: Setting the original resolution on Subviewport "size_2d_override", and target resolution on its "size" makes the viewport actually respect its resolution and scale to. Which works for me 🎉

Yes, it works.
It might be worth detailing in the documentation the correct usage of these related properties.

Or when stretch of SubViewportContainer is checked, the current size of SubViewport is automatically used to set size_2d_override.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants