OpenGLRenderer: Try to fix EGLContext sharing with X11
This commit is contained in:
parent
f4186fdeac
commit
bc2f18c852
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<EGLConfig, 0xFF> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue