libretro: Try for a GLES context first depending on preferred renderer

This commit is contained in:
Connor McLaughlin 2020-08-04 02:08:54 +10:00
parent e198e31598
commit 3df1670809
3 changed files with 37 additions and 10 deletions

View file

@ -824,8 +824,13 @@ bool LibretroHostInterface::RequestHardwareRendererContext()
break;
case GPURenderer::HardwareOpenGL:
m_hw_render_callback_valid = LibretroOpenGLHostDisplay::RequestHardwareRendererContext(&m_hw_render_callback);
break;
{
const bool prefer_gles =
(preferred_renderer == RETRO_HW_CONTEXT_OPENGLES2 || preferred_renderer == RETRO_HW_CONTEXT_OPENGLES_VERSION);
m_hw_render_callback_valid =
LibretroOpenGLHostDisplay::RequestHardwareRendererContext(&m_hw_render_callback, prefer_gles);
}
break;
default:
Log_ErrorPrintf("Unhandled renderer %s", Settings::GetRendererName(renderer));

View file

@ -23,15 +23,10 @@ void LibretroOpenGLHostDisplay::SetVSync(bool enabled)
Log_DevPrintf("Ignoring SetVSync(%u)", BoolToUInt32(enabled));
}
bool LibretroOpenGLHostDisplay::RequestHardwareRendererContext(retro_hw_render_callback* cb)
static bool TryDesktopVersions(retro_hw_render_callback* cb)
{
// Prefer a desktop OpenGL context where possible. If we can't get this, try OpenGL ES.
static constexpr std::array<std::tuple<u32, u32>, 11> desktop_versions_to_try = {
{/*{4, 6}, {4, 5}, {4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0}, {3, 3}, {3, 2}, */ {3, 1}, {3, 0}}};
static constexpr std::array<std::tuple<u32, u32>, 4> es_versions_to_try = {{{3, 2}, {3, 1}, {3, 0}}};
cb->cache_context = true;
cb->bottom_left_origin = true;
{/*{4, 6}, {4, 5}, {4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0}, */ {3, 3}, {3, 2}, {3, 1}, {3, 0}}};
for (const auto& [major, minor] : desktop_versions_to_try)
{
@ -52,6 +47,13 @@ bool LibretroOpenGLHostDisplay::RequestHardwareRendererContext(retro_hw_render_c
return true;
}
return false;
}
static bool TryESVersions(retro_hw_render_callback* cb)
{
static constexpr std::array<std::tuple<u32, u32>, 4> es_versions_to_try = {{{3, 2}, {3, 1}, {3, 0}}};
for (const auto& [major, minor] : es_versions_to_try)
{
if (major >= 3 && minor > 0)
@ -71,6 +73,26 @@ bool LibretroOpenGLHostDisplay::RequestHardwareRendererContext(retro_hw_render_c
return true;
}
return false;
}
bool LibretroOpenGLHostDisplay::RequestHardwareRendererContext(retro_hw_render_callback* cb, bool prefer_gles)
{
// Prefer a desktop OpenGL context where possible. If we can't get this, try OpenGL ES.
cb->cache_context = true;
cb->bottom_left_origin = true;
if (!prefer_gles)
{
if (TryDesktopVersions(cb) || TryESVersions(cb))
return true;
}
else
{
if (TryESVersions(cb) || TryDesktopVersions(cb))
return true;
}
Log_ErrorPrint("Failed to set any GL HW renderer");
return false;
}

View file

@ -13,7 +13,7 @@ public:
LibretroOpenGLHostDisplay();
~LibretroOpenGLHostDisplay();
static bool RequestHardwareRendererContext(retro_hw_render_callback* cb);
static bool RequestHardwareRendererContext(retro_hw_render_callback* cb, bool prefer_gles);
RenderAPI GetRenderAPI() const override;