I'm implementing in Android and native C++ a scene drawing for android using EGL 1.1.
Currently using Android's glSurfaceView
- which allows me to draw to a back buffer which is displayed at the end of "onDrawFrame" - when the back buffer and the front buffer are swapped.
My problem is this: I need to be able to display the back buffer and continue writing as if I havn't swapped. The reason behind this demand is that the scene is very large, and building it each frame is not possible, neither is waiting for the end of the drawing - since the user will have to wait for too long.
In other words - I need to build the scene incrementally.
At a certain point during the rendering, I decide it's time and I call eglSwapBuffers
which displays the drawn content from the back buffer, but when I continue writing obviously I'm writing to the 'former-front-buffer' which is out of sync.. (not containing the things I've drawn so far).
As far as I see my only option is to copy the back buffer before swapping. pseudo:
- Draw to back buffer
- Copy Back Buffer to temp Buffer
- Swap
- Copy temp buffer to (the new) back buffer
- Draw more things to back buffer
- And so on...
Is there a way to do steps 2,4?
- Is
glCopyPixels
useful in this case? example? - Is
glBlitFramebuffer
?
Or am I approaching this all wrong?
Things I already did :
I tried setting
EGL_SWAP_BEHAVIOR
toEGL_BUFFER_PRESERVED
but it only seems to work on certain devices (as described in the khronos notes) :Some surfaces allow applications to control whether or not the color buffer contents are preserved
Re-rendering the scene in each frame - not possible. I've read many times that this is recommended.