mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-02-16 19:05:39 +00:00
OpenGLContext: Add SupportsNegativeSwapInterval()
This commit is contained in:
parent
7b93edada1
commit
2ad67ad3ee
|
@ -50,9 +50,10 @@ 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 IsCurrent() const = 0;
|
||||||
virtual bool MakeCurrent() = 0;
|
virtual bool MakeCurrent() = 0;
|
||||||
virtual bool DoneCurrent() = 0;
|
virtual bool DoneCurrent() = 0;
|
||||||
|
virtual bool SupportsNegativeSwapInterval() const = 0;
|
||||||
virtual bool SetSwapInterval(s32 interval) = 0;
|
virtual bool SetSwapInterval(s32 interval) = 0;
|
||||||
virtual std::unique_ptr<OpenGLContext> CreateSharedContext(const WindowInfo& wi, Error* error) = 0;
|
virtual std::unique_ptr<OpenGLContext> CreateSharedContext(const WindowInfo& wi, Error* error) = 0;
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,10 @@ 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 IsCurrent() const override;
|
||||||
bool MakeCurrent() override;
|
bool MakeCurrent() override;
|
||||||
bool DoneCurrent() override;
|
bool DoneCurrent() override;
|
||||||
|
bool SupportsNegativeSwapInterval() const override;
|
||||||
bool SetSwapInterval(s32 interval) override;
|
bool SetSwapInterval(s32 interval) override;
|
||||||
std::unique_ptr<OpenGLContext> CreateSharedContext(const WindowInfo& wi, Error* error) override;
|
std::unique_ptr<OpenGLContext> CreateSharedContext(const WindowInfo& wi, Error* error) override;
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ bool OpenGLContextAGL::SwapBuffers()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenGLContextAGL::IsCurrent()
|
bool OpenGLContextAGL::IsCurrent() const
|
||||||
{
|
{
|
||||||
return (m_context != nil && [NSOpenGLContext currentContext] == m_context);
|
return (m_context != nil && [NSOpenGLContext currentContext] == m_context);
|
||||||
}
|
}
|
||||||
|
@ -140,6 +140,11 @@ bool OpenGLContextAGL::DoneCurrent()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OpenGLContextAGL::SupportsNegativeSwapInterval() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool OpenGLContextAGL::SetSwapInterval(s32 interval)
|
bool OpenGLContextAGL::SetSwapInterval(s32 interval)
|
||||||
{
|
{
|
||||||
GLint gl_interval = static_cast<GLint>(interval);
|
GLint gl_interval = static_cast<GLint>(interval);
|
||||||
|
|
|
@ -291,7 +291,7 @@ bool OpenGLContextEGL::SwapBuffers()
|
||||||
return eglSwapBuffers(m_display, m_surface);
|
return eglSwapBuffers(m_display, m_surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenGLContextEGL::IsCurrent()
|
bool OpenGLContextEGL::IsCurrent() const
|
||||||
{
|
{
|
||||||
return m_context && eglGetCurrentContext() == m_context;
|
return m_context && eglGetCurrentContext() == m_context;
|
||||||
}
|
}
|
||||||
|
@ -312,6 +312,11 @@ bool OpenGLContextEGL::DoneCurrent()
|
||||||
return eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
return eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OpenGLContextEGL::SupportsNegativeSwapInterval() const
|
||||||
|
{
|
||||||
|
return m_supports_negative_swap_interval;
|
||||||
|
}
|
||||||
|
|
||||||
bool OpenGLContextEGL::SetSwapInterval(s32 interval)
|
bool OpenGLContextEGL::SetSwapInterval(s32 interval)
|
||||||
{
|
{
|
||||||
return eglSwapInterval(m_display, interval);
|
return eglSwapInterval(m_display, interval);
|
||||||
|
@ -473,10 +478,10 @@ void OpenGLContextEGL::DestroySurface()
|
||||||
|
|
||||||
bool OpenGLContextEGL::CreateContext(const Version& version, EGLContext share_context)
|
bool OpenGLContextEGL::CreateContext(const Version& version, EGLContext share_context)
|
||||||
{
|
{
|
||||||
Log_DevPrintf("Trying version %u.%u (%s)", version.major_version, version.minor_version,
|
Log_DevFmt("Trying version {}.{} ({})", version.major_version, version.minor_version,
|
||||||
version.profile == OpenGLContext::Profile::ES ?
|
version.profile == OpenGLContext::Profile::ES ?
|
||||||
"ES" :
|
"ES" :
|
||||||
(version.profile == OpenGLContext::Profile::Core ? "Core" : "None"));
|
(version.profile == OpenGLContext::Profile::Core ? "Core" : "None"));
|
||||||
int surface_attribs[16] = {
|
int surface_attribs[16] = {
|
||||||
EGL_RENDERABLE_TYPE,
|
EGL_RENDERABLE_TYPE,
|
||||||
(version.profile == Profile::ES) ?
|
(version.profile == Profile::ES) ?
|
||||||
|
@ -531,14 +536,14 @@ bool OpenGLContextEGL::CreateContext(const Version& version, EGLContext share_co
|
||||||
EGLint num_configs;
|
EGLint num_configs;
|
||||||
if (!eglChooseConfig(m_display, surface_attribs, nullptr, 0, &num_configs) || num_configs == 0)
|
if (!eglChooseConfig(m_display, surface_attribs, nullptr, 0, &num_configs) || num_configs == 0)
|
||||||
{
|
{
|
||||||
Log_ErrorPrintf("eglChooseConfig() failed: %d", eglGetError());
|
Log_ErrorFmt("eglChooseConfig() failed: 0x{:x}", static_cast<unsigned>(eglGetError()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<EGLConfig> configs(static_cast<u32>(num_configs));
|
std::vector<EGLConfig> configs(static_cast<u32>(num_configs));
|
||||||
if (!eglChooseConfig(m_display, surface_attribs, configs.data(), num_configs, &num_configs))
|
if (!eglChooseConfig(m_display, surface_attribs, configs.data(), num_configs, &num_configs))
|
||||||
{
|
{
|
||||||
Log_ErrorPrintf("eglChooseConfig() failed: %d", eglGetError());
|
Log_ErrorFmt("eglChooseConfig() failed: 0x{:x}", static_cast<unsigned>(eglGetError()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
configs.resize(static_cast<u32>(num_configs));
|
configs.resize(static_cast<u32>(num_configs));
|
||||||
|
@ -555,7 +560,7 @@ bool OpenGLContextEGL::CreateContext(const Version& version, EGLContext share_co
|
||||||
|
|
||||||
if (!config.has_value())
|
if (!config.has_value())
|
||||||
{
|
{
|
||||||
Log_WarningPrintf("No EGL configs matched exactly, using first.");
|
Log_WarningPrint("No EGL configs matched exactly, using first.");
|
||||||
config = configs.front();
|
config = configs.front();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,21 +578,33 @@ bool OpenGLContextEGL::CreateContext(const Version& version, EGLContext share_co
|
||||||
|
|
||||||
if (!eglBindAPI((version.profile == Profile::ES) ? EGL_OPENGL_ES_API : EGL_OPENGL_API))
|
if (!eglBindAPI((version.profile == Profile::ES) ? EGL_OPENGL_ES_API : EGL_OPENGL_API))
|
||||||
{
|
{
|
||||||
Log_ErrorPrintf("eglBindAPI(%s) failed", (version.profile == Profile::ES) ? "EGL_OPENGL_ES_API" : "EGL_OPENGL_API");
|
Log_ErrorFmt("eglBindAPI({}) failed", (version.profile == Profile::ES) ? "EGL_OPENGL_ES_API" : "EGL_OPENGL_API");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_context = eglCreateContext(m_display, config.value(), share_context, attribs);
|
m_context = eglCreateContext(m_display, config.value(), share_context, attribs);
|
||||||
if (!m_context)
|
if (!m_context)
|
||||||
{
|
{
|
||||||
Log_ErrorPrintf("eglCreateContext() failed: %d", eglGetError());
|
Log_ErrorFmt("eglCreateContext() failed: 0x{:x}", static_cast<unsigned>(eglGetError()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log_InfoPrintf("Got version %u.%u (%s)", version.major_version, version.minor_version,
|
Log_InfoFmt("Got version {}.{} ({})", version.major_version, version.minor_version,
|
||||||
version.profile == OpenGLContext::Profile::ES ?
|
version.profile == OpenGLContext::Profile::ES ?
|
||||||
"ES" :
|
"ES" :
|
||||||
(version.profile == OpenGLContext::Profile::Core ? "Core" : "None"));
|
(version.profile == OpenGLContext::Profile::Core ? "Core" : "None"));
|
||||||
|
|
||||||
|
EGLint min_swap_interval, max_swap_interval;
|
||||||
|
m_supports_negative_swap_interval = false;
|
||||||
|
if (eglGetConfigAttrib(m_display, config.value(), EGL_MIN_SWAP_INTERVAL, &min_swap_interval) &&
|
||||||
|
eglGetConfigAttrib(m_display, config.value(), EGL_MAX_SWAP_INTERVAL, &max_swap_interval))
|
||||||
|
{
|
||||||
|
Log_VerboseFmt("EGL_MIN_SWAP_INTERVAL = {}", min_swap_interval);
|
||||||
|
Log_VerboseFmt("EGL_MAX_SWAP_INTERVAL = {}", max_swap_interval);
|
||||||
|
m_supports_negative_swap_interval = (min_swap_interval <= -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log_InfoFmt("Negative swap interval/tear-control is {}supported", m_supports_negative_swap_interval ? "" : "NOT ");
|
||||||
|
|
||||||
m_config = config.value();
|
m_config = config.value();
|
||||||
m_version = version;
|
m_version = version;
|
||||||
|
|
|
@ -20,9 +20,10 @@ 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 IsCurrent() const override;
|
||||||
bool MakeCurrent() override;
|
bool MakeCurrent() override;
|
||||||
bool DoneCurrent() override;
|
bool DoneCurrent() override;
|
||||||
|
bool SupportsNegativeSwapInterval() const override;
|
||||||
bool SetSwapInterval(s32 interval) override;
|
bool SetSwapInterval(s32 interval) override;
|
||||||
virtual std::unique_ptr<OpenGLContext> CreateSharedContext(const WindowInfo& wi, Error* error) override;
|
virtual std::unique_ptr<OpenGLContext> CreateSharedContext(const WindowInfo& wi, Error* error) override;
|
||||||
|
|
||||||
|
@ -52,4 +53,5 @@ protected:
|
||||||
EGLConfig m_config = {};
|
EGLConfig m_config = {};
|
||||||
|
|
||||||
bool m_use_ext_platform_base = false;
|
bool m_use_ext_platform_base = false;
|
||||||
|
bool m_supports_negative_swap_interval = false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -160,6 +160,11 @@ bool OpenGLContextWGL::DoneCurrent()
|
||||||
return wglMakeCurrent(m_dc, nullptr);
|
return wglMakeCurrent(m_dc, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OpenGLContextWGL::SupportsNegativeSwapInterval() const
|
||||||
|
{
|
||||||
|
return GLAD_WGL_EXT_swap_control && GLAD_WGL_EXT_swap_control_tear;
|
||||||
|
}
|
||||||
|
|
||||||
bool OpenGLContextWGL::SetSwapInterval(s32 interval)
|
bool OpenGLContextWGL::SetSwapInterval(s32 interval)
|
||||||
{
|
{
|
||||||
if (!GLAD_WGL_EXT_swap_control)
|
if (!GLAD_WGL_EXT_swap_control)
|
||||||
|
|
|
@ -25,9 +25,10 @@ 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 IsCurrent() const override;
|
||||||
bool MakeCurrent() override;
|
bool MakeCurrent() override;
|
||||||
bool DoneCurrent() override;
|
bool DoneCurrent() override;
|
||||||
|
bool SupportsNegativeSwapInterval() const override;
|
||||||
bool SetSwapInterval(s32 interval) override;
|
bool SetSwapInterval(s32 interval) override;
|
||||||
std::unique_ptr<OpenGLContext> CreateSharedContext(const WindowInfo& wi, Error* error) override;
|
std::unique_ptr<OpenGLContext> CreateSharedContext(const WindowInfo& wi, Error* error) override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue