title: Android camera surfaceTexture - How to preserve previous frames?
body: <p>I'm using SurfaceTexture for live camera preview. This sends the data stream directly to the GPU as a texture.</p>
  
  <p>This texture gets overwriten with each new camera frame coming in.</p>
  
  <p><strong>Now - I want to avoid this overwriting and retain last several(n) previous frames in the memory (which is my ultimate goal here)</strong></p>
  
  <p>The data from the camera coming in would always overwrite the oldest texture from the n amount of textures available. I just need to alternate between them.</p>
  
  <p>These textures need to be available for immediate rendering as the data are coming in. </p>
  
  <p>I dont need: to save captured data as byte buffer and convert it back to new texture = slow, all must be in real time. Performance is a key here.</p>
  
  <p>I have used this program example to run the camera in surfaceTexture mode: <a href="http://maninara.blogspot.co.uk/2012/09/render-camera-preview-using-opengl-es.html" rel="nofollow">http://maninara.blogspot.co.uk/2012/09/render-camera-preview-using-opengl-es.html</a></p>
  
  <p>I have tried to attach a new texture using attachToGLContext(int texName) method of SurfaceTexture class, but it doesnt seem to allow me to do that without destroying the previous one, seems like i must use "detachFromGLContext()" before attaching a new one..</p>
  
  <p><a href="http://developer.android.com/reference/android/graphics/SurfaceTexture.html" rel="nofollow">http://developer.android.com/reference/android/graphics/SurfaceTexture.html</a></p>
  
  <p>Any help appreciated.</p>