diff --git a/include/Nazara/OpenGLRenderer/Wrapper/Linux/EGLContextX11.hpp b/include/Nazara/OpenGLRenderer/Wrapper/Linux/EGLContextX11.hpp index 0dcbae724..8689089be 100644 --- a/include/Nazara/OpenGLRenderer/Wrapper/Linux/EGLContextX11.hpp +++ b/include/Nazara/OpenGLRenderer/Wrapper/Linux/EGLContextX11.hpp @@ -20,11 +20,15 @@ namespace Nz::GL EGLContextX11(EGLContextX11&&) = default; ~EGLContextX11() = default; + bool Create(const ContextParams& params, const EGLContextBase* shareContext = nullptr) override; bool Create(const ContextParams& params, WindowHandle window, const EGLContextBase* shareContext = nullptr) override; void Destroy() override; EGLContextX11& operator=(const EGLContextX11&) = default; EGLContextX11& operator=(EGLContextX11&&) = default; + + private: + ::Display* m_xdisplay = nullptr; }; } diff --git a/src/Nazara/OpenGLRenderer/Wrapper/Linux/EGLContextX11.cpp b/src/Nazara/OpenGLRenderer/Wrapper/Linux/EGLContextX11.cpp index 894ff155b..c6bf1e3f0 100644 --- a/src/Nazara/OpenGLRenderer/Wrapper/Linux/EGLContextX11.cpp +++ b/src/Nazara/OpenGLRenderer/Wrapper/Linux/EGLContextX11.cpp @@ -8,6 +8,54 @@ namespace Nz::GL { + bool EGLContextX11::Create(const ContextParams& params, const EGLContextBase* shareContext) + { + Destroy(); //< In case a previous display or surface hasn't been released + + m_params = params; + + if (!BindAPI()) + return false; + + m_xdisplay = XOpenDisplay(nullptr); + if (!m_xdisplay) + { + NazaraError("failed to connect to X server"); + return false; + } + + m_display = m_loader.eglGetDisplay(m_xdisplay); + if (!m_display) + { + NazaraError("failed to retrieve default EGL display"); + return false; + } + + if (!InitDisplay()) + return false; + + std::size_t configCount; + std::array configs; + if (!ChooseConfig(configs.data(), configs.size(), &configCount)) + return false; + + EGLint surfaceAttributes[] = { + EGL_WIDTH, 1, + EGL_HEIGHT, 1, + EGL_NONE + }; + + std::size_t configIndex = 0; + for (; configIndex < configCount; ++configIndex) + { + m_surface = m_loader.eglCreatePbufferSurface(m_display, configs[configIndex], surfaceAttributes); + if (m_surface) + break; + } + + return CreateInternal(configs[configIndex], shareContext); + } + bool EGLContextX11::Create(const ContextParams& params, WindowHandle window, const EGLContextBase* shareContext) { assert(window.type == WindowManager::X11); @@ -48,5 +96,11 @@ namespace Nz::GL void EGLContextX11::Destroy() { EGLContextBase::Destroy(); + + if (m_xdisplay) + { + XCloseDisplay(m_xdisplay); + m_xdisplay = nullptr; + } } }