0

I have an Android activity using a texture with dynamic content (drawn into via Framebuffer / Renderbuffer).

When the activity is paused / resumed, the texture (like all textures) is lost and must be recreated.

Is there a way to save the content of the dynamic texture into some persistent object on pause and recreate the texture from this object on resume?

I already found some threads describing hack-like ways to prevent the textures from being invalidated on pause, but if possible I'd like to do it "by the book" and free the texture memory on pause / recreate textures on resume.

genpfault
  • 51,148
  • 11
  • 85
  • 139
TomMKV
  • 1
  • 1

1 Answers1

0

You can use glReadPixels to transfer the FBO's contents into a persistent buffer of your app. Then, upon resume you can load that data back into the textures. Restoring a renderbuffer would require to load into a intermediary texture, and drawing then that using a full viewport quad to the FBO with the renderbuffer attached. Hence I suggest you don't use Renderbuffers, if you can avoid them. Using a texture you can save the intermediary step.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • I was able to save pixel data using glReadPixels and recreate a texture from the saved data. The problem is that the saved pixel data is the current content of the screen, NOT the pixel data of the texture attached to the framebuffer object. How can I specify the attached texture instead of the screen as source for glReadPixels? – TomMKV Sep 11 '13 at 12:40
  • @TomMKV: It helps to read the documentation and *also* the references. The reference manual for `glReadPixels` directly links to `glReadBuffer` which, as it's name suggests, exactly does that. `glReadBuffer(GL_COLOR_ATTACHMENT…)` selects (surprise ;) ) which color attachment of the currently bound FBO to read from. – datenwolf Sep 11 '13 at 12:51
  • @datenwolf glReadBuffer is not available anymore in android GLES20 – Predrag Manojlovic Jul 04 '16 at 16:02