Reputation: 999
For an application i want to render things in background even when the app is not currently displayed. The official docs write to open a GLcontext via a GLSurfaceView. For not displaying graphics and rendering into another target there seems not to be a real solution.
So the Question is how to create a GL-context without GLSurfaceView in Android?
Use case: Record a video and add current time as text directly into video. For that CPU-based image-manipulation is simply to slow to be performed live. At least if the video should be also displayed while recording. OpenGL could render everything simply into a Framebuffer/Renderbuffer.
Upvotes: 3
Views: 4787
Reputation: 54642
You don't have to use GLSurfaceView
to do OpenGL rendering. If you look at the source code, you can see that it's only using only publicly available APIs. It is merely a convenience class that makes the most common uses of OpenGL under Android (using OpenGL to draw the content of a view) very easy. If your use case is different then you just... don't use it.
The API you use for creating contexts and rendering surfaces more directly is EGL. There are two versions of it available in the Android Java frameworks: EGL10 and EGL14. EGL10 is very old, and I would strongly recommend using EGL14.
The EGL calls are not really documented in the Android SDK documentation, but you can use the man pages on www.khronos.org to see the calls explained.
Using EGL directly, you can create a context and an off-screen rendering surface that will allow you to use OpenGL without any kind of view.
I posted complete code showing how to create a context with an off-screen rendering surface in a previous answer here: GLES10.glGetIntegerv returns 0 in Lollipop only.
Upvotes: 9
Reputation: 1773
Already answered here and here
I think the most simple is what is described in second link when they say :
set it's view size 1pixel&1pixel, put it visible(user cannot see it) and in OnDraw bind FBO to the main texture and render it
So you would still create a GLSurfaceView (just to get a context) but you would make it 1x1 and invisible.
Or you could use a translucent GLSurfaceView as suggested in my comment (I am not sure this will work on any device, this seems to be a bit tricky to setup).
Upvotes: 0