Skip to content

Commit 0c36e16

Browse files
hramrachsethhillbrand
authored andcommitted
Replace glew with epoxy
Glew has the problem that it has to be selected at build time if GLX or EGL is supported by the library, and this in not encoded in the library name, nor ABI, nor anything. Then it's easy to get into the situation that a binary is built but cannot run because glew supports an API different from the one used by wxWidgets, or the binary fails to link in the end after all objects are compiled. epoxy can support both with the same library avoiding this problem. epoxy is not initialized explicitly, replaced initialization with version check where one was not done already. It seems to be available as vcpkg https://vcpkg.link/ports/libepoxy There are problems related to GL context switching on Windows which does not seem to be used in kicad https://github.com/anholt/libepoxy#known-issues-when-running-on-windows There is also a problem related to multithreaded rendering on Windows anholt/libepoxy#265 It's harder to tell if threading is used for rendering but it does not look like kicad is doing anything complex enough to warrant using multiple rendering threads. Fixes https://gitlab.com/kicad/code/kicad/-/issues/20630 Fixes https://gitlab.com/kicad/code/kicad/-/issues/12543
1 parent d2307fd commit 0c36e16

34 files changed

+193
-85881
lines changed

3d-viewer/3d_canvas/eda_3d_canvas.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
2323
*/
2424

25-
#include <gal/opengl/kiglew.h> // Must be included first
25+
#include <gal/opengl/kiepoxy.h> // Must be included first
2626
#include <gal/opengl/gl_utils.h>
2727
#include <wx/tokenzr.h>
2828

@@ -226,21 +226,12 @@ bool EDA_3D_CANVAS::initializeOpenGL()
226226
{
227227
wxLogTrace( m_logTrace, wxT( "EDA_3D_CANVAS::initializeOpenGL" ) );
228228

229-
const GLenum err = glewInit();
230-
231-
if( GLEW_OK != err )
229+
// Check the OpenGL version (minimum 2.1 is required)
230+
if( epoxy_gl_version() < 21 )
232231
{
233-
const wxString msgError = (const char*) glewGetErrorString( err );
234-
235-
wxLogMessage( msgError );
236-
232+
wxLogMessage( wxS( "OpenGL 2.1 or higher is required!" ) );
237233
return false;
238234
}
239-
else
240-
{
241-
wxLogTrace( m_logTrace, wxT( "EDA_3D_CANVAS::initializeOpenGL Using GLEW version %s" ),
242-
From_UTF8( (char*) glewGetString( GLEW_VERSION ) ) );
243-
}
244235

245236
SetOpenGLInfo( (const char*) glGetString( GL_VENDOR ), (const char*) glGetString( GL_RENDERER ),
246237
(const char*) glGetString( GL_VERSION ) );

3d-viewer/3d_model_viewer/eda_3d_model_viewer.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* 3d models that come in the original data from the files without any transformations.
2828
*/
2929

30-
#include <gal/opengl/kiglew.h> // Must be included first
30+
#include <gal/opengl/kiepoxy.h> // Must be included first
3131
#include <iostream>
3232
#include "3d_rendering/opengl/3d_model.h"
3333
#include "eda_3d_model_viewer.h"
@@ -183,23 +183,17 @@ void EDA_3D_MODEL_VIEWER::Clear3DModel()
183183

184184
void EDA_3D_MODEL_VIEWER::ogl_initialize()
185185
{
186-
const GLenum err = glewInit();
187-
188-
if( GLEW_OK != err )
189-
{
190-
const wxString msgError = (const char*) glewGetErrorString( err );
191-
192-
wxLogMessage( msgError );
193-
}
194-
else
195-
{
196-
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::ogl_initialize Using GLEW version %s" ),
197-
From_UTF8( (char*) glewGetString( GLEW_VERSION ) ) );
198-
}
186+
// Check the OpenGL version (minimum 2.1 is required)
187+
if( epoxy_gl_version() < 21 )
188+
wxLogMessage( wxS( "OpenGL 2.1 or higher is required!" ) );
199189

200190
SetOpenGLInfo( (const char*) glGetString( GL_VENDOR ), (const char*) glGetString( GL_RENDERER ),
201191
(const char*) glGetString( GL_VERSION ) );
202192

193+
wxString version = From_UTF8( (char*) glGetString( GL_VERSION ) );
194+
195+
wxLogTrace( m_logTrace, wxS( "EDA_3D_MODEL_VIEWER::%s OpenGL version string %s." ), __WXFUNCTION__, version );
196+
203197
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
204198
glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
205199
glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST );

3d-viewer/3d_rendering/opengl/3d_model.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
#include <algorithm>
3030
#include <stdexcept>
31-
#include <gal/opengl/kiglew.h> // Must be included first
31+
#include <gal/opengl/kiepoxy.h> // Must be included first
3232

3333
#include "3d_model.h"
3434
#include "../common_ogl/ogl_utils.h"

3d-viewer/3d_rendering/opengl/render_3d_opengl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525

2626
#include <cstdint>
27-
#include <gal/opengl/kiglew.h> // Must be included first
27+
#include <gal/opengl/kiepoxy.h> // Must be included first
2828

2929
#include "plugins/3dapi/xv3d_types.h"
3030
#include "render_3d_opengl.h"

3d-viewer/3d_rendering/raytracing/render_3d_raytrace_gl.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
2424
*/
2525

26-
#include <gal/opengl/kiglew.h> // Must be included first
26+
#include <gal/opengl/kiepoxy.h> // Must be included first
2727

2828
#include <algorithm>
2929
#include <atomic>
@@ -217,7 +217,7 @@ bool RENDER_3D_RAYTRACE_GL::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
217217

218218
void RENDER_3D_RAYTRACE_GL::initPbo()
219219
{
220-
if( GLEW_ARB_pixel_buffer_object )
220+
if( epoxy_has_gl_extension( "GL_ARB_pixel_buffer_object" ) )
221221
{
222222
m_openglSupportsVertexBufferObjects = true;
223223

@@ -238,7 +238,6 @@ void RENDER_3D_RAYTRACE_GL::initPbo()
238238
glBufferDataARB( GL_PIXEL_UNPACK_BUFFER_ARB, m_pboDataSize, 0, GL_STREAM_DRAW_ARB );
239239
glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, 0 );
240240

241-
wxLogTrace( m_logTrace,
242-
wxT( "RENDER_3D_RAYTRACE_GL:: GLEW_ARB_pixel_buffer_object is supported" ) );
241+
wxLogTrace( m_logTrace, wxS( "RENDER_3D_RAYTRACE_GL:: GL_ARB_pixel_buffer_object is supported" ) );
243242
}
244243
}

3d-viewer/common_ogl/ogl_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929

3030
#include <stdexcept>
31-
#include <gal/opengl/kiglew.h> // Must be included first
31+
#include <gal/opengl/kiepoxy.h> // Must be included first
3232

3333
#include "openGL_includes.h"
3434
#include "ogl_utils.h"

CMakeLists.txt

Lines changed: 41 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,6 @@ option( KICAD_UPDATE_CHECK
115115
"Build in update check"
116116
ON )
117117

118-
# EGL is only needed on Linux with Wayland
119-
cmake_dependent_option( KICAD_USE_EGL
120-
"Build KiCad with EGL backend support for Wayland."
121-
OFF "UNIX_NOT_APPLE"
122-
OFF)
123-
124-
cmake_dependent_option( KICAD_USE_BUNDLED_GLEW
125-
"Use the bundled version of GLEW - only available when KICAD_USE_EGL is set"
126-
ON "KICAD_USE_EGL"
127-
OFF )
128-
129118
cmake_dependent_option( KICAD_WAYLAND
130119
"Support Wayland features"
131120
ON "KICAD_USE_EGL"
@@ -286,16 +275,6 @@ add_compile_definitions( $<$<BOOL:${KICAD_GAL_PROFILE}>:KICAD_GAL_PROFILE> )
286275
add_compile_definitions( $<$<BOOL:${KICAD_WIN32_VERIFY_CODESIGN}>:KICAD_WIN32_VERIFY_CODESIGN> )
287276
add_compile_definitions( $<$<BOOL:${KICAD_UPDATE_CHECK}>:KICAD_UPDATE_CHECK> )
288277

289-
if( KICAD_USE_EGL )
290-
message( STATUS "Configuring KiCad for the wxGLCanvas EGL backend" )
291-
add_compile_definitions( KICAD_USE_EGL )
292-
endif()
293-
294-
if( KICAD_WAYLAND )
295-
message( STATUS "Configuring KiCad to support Wayland features" )
296-
add_compile_definitions( KICAD_WAYLAND )
297-
endif()
298-
299278
if( KICAD_IPC_API )
300279
add_definitions( -DKICAD_IPC_API )
301280
endif()
@@ -755,50 +734,6 @@ if( KICAD_BUILD_I18N )
755734
find_package( Gettext REQUIRED )
756735
endif()
757736

758-
#
759-
# Find OpenGL library, required
760-
#
761-
if( KICAD_USE_EGL )
762-
find_package( OpenGL REQUIRED COMPONENTS OpenGL EGL )
763-
else()
764-
set( OpenGL_GL_PREFERENCE "LEGACY" ) # CMake 3.11+ setting; see 'cmake --help-policy CMP0072'
765-
find_package( OpenGL REQUIRED )
766-
endif()
767-
768-
#
769-
# Find GLEW library, required
770-
#
771-
# The EGL canvas on GTK requires the use of a GLEW version compiled with an EGL flag.
772-
# The one built in the thirdparty directory has the flag for EGL set, so we use it unless told
773-
# otherwise. Then we search for the system GLEW version and use that instead.
774-
#
775-
if( KICAD_USE_EGL AND KICAD_USE_BUNDLED_GLEW AND UNIX AND NOT APPLE )
776-
if( OpenGL_EGL_FOUND )
777-
message( STATUS "Found OpenGL EGL library: ${OPENGL_egl_LIBRARY}" )
778-
else()
779-
message( FATAL_ERROR "OpenGL EGL library not found" )
780-
endif()
781-
782-
# Add the custom GLEW target
783-
add_subdirectory( thirdparty/glew )
784-
785-
# Set the standard package variables to point to our custom target to mimic the system version.
786-
set( GLEW_LIBRARIES glew )
787-
set( GLEW_FOUND TRUE )
788-
include_directories( SYSTEM $<TARGET_PROPERTY:glew,INCLUDE_DIRECTORIES> )
789-
else()
790-
find_package( GLEW REQUIRED )
791-
check_find_package_result( GLEW_FOUND "GLEW" )
792-
include_directories( SYSTEM ${GLEW_INCLUDE_DIR} )
793-
endif()
794-
795-
#
796-
# Find GLM library, required
797-
#
798-
find_package( GLM 0.9.8 REQUIRED )
799-
add_compile_definitions( GLM_FORCE_CTOR_INIT )
800-
include_directories( SYSTEM ${GLM_INCLUDE_DIR} )
801-
802737
#
803738
# Find zlib library, required
804739
#
@@ -1077,6 +1012,8 @@ else()
10771012
message( FATAL_ERROR "Unable to detect wxWidgets port")
10781013
endif()
10791014

1015+
message(STATUS "wxUSE_GLCANVAS_EGL=${wxWidgets_GLCANVAS_EGL}")
1016+
10801017
if( NOT MSVC )
10811018
if( ${wxWidgets_VERSION_STRING} VERSION_LESS 3.2 )
10821019
message( FATAL_ERROR "wxWidgets 3.2.0 or greater is required" )
@@ -1111,6 +1048,45 @@ if( APPLE )
11111048
)
11121049
endif()
11131050

1051+
#
1052+
# Find OpenGL library, required
1053+
#
1054+
if( wxWidgets_GLCANVAS_EGL EQUAL 1 )
1055+
set( KICAD_USE_EGL ON )
1056+
find_package( OpenGL REQUIRED COMPONENTS OpenGL EGL )
1057+
else()
1058+
set( KICAD_USE_EGL OFF )
1059+
set( OpenGL_GL_PREFERENCE "LEGACY" ) # CMake 3.11+ setting; see 'cmake --help-policy CMP0072'
1060+
find_package( OpenGL REQUIRED )
1061+
endif()
1062+
if( NOT OPENGL_GLU_FOUND )
1063+
MESSAGE( FATAL_ERROR "The OpenGL GLU library is required." )
1064+
endif()
1065+
1066+
if( KICAD_USE_EGL )
1067+
message( STATUS "Configuring KiCad for the wxGLCanvas EGL backend" )
1068+
add_compile_definitions( KICAD_USE_EGL )
1069+
endif()
1070+
1071+
if( KICAD_WAYLAND )
1072+
message( STATUS "Configuring KiCad to support Wayland features" )
1073+
add_compile_definitions( KICAD_WAYLAND )
1074+
endif()
1075+
1076+
#
1077+
# Find Epoxy library, required
1078+
#
1079+
find_package( epoxy REQUIRED )
1080+
check_find_package_result( EPOXY_FOUND "epoxy" )
1081+
include_directories( SYSTEM ${epoxy_INCLUDE_DIR} )
1082+
1083+
#
1084+
# Find GLM library, required
1085+
#
1086+
find_package( GLM 0.9.8 REQUIRED )
1087+
add_compile_definitions( GLM_FORCE_CTOR_INIT )
1088+
include_directories( SYSTEM ${GLM_INCLUDE_DIR} )
1089+
11141090

11151091
if( KICAD_USE_SENTRY )
11161092
set( KICAD_SENTRY_DSN "" CACHE STRING "The sentry DSN used with sentry integration" )

LICENSE.README

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ Licensed under MIT:
3535
- sentry-native in thirdparty/sentry-native
3636
- thread-pool in thirdparty/thread-pool
3737
- tinyspline_lib in thirdparty/tinyspline_lib
38-
Licensed under MIT and BSD:
39-
- glew in thirdparty/glew
4038
Licensed under BSD:
4139
- pybind11 in thirdparty/pybind11
4240
Licensed under BSD2:

cmake/FindGLEW.cmake

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)