From 66922b3bd296584639d4daa494a0491cfcd5e36a Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 14 Sep 2023 03:51:06 +0300 Subject: [PATCH] Add hacks for EGL on Wayland --- common/gal/opengl/opengl_gal.cpp | 15 +++++++++++++++ common/gl_context_mgr.cpp | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 1e905fdad7..b7087e59b4 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -2553,7 +2553,9 @@ unsigned int OPENGL_GAL::getNewGroupNumber() void OPENGL_GAL::init() { +#ifndef KICAD_USE_EGL wxASSERT( IsShownOnScreen() ); +#endif // KICAD_USE_EGL wxASSERT_MSG( m_isContextLocked, "This should only be called from within a locked context." ); @@ -2562,6 +2564,19 @@ void OPENGL_GAL::init() throw std::runtime_error( "Could not create the tesselator" ); GLenum err = glewInit(); +#ifdef KICAD_USE_EGL + // TODO: better way to check when EGL is ready (init fails at "getString(GL_VERSION)") + for( int i = 0; i < 10; i++ ) + { + if( GLEW_OK == err ) + break; + + std::this_thread::sleep_for( std::chrono::milliseconds( 250 ) ); + err = glewInit(); + } + +#endif // KICAD_USE_EGL + if( GLEW_OK != err ) throw std::runtime_error( (const char*) glewGetErrorString( err ) ); diff --git a/common/gl_context_mgr.cpp b/common/gl_context_mgr.cpp index 20eaa07044..5b3be3f050 100644 --- a/common/gl_context_mgr.cpp +++ b/common/gl_context_mgr.cpp @@ -92,8 +92,14 @@ void GL_CONTEXT_MANAGER::LockCtx( wxGLContext* aContext, wxGLCanvas* aCanvas ) // Prevent assertion failure in wxGLContext::SetCurrent during GAL teardown #ifdef __WXGTK__ + +#ifdef KICAD_USE_EGL + if( canvas->GTKGetDrawingWindow() ) +#else if( canvas->GetXWindow() ) -#endif +#endif // KICAD_USE_EGL + +#endif // __WXGTK__ { canvas->SetCurrent( *aContext ); }