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 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;

View File

@ -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;

View File

@ -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];

View File

@ -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))

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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))

View File

@ -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;

View File

@ -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;
}