I am using openGL to playback an image sequence on a 60fps monitor. All images are preloaded in memory. Vsync enabled. Double buffering. Windows 7-64bit.
The problem I have is as most times the swapbuffer are called every 16.7ms, once a while I have a delay, i.e., the time between two swapbuffers increased to 33.3ms, or even longer, so I have a dropped frame rate and thus a glitch in playback.
The rendering part takes much less than 16ms to finish, so my guess is that some background process takes some time and blocked the swapbuffers. Anyone knows how to ensure calling swapbuffers at every vsync?
First ensure that your drawing code takes less than 16ms. I could bet it takes longer from time to time causing the problem. Try to measure execution time on both CPU and GPU.
In a modern non-realtime OS it is hard to make guarantees time guarantees. I suppose you have disabled all services you don’t need (indexation of disks, anti-virus, automatic wifi, etc) ?
If you disable vsync, do you still sometimes have such delays ?
If you can try WGL_EXT_swap_control_tear indeed it sounds like a good idea.
Or use glFinish() right before or right after the swap (or both). It will somewhat reduce the performance (less parallelism) but I observed that it makes it more even.
The background services are exactly what I worried about…and I can only try to disable as much as I can. The good news is that when I switched from my laptop (Dell precision M6500 with Quadro FX2800M) to a much more powerful workstation with Xeon and Quadro FX5800, I don’t see this swapbuffers delay anymore.
As suggested, I also tried to see whether there is delay when vsync is disabled… On my laptop, I do see the delay once a while, as typical time between swapbuffers is around 2.5ms, once a while I see a gap more than 10 times longer than that.