mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-10-06 09:05:29 +00:00
Fix BGFX_RESET_VSYNC not affecting secondary swap chains on D3D11, Vulkan, OpenGL (#3675)
Toggling BGFX_RESET_VSYNC via bgfx::reset() only updated the main/init swap chain. Secondary swap chains created through createFrameBuffer(nwh, ...) kept their initial vsync state, leaving framerate capped at refresh rate. D3D12 already handled this correctly. D3D11: forward present flags to FrameBufferD3D11::present so it can pass DXGI_PRESENT_ALLOW_TEARING alongside syncInterval=0. Compute presentFlags once in flip() and reuse for both secondary framebuffers and the main swap chain. Vulkan: in updateResolution, iterate m_windows and call FrameBufferVK::update on each valid secondary framebuffer so SwapChainVK::update sees the new BGFX_RESET_VSYNC and recreates the swapchain with the correct present mode. OpenGL (WGL/EGL): wglSwapIntervalEXT is per-context, eglSwapInterval is per-surface. Cache the desired interval in GlContext::m_swapInterval and re-apply it in makeCurrent() whenever a different context/surface becomes current, so secondary SwapChainGL instances pick up the current value. Also honor the initial BGFX_RESET_VSYNC flag in create() instead of hard-coding 0.
This commit is contained in:
@@ -295,9 +295,10 @@ namespace bgfx { namespace gl
|
||||
BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "wglMakeCurrent failed!");
|
||||
m_current = NULL;
|
||||
|
||||
m_swapInterval = !!(_resolution.reset & BGFX_RESET_VSYNC) ? 1 : 0;
|
||||
if (NULL != wglSwapIntervalEXT)
|
||||
{
|
||||
wglSwapIntervalEXT(0);
|
||||
wglSwapIntervalEXT(m_swapInterval);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,10 +330,15 @@ namespace bgfx { namespace gl
|
||||
|
||||
void GlContext::resize(const Resolution& _resolution)
|
||||
{
|
||||
const bool vsync = !!(_resolution.reset & BGFX_RESET_VSYNC);
|
||||
m_swapInterval = vsync ? 1 : 0;
|
||||
|
||||
if (NULL != wglSwapIntervalEXT)
|
||||
{
|
||||
const bool vsync = !!(_resolution.reset & BGFX_RESET_VSYNC);
|
||||
wglSwapIntervalEXT(vsync ? 1 : 0);
|
||||
// Apply to the currently-bound (main) context. Secondary SwapChainGL contexts
|
||||
// get the value applied lazily in makeCurrent() when they become current, since
|
||||
// wglSwapIntervalEXT is per-context on Windows.
|
||||
wglSwapIntervalEXT(m_swapInterval);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,6 +399,14 @@ namespace bgfx { namespace gl
|
||||
{
|
||||
_swapChain->makeCurrent();
|
||||
}
|
||||
|
||||
// wglSwapIntervalEXT is per-context on Windows, so re-apply the cached interval
|
||||
// every time a different context becomes current. Without this, secondary swap
|
||||
// chains keep their driver default (typically vsync ON) even after resize().
|
||||
if (NULL != wglSwapIntervalEXT)
|
||||
{
|
||||
wglSwapIntervalEXT(m_swapInterval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user