-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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] Window transparency support on Android #51935
Merged
akien-mga
merged 1 commit into
godotengine:3.x
from
nekomatata:android-transparency-3.x
Sep 15, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pouleyKetchoupp Can you clarify what this does? According to the documentation:
Which would mean that it would prevent additional component from rendering on top of the surface; is that the desired behavior?
Could you also walk me through how per-pixel transparency is achieved; it may help me understand better the logic in the PR.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this allows Godot rendering to be displayed on top, so a plugin can render behind the transparent surface, rather than always in front (like it does by default). As a side effect, plugins can't render on top of the surface when this is enabled, as you mentioned, but it's the only way I've found to achieve transparent rendering.
Transparent rendering is achieved this way:
per_pixel_transparency/allowed
&per_pixel_transparency/enabled
are both set to true in Project Settingsget_tree().get_root().transparent_bg = true;
is called at runtime to make the viewport transparent--translucent
is added to the command line (this step is needed on 3.x becauseMain::setup()
is called after the surface is initialized, it won't be needed on master).--translucent
command line is checked to create a surface with transparent capabilities (on master it will just check the project settings directly)(from what I've seen, both this and
setZOrderOnTop(true)
are needed for transparency to work correctly)The result is the plugin does its custom rendering (for example camera preview) and Godot draws on top of it with transparent background (for example to add UI elements).
Let me know if there's more I can clarify!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember that transparent viewports aren't supported yet with the Vulkan renderer: #40651
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pouleyKetchoupp Sorry for the delay, I was out for the past week.
Regarding ordering of the surface and of the plugins' views, we control that logic here and here, so couldn't just have a flag that tells us if
translucent
is enabled, and changed the order of the views as shown in your sample code?With that approach, would we still need to set the
setZOrderOnTop(...)
flag?Also, when you say the surface is transparent, does that mean that any view(s)
behind
it will be visible? I'm trying to clarify here since making the background transparent in Godot may not mean the same as making the surface view background transparent (which would allow to see underlying views).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries!
I'm not sure why (it could be the way GL surfaces work), but both are needed for the system to work correctly.
I've tested again since last time and here's how it goes:
-
setZOrderOnTop
is needed for transparent rendering, without it the Godot surface renders with black background and any view behind it is not visible.-Changing the order of views is not strictly needed if
setZOrderOnTop
is set, but it helps with inputs as it allows Godot inputs to be taken over views placed behind.Yes, it allows other views to be visible behind it.
Using this feature, you can also make a transparent app and see the device desktop in the background. But that requires to also change the style of the main Godot app to this:
So far I haven't found a nice way to enable it in the export process or by code, but it would be a nice addition to this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About setting the transparent theme in the app:
From what I've just tested, changing the theme to a new one with
windowIsTranslucent
attribute even in the apponCreate
function is not enough to make it work. It can modify the color but not the translucent flag.I guess the best way to handle it would be to change the theme in the manifest file during export, but do you know how to handle it with custom builds? It looks like the export process fixes the manifest file only for standard builds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pouleyKetchoupp Do you have an example for the logic you use to update the theme?
In general, the theme needs to be set before even calling
setContentView(...)
.So the logic should look something like:
where
GodotAppTranslucentTheme
would be as you described above:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on your example, even just setting the transparent theme without checking any flag like this:
doesn't seem to work, unless windowIsTranslucent is set to true in the default theme as well.
It looks like this flag can't be changed once the app is being created, and it works by adding it in the default theme only because the splash theme inherits from the default theme (unless I'm missing something).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pouleyKetchoupp I thought you were still looking into this. If not, I'm good with approving and unblocking this PR, and attempting to update the app theme for translucency in another PR. For that approach, can you create an issue that documents what you already tried; I can then take a look and see if anything is missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the confusion! Yes let me finalize this PR and open an issue to solve the app theme thing separately.