godot: Screen capture not working (Android & iOS)

Godot version: 3.0-stable

OS/device including version:

Android 7.0, GPU: Mali-T860MP2

Issue description: The screen capture official demo is not working on my device. After some debugging I’ve found that the img var is returning null at this point:

	get_viewport().set_clear_mode(Viewport.CLEAR_MODE_ONLY_NEXT_FRAME)
	# Let two frames pass to make sure the screen was captured
	yield(get_tree(), "idle_frame")
	yield(get_tree(), "idle_frame")

	# Retrieve the captured image
	var img = get_viewport().get_texture().get_data()

Steps to reproduce: Just run the demo on a mobile device and press the “Capture screen” button.

Minimal reproduction project: https://github.com/godotengine/godot-demo-projects/tree/master/viewport/screen_capture

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 32 (19 by maintainers)

Most upvoted comments

I will try to fix this for Godot 3.1

The way to do this properly, IMO, when running on mobile, is to

  1. Create a framebuffer and a texture, it could be an existing texture but I advise a new RGBA one, else many formats, like the compressed ones, can’t be obtained.
  2. Render the texture to it, and then reconvert the texture to the format. (if compressed, do not recompress)
  3. Delete the framebuffer and newly created texture

@JFonS or @elasota Do you think you could lend a hand with this? I am not around until Tuesday.

It’s a core feature and should work on all platforms (as it always worked). The module solution can be used just as a workaround.

I implemented texture_get_data for OpenGL ES #23125 which should fix this issue. I need someone to test it on both Android and iOS to make sure it works properly.

Also having this same issue using Godot v3 (master); Shin-NiL Godot-Share module example works perfectly fine on PC (it uses Screen-Capture), but it won’t work on Android as .get_data returns null.

There still no workaround for screen capture yet? This is somewhat crucial for mobile games sharing systems.

I’m sorry @JFonS it was my fault. I thought it was merged on alpha2. I’ve tested with master now and it’s working fine with GLES2 and GLES3.

Thank you very much for your hard work 😉