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

@@ -50,12 +50,32 @@ namespace Nz::GL
throw std::runtime_error("failed to create load context");
ContextParams params;
// 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
};
if (!m_baseContext.Create(&loadContext, params))
throw std::runtime_error("failed to create load context");
bool created = false;
for (GL::ContextType contextType : contextTypes)
{
params.type = contextType;
if (!m_baseContext.Initialize(params))
throw std::runtime_error("failed to load OpenGL functions");
if (!m_baseContext.Create(&loadContext, params) || m_baseContext.GetParams().type != contextType)
continue;
if (!m_baseContext.Initialize(params))
continue;
created = true;
break;
}
if (!created)
throw std::runtime_error("failed to create or initialize base context");
}
std::unique_ptr<Context> WGLLoader::CreateContext(const OpenGLDevice* device, const ContextParams& params, Context* shareContext) const
@@ -94,6 +114,11 @@ namespace Nz::GL
return context;
}
ContextType WGLLoader::GetPreferredContextType() const
{
return m_baseContext.GetParams().type;
}
GLFunction WGLLoader::LoadFunction(const char* name) const
{
GLFunction func = reinterpret_cast<GLFunction>(wglGetProcAddress(name));