I am trying to optimize my SDL rendering loop for an immediate mode GUI application that doesn't need to be redrawn every frame. I have vSync turned on and would like to skip buffer clearing / drawing altogether if the GUI hasn't changed.
The problem is, swapping buffers without redrawing causes flickering because of double / triple buffering. On the other hand, also skipping the buffer swap causes the program to run full throttle because the waiting is effectively done in
Ideally I would need some kind of function that waits for vSync without swapping buffers, but I haven't seen one in the SDL documentation. I've tried the following solutions but none are satisfying:
- Drawing VBOs every frame even if they haven't been updated. That will reduce load on the CPU but not on the GPU, so not ideal.
- Keeping track of which backbuffers are up to date, and only redraw them if they are dirty. This worked in my testing but requires to make some assumptions (the number of backbuffers, and hoping the driver didn't replace them with fresh ones). So not reliable enough.
- Manually waiting with a small delay. Probably the most reliable, but still not ideal.