From dfdbc9a8ce3e7ca05b639924365b92a51839e977 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 8 Dec 2022 13:17:20 +1000 Subject: [PATCH] OpenGLHostDisplay: Update sync interval on MakeCurrent() --- src/common/gl/context.h | 1 + src/common/gl/context_agl.h | 1 + src/common/gl/context_agl.mm | 5 +++++ src/common/gl/context_egl.cpp | 5 +++++ src/common/gl/context_egl.h | 1 + src/common/gl/context_glx.cpp | 5 +++++ src/common/gl/context_glx.h | 1 + src/common/gl/context_wgl.cpp | 5 +++++ src/common/gl/context_wgl.h | 1 + src/frontend-common/opengl_host_display.cpp | 6 ++++-- 10 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/common/gl/context.h b/src/common/gl/context.h index f24478658..f4c90311c 100644 --- a/src/common/gl/context.h +++ b/src/common/gl/context.h @@ -46,6 +46,7 @@ public: virtual bool ChangeSurface(const WindowInfo& new_wi) = 0; virtual void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) = 0; virtual bool SwapBuffers() = 0; + virtual bool IsCurrent() = 0; virtual bool MakeCurrent() = 0; virtual bool DoneCurrent() = 0; virtual bool SetSwapInterval(s32 interval) = 0; diff --git a/src/common/gl/context_agl.h b/src/common/gl/context_agl.h index 2fb502e0a..f26547e33 100644 --- a/src/common/gl/context_agl.h +++ b/src/common/gl/context_agl.h @@ -29,6 +29,7 @@ public: bool ChangeSurface(const WindowInfo& new_wi) override; void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override; bool SwapBuffers() override; + bool IsCurrent() override; bool MakeCurrent() override; bool DoneCurrent() override; bool SetSwapInterval(s32 interval) override; diff --git a/src/common/gl/context_agl.mm b/src/common/gl/context_agl.mm index ec6b729c1..96ab9b135 100644 --- a/src/common/gl/context_agl.mm +++ b/src/common/gl/context_agl.mm @@ -121,6 +121,11 @@ bool ContextAGL::SwapBuffers() return true; } +bool ContextAGL::IsCurrent() +{ + return (m_context != nil && [NSOpenGLContext currentContext] == m_context); +} + bool ContextAGL::MakeCurrent() { [m_context makeCurrentContext]; diff --git a/src/common/gl/context_egl.cpp b/src/common/gl/context_egl.cpp index db321edde..8bf4ca040 100644 --- a/src/common/gl/context_egl.cpp +++ b/src/common/gl/context_egl.cpp @@ -133,6 +133,11 @@ bool ContextEGL::SwapBuffers() return eglSwapBuffers(m_display, m_surface); } +bool ContextEGL::IsCurrent() +{ + return m_context && eglGetCurrentContext() == m_context; +} + bool ContextEGL::MakeCurrent() { if (!eglMakeCurrent(m_display, m_surface, m_surface, m_context)) diff --git a/src/common/gl/context_egl.h b/src/common/gl/context_egl.h index 8d7e99396..eb228d855 100644 --- a/src/common/gl/context_egl.h +++ b/src/common/gl/context_egl.h @@ -20,6 +20,7 @@ public: virtual bool ChangeSurface(const WindowInfo& new_wi) override; virtual void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override; bool SwapBuffers() override; + bool IsCurrent() override; bool MakeCurrent() override; bool DoneCurrent() override; bool SetSwapInterval(s32 interval) override; diff --git a/src/common/gl/context_glx.cpp b/src/common/gl/context_glx.cpp index 29b2564dd..568e715c4 100644 --- a/src/common/gl/context_glx.cpp +++ b/src/common/gl/context_glx.cpp @@ -123,6 +123,11 @@ bool ContextGLX::SwapBuffers() return true; } +bool ContextGLX::IsCurrent() +{ + return (m_context && glXGetCurrentContext() == m_context); +} + bool ContextGLX::MakeCurrent() { return (glXMakeContextCurrent(GetDisplay(), GetDrawable(), GetDrawable(), m_context) == True); diff --git a/src/common/gl/context_glx.h b/src/common/gl/context_glx.h index b28f984a7..5ed48a9e3 100644 --- a/src/common/gl/context_glx.h +++ b/src/common/gl/context_glx.h @@ -21,6 +21,7 @@ public: bool ChangeSurface(const WindowInfo& new_wi) override; void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override; bool SwapBuffers() override; + bool IsCurrent() override; bool MakeCurrent() override; bool DoneCurrent() override; bool SetSwapInterval(s32 interval) override; diff --git a/src/common/gl/context_wgl.cpp b/src/common/gl/context_wgl.cpp index 6a05269e8..2b5d22b74 100644 --- a/src/common/gl/context_wgl.cpp +++ b/src/common/gl/context_wgl.cpp @@ -129,6 +129,11 @@ bool ContextWGL::SwapBuffers() return ::SwapBuffers(m_dc); } +bool ContextWGL::IsCurrent() +{ + return (m_rc && wglGetCurrentContext() == m_rc); +} + bool ContextWGL::MakeCurrent() { if (!wglMakeCurrent(m_dc, m_rc)) diff --git a/src/common/gl/context_wgl.h b/src/common/gl/context_wgl.h index b4692bd96..6a032b5a1 100644 --- a/src/common/gl/context_wgl.h +++ b/src/common/gl/context_wgl.h @@ -24,6 +24,7 @@ public: bool ChangeSurface(const WindowInfo& new_wi) override; void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override; bool SwapBuffers() override; + bool IsCurrent() override; bool MakeCurrent() override; bool DoneCurrent() override; bool SetSwapInterval(s32 interval) override; diff --git a/src/frontend-common/opengl_host_display.cpp b/src/frontend-common/opengl_host_display.cpp index c7b6f633e..cab46fce1 100644 --- a/src/frontend-common/opengl_host_display.cpp +++ b/src/frontend-common/opengl_host_display.cpp @@ -328,7 +328,6 @@ bool OpenGLHostDisplay::SetupDevice() if (!CreateResources()) return false; - SetSwapInterval(); return true; } @@ -340,6 +339,7 @@ bool OpenGLHostDisplay::MakeCurrent() return false; } + SetSwapInterval(); return true; } @@ -361,7 +361,9 @@ bool OpenGLHostDisplay::ChangeWindow(const WindowInfo& new_wi) m_window_info = m_gl_context->GetWindowInfo(); // Update swap interval for new surface. - SetSwapInterval(); + if (m_gl_context->IsCurrent()) + SetSwapInterval(); + return true; }