[client] adjusted presentation time to be more accurate

This commit is contained in:
Geoffrey McRae 2017-12-07 16:10:00 +11:00
parent 032602f336
commit 1d5f98db32

View file

@ -161,19 +161,17 @@ inline uint64_t microtime()
uint64_t detectPresentTime() uint64_t detectPresentTime()
{ {
// warm up first as the GPU driver may have multiple buffers
for(int i = 0; i < 10; ++i)
SDL_RenderPresent(state.renderer);
// time 10 iterations and compute the average
const uint64_t start = microtime();
for(int i = 0; i < 10; ++i)
SDL_RenderPresent(state.renderer);
const uint64_t t = (microtime() - start) / 10;
// ensure all buffers are flushed
glFinish(); glFinish();
// time 20 iterations and compute the average
const uint64_t start = microtime();
for(int i = 0; i < 20; ++i)
{
SDL_RenderPresent(state.renderer);
glFinish();
}
const uint64_t t = (microtime() - start) / 20;
DEBUG_INFO("detected: %lu (%f Hz)", t, 1000000.0f / t); DEBUG_INFO("detected: %lu (%f Hz)", t, 1000000.0f / t);
return t; return t;
} }