Author Topic: Remake; vsync & timing  (Read 779 times)

0 Members and 1 Guest are viewing this topic.

Offline vtlmks

  • ZX 81
  • *
  • Posts: 12
  • Karma: 0
    • View Profile
Remake; vsync & timing
« on: June 18, 2017 »
So, I'm doing a few Amiga remakes. But I haven't come up with a good way to solve the timing.

There are a lot of refresh rates out there, even if we only take into account the LCD ones. 60Hz, 100Hz, 120Hz, 132Hz, 144Hz; only one divisible with 50Hz (Amiga Pal).

What I could do is let 60Hz run at 60Hz; 100Hz, 120Hz, 132Hz I divide by two, which would suck for 132Hz - 66hz refresh rate, and divide 144Hz by three, making the remake run a tad bit slow. And any refresh rates I don't know of, or can't query from windows with GetDeviceCaps(... VREFRESH) I'd just have to run at full speed I guess.

Or I could make sure to update a frame in 20ms (50Hz) and do a SwapBuffers(..) then and have it tear and look very non-smooth. What would be the preferred way?

Some background; I'm doing the rendering to a 352x272 pixel buffer, and I rather want to not use sub-pixel scrolling with openGL, else it would be a lot simpler. However, if that is the only way to solve it I might think it over again, but I rather hope not, would be very nice with integer pixel positions.

Well, Thanks for your time, and I hope to get some fun ideas to explore :) Cheers!

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2715
  • Karma: 484
    • View Profile
    • http://www.rbraz.com/
Re: Remake; vsync & timing
« Reply #1 on: June 18, 2017 »
Hi vtlmks,

It's really a hard problem, I've read/watched a lot on this topic and I'm still not sure the correct way to solve it either.

For my little intros, I'm still using something like this:
Code: [Select]
QueryPerformanceCounter(&HTimerVal);
FrameRate = (double)(((double)HTimerVal.QuadPart - LastTickCount)/HTimerFreq);
LastTickCount = (double)HTimerVal.QuadPart;

I've watched some videos by Casey Muratori about this topic, check out it here, it's a great explanation about variable framerate monitors, and will try it someday, might be useful for you too.
« Last Edit: August 06, 2017 by rbz »
Challenge Trophies Won:

Offline vtlmks

  • ZX 81
  • *
  • Posts: 12
  • Karma: 0
    • View Profile
Re: Remake; vsync & timing
« Reply #2 on: June 18, 2017 »
Hi rbz,

Thanks for the link, I'll check it out right away. I did more or less exactly what you do when I just used GDI to display my software rendered frame, but now that I changed to display the frame with openGL the problem got a bit worse as many people either force, or disable, vsync completely.

Thanks again!

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2715
  • Karma: 484
    • View Profile
    • http://www.rbraz.com/
Re: Remake; vsync & timing
« Reply #3 on: July 02, 2017 »
I found some people talking about directdraw "WaitForVerticalBlank" function, so I've made a test and it seems to work.

I've a laptop that runs opengl programs at 120+ fps and after applying WaitForVerticalBlank it get synchronized with monitor refresh rate which was 60hz.

Check it out to see if this have any use for you.

Attached an example here for you to test, press "Enter" to switch on/off WaitForVerticalBlank, ESC to exit.
« Last Edit: July 02, 2017 by rbz »
Challenge Trophies Won:

Offline vtlmks

  • ZX 81
  • *
  • Posts: 12
  • Karma: 0
    • View Profile
Re: Remake; vsync & timing
« Reply #4 on: July 05, 2017 »
Thanks, I checked it out, seem to work great, easy solution. :)

I also watched the episode with Casey Moratori that you linked to, and made a similar delay as he did to sync to an arbitrary frame rate (50Hz in my case), I was thinking that I will have a switch to select between that and 60Hz.



Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2715
  • Karma: 484
    • View Profile
    • http://www.rbraz.com/
Re: Remake; vsync & timing
« Reply #5 on: July 05, 2017 »
Nice!
Looking forward to see those remakes  :D
Challenge Trophies Won:

Offline vtlmks

  • ZX 81
  • *
  • Posts: 12
  • Karma: 0
    • View Profile
Re: Remake; vsync & timing
« Reply #6 on: July 06, 2017 »
One of them is almost ready for release, I went on a sidetrack by starting to write a debugsystem/profiler, but I'll try to finish it up soon, one of the remakes I'm doing is 'Fashion - Fashinating' megademo (4 parts) Always liked that one, the other one I've started on is the 'Spreadpoint - Woooow' demo.

I wont set a date as I'm also in the midst of moving houses so could take a few weeks, but should be sooner.