Is there a function to check if Adaptive vsync is supported?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Trastaroots
Prole
Posts: 3
Joined: Fri Apr 07, 2023 11:31 pm

Is there a function to check if Adaptive vsync is supported?

Post by Trastaroots »

Hi there, :)

I was working on my options menu, while looking through the wiki I noticed that adaptive vsync wasn't supported on all graphics drivers.
So I thought maybe there's a function to check if it is supported or not, but couldn't find one.

But I know you can set the vsync inside conf.lua to either 0 or 1 or -1(adaptive).

So my questions are:
  • What would happen if t.window.vsync = -1 will the game just crash or love just set vsync to either 0 or 1 ?
  • Is there a function to check if adaptive vsync is supported ? Have I just missed it somewhere on the wiki ?
  • Is the code below a valid way to check if it is supported ?

Code: Select all

function window.isAdaptiveVSyncSupported()
    local refreshRate = love.window.getDPIScale() * love.window.getDisplayRefreshRate()
    local frameRate = 60
    return refreshRate % frameRate == 0
end
the code above, in theory:
Check the refresh rate of the monitor and compare it to the desired frame rate of the game. If the refresh rate is a multiple of the frame rate, then adaptive VSync is supported.

Thanks in advance !
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Is there a function to check if Adaptive vsync is supported?

Post by slime »

Trastaroots wrote: Sat Apr 08, 2023 12:32 am
  • What would happen if t.window.vsync = -1 will the game just crash or love just set vsync to either 0 or 1 ?
If -1 (adaptive vsync) is requested but not supported, love will try setting it to 1 (regular vsync) instead. Even that request might fail if the user has set up their graphics driver settings to override app vsync settings.

love.window.getVSync will return the actual current vsync value.
Trastaroots wrote: Sat Apr 08, 2023 12:32 am
  • Is there a function to check if adaptive vsync is supported ? Have I just missed it somewhere on the wiki ?
Not without trying to set it and then calling getVSync.
Trastaroots wrote: Sat Apr 08, 2023 12:32 am
  • Is the code below a valid way to check if it is supported ?

Code: Select all

function window.isAdaptiveVSyncSupported()
    local refreshRate = love.window.getDPIScale() * love.window.getDisplayRefreshRate()
    local frameRate = 60
    return refreshRate % frameRate == 0
end
I don't think that will do what you expect.

DPI scale is completely unrelated to refresh rate (it's a thing that affects resolution and content scale rather than refresh rate).

Also getDisplayRefreshRate isn't a function that exists in love (love.window.getMode returns the current refresh rate as part of its settings table). Where did you get that code from?
Trastaroots
Prole
Posts: 3
Joined: Fri Apr 07, 2023 11:31 pm

Re: Is there a function to check if Adaptive vsync is supported?

Post by Trastaroots »

So basically when I toggle the checkbox I Should set and get VSync and if getVSync return 1 or -1 everything is fine and if getVSync return 0 then I just uncheck the checkbox and potentially use love.window.showMessageBox() to inform the user.
I don't think that will do what you expect.

DPI scale is completely unrelated to refresh rate (it's a thing that affects resolution and content scale rather than refresh rate).

Also getDisplayRefreshRate isn't a function that exists in love (love.window.getMode returns the current refresh rate as part of its settings table). Where did you get that code from?
Actually I came up with that code, although I think getDisplayRefreshRate came from an old forum post I found online a few weeks ago. (not this forum)

Maybe an old function that got removed ? either that or it what just complete bs.
RNavega
Party member
Posts: 355
Joined: Sun Aug 16, 2020 1:28 pm

Re: Is there a function to check if Adaptive vsync is supported?

Post by RNavega »

Trastaroots wrote: Sat Apr 08, 2023 2:28 am if getVSync return [something other than -1] then I just uncheck the checkbox and potentially use love.window.showMessageBox() to inform the user.
IMO it's better UI/UX to let the checkbox stay ticked as the user chose it instead of forcing it to change, and then show the warning message (maybe as a tooltip from a new UI element shown next to the checkbox, a warning sign ⚠).
Trastaroots
Prole
Posts: 3
Joined: Fri Apr 07, 2023 11:31 pm

Re: Is there a function to check if Adaptive vsync is supported?

Post by Trastaroots »

IMO it's better UI/UX to let the checkbox stay ticked as the user chose it instead of forcing it to change, and then show the warning message (maybe as a tooltip from a new UI element shown next to the checkbox, a warning sign ⚠).
Yeah, actually I might just do that, thx for the idea! I tried to use the showMessageBox function, but it seems more adapted for an app than a game.
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests