OpenGLRenderer: Choose between OpenGL/OpenGL ES at loading

This commit is contained in:
Jérôme Leclercq
2021-11-02 09:13:12 +01:00
parent d872428658
commit 9946c17a23
7 changed files with 79 additions and 28 deletions

View File

@@ -81,14 +81,38 @@ namespace Nz::GL
const char* vendor = eglQueryString(m_defaultDisplay, EGL_VENDOR);
NazaraNotice("Initialized EGL " + std::to_string(major) + "." + std::to_string(minor) + " display (" + vendor + ")");
// Try to create a dummy context in order to check EGL support (FIXME: is this really necessary?)
/*ContextParams params;
EGLContextBase baseContext(nullptr, *this);
if (!baseContext.Create(params))
throw std::runtime_error("failed to create load context");
// Try to create a dummy context in order to check OpenGL / OpenGL ES support
if (!baseContext.Initialize(params))
throw std::runtime_error("failed to load OpenGL functions");*/
// Favor OpenGL on desktop and OpenGL ES on mobile
std::array<GL::ContextType, 2> contextTypes = {
#if defined(NAZARA_PLATFORM_DESKTOP)
GL::ContextType::OpenGL, GL::ContextType::OpenGL_ES
#else
GL::ContextType::OpenGL_ES, GL::ContextType::OpenGL
#endif
};
ContextParams params;
bool created = false;
for (GL::ContextType contextType : contextTypes)
{
params.type = contextType;
EGLContextBase baseContext(nullptr, *this);
if (!baseContext.Create(params) || baseContext.GetParams().type != contextType)
continue;
if (!baseContext.Initialize(params)) //< Is this really necessary?
continue;
created = true;
m_preferredContextType = contextType;
break;
}
if (!created)
throw std::runtime_error("failed to create or initialize base context");
}
EGLLoader::~EGLLoader()
@@ -170,6 +194,11 @@ namespace Nz::GL
return context;
}
ContextType EGLLoader::GetPreferredContextType() const
{
return m_preferredContextType;
}
GLFunction EGLLoader::LoadFunction(const char* name) const
{
GLFunction func = reinterpret_cast<GLFunction>(m_eglLib.GetSymbol(name));