Author Topic: Capping display framerate  (Read 9307 times)

jjzazuet

  • Jr. Member
  • **
  • Posts: 16
    • Unsung Stories
Capping display framerate
« on: November 20, 2012, 02:46:43 AM »
Hi. Jesus again.

This time I have a question regarding application timing and rendering frequency.

By using the framework, my main Display output class (which extends from scene) gets updated when the method gets called.

I have found out that if I use the provided TimerSystem utility class and update a timer each time this method is called, the number of frames per second reported by the timer will be more than 500 in my current system if I disable VSync on my graphics card's settings.

If I turn it on, the timer will instead report a number close to 60.0, as expected.

The question is, how can I impose an internal frame rate cap inside the application, regardless of the video card's VSync setting? I'm only interested in rendering at standard multimedia framerates (15.00, 29.97, 30, 60, etc.)

I've been thinking about using nanosleep calls or some other timer utility class but I'm still trying to understand what to do.

Thanks again for your time and help!

JZM

jjzazuet

  • Jr. Member
  • **
  • Posts: 16
    • Unsung Stories
Re: Capping display framerate
« Reply #1 on: November 20, 2012, 04:42:25 AM »
One more question.

Is it possible for my application to control when will render get called?

Thanks!

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Capping display framerate
« Reply #2 on: November 20, 2012, 11:08:18 AM »
If you wish to force a framerate to a specific value, the vsync must be disabled and render must be called periodically at a given framerate.

If you're using a SWT canvas, the render loop is controlled by the SWT calls 'display.asyncExec' from SwtSceneTarget. More easily, you can possibly control the SWT display refresh rate if SWT allow to do that.

If you're not using SWT, you can enable/disable VSync with DisplayCapabilities.setVsyncMode. RenderLoop (accessible from ISCeneTarget) allow to pause/resume rendering but this will certainly not be usable for what you want.
The easiest would be to expose in RenderLoop a method to cap the framerate. It could also be possible to implement your own render loop (ISCeneTarget implements IDisplayable.onDisplay which trigger the call to 'render' for a frame).

Let me know what you're using or need.

jjzazuet

  • Jr. Member
  • **
  • Posts: 16
    • Unsung Stories
Re: Capping display framerate
« Reply #3 on: November 21, 2012, 02:08:59 PM »
Useful information indeed. Thanks!

I'm using SWT so I guess I'm going to try to control the framerate from within SWTSceneTarget.

I'll check back if I run into another roadblock.

Cheers!

JZM

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Capping display framerate
« Reply #4 on: November 21, 2012, 02:25:17 PM »
Lwjgl provides a method to render at a constant framerate which you can use with SWT:

I think it should work if you call it between canvas.swapBuffers and repaint in the SwtSceneTarget.
« Last Edit: November 21, 2012, 02:28:20 PM by jerome_j »