diff --git a/include/Nazara/OpenGLRenderer/OpenGLDevice.hpp b/include/Nazara/OpenGLRenderer/OpenGLDevice.hpp index ea1bc1562..530069919 100644 --- a/include/Nazara/OpenGLRenderer/OpenGLDevice.hpp +++ b/include/Nazara/OpenGLRenderer/OpenGLDevice.hpp @@ -28,8 +28,8 @@ namespace Nz OpenGLDevice(OpenGLDevice&&) = delete; ///TODO? ~OpenGLDevice(); - std::unique_ptr CreateContext(const GL::ContextParams& params) const; - std::unique_ptr CreateContext(const GL::ContextParams& params, WindowHandle handle) const; + std::unique_ptr CreateContext(GL::ContextParams params) const; + std::unique_ptr CreateContext(GL::ContextParams params, WindowHandle handle) const; const RenderDeviceInfo& GetDeviceInfo() const override; const RenderDeviceFeatures& GetEnabledFeatures() const override; diff --git a/include/Nazara/Prerequisites.hpp b/include/Nazara/Prerequisites.hpp index 0b5b069c2..f8c47dfb5 100644 --- a/include/Nazara/Prerequisites.hpp +++ b/include/Nazara/Prerequisites.hpp @@ -91,6 +91,7 @@ // Try to identify target platform via defines #if defined(_WIN32) + #define NAZARA_PLATFORM_DESKTOP #define NAZARA_PLATFORM_WINDOWS #define NAZARA_EXPORT __declspec(dllexport) @@ -123,14 +124,16 @@ #endif #endif #elif defined(__linux__) || defined(__unix__) + #define NAZARA_PLATFORM_DESKTOP #define NAZARA_PLATFORM_LINUX #define NAZARA_PLATFORM_POSIX #define NAZARA_EXPORT __attribute__((visibility ("default"))) #define NAZARA_IMPORT __attribute__((visibility ("default"))) #elif defined(__APPLE__) && defined(__MACH__) - #define NAZARA_PLATFORM_MACOSX - #define NAZARA_PLATFORM_POSIX + #define NAZARA_PLATFORM_DESKTOP + #define NAZARA_PLATFORM_MACOSX + #define NAZARA_PLATFORM_POSIX #define NAZARA_EXPORT __attribute__((visibility ("default"))) #define NAZARA_IMPORT __attribute__((visibility ("default"))) diff --git a/src/Nazara/OpenGLRenderer/OpenGLDevice.cpp b/src/Nazara/OpenGLRenderer/OpenGLDevice.cpp index 1e51f5902..921cb2ebf 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLDevice.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLDevice.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -22,7 +23,25 @@ namespace Nz OpenGLDevice::OpenGLDevice(GL::Loader& loader) : m_loader(loader) { - m_referenceContext = loader.CreateContext(this, {}); + // Favor OpenGL on desktop and OpenGL ES on mobile + std::array contextTypes = { +#if defined(NAZARA_PLATFORM_DESKTOP) + GL::ContextType::OpenGL, GL::ContextType::OpenGL_ES +#else + GL::ContextType::OpenGL_ES, GL::ContextType::OpenGL +#endif + }; + + for (GL::ContextType contextType : contextTypes) + { + GL::ContextParams params; + params.type = contextType; + + m_referenceContext = loader.CreateContext(this, params); + if (m_referenceContext) + break; + } + if (!m_referenceContext) throw std::runtime_error("failed to create reference context"); @@ -75,16 +94,20 @@ namespace Nz m_referenceContext.reset(); } - std::unique_ptr OpenGLDevice::CreateContext(const GL::ContextParams& params) const + std::unique_ptr OpenGLDevice::CreateContext(GL::ContextParams params) const { + params.type = m_referenceContext->GetParams().type; + auto contextPtr = m_loader.CreateContext(this, params, m_referenceContext.get()); m_contexts.insert(contextPtr.get()); return contextPtr; } - std::unique_ptr OpenGLDevice::CreateContext(const GL::ContextParams& params, WindowHandle handle) const + std::unique_ptr OpenGLDevice::CreateContext(GL::ContextParams params, WindowHandle handle) const { + params.type = m_referenceContext->GetParams().type; + auto contextPtr = m_loader.CreateContext(this, params, handle, m_referenceContext.get()); m_contexts.insert(contextPtr.get());