8

I need to apply some pixel shaders to a bitmap (using OpenGL) and send result to server. Rendering is supposed to be made in background so I can't create GLSurfaceView for this purpose. So my question is: is it possible to make OpenGL rendering on Android without using GLSurfaceView? Like rendering directly to bitmap, or canvas or some sort of buffer/array? Or may by it is possible to use some kind of dummy GLSurfaceView?

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Dmitry Ryadnenko
  • 22,222
  • 4
  • 42
  • 56
  • Possible duplicate of [Run Android OpenGL in Background as Rendering Resource for App?](http://stackoverflow.com/questions/6524212/run-android-opengl-in-background-as-rendering-resource-for-app) – Ciro Santilli OurBigBook.com Feb 16 '17 at 10:19

2 Answers2

4

This SO post contains a link to an anddev post. A bit downwards, somebody created a PixelBuffer class that reuses the GLSurfaceView.Renderer interface, but apart from that, only EGL.

Community
  • 1
  • 1
Stefan Hanke
  • 3,458
  • 2
  • 30
  • 34
  • 1
    Luckily I just finished my own renderer based on same idea. Thank you for the answer and link thought. It can be useful for others. – Dmitry Ryadnenko Mar 23 '12 at 07:38
  • The PixelBuffer object mentioned does contain a good proof of concept, but it has a critical performance problem: Once the buffer is rendered, a second copy of the bitmap is made by copying each pixel in a loop which can cause a 100% or more runtime increase! Just goes to show it's important to keep your reference frames straight in OGL. – tomwhipple Jun 21 '12 at 00:56
  • 1
    Also, PixelBuffer works on some phones but not others. Yay fragmentation! – tomwhipple Jun 21 '12 at 01:23
0

It sounds like you want to render to a frame buffer object (i.e. directly to a texture). This is definitely possible. Just search around for the answer here or on the web. I found this one without trying too hard. I'm not sure if you're using GL ES 1.1 or 2.0 though.

http://blog.shayanjaved.com/2011/05/13/android-opengl-es-2-0-render-to-texture/

It also looks like APIDemos in the SDK has a sample for 1.1

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/FrameBufferObjectActivity.html

robertly
  • 2,132
  • 14
  • 9
  • Thank you for the answer. As I can see both methods depends on GLSurfaceView. I need my rendering to be made without any screen/activity/layout available. I mean in some background thread. I wonder if GLSurfaceView is able to create GL context without being able to initialize it's surface (as it requires a screen to draw to). Thank you for the hint anyway this seems to be useful. – Dmitry Ryadnenko Mar 21 '12 at 15:18
  • @boulder does the GLSurfaceView not initialize if it is off the screen? What if it is on the screen by 1px? – Brad Moore Mar 02 '14 at 22:12
  • @BradMoore I don't remember now. You can check this yourself quite easy. As far as I remember it's not possible to use GLSurfaceView without a screen. 1px wasn't an option since rendering should have been done on service. – Dmitry Ryadnenko Mar 04 '14 at 13:05
  • These links go nowhere now :( – eri0o Sep 09 '19 at 18:08