-
-
Notifications
You must be signed in to change notification settings - Fork 21k
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
Screen capture not working (Android & iOS) #16694
Comments
As additional note, it's working fine on my PC (Windows 10). |
extends Sprite3D
func _ready():
var view = $"Viewport"
yield(get_tree(), "idle_frame")
yield(get_tree(), "idle_frame")
print("view.get_texture() = ",view.get_texture())
print("view.get_texture().get_data() = ",view.get_texture().get_data())
it happens also with |
Not working on iPhone X simulator too. Same behavior, |
I've tried everything, and the problem is to get_data on any texture, besides being the viewport one or not. (On pc/Linux works, on android it doesn't) I've also tried with the nightly build from https://hugo.pro/projects/godot-builds/, but no luck. |
Hi, how is this issue going on? this is a really important part for the game I'm finishing and I understand the issue is in saving the image, isn't it? |
I can confirm that Texture.get_data() doesn't work on Android. It always returns null. |
As I can see |
Nope, for me it fails for ImageTextures too. Maybe it has something to do with the texture format or compression? |
@ProbDenis it's strange, because it worked for me... I have no idea what is hapenning here :( |
I could solve this making a custom module for android and recomoiling templates... I dunno how yo share the code or push it in the git... any suggestions? |
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. |
Adding a me too here. I'm calling .get_data on an ImageTexture. Works fine on windows but returns null on Android. |
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. |
This is one of the reasons why I'm stuck in version 2.1.* :( |
I will try to fix this for Godot 3.1 |
An option can be get back the Godot 2 function:
|
I've been trying to port code from 3.0 to 2.0, to try to get screenshot functionality into old android phones that don't support GLES3. I've done this quick hack into viewport.cpp just to see if it works, but glReadPixels segfaults about one in six times. I'm using the OP's MRP to test it. I'd be grateful if anyone could give me some help. Ref<Image> ViewportTexture::get_data() const {
// 1 == GLES2
if (OS::get_singleton()->get_current_video_driver() == 1){
int width = this->get_width();
int height = this->get_height();
int size = width * height * 4;
glPixelStorei(GL_PACK_ALIGNMENT, 4);
Image *img = new Image(width, height, false , Image::FORMAT_RGBA8);
img->lock();
glReadPixels(0,0,width, height, GL_RGBA, GL_UNSIGNED_BYTE, img->write_lock.ptr());
img->unlock();
return Ref<Image>(img);
}
else{
ERR_FAIL_COND_V(!vp, Ref<Image>());
return VS::get_singleton()->texture_get_data(vp->texture_rid);
}
} |
The way to do this properly, IMO, when running on mobile, is to
@JFonS or @elasota Do you think you could lend a hand with this? I am not around until Tuesday. |
I've been following this SO question: https://stackoverflow.com/questions/1024603/opengl-es-render-to-texture#1024634 I noticed that most of this code is already implemented on render_target_create and render_target_set_size(). However, I'm stuck here. What function can I call that renders everything to the set render_target without resetting it? |
I feel like this should be working. Any pointers? |
@jabcross I have quite some things to work on now, but I will eventually take a look at this issue. Where exactly in the code are you doing these changes? |
@JFonS That's great to hear! It's in the GLES part of rasterizer_storage_gles2::texture_get_data(): |
This is related so I'm commenting to this issue rather than opening a new one. The issue is viewport.get_texture().get_data() can actually crash the game even in Windows. Anyways, here is reproduction code: Just press the button. Result (on master) is:
BTW I agree that this functionality is very important and a core functionality that should be usable. |
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. |
Thanks @JFonS , I've tested your changes on my Android device using the official screen capture demo. * as a side note, the booting stage using GLES 2 is extremely slow (about 15s to open the app), but that's most likely another issue. |
@JFonS We are working in an alternative implementation (nothing pull-requestable yet) and it looks very different than yours. And here is how we are doing the screenshot: jahd2602@42fbfa7 |
Thanks for testing @Shin-NiL. I'm not sure about the cause of the GLES3 mess. It looks like the shape is fine but the colors are interpreted in a wrong format. I will do some some changes later today to try and fix this. @jahd2602 I'm by no means an OpenGL ES expert, I just implemented what reduz wrote:
If you solution works it will probably be better, since my PR is basically a hack. |
@JFonS our version (jahd2602, vnen and mine) works like it used to in Godot 2, which means it captures the whole framebuffer, and not a specific texture. texture_get_data() should work for any texture, and not just viewports, right? Thanks for your help, btw. |
@jabcross Yes, that's the idea. Although it still lacks support for mipmaps and compressed textures. It looks like it works fine for screen caputre in GLES2 but I'm having some trouble getting it to work in GLES3. |
@Shin-NiL I updated my PR and it worked fine for me in GLES3. Have you tested the screen capture demo using a build from current master? |
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 ;) |
My version of Godot is 3.1.1 and it is not working on my iOS device, is it not fixed? |
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:
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
The text was updated successfully, but these errors were encountered: