No announcement yet.

Limit FPS without Vsync.

  • Filter
  • Time
  • Show
Clear All
new posts

  • Limit FPS without Vsync.

    Sorry to bother again.

    I am (finally) trying to build a template for a new project but I am kinda running into a stupid thing. I am not able to limit the framerate (with the timer) without enabling Vsync. Could you edit one of the Delphi Examples to limit the rendering to the value of Ftimer.maxframerate?

  • #2
    To explain that a bit.
    In Afterwarp 1.1 you created a Timer, set a procedure for process and one for timer. The onTimer event handled the rendering. the onprocess event the logic.
    Ftimer.process was called at the end of the ontimer event. Ftimer.execute was called in applicationidle.

    Now in the Drawable Texture example for example, the rendering is done by RenderingControlPaint.
    Ftimer.maxframerate does nothing. I added the onTimer event as a test like it was used in 1.1 and moved all the rendering stuff to it. Still works but maxframerate is still ignored.
    Last edited by Zimond; 08-31-2021, 10:42 PM.


    • #3
      You should set FTimer.MaxFrameRate to some value, e.g. 100 FPS, then in your rendering code, call FTimer.Execute(True, True) - this should limit the rendering to the given frame rate. Please note that Execute will call Sleep to limit the frame rate, which has precision of 10 ms on Windows platform (on other platforms, it is much more precise). As a result, animations might stutter. It is better to either use VSync, or use processing independent of rendering (either through TTimer.OnProcess event and TTimer.Process call, or using TTimer.Latency directly to control the speed of movement).

      In other words, in DrawableTexture example, make sure Execute is called with both parameters set to True and that MaxFrameRate is relatively low, e.g. 100 or 50 FPS. If MaxFrameRate gets ignored, it could be a bug, but I have yet to confirm it.

      Currently I am on a trip so don't have access to development environment, but I can show an example when am going to get back. Also, there has been a feature request to improve precision of MaxFrameRate on Windows, which can be accomplished by moving processing to a different thread, then mixing Sleep with calls such as SwitchToThread and/or YieldProcessor, to ensure accurate FPS limit without resorting to VSync. This is scheduled for incoming Afterwarp v2 updates.


      • #4
        I tried execute (true, true) already and it did kind of limit the frame rate but in a completely unpredictive way. Im not talking about +- 10fps which I know is to be expected. When I set it to 60 i get 33fps.
        120 results in 67, but then it stops increasing this way, 240 maxframerate still resukts in something 70. At a certain point about 500 or so it collapses back to unthottled with 4 digits of fps.
        Of course i can ignore this for now and continue, if you could check this some day in the future that would be nice