OpenGLHostDisplay: Update sync interval on MakeCurrent()

This commit is contained in:
Connor McLaughlin 2022-12-08 13:17:20 +10:00
parent 9d23df3aba
commit dfdbc9a8ce
10 changed files with 29 additions and 2 deletions

View file

@ -46,6 +46,7 @@ public:
virtual bool ChangeSurface(const WindowInfo& new_wi) = 0; virtual bool ChangeSurface(const WindowInfo& new_wi) = 0;
virtual void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) = 0; virtual void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) = 0;
virtual bool SwapBuffers() = 0; virtual bool SwapBuffers() = 0;
virtual bool IsCurrent() = 0;
virtual bool MakeCurrent() = 0; virtual bool MakeCurrent() = 0;
virtual bool DoneCurrent() = 0; virtual bool DoneCurrent() = 0;
virtual bool SetSwapInterval(s32 interval) = 0; virtual bool SetSwapInterval(s32 interval) = 0;

View file

@ -29,6 +29,7 @@ public:
bool ChangeSurface(const WindowInfo& new_wi) override; bool ChangeSurface(const WindowInfo& new_wi) override;
void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override; void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override;
bool SwapBuffers() override; bool SwapBuffers() override;
bool IsCurrent() override;
bool MakeCurrent() override; bool MakeCurrent() override;
bool DoneCurrent() override; bool DoneCurrent() override;
bool SetSwapInterval(s32 interval) override; bool SetSwapInterval(s32 interval) override;

View file

@ -121,6 +121,11 @@ bool ContextAGL::SwapBuffers()
return true; return true;
} }
bool ContextAGL::IsCurrent()
{
return (m_context != nil && [NSOpenGLContext currentContext] == m_context);
}
bool ContextAGL::MakeCurrent() bool ContextAGL::MakeCurrent()
{ {
[m_context makeCurrentContext]; [m_context makeCurrentContext];

View file

@ -133,6 +133,11 @@ bool ContextEGL::SwapBuffers()
return eglSwapBuffers(m_display, m_surface); return eglSwapBuffers(m_display, m_surface);
} }
bool ContextEGL::IsCurrent()
{
return m_context && eglGetCurrentContext() == m_context;
}
bool ContextEGL::MakeCurrent() bool ContextEGL::MakeCurrent()
{ {
if (!eglMakeCurrent(m_display, m_surface, m_surface, m_context)) if (!eglMakeCurrent(m_display, m_surface, m_surface, m_context))

View file

@ -20,6 +20,7 @@ public:
virtual bool ChangeSurface(const WindowInfo& new_wi) override; virtual bool ChangeSurface(const WindowInfo& new_wi) override;
virtual void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override; virtual void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override;
bool SwapBuffers() override; bool SwapBuffers() override;
bool IsCurrent() override;
bool MakeCurrent() override; bool MakeCurrent() override;
bool DoneCurrent() override; bool DoneCurrent() override;
bool SetSwapInterval(s32 interval) override; bool SetSwapInterval(s32 interval) override;

View file

@ -123,6 +123,11 @@ bool ContextGLX::SwapBuffers()
return true; return true;
} }
bool ContextGLX::IsCurrent()
{
return (m_context && glXGetCurrentContext() == m_context);
}
bool ContextGLX::MakeCurrent() bool ContextGLX::MakeCurrent()
{ {
return (glXMakeContextCurrent(GetDisplay(), GetDrawable(), GetDrawable(), m_context) == True); return (glXMakeContextCurrent(GetDisplay(), GetDrawable(), GetDrawable(), m_context) == True);

View file

@ -21,6 +21,7 @@ public:
bool ChangeSurface(const WindowInfo& new_wi) override; bool ChangeSurface(const WindowInfo& new_wi) override;
void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override; void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override;
bool SwapBuffers() override; bool SwapBuffers() override;
bool IsCurrent() override;
bool MakeCurrent() override; bool MakeCurrent() override;
bool DoneCurrent() override; bool DoneCurrent() override;
bool SetSwapInterval(s32 interval) override; bool SetSwapInterval(s32 interval) override;

View file

@ -129,6 +129,11 @@ bool ContextWGL::SwapBuffers()
return ::SwapBuffers(m_dc); return ::SwapBuffers(m_dc);
} }
bool ContextWGL::IsCurrent()
{
return (m_rc && wglGetCurrentContext() == m_rc);
}
bool ContextWGL::MakeCurrent() bool ContextWGL::MakeCurrent()
{ {
if (!wglMakeCurrent(m_dc, m_rc)) if (!wglMakeCurrent(m_dc, m_rc))

View file

@ -24,6 +24,7 @@ public:
bool ChangeSurface(const WindowInfo& new_wi) override; bool ChangeSurface(const WindowInfo& new_wi) override;
void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override; void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override;
bool SwapBuffers() override; bool SwapBuffers() override;
bool IsCurrent() override;
bool MakeCurrent() override; bool MakeCurrent() override;
bool DoneCurrent() override; bool DoneCurrent() override;
bool SetSwapInterval(s32 interval) override; bool SetSwapInterval(s32 interval) override;

View file

@ -328,7 +328,6 @@ bool OpenGLHostDisplay::SetupDevice()
if (!CreateResources()) if (!CreateResources())
return false; return false;
SetSwapInterval();
return true; return true;
} }
@ -340,6 +339,7 @@ bool OpenGLHostDisplay::MakeCurrent()
return false; return false;
} }
SetSwapInterval();
return true; return true;
} }
@ -361,7 +361,9 @@ bool OpenGLHostDisplay::ChangeWindow(const WindowInfo& new_wi)
m_window_info = m_gl_context->GetWindowInfo(); m_window_info = m_gl_context->GetWindowInfo();
// Update swap interval for new surface. // Update swap interval for new surface.
SetSwapInterval(); if (m_gl_context->IsCurrent())
SetSwapInterval();
return true; return true;
} }