diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-02-24 19:01:43 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-02-24 19:01:43 +0000 |
| commit | 8427a73c36f0755be8d9407636b75db574c315aa (patch) | |
| tree | 7b4923a541dc32116190fc5d1b7fef9943ec2c7f /Graphics/GraphicsEngineOpenGL | |
| parent | CMake: setting C_STANDARD to 11 in set_common_target_properties (diff) | |
| download | DiligentCore-8427a73c36f0755be8d9407636b75db574c315aa.tar.gz DiligentCore-8427a73c36f0755be8d9407636b75db574c315aa.zip | |
Enabled VSync control in GL backend (on Windows and Linux)
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
7 files changed, 25 insertions, 7 deletions
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<Window>(m_WindowId); auto display = reinterpret_cast<Display*>(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<RenderDeviceGLImpl>(); auto& GLContext = pDeviceGL->m_GLContext; - GLContext.SwapBuffers(); + GLContext.SwapBuffers(static_cast<int>(SyncInterval)); #elif PLATFORM_MACOS LOG_ERROR("Swap buffers operation must be performed by the app on MacOS"); #else |
