11#include < Carna/egl/EGLContext.h>
22#include < EGL/egl.h>
33#include < cstdlib>
4+ #include < unordered_set>
45
56// see: https://developer.nvidia.com/blog/egl-eye-opengl-visualization-without-x-server/
67
@@ -83,10 +84,14 @@ void Carna::egl::EGLContext::Details::activate() const
8384// Carna :: egl :: EGLContext
8485// ----------------------------------------------------------------------------------
8586
87+ static std::unordered_set< Carna::egl::EGLContext* > eglContextInstances;
88+
89+
8690Carna::egl::EGLContext::EGLContext ( Details* _pimpl )
8791 : Carna::base::GLContext( false )
8892 , pimpl( _pimpl ) // TODO: rename to `pimpl`
8993{
94+ eglContextInstances.insert ( this );
9095}
9196
9297
@@ -111,7 +116,8 @@ Carna::egl::EGLContext* Carna::egl::EGLContext::create()
111116 pimpl->eglSurf = eglCreatePbufferSurface ( pimpl->eglDpy , eglCfg, PBUFFER_ATTRIBS );
112117 CARNA_ASSERT ( pimpl->eglSurf != EGL_NO_SURFACE );
113118
114- pimpl->eglCtx = eglCreateContext ( pimpl->eglDpy , eglCfg, EGL_NO_CONTEXT, NULL );
119+ const ::EGLContext shareContext = eglContextInstances.empty () ? EGL_NO_CONTEXT : ( *eglContextInstances.begin () )->pimpl ->eglCtx ;
120+ pimpl->eglCtx = eglCreateContext ( pimpl->eglDpy , eglCfg, shareContext, NULL );
115121 CARNA_ASSERT ( pimpl->eglCtx != EGL_NO_CONTEXT );
116122
117123 pimpl->activate ();
@@ -122,6 +128,7 @@ Carna::egl::EGLContext* Carna::egl::EGLContext::create()
122128
123129Carna::egl::EGLContext::~EGLContext ()
124130{
131+ eglContextInstances.erase ( this );
125132 eglDestroyContext ( pimpl->eglDpy , pimpl->eglCtx );
126133 eglDestroySurface ( pimpl->eglDpy , pimpl->eglSurf );
127134}
0 commit comments