I have been getting very glitchy timings in my render loop causing rendering to stutter. I have set up timing around my glXSwapBuffers
call like so:
Timer timer;
glXSwapBuffers(display, window);
timer();
if (timer.elapsed_seconds > 0.1)
printf("stutter(%f)\n\r", timer.elapsed_seconds);
And am getting results like:
stutter(0.109081)
stutter(0.108956)
stutter(0.662115)
stutter(0.759556)
stutter(0.657789)
stutter(0.283185)
stutter(0.105581)
stutter(0.106285)
stutter(0.572289)
stutter(0.199908)
stutter(0.218540)
stutter(0.752033)
stutter(0.148225)
What could be causing glXSwapBuffers to take so long to call? How can I fix the stuttering?
After much testing and debugging I found that my Timer
class was computing the difference between two timestamps wrong. The tv_nsec
component was being incorrectly divided causing elapsedSeconds
to return varying results.
After correcting this the stuttering went away immediately.