bovacu
August 6, 2025, 11:40am
1
Hi, I just switched my whole engine rendering system from BGFX to SDL3 GPU and one of the points I don’t know how to convert from one API to the other, is how to enable/disable VSync. I know it exists the
SDL_SetRenderVSync
But I’m not using the SDL_Renderer, I’m using the SDL_GPU API, so that won’t help, do you guys know how to achieve this?
Thanks.
sjr
August 6, 2025, 7:46pm
2
The swapchain parameters are what determines if vsync is on/off, and what kind of vsync to use if it’s on.
You use SDL_SetGPUSwapchainParameters()
to change it.
Something like:
// In your setup code somewhere:
// Can check to see what other swapchain compositions are supported with SDL_WindowSupportsGPUSwapchainComposition()
SDL_GPUSwapchainComposition swapchainComposition = SDL_GPU_SWAPCHAINCOMPOSITION_SDR;
// Check to see if MAILBOX present mode is supported
bool supportsMailbox = SDL_WindowSupportsGPUPresentMode(gpuDevice, window, SDL_GPU_PRESENTMODE_MAILBOX);
// after claiming the window
SDL_SetGPUSwapchainParameters(gpuDevice, window, swapchainComposition, supportsMailbox ? SDL_GPU_PRESENTMODE_MAILBOX : SDL_GPU_PRESENTMODE_VSYNC);
...
// elsewhere
bool ToggleVsync(bool vsync) {
SDL_GPUPresentMode presentMode = SDL_GPU_PRESENTMODE_IMMEDIATE; // vsync OFF
if(vsync) {
presentMode = supportsMailbox ? SDL_GPU_PRESENTMODE_MAILBOX : SDL_GPU_PRESENTMODE_VSYNC;
}
if(!SDL_SetGPUSwapchainParameters(gpuDevice, window, swapchainComposition, presentMode) {
// failure
return false;
}
return true;
}
2 Likes
bovacu
August 6, 2025, 8:19pm
3
That is perfect, exactly what I needed, thank you so much!