Retaining drawn objects after app goes into background

Hi,

I’m drawing a waveform programmatically by drawing vertical lines using
glDrawArrays(GL_LINES, 0, noOfVertices);

I’ve enabled kEAGLDrawablePropertyRetainedBacking on my GLKView and am getting the results I want.
My waveform that is drawn programmatically is being retained and OpenGL ES doesn’t need to redraw the prior waveform bits for every frame.
However, I have an issue - when my app resigns (goes into background), and comes again to the foreground, the previous drawn OpenGL drawn objects are cleared. I actually see what I previously drew for a split second, and then it is cleared away.
I commented out all the glClear commands in my code, but it doesn’t help. The clearing on the app coming into foreground still happens.

In my case, redrawing all the lines of the waveform is not really an option as it’s resource intensive.

How do I retain the backing even when my app resigns ? Many thanks for your help here.

OpenGL ES is not designed to be used this way. It might work sometimes, but this is going to be very dependent on the OpenGL ES and EGL drivers your app is running on.

For example, most OpenGL ES GPUs (such as PowerVR and Adreno) are tile-based deferred renderers which rely upon the glClear call to know when to clear their internal buffers. Not doing the glClear call will produce unpredictable behavior.

Also, OpenGL ES renderers do not really draw lines. They are rendered as degenerate triangles.

Why do you even need a graphics API to just draw vertical lines?

Regards, Clay

I’m drawing a waveform that shows the recording input of my app in real time. Is there any tried and true way for doing this in OpenGL ES? Thanks for your reply.

OpenGL does not know anything about waveforms.

Maybe you need OpenGL to animate your graphics with some special effects? Otherwise, I would look at using a simpler 2D API that is native to iOS, or just draw the vertical line pixels directly into a bitmap with a loop.

Regards, Clay

Yes, I do need some animation on other aspects of my glkview, plus the wave input is being displayed in real time. My app is quite timing critical, and I read that opengl es will give me the best performance, hence I did it this way. So far, it has been ok except for this instance where glclear is somehow clearing my view when coming back from the background.

I’m interested in your second suggestion, drawing vertical line pixels directly with a loop - how does that work? Is it opengl?

Just a thought, I’m able to render my waveform to a texture, and print it to the screen at every frame right? Is this a good practice to go about this instead of my enabling retain graphics way?

You could save your texture image data to a file in an uncompressed RGB format, then redraw the entire waveform using it whenever the app is resumed.

Regards, Clay

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.