Skip to content

Commit c70983d

Browse files
committed
Fix bug in EGLContext (enable resource sharing)
1 parent 410c65a commit c70983d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/egl/EGLContext.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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+
8690
Carna::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

123129
Carna::egl::EGLContext::~EGLContext()
124130
{
131+
eglContextInstances.erase( this );
125132
eglDestroyContext( pimpl->eglDpy, pimpl->eglCtx );
126133
eglDestroySurface( pimpl->eglDpy, pimpl->eglSurf );
127134
}

test/test_integration.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ def test(self):
136136
def test__animated(self):
137137
r, camera = self.r, self.camera
138138

139-
# Render the scene once
140139
# .. OpaqueRenderingStage: example-animation-start
141140
# Define animation
142141
animation = carna.animation(

0 commit comments

Comments
 (0)