Renderer: Split OpenGL and OpenGL ES in two RenderAPI enums

This commit is contained in:
SirLynix
2022-12-25 16:11:28 +01:00
parent fe69cc0d27
commit e4064997d8
9 changed files with 75 additions and 30 deletions

View File

@@ -55,7 +55,7 @@ namespace Nz
bool OpenGLRenderer::Prepare(const Renderer::Config& config)
{
std::unique_ptr<GL::Loader> loader = SelectLoader();
std::unique_ptr<GL::Loader> loader = SelectLoader(config);
if (!loader)
{
NazaraError("Failed to initialize OpenGL loader");
@@ -70,12 +70,12 @@ namespace Nz
return true;
}
std::unique_ptr<GL::Loader> OpenGLRenderer::SelectLoader()
std::unique_ptr<GL::Loader> OpenGLRenderer::SelectLoader(const Renderer::Config& config)
{
#ifdef NAZARA_PLATFORM_WINDOWS
try
{
return std::make_unique<GL::WGLLoader>();
return std::make_unique<GL::WGLLoader>(config);
}
catch (const std::exception& e)
{
@@ -86,7 +86,7 @@ namespace Nz
#if defined(NAZARA_PLATFORM_WINDOWS) || defined(NAZARA_PLATFORM_LINUX)
try
{
return std::make_unique<GL::EGLLoader>();
return std::make_unique<GL::EGLLoader>(config);
}
catch (const std::exception& e)
{
@@ -99,13 +99,19 @@ namespace Nz
RenderAPI OpenGLRenderer::QueryAPI() const
{
return RenderAPI::OpenGL;
return (m_device->GetReferenceContext().GetParams().type == GL::ContextType::OpenGL) ? RenderAPI::OpenGL : RenderAPI::OpenGL_ES;
}
std::string OpenGLRenderer::QueryAPIString() const
{
const auto& params = m_device->GetReferenceContext().GetParams();
std::ostringstream ss;
ss << "OpenGL ES renderer 3.0";
ss << "OpenGL";
if (params.type == GL::ContextType::OpenGL_ES)
ss << " ES";
ss << " renderer " << params.glMajorVersion << "." << params.glMinorVersion;
return ss.str();
}

View File

@@ -52,7 +52,7 @@ namespace Nz::GL
EGLLoader& loader;
};
EGLLoader::EGLLoader() :
EGLLoader::EGLLoader(const Renderer::Config& config) :
m_defaultDisplay(nullptr)
{
if (!m_eglLib.Load("libEGL"))
@@ -80,14 +80,29 @@ namespace Nz::GL
// Try to create a dummy context in order to check OpenGL / OpenGL ES support
// Favor OpenGL on desktop and OpenGL ES on mobile
std::array<GL::ContextType, 2> contextTypes = {
std::array<GL::ContextType, 2> contextTypes;
RenderAPI preferredAPI = config.preferredAPI;
if (preferredAPI == RenderAPI::Unknown)
{
// Favor OpenGL on desktop and OpenGL ES on mobile
#if defined(NAZARA_PLATFORM_DESKTOP)
GL::ContextType::OpenGL, GL::ContextType::OpenGL_ES
preferredAPI = RenderAPI::OpenGL;
#else
GL::ContextType::OpenGL_ES, GL::ContextType::OpenGL
preferredAPI = RenderAPI::OpenGL_ES;
#endif
};
}
if (config.preferredAPI == RenderAPI::OpenGL_ES)
{
contextTypes[0] = GL::ContextType::OpenGL_ES;
contextTypes[1] = GL::ContextType::OpenGL;
}
else
{
contextTypes[0] = GL::ContextType::OpenGL;
contextTypes[1] = GL::ContextType::OpenGL_ES;
}
ContextParams params;

View File

@@ -9,7 +9,7 @@
namespace Nz::GL
{
WGLLoader::WGLLoader() :
WGLLoader::WGLLoader(const Renderer::Config& config) :
m_baseContext(nullptr, *this)
{
if (!m_opengl32Lib.Load("opengl32" NAZARA_DYNLIB_EXTENSION))
@@ -50,14 +50,29 @@ 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 = {
std::array<GL::ContextType, 2> contextTypes;
RenderAPI preferredAPI = config.preferredAPI;
if (preferredAPI == RenderAPI::Unknown)
{
// Favor OpenGL on desktop and OpenGL ES on mobile
#if defined(NAZARA_PLATFORM_DESKTOP)
GL::ContextType::OpenGL, GL::ContextType::OpenGL_ES
preferredAPI = RenderAPI::OpenGL;
#else
GL::ContextType::OpenGL_ES, GL::ContextType::OpenGL
preferredAPI = RenderAPI::OpenGL_ES;
#endif
};
}
if (config.preferredAPI == RenderAPI::OpenGL_ES)
{
contextTypes[0] = GL::ContextType::OpenGL_ES;
contextTypes[1] = GL::ContextType::OpenGL;
}
else
{
contextTypes[0] = GL::ContextType::OpenGL;
contextTypes[1] = GL::ContextType::OpenGL_ES;
}
bool created = false;
for (GL::ContextType contextType : contextTypes)