Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Cross-platform detect monitor frequency ?  (Read 5498 times)

0 Members and 1 Guest are viewing this topic.

Redee

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Cross-platform detect monitor frequency ?
« on: September 26, 2015, 02:22:28 pm »
Detection monitor frequency for Windows / MacOS / Linux ?
Using SFML api how ?

Me need to detect screen frequency before generated window, from OS.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Cross-platform detect monitor frequency ?
« Reply #1 on: September 26, 2015, 02:47:37 pm »
http://en.sfml-dev.org/forums/index.php?topic=18950.msg136924#msg136924
.... when it finally happens.

Otherwise you need to lookup specific functions for each OS to determine the refresh rate (on your own).

What I am most interested in though, why must you know the refresh rate? To me without a good reason it sounds like it maybe a design flaw that you must know the requested information. To me this seems like the XY problem.
« Last Edit: September 26, 2015, 03:14:58 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Cross-platform detect monitor frequency ?
« Reply #2 on: September 26, 2015, 09:43:27 pm »
Monitor frequency is not so easy, because the system may have 2-3 displays with different frequency. And an application window may be placed between two displays. So, the parts of app window will be displayed on several displays simultaneously. It will cause an issue if such cases will not be handled in application properly.

Under windows and directx I was used MonitorFromWindow to detect which monitor displays most bigger part of window. And used it to obtain monitor frequency.

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Cross-platform detect monitor frequency ?
« Reply #3 on: September 26, 2015, 11:35:34 pm »
Like zsbzsb mentioned I am working on multi screen support. It also adds the ability to get the screens refresh rate for every screen like this: sf::Screen::get(id).refreshRate. Currently there is only a windows implementation. But I would be happy if you could test it and see if it works for you. My branch: https://github.com/Foaly/SFML/tree/multi-monitor

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Cross-platform detect monitor frequency ?
« Reply #4 on: September 27, 2015, 04:21:17 am »
Quote from: zsbzsb

What I am most interested in though, why must you know the refresh rate? To me without a good reason it sounds like it maybe a design flaw that you must know the requested information.

I used it, because in some cases, foe example - rendered image may contains some effect named "multicolor". It means that color of an object may be changed on every frame. So renderer should be synchronized with physical refresh rate. Otherwise actual color visible to the user may looks like random flicks.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Cross-platform detect monitor frequency ?
« Reply #5 on: September 27, 2015, 07:08:42 am »
If you just need to sync to it but not actually know the actual value, the that sounds like what you need is setVerticalSyncEnabled.

Redee

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: Cross-platform detect monitor frequency ?
« Reply #6 on: September 27, 2015, 09:04:58 am »
On Windows I already have solution.
And its for setVerticalSync also.
For my game logic need to detect monitor freq to measure parts of exact time.

Ok setVertSync good but I cant easily take freq.
We can before game run some measure of screen frame time - and will see how refresh of its monitor.

Maybe its best solution without systems api.
Or we must release separated solutions for each OS.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 878
    • View Profile
Re: Cross-platform detect monitor frequency ?
« Reply #7 on: September 28, 2015, 12:01:15 pm »
Don't rely on refresh rate for syncing your game logic or animations. Better use timers (sf::Clock). Depending on the user's hardware, there might be nothing such as an actual/current refresh rate at all (e.g. Nvidia's GSync).

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Cross-platform detect monitor frequency ?
« Reply #8 on: September 28, 2015, 09:39:32 pm »
On Windows I already have solution.
And its for setVerticalSync also.
For my game logic need to detect monitor freq to measure parts of exact time.

Ok setVertSync good but I cant easily take freq.
We can before game run some measure of screen frame time - and will see how refresh of its monitor.

Maybe its best solution without systems api.
Or we must release separated solutions for each OS.

you can enable vblank sync and measure interval between frames. You can do it on app startup, so in that way you can calculate the real frame rate.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Cross-platform detect monitor frequency ?
« Reply #9 on: September 28, 2015, 09:43:17 pm »
you can enable vblank sync and measure interval between frames. You can do it on app startup, so in that way you can calculate the real frame rate.

Uhh... no, this is a terribly messed up hack solution to a non issue.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Cross-platform detect monitor frequency ?
« Reply #10 on: September 29, 2015, 07:44:43 pm »
you can enable vblank sync and measure interval between frames. You can do it on app startup, so in that way you can calculate the real frame rate.

Uhh... no, this is a terribly messed up hack solution to a non issue.

Actually, sometimes its needed, because the system may report invalid frame rate and the real one may be a little different. In some cases, when refresh rate is used to synchronize output it may cause big issues...
The best way is to use QueryPerformanceCounter on windows platform. I remember that I even read some article about it which describes pros and cons of using TSC vs QueryPerformanceCounter for such purposes.

I'm agree that it's hard solution and is not intended for usual graphics projects. But using such technique is very useful for realtime monitoring of renderer performance.
« Last Edit: September 29, 2015, 07:51:03 pm by mkalex777 »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Cross-platform detect monitor frequency ?
« Reply #11 on: September 29, 2015, 07:52:17 pm »
Shouldn't the real fix be to decouple your logic from your refresh rate?
The rate at which you update game logic, physics and what-not ought to be completely decoupled from the rate at which you render frames. If the two interact, then that's where your problem is.
« Last Edit: September 29, 2015, 07:58:57 pm by Jesper Juhl »

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Cross-platform detect monitor frequency ?
« Reply #12 on: September 29, 2015, 07:58:01 pm »
Souldn't the real fix be to decouple your logic from your refresh rate?
The rate at which you update game logic, physics and what-not ought to be completely decoupled from the rate at which you render frames. If the two interact, then that's where your problem is.

I talked about the case when realtime effect of switching object color is need to be synchronized with refresh rate. It's not about logic, it's about video effects...

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: Cross-platform detect monitor frequency ?
« Reply #13 on: September 29, 2015, 07:59:37 pm »
So we got one very exotic corner case. Any other examples?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Cross-platform detect monitor frequency ?
« Reply #14 on: September 29, 2015, 08:02:55 pm »
So we got one very exotic corner case. Any other examples?

For usual project simple method which returns the value reported by the system ismore than  enough :)

 

anything