I'm working on an OpenGL app where the screen image is often static. I can think of 3 ways to handle this situation:
- Simply keep rendering the entire screen over and over anyways
- Ask OpenGL to call the render loop only when there are changes
- Only redraw the image when it changed and exit from render loop immediately otherwise
Clearly option 1 would be a gigantic waste of processing power (i.e. battery charge on mobile devices) and option 2 would be the optimal solution.
The power consumption difference between option 2 and option 3 is probably very minimal though (correct me if I'm wrong), since the unnecessary call to the render-loop and any associated setup-overhead should be tiny. It turns out that for my multi-threaded rendering pipeline option 3 would be a LOT easier to implement than option 2. So, I would like to give that a shot first if I can make it work.
When I tried it by rendering a static image once, the screen started flickering between that image and black like crazy. My guess is that this is due to double (or triple?) buffering: My image only gets drawn into one of the buffers, but on every call to the render-loop, the buffers are flipped, so that the image ends up on the screen only when that one buffer happens to be the active one.
Simple solution: Draw the static image once into every buffer and only then start exiting the render-loop immediately.
For this I need to know the number of buffers, i.e. the number of times I need to draw the image. Is there a way to query this number? Or can I somehow prevent the buffer switch if my render-loop turns into a NO-OP?
I am building an OpenGL ES 1.0 and an OpenGL ES 2.0 version of this code for maximal device support.