processing / processing-android

Processing mode and core library to create Android apps with Processing
http://android.processing.org
781 stars 293 forks source link

saveframe not working, and glreadpixels is slow #56

Open hiitsu opened 10 years ago

hiitsu commented 10 years ago

saveFrame gives me error that glreadbuffer not implemented or supported (galaxy 2).

im trying to take screenshots of the rendered 3d to produce animated gif out of those, im using glreadpixels and its too slow ~200-400ms (galaxy 2 and few newer devies) for my purposes.

is there a faster way to do it with processing core by hooking another fbo somehow, or injecting pure opengl that would work with opengl es 1.1 and 2.0 devices?

my 3d scenes aren't too complicated so i've been thinking of moving to pure software renderer but seems like swimming to wrong direction since opengl renderer is the only one use all over atm.

codeanticode commented 10 years ago

Thanks for reporting. What about rendering your scene into an offscreen PGraphics (which is internally backed by an FBO), and then saving it as an image?

hiitsu commented 10 years ago

seems this really isn't processing-android only problem, a lot threads over internet seem to discuss how to make this faster mobiles, they all discuss about PBO and FBO trickery which I dont have clue if they're in processing-core and if they could be applied to processing project without messing up the rendering engine

I tried first draw offscreen PGraphics by beginDraw, do drawing, endDraw, then image() call that offscreen to main PApplet and then tried different get() call variations. I took that trefoil example as base and did timings, notes: -fastest was to do to main surface directly without offscreen do get() and keep pimages in memory -it seemed that get() calls fail if offscreen is used and not first drawn to main Pgraphics (for me it wouldnt matter if shown or not) -using save() naturally was always slower due the file i/o for both main and offscreen. -using power of two offscreen sizes didnt seem to affect (like suggested in many non processing discussions in internet)

whats your best guess how should i try it?

codeanticode commented 10 years ago

Hi, I've heard about PBOs, and even tried to implement them in GLGraphics a while ago. They are cool because allow you to do asynchronous transfers between GPU and CPU memory, meaning that you can keep rendering your frames while you copy the screen textures to the CPU and then to disk (at least, that's the general idea). However, I didn't manage to include PBO support in the GL renderers in processing 2+

You can actually use low-level opengl functions inside your sketch, and even create PBOs and FBOs manually. One advantage of the GL renderers in Processing 2+ is that they are much tightly integrated with GL under hood, so you can mix Processing calls with GL calls with much less trouble than in earlier versions of Processing. So, following threads like thread has some useful discussion) you could figure out how to implement your PBO-based screen grabbing code with GL, and incorporate into your sketch.

omerjerk commented 10 years ago

I tested saveFrame() and according to me it is working fine at least in P2D mode. One fault was that the images are being saved in '/data/data//files/' . IMO, for a normal user, saving images to this location is irrelevant and these should rather be saved in /sdcard/. I'm sending a patch regarding this.

FlorentDeloison commented 10 years ago

Hi,

saveFrame works in P2D mode, but not in the P3D renderer. Really annoying... Here is the error: java.lang.RuntimeException: GL function glReadBuffer() is not available on this hardware (or driver) Read http://wiki.processing.org/w/OpenGL_Issues for help.

Tested on a Nexus 4 and a Samsung Galaxy Note 10.1.

JuanIrache commented 10 years ago

Hello.

I'm bumping into the same error when using loadPixels(), but for some reason this was not happening with previous versions of the Android Mode. So what I do is a use my old processing-core in Eclipse and the error is gone. That's a pity, because other bugs were solved in newer versions.

You can find the file that is working fine for me here, in case it helps solving the problem or getting someone's job done. Not sure if this is the right way to report about this. https://www.dropbox.com/s/u8emvavadwzepky/processing-core.jar?dl=0

Regards.

JuanIrache commented 9 years ago

Hi again,

Has someone found a workaround to getting the loadPixels() or saveFrame() to work? Even if it's slow. I've been looking around but found no way to implement glreadpixels and grab the pixels' data.

Thank you!

codeanticode commented 9 years ago

Hello, I will take a look at this as soon as I have a chance. Thanks for pointing out that the bug was not happening in older versions of the android mode, that's useful to know.

JuanIrache commented 9 years ago

This seems to have been fixed on the November 5 release. The problem I'm now facing is my app crashes in some devices when I try to loadPixels(). It throws an OutOfMemoryError (which I was not seing before). Could this be related to the previous problem? Or should I create a new bug report?

I'm comparing to a March 2013 version of the Android Mode, so I am not sure if this issue is strictly new or if it was present in other recent builds.

Thank you.

codeanticode commented 9 years ago

Hi, please open a new issue about the crash, adding the information of the devices.