Get main loop interval when using requestAnimationFrame

276 views
Skip to first unread message

Sagar

unread,
Mar 21, 2017, 2:44:00 AM3/21/17
to emscripten-discuss
The main loop in Emscripten gets called at 60Hz on a typical display (with requestAnimationFrame). What about high frame rate monitors like 120Hz or 144Hz? Does the browser limit the frame rate to 60Hz or would the main loop get called at the display refresh rate? If the latter, is there any emscripten API to check what the refresh rate is?

Jukka Jylänki

unread,
Mar 21, 2017, 8:43:44 AM3/21/17
to emscripte...@googlegroups.com
emscripten_set_main_loop_timing with rAF mode implements a "swap interval" concept to mirror native eglSwapInterval() etc aPIs, so a swap interval of 1 runs at each rAF tick, so 144Hz/120Hz/60Hz depending on the display's native speed, and swap interval of 2 will run at half speed i.e. 72Hz/60Hz/30Hz, and so on.

There unfortunately does not exist a web API to query what the display refresh rate is, and it can change on the fly when user moves the browser window in a multi monitor setup e.g. from a 120Hz monitor over to a 60Hz monitor. Check out https://github.com/Mozilla-Games/browser_feature_test for a test code that tests what the refresh rate is at runtime. You can run that live at https://s3.amazonaws.com/mozilla-games/browser_feature_test/example.html, and the resulting page should tell you the measured refresh rate of the monitor. You could run that kind of estimation as e.g. a preRun action on the page.

There is a bug report at https://bugzilla.mozilla.org/show_bug.cgi?id=1052360 to request support in browser, although the issue is that such APIs should go through a standards body to get widely adopted, and there haven't been any shipped games on the web that would have really needed this to motivate driving such spec work.

2017-03-21 8:44 GMT+02:00 Sagar <sagar....@gmail.com>:
The main loop in Emscripten gets called at 60Hz on a typical display (with requestAnimationFrame). What about high frame rate monitors like 120Hz or 144Hz? Does the browser limit the frame rate to 60Hz or would the main loop get called at the display refresh rate? If the latter, is there any emscripten API to check what the refresh rate is?

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages