godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.26k stars 101 forks source link

Android: Choose between surfaceView and TextureView #12630

Closed WouterVandenputte closed 3 weeks ago

WouterVandenputte commented 3 weeks ago

Describe the project you are working on

A Flutter mobile app that displays a 3D Godot view

Describe the problem or limitation you are having in your project

Flutter is unable to:

Both are very basic functionalities of any app that are impossible now when integrating Godot inside a Flutter app.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The Godot view inside GodotFragment is rendering via SurfaceView, which has special properties in the Android rendering pipeline:

A SurfaceView renders in a separate layer above the normal view hierarchy. As a result, you can't overlay Flutter widgets on top of it, even if it’s inside a Stack.

From the Android doc: Unlike SurfaceView, TextureView does not create a separate window but behaves as a regular View. This key difference allows a TextureView to have translucency, arbitrary rotations, and complex clipping. For example, you can make a TextureView semi-translucent by calling myView.setAlpha(0.5f).

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

A dropdown or button inside the project preferences could allow the developer to choose between either SurfaceView (default) or TextureView

If this enhancement will not be used often, can it be worked around with a few lines of script?

No, it would require changing and compiling the GodotEngine.

Is there a reason why this should be core and not an add-on in the asset library?

This modification must be done inside the Engine

m4gr3d commented 3 weeks ago

The issue is due to the fact that both Godot and Flutter renders to a surface. Android has apis to set the z-order for SurfaceViews but being unfamiliar with Flutter, I don't know if those are accessible to app developers.

Regardless, it looks like Flutter provides apis to render to a texture instead of a surface, so you should investigate that approach instead. Godot's surfaceview integration is pretty complex, so we're unlikely to consider supporting TextureView especially given performance considerations.

WouterVandenputte commented 3 weeks ago

The issue is due to the fact that both Godot and Flutter renders to a surface. Android has apis to set the z-order for SurfaceViews but being unfamiliar with Flutter, I don't know if those are accessible to app developers.

Regardless, it looks like Flutter provides apis to render to a texture instead of a surface, so you should investigate that approach instead. Godot's surfaceview integration is pretty complex, so we're unlikely to consider supporting TextureView especially given performance considerations.

I actually already took a look at that setZOrderOnTop Method, but I’d need to call that on the GodotFragment’s internal SurfaceView which is not exposed to us.

m4gr3d commented 3 weeks ago

The issue is due to the fact that both Godot and Flutter renders to a surface. Android has apis to set the z-order for SurfaceViews but being unfamiliar with Flutter, I don't know if those are accessible to app developers. Regardless, it looks like Flutter provides apis to render to a texture instead of a surface, so you should investigate that approach instead. Godot's surfaceview integration is pretty complex, so we're unlikely to consider supporting TextureView especially given performance considerations.

I actually already took a look at that setZOrderOnTop Method, but I’d need to call that on the GodotFragment’s internal SurfaceView which is not exposed to us.

It's exposed, but require knowledge of the Godot's view hierarchy. See https://github.com/m4gr3d/Godot-Android-Samples/issues/22#issuecomment-2899818618