Renderer: Split OpenGL and OpenGL ES in two RenderAPI enums
This commit is contained in:
parent
fe69cc0d27
commit
e4064997d8
|
|
@ -35,7 +35,7 @@ namespace Nz
|
||||||
bool Prepare(const Renderer::Config& config) override;
|
bool Prepare(const Renderer::Config& config) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<GL::Loader> SelectLoader();
|
std::unique_ptr<GL::Loader> SelectLoader(const Renderer::Config& config);
|
||||||
|
|
||||||
std::shared_ptr<OpenGLDevice> m_device;
|
std::shared_ptr<OpenGLDevice> m_device;
|
||||||
std::unique_ptr<GL::Loader> m_loader;
|
std::unique_ptr<GL::Loader> m_loader;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include <Nazara/OpenGLRenderer/Config.hpp>
|
#include <Nazara/OpenGLRenderer/Config.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/Loader.hpp>
|
#include <Nazara/OpenGLRenderer/Wrapper/Loader.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/EGL/EGLContextBase.hpp>
|
#include <Nazara/OpenGLRenderer/Wrapper/EGL/EGLContextBase.hpp>
|
||||||
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Nz::GL
|
namespace Nz::GL
|
||||||
|
|
@ -21,7 +22,7 @@ namespace Nz::GL
|
||||||
friend SymbolLoader;
|
friend SymbolLoader;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EGLLoader();
|
EGLLoader(const Renderer::Config& config);
|
||||||
~EGLLoader();
|
~EGLLoader();
|
||||||
|
|
||||||
std::unique_ptr<Context> CreateContext(const OpenGLDevice* device, const ContextParams& params, Context* shareContext) const override;
|
std::unique_ptr<Context> CreateContext(const OpenGLDevice* device, const ContextParams& params, Context* shareContext) const override;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/Loader.hpp>
|
#include <Nazara/OpenGLRenderer/Wrapper/Loader.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/WGL/WGLContext.hpp>
|
#include <Nazara/OpenGLRenderer/Wrapper/WGL/WGLContext.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/WGL/WGLFunctions.hpp>
|
#include <Nazara/OpenGLRenderer/Wrapper/WGL/WGLFunctions.hpp>
|
||||||
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Nz::GL
|
namespace Nz::GL
|
||||||
|
|
@ -20,7 +21,7 @@ namespace Nz::GL
|
||||||
class NAZARA_OPENGLRENDERER_API WGLLoader : public Loader
|
class NAZARA_OPENGLRENDERER_API WGLLoader : public Loader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WGLLoader();
|
WGLLoader(const Renderer::Config& config);
|
||||||
~WGLLoader() = default;
|
~WGLLoader() = default;
|
||||||
|
|
||||||
std::unique_ptr<Context> CreateContext(const OpenGLDevice* device, const ContextParams& params, Context* shareContext) const override;
|
std::unique_ptr<Context> CreateContext(const OpenGLDevice* device, const ContextParams& params, Context* shareContext) const override;
|
||||||
|
|
|
||||||
|
|
@ -127,13 +127,14 @@ namespace Nz
|
||||||
|
|
||||||
enum class RenderAPI
|
enum class RenderAPI
|
||||||
{
|
{
|
||||||
Direct3D, ///< Microsoft Render API, only works on MS platforms
|
Direct3D, //< Microsoft Render API, only works on MS platforms
|
||||||
Mantle, ///< AMD Render API, Vulkan predecessor, only works on AMD GPUs
|
Mantle, //< AMD Render API, Vulkan predecessor, only works on AMD GPUs
|
||||||
Metal, ///< Apple Render API, only works on OS X platforms
|
Metal, //< Apple Render API, only works on OS X platforms
|
||||||
OpenGL, ///< Khronos Render API, works on Web/Desktop/Mobile and some consoles
|
OpenGL, //< Khronos Render API, works on Desktop and some consoles
|
||||||
Vulkan, ///< New Khronos Render API, made to replace OpenGL, works on desktop (Windows/Linux) and mobile (Android), and Apple platform using MoltenVK
|
OpenGL_ES, //< Khronos Render API, works on Web, Mobile and some consoles
|
||||||
|
Vulkan, //< New Khronos Render API, made to replace OpenGL, works on desktop (Windows/Linux) and mobile (Android), and Apple platform using MoltenVK
|
||||||
|
|
||||||
Unknown, ///< RenderAPI not corresponding to an entry of the enum, or result of a failed query
|
Unknown, //< RenderAPI not corresponding to an entry of the enum, or result of a failed query
|
||||||
|
|
||||||
Max = Unknown
|
Max = Unknown
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ namespace Nz
|
||||||
|
|
||||||
bool OpenGLRenderer::Prepare(const Renderer::Config& config)
|
bool OpenGLRenderer::Prepare(const Renderer::Config& config)
|
||||||
{
|
{
|
||||||
std::unique_ptr<GL::Loader> loader = SelectLoader();
|
std::unique_ptr<GL::Loader> loader = SelectLoader(config);
|
||||||
if (!loader)
|
if (!loader)
|
||||||
{
|
{
|
||||||
NazaraError("Failed to initialize OpenGL loader");
|
NazaraError("Failed to initialize OpenGL loader");
|
||||||
|
|
@ -70,12 +70,12 @@ namespace Nz
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<GL::Loader> OpenGLRenderer::SelectLoader()
|
std::unique_ptr<GL::Loader> OpenGLRenderer::SelectLoader(const Renderer::Config& config)
|
||||||
{
|
{
|
||||||
#ifdef NAZARA_PLATFORM_WINDOWS
|
#ifdef NAZARA_PLATFORM_WINDOWS
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return std::make_unique<GL::WGLLoader>();
|
return std::make_unique<GL::WGLLoader>(config);
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
|
|
@ -86,7 +86,7 @@ namespace Nz
|
||||||
#if defined(NAZARA_PLATFORM_WINDOWS) || defined(NAZARA_PLATFORM_LINUX)
|
#if defined(NAZARA_PLATFORM_WINDOWS) || defined(NAZARA_PLATFORM_LINUX)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return std::make_unique<GL::EGLLoader>();
|
return std::make_unique<GL::EGLLoader>(config);
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
|
|
@ -99,13 +99,19 @@ namespace Nz
|
||||||
|
|
||||||
RenderAPI OpenGLRenderer::QueryAPI() const
|
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
|
std::string OpenGLRenderer::QueryAPIString() const
|
||||||
{
|
{
|
||||||
|
const auto& params = m_device->GetReferenceContext().GetParams();
|
||||||
|
|
||||||
std::ostringstream ss;
|
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();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ namespace Nz::GL
|
||||||
EGLLoader& loader;
|
EGLLoader& loader;
|
||||||
};
|
};
|
||||||
|
|
||||||
EGLLoader::EGLLoader() :
|
EGLLoader::EGLLoader(const Renderer::Config& config) :
|
||||||
m_defaultDisplay(nullptr)
|
m_defaultDisplay(nullptr)
|
||||||
{
|
{
|
||||||
if (!m_eglLib.Load("libEGL"))
|
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
|
// 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)
|
#if defined(NAZARA_PLATFORM_DESKTOP)
|
||||||
GL::ContextType::OpenGL, GL::ContextType::OpenGL_ES
|
preferredAPI = RenderAPI::OpenGL;
|
||||||
#else
|
#else
|
||||||
GL::ContextType::OpenGL_ES, GL::ContextType::OpenGL
|
preferredAPI = RenderAPI::OpenGL_ES;
|
||||||
#endif
|
#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;
|
ContextParams params;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
namespace Nz::GL
|
namespace Nz::GL
|
||||||
{
|
{
|
||||||
WGLLoader::WGLLoader() :
|
WGLLoader::WGLLoader(const Renderer::Config& config) :
|
||||||
m_baseContext(nullptr, *this)
|
m_baseContext(nullptr, *this)
|
||||||
{
|
{
|
||||||
if (!m_opengl32Lib.Load("opengl32" NAZARA_DYNLIB_EXTENSION))
|
if (!m_opengl32Lib.Load("opengl32" NAZARA_DYNLIB_EXTENSION))
|
||||||
|
|
@ -50,14 +50,29 @@ namespace Nz::GL
|
||||||
throw std::runtime_error("failed to create load context");
|
throw std::runtime_error("failed to create load context");
|
||||||
|
|
||||||
ContextParams params;
|
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)
|
#if defined(NAZARA_PLATFORM_DESKTOP)
|
||||||
GL::ContextType::OpenGL, GL::ContextType::OpenGL_ES
|
preferredAPI = RenderAPI::OpenGL;
|
||||||
#else
|
#else
|
||||||
GL::ContextType::OpenGL_ES, GL::ContextType::OpenGL
|
preferredAPI = RenderAPI::OpenGL_ES;
|
||||||
#endif
|
#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;
|
bool created = false;
|
||||||
for (GL::ContextType contextType : contextTypes)
|
for (GL::ContextType contextType : contextTypes)
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ namespace Nz
|
||||||
NazaraRendererPrefix "NazaraMantleRenderer" NazaraRendererDebugSuffix, // Mantle
|
NazaraRendererPrefix "NazaraMantleRenderer" NazaraRendererDebugSuffix, // Mantle
|
||||||
NazaraRendererPrefix "NazaraMetalRenderer" NazaraRendererDebugSuffix, // Metal
|
NazaraRendererPrefix "NazaraMetalRenderer" NazaraRendererDebugSuffix, // Metal
|
||||||
NazaraRendererPrefix "NazaraOpenGLRenderer" NazaraRendererDebugSuffix, // OpenGL
|
NazaraRendererPrefix "NazaraOpenGLRenderer" NazaraRendererDebugSuffix, // OpenGL
|
||||||
|
NazaraRendererPrefix "NazaraOpenGLRenderer" NazaraRendererDebugSuffix, // OpenGL_ES
|
||||||
NazaraRendererPrefix "NazaraVulkanRenderer" NazaraRendererDebugSuffix, // Vulkan
|
NazaraRendererPrefix "NazaraVulkanRenderer" NazaraRendererDebugSuffix, // Vulkan
|
||||||
|
|
||||||
nullptr // Unknown
|
nullptr // Unknown
|
||||||
|
|
@ -98,6 +99,11 @@ namespace Nz
|
||||||
};
|
};
|
||||||
std::vector<RendererImplementations> implementations;
|
std::vector<RendererImplementations> implementations;
|
||||||
|
|
||||||
|
RenderAPI preferredAPI = config.preferredAPI;
|
||||||
|
// OpenGL and OpenGL ES are handled by the same implementation (OpenGLES will be handled in OpenGLRenderer code)
|
||||||
|
if (preferredAPI == RenderAPI::OpenGL_ES)
|
||||||
|
preferredAPI = RenderAPI::OpenGL;
|
||||||
|
|
||||||
#ifdef NAZARA_RENDERER_EMBEDDEDBACKENDS
|
#ifdef NAZARA_RENDERER_EMBEDDEDBACKENDS
|
||||||
auto RegisterImpl = [&](RenderAPI api, auto ComputeScore, std::function<std::unique_ptr<RendererImpl>()> factory)
|
auto RegisterImpl = [&](RenderAPI api, auto ComputeScore, std::function<std::unique_ptr<RendererImpl>()> factory)
|
||||||
{
|
{
|
||||||
|
|
@ -112,7 +118,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
auto& impl = implementations.emplace_back();
|
auto& impl = implementations.emplace_back();
|
||||||
impl.factory = std::move(factory);
|
impl.factory = std::move(factory);
|
||||||
impl.score = (config.preferredAPI == api) ? std::numeric_limits<int>::max() : score;
|
impl.score = (preferredAPI == api) ? std::numeric_limits<int>::max() : score;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -132,7 +138,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
auto& impl = implementations.emplace_back();
|
auto& impl = implementations.emplace_back();
|
||||||
impl.fileName = std::move(fileName);
|
impl.fileName = std::move(fileName);
|
||||||
impl.score = (config.preferredAPI == api) ? std::numeric_limits<int>::max() : score;
|
impl.score = (preferredAPI == api) ? std::numeric_limits<int>::max() : score;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ namespace Nz
|
||||||
std::string VulkanRenderer::QueryAPIString() const
|
std::string VulkanRenderer::QueryAPIString() const
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << "Vulkan renderer " << VK_VERSION_MAJOR(APIVersion) << '.' << VK_VERSION_MINOR(APIVersion) << '.' << VK_VERSION_PATCH(APIVersion);
|
ss << "Vulkan renderer " << VK_API_VERSION_MAJOR(APIVersion) << '.' << VK_API_VERSION_MINOR(APIVersion) << '.' << VK_API_VERSION_PATCH(APIVersion);
|
||||||
|
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue