How to check if VSYNC has been turned on in SDL2?

How can I see if the vsync has been turned on after using SDL_RenderSetVSync() (other than doing it the dirty way by looking at renderer->SetVSync and renderer->simulate_vsync (I don’t even know if this is correct))

Currently there is no other option than just reading the state of the SDL_HINT_RENDER_VSYNC hint via SDL_GetHint and testing the result string (0 or 1). I proposed adding the SDL_RenderGetVSync function — it is implemented in SDL3, so still we don’t have it in SDL2.

You can look inside the pointer to the renderer and check the status of wanted_vsync, as below. It will be a dirty hack, but it will work.

I can’t find SDL_HINT_RENDER_VSYNC being set anywhere other than when you create the renderer.

So I guess for the situation with SDL_RenderSetVSync, I could just copy paste the SDL3 code for SDL_RenderGetVSync. Looks pretty straight forward.

If I do it immediately after Set-ting, so I need to check the magic render values, or can I just do it dirty with one line? Like, the renderer should be valid unless the function failed, right?

EDIT: Ok, I may be wrong regarding the hints. It’s a really confusing mechanism that I will make a separate thread for.

So do it. There is no way in SDL2 to check if VSync is enabled other than reading the hint or reading the private field of the renderer structure, same as in the current SDL_RenderGetVSync.

I don’t know why SDL_RenderGetVSync was implemented in SDL3 only.

You can always just keep track yourself. Set your own flag based on whether or not the renderer is being created with SDL_RENDER_PRESENTVSYNC, and have your own wrapper function around SDL_RenderSetVsync() that sets/clears this flag.

1 Like

Ok guys I have an update.

I just realized that you don’t have to check if vsync has been set by SDL_RenderSetVSync, because it will 100% fail if renderer is wrong or the vsync argument isn’t 0 or 1.

And renderer->wanted_vsync will 100% be set if the code gets to that point.

And even if normal vsync can’t be used, it will use the backup and set the renderer->simulate_vsync flag.

Only thing that could possibly turn off renderer->wanted_vsync is the os-specific renderer->SetVSync() function pointer, but I looked at several and couldn’t find anything that would indicate that such change would be done - implying that renderer->wanted_vsync will always be on regardless if renderer->simulate_vsync is on or off.