Skip to content

Conversation

@m4gr3d
Copy link
Contributor

@m4gr3d m4gr3d commented Jun 13, 2025

Follow up to #106709 to address #106709 (comment)

@m4gr3d m4gr3d added this to the 4.5 milestone Jun 13, 2025
@m4gr3d m4gr3d requested a review from a team as a code owner June 13, 2025 03:55
@m4gr3d m4gr3d force-pushed the address_transparency_feedback branch from 55c8fbe to 7785a65 Compare June 13, 2025 04:02
@akien-mga akien-mga changed the title Address remaining feedback on https://github.com/godotengine/godot/pull/106709 Address remaining feedback on Android background transparency Jun 13, 2025
Copy link
Member

@syntaxerror247 syntaxerror247 left a comment

Choose a reason for hiding this comment

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

@m4gr3d This looks really good now. But I'm still having one issue, the surface doesn't seems to be updated/refreshed properly.

default void setPixelFormat(int format) {
SurfaceView surfaceView = getView();
if (surfaceView != null && surfaceView.getHolder() != null) {
surfaceView.getHolder().setFormat(format);
Copy link
Member

Choose a reason for hiding this comment

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

Just setting the format doesn't seems to be enough. The surface needs to be updated/refreshed.
I tried refreshing it with an hack and it seems to work for vulkan but opengl is still buggy.

Before my hack (This PR):
Opengl

Screenrecorder-2025-06-13-17-16-09-513.mp4

Vulkan

Screenrecorder-2025-06-13-17-14-53-256.mp4

After my hack

Opengl

Screenrecorder-2025-06-13-19-28-17-173.mp4

Vulkan

Screenrecorder-2025-06-13-19-29-20-652.mp4

default void setPixelFormat(int format) {
SurfaceView surfaceView = getView();
if (surfaceView != null && surfaceView.getHolder() != null) {
surfaceView.getHolder().setFormat(format);
Copy link
Member

Choose a reason for hiding this comment

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

My hack is simply hiding and then showing the view. But I believe you can come up with a better solution :)

surfaceView.getHolder().setFormat(format);
surfaceView.setVisibility(View.GONE);
surfaceView.setVisibility(View.VISIBLE);

@m4gr3d m4gr3d force-pushed the address_transparency_feedback branch 2 times, most recently from c7c426b to 4ca7722 Compare June 19, 2025 02:11
@Alex2782
Copy link
Member

Alex2782 commented Jun 22, 2025

OK on Samsung Tab S7 with Mobile Renderer. (Android 13)

Godot Engine v4.5.beta.custom_build.4ca772276 (2025-06-19 02:10:56 UTC) - https://godotengine.org
Vulkan 1.1.128 - Forward Mobile - Using Device #0: Qualcomm - Adreno (TM) 650

Not on Pixel 8a, Mali GPU. (Android 16)
I think it's like in the video from @syntaxerror247 (Tested as Android export, not via editor)


OpenGLES/Compatibility is faulty on both devices, making it seem as if the app is frozen.

Changing surfaceView.setVisibility only partially works; on the Samsung Tab S7, the app is completely transparent at first, which seems like a crash. But touching the screen shows the UI again, without any 3D content.

@Alex2782
Copy link
Member

Note: In the demo, application/run/low_processor_mode is enabled. If I disable it, the "visibility hack" works better.

@m4gr3d m4gr3d force-pushed the address_transparency_feedback branch 2 times, most recently from 3f5d56d to 5296b54 Compare July 7, 2025 19:10
@m4gr3d m4gr3d requested a review from a team as a code owner July 7, 2025 19:10
@m4gr3d m4gr3d force-pushed the address_transparency_feedback branch from 5296b54 to 3ade4b4 Compare July 7, 2025 19:11
@m4gr3d
Copy link
Contributor Author

m4gr3d commented Jul 7, 2025

@syntaxerror247 @Alex2782 After some explorations, it doesn't look like we can (yet) support switching transparency at runtime.

The update to the pixel format causes the surface to be destroyed and recreated. On opengl on Android, we don't support that at all, and typically restart the app when such event occurs (see

// Rendering context recreated because it was lost; restart app to let it reload everything
), which negates the point of being able to switch the transparency at runtime.
With vulkan, things are a bit better and we can continue without having to restart the app, but doing so still seems to create some issues as a bunch of warnings appear in the logs following the surface recreation.

TLDR; handling surface recreation is an area we'll need to improve on before we're able to enable switching transparency on/off at runtime. cc @clayjohn
As such, in the meantime transparency can only be set at start-time and is controlled by the display/window/per_pixel_transparency/allowed project setting. The display/window/size/transparent setting and the WINDOW_FLAG_TRANSPARENT flag have no effect on Android.

If display/window/per_pixel_transparency/allowed is enabled, the project can still control its transparency via get_viewport().transparent_bg.
Note however there seems to be a bug on how this is handled between vulkan and opengl. It works as expected on opengl, but on vulkan, the background seems to inherit some transparency even when get_viewport().transparent_bg == false. I'll create a bug for the rendering team for the latter issue.

Edit: I've created #108386 to track the described issue with the vulkan renderer.

@Calinou
Copy link
Member

Calinou commented Jul 7, 2025

TLDR; handling surface recreation is an area we'll need to improve on before we're able to enable switching transparency on/off at runtime.

See also godotengine/godot-proposals#6423.

@m4gr3d
Copy link
Contributor Author

m4gr3d commented Jul 15, 2025

@syntaxerror247 @Alex2782 Ping on this PR.

Note that I think I may have an approach to enable switching the transparency at runtime, but this builds on top of an upcoming large set of changes, so that capability would be 4.6 at the earliest.

In the meantime, we should move ahead with the current capability and limitations for 4.5.

@Repiteo Repiteo merged commit 64c58c2 into godotengine:master Jul 16, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Jul 16, 2025

Thanks!

@m4gr3d m4gr3d deleted the address_transparency_feedback branch July 16, 2025 23:19
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.

5 participants