From 8427a73c36f0755be8d9407636b75db574c315aa Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 24 Feb 2020 11:01:43 -0800 Subject: Enabled VSync control in GL backend (on Windows and Linux) --- Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.hpp | 2 +- Graphics/GraphicsEngineOpenGL/include/GLContextLinux.hpp | 2 +- Graphics/GraphicsEngineOpenGL/include/GLContextWindows.hpp | 2 +- Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp | 2 +- Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp | 9 ++++++++- Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp | 13 ++++++++++++- Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp | 2 +- 7 files changed, 25 insertions(+), 7 deletions(-) (limited to 'Graphics/GraphicsEngineOpenGL') diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.hpp b/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.hpp index e7d98d85..d50c7e51 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.hpp @@ -39,7 +39,7 @@ public: bool Init(ANativeWindow* window); - void SwapBuffers(); + void SwapBuffers(int SwapInterval); void UpdateScreenSize(); diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextLinux.hpp b/Graphics/GraphicsEngineOpenGL/include/GLContextLinux.hpp index 5e616492..abff9239 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLContextLinux.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/GLContextLinux.hpp @@ -33,7 +33,7 @@ public: GLContext(const struct EngineGLCreateInfo& InitAttribs, struct DeviceCaps& DeviceCaps, const struct SwapChainDesc* pSCDesc); ~GLContext(); - void SwapBuffers(); + void SwapBuffers(int SwapInterval); NativeGLContextType GetCurrentNativeGLContext(); diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.hpp b/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.hpp index 48c0a7ac..286e60e3 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.hpp @@ -37,7 +37,7 @@ public: GLContext(const struct EngineGLCreateInfo& InitAttribs, struct DeviceCaps& DeviceCaps, const struct SwapChainDesc* pSCDesc); ~GLContext(); - void SwapBuffers(); + void SwapBuffers(int SwapInterval); NativeGLContextType GetCurrentNativeGLContext(); diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp index 705124eb..233cc487 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp @@ -248,7 +248,7 @@ GLContext::~GLContext() Terminate(); } -void GLContext::SwapBuffers() +void GLContext::SwapBuffers(int /*SwapInterval*/) { if (surface_ == EGL_NO_SURFACE) { diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp index a8e2e852..dac8af2d 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp @@ -155,10 +155,17 @@ GLContext::~GLContext() { } -void GLContext::SwapBuffers() +void GLContext::SwapBuffers(int SwapInterval) { if (m_WindowId != 0 && m_pDisplay != nullptr) { +#if GLX_EXT_swap_control + if (glXSwapIntervalEXT != nullptr) + { + glXSwapIntervalEXT(SwapInterval); + } +#endif + auto wnd = static_cast(m_WindowId); auto display = reinterpret_cast(m_pDisplay); glXSwapBuffers(display, wnd); diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp index 2aef9128..754902d0 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp @@ -307,12 +307,23 @@ GLContext::~GLContext() } } -void GLContext::SwapBuffers() +void GLContext::SwapBuffers(int SwapInterval) { if (m_WindowHandleToDeviceContext) + { +#if WGL_EXT_swap_control + if (wglSwapIntervalEXT != nullptr) + { + wglSwapIntervalEXT(SwapInterval); + } +#endif + ::SwapBuffers(m_WindowHandleToDeviceContext); + } else + { LOG_ERROR("Swap buffer failed because window handle to device context is not initialized"); + } } GLContext::NativeGLContextType GLContext::GetCurrentNativeGLContext() diff --git a/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp index 7c0dcfa8..a9af9b5d 100644 --- a/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp @@ -88,7 +88,7 @@ void SwapChainGLImpl::Present(Uint32 SyncInterval) #if PLATFORM_WIN32 || PLATFORM_LINUX || PLATFORM_ANDROID auto* pDeviceGL = m_pRenderDevice.RawPtr(); auto& GLContext = pDeviceGL->m_GLContext; - GLContext.SwapBuffers(); + GLContext.SwapBuffers(static_cast(SyncInterval)); #elif PLATFORM_MACOS LOG_ERROR("Swap buffers operation must be performed by the app on MacOS"); #else -- cgit v1.2.3