Home Game Development c++ – Odd SDL VSYNC behaviour when monitor is ready to 50 Hz

c++ – Odd SDL VSYNC behaviour when monitor is ready to 50 Hz

0
c++ – Odd SDL VSYNC behaviour when monitor is ready to 50 Hz

[ad_1]

I’m observing unusual behaviour with VSync in SDL. I’ve this code:

int primary()
{
   SDL_Init(SDL_INIT_EVERYTHING);
   SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");

   auto window = SDL_CreateWindow("window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1200, 480, 0);
   auto renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

   whereas (true)
   {
      static auto begin = std::chrono::high_resolution_clock::now();
      auto finish = std::chrono::high_resolution_clock::now();
      auto elapsed_us = std::chrono::duration_cast<std::chrono::microseconds>(finish - begin).depend();
      begin = finish;

      std::cout << elapsed_us << std::endl;

      SDL_RenderPresent(renderer);
   }
}

So once I set my monitor to 60 Hz I get output as anticipated:

16673
17489
16011
16653
...

Meaning every cycle’s length is round 16.667 ms. Same once I set my monitor to 75 Hz it showscorrect values round 13.333 ms.

But once I set it to 50 Hz the output might be like this:

16845
3131
16702
3424
16772
3158
16825
3147
16872
3129
...

It looks as if the VSync sign comes twice per 20 ms interval. Once at round 16.667 ms mark and the second time at 20 ms.

How can this be defined?

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here