Introduce EGL backend support for the OpenGL canvas

wxWidgets 3.1.5+ on Linux will compile with the Wayland EGL
canvas as the backend instead of the X11 backend. This requires a
version of GLEW compiled with the proper EGL defines and a different
header/code for certain parts that are X11 GLEW specific.

This introduces an in-tree version of GLEW that will be built with the
GLEW_EGL flag then statically linked into the KiCad executables when
EGL support is needed.
This commit is contained in:
Ian McInerney 2020-11-10 23:24:01 +00:00
parent ce3b2921bd
commit 11e6cac42b
25 changed files with 85806 additions and 21 deletions

View File

@ -27,7 +27,7 @@
* @brief Implementation of a 3d canvas * @brief Implementation of a 3d canvas
*/ */
#include <GL/glew.h> // Must be included first #include <gal/opengl/kiglew.h> // Must be included first
#include <gl_utils.h> #include <gl_utils.h>
#include <wx/tokenzr.h> #include <wx/tokenzr.h>

View File

@ -27,11 +27,7 @@
* @brief * @brief
*/ */
// Apple, in their infinite wisdom, has decided to mark OpenGL as deprecated. #include <gal/opengl/kiglew.h> // Must be included first
// Luckily we can silence warnings about its deprecation. This is needed on the GLEW
// includes since they seem to transitively include the OpenGL headers.
#define GL_SILENCE_DEPRECATION 1
#include <GL/glew.h>
#include "c3d_render_ogl_legacy.h" #include "c3d_render_ogl_legacy.h"
#include "ogl_legacy_utils.h" #include "ogl_legacy_utils.h"

View File

@ -28,7 +28,8 @@
* @brief * @brief
*/ */
#include <GL/glew.h> #include <gal/opengl/kiglew.h> // Must be included first
#include "c_ogl_3dmodel.h" #include "c_ogl_3dmodel.h"
#include "ogl_legacy_utils.h" #include "ogl_legacy_utils.h"
#include "../common_ogl/ogl_utils.h" #include "../common_ogl/ogl_utils.h"

View File

@ -27,7 +27,8 @@
* @brief * @brief
*/ */
#include <GL/glew.h> #include <gal/opengl/kiglew.h> // Must be included first
#include <algorithm> #include <algorithm>
#include <atomic> #include <atomic>
#include <chrono> #include <chrono>

View File

@ -27,7 +27,7 @@
* @brief implements generic openGL functions that are common to any openGL target * @brief implements generic openGL functions that are common to any openGL target
*/ */
#include <GL/glew.h> #include <gal/opengl/kiglew.h> // Must be included first
#include "openGL_includes.h" #include "openGL_includes.h"
#include "ogl_utils.h" #include "ogl_utils.h"

View File

@ -34,6 +34,7 @@ endif()
project( kicad ) project( kicad )
include( GNUInstallDirs ) include( GNUInstallDirs )
include( CMakeDependentOption )
# Path to local CMake modules. # Path to local CMake modules.
set( CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules ) set( CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules )
@ -126,6 +127,15 @@ option( KICAD_WIN32_DPI_AWARE
"Turn on DPI awareness for Windows builds only" "Turn on DPI awareness for Windows builds only"
OFF ) OFF )
option( KICAD_USE_EGL
"Build KiCad with EGL backend support for Wayland."
OFF )
cmake_dependent_option( KICAD_USE_BUNDLED_GLEW
"Use the bundled version of GLEW - only available when KICAD_USE_EGL is set"
ON "KICAD_USE_EGL"
OFF )
# when option KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES is enabled: # when option KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES is enabled:
# PYTHON_EXECUTABLE can be defined when invoking cmake # PYTHON_EXECUTABLE can be defined when invoking cmake
# ( use -DPYTHON_EXECUTABLE=<python path>/python.exe or python2 ) # ( use -DPYTHON_EXECUTABLE=<python path>/python.exe or python2 )
@ -447,6 +457,12 @@ if( KICAD_USE_OCC )
unset( KICAD_USE_OCE CACHE ) unset( KICAD_USE_OCE CACHE )
endif() endif()
if( KICAD_USE_EGL AND UNIX AND NOT APPLE )
message( STATUS "Configuring KiCad for the wxGLCanvas EGL backend" )
add_definitions( -DKICAD_USE_EGL )
elseif( KICAD_USE_EGL )
message( STATUS "Ignoring KICAD_USE_EGL since not on Linux" )
endif()
# KIFACE_SUFFIX is the file extension used for top level program modules which # KIFACE_SUFFIX is the file extension used for top level program modules which
# implement the KIFACE interface. A valid suffix starts with a period '.'. # implement the KIFACE interface. A valid suffix starts with a period '.'.
@ -599,7 +615,25 @@ find_package( OpenGL REQUIRED )
# #
# Find GLEW library, required # Find GLEW library, required
# #
if( NOT GLEW_FOUND ) # The EGL canvas on GTK requires the use of a GLEW version compiled with an EGL flag.
# The one built in the thirdparty directory has the flag for EGL set, so we use it unless told
# otherwise. Then we search for the system GLEW version and use that instead.
#
if( KICAD_USE_EGL AND KICAD_USE_BUNDLED_GLEW AND UNIX AND NOT APPLE )
if( OpenGL_EGL_FOUND )
message( STATUS "Found OpenGL EGL library: ${OPENGL_egl_LIBRARY}" )
else()
message( FATAL_ERROR "OpenGL EGL library not found" )
endif()
# Add the custom GLEW target
add_subdirectory( thirdparty/glew )
# Set the standard package variables to point to our custom target to mimic the system version.
set( GLEW_LIBRARIES glew )
set( GLEW_FOUND TRUE )
include_directories( SYSTEM $<TARGET_PROPERTY:glew,PRIVATE_INCLUDE_DIRECTORIES> )
else()
find_package( GLEW REQUIRED ) find_package( GLEW REQUIRED )
check_find_package_result( GLEW_FOUND "GLEW" ) check_find_package_result( GLEW_FOUND "GLEW" )
include_directories( SYSTEM ${GLEW_INCLUDE_DIR} ) include_directories( SYSTEM ${GLEW_INCLUDE_DIR} )

View File

@ -198,6 +198,17 @@ passed via the OCE_DIR flag. This option is enabled by default.
Alternatively KICAD_USE_OCC can be used instead of OCE. Both options are not supposed to be enabled Alternatively KICAD_USE_OCC can be used instead of OCE. Both options are not supposed to be enabled
at the same time. at the same time.
## Wayland EGL support ## {#egl_opt}
The KICAD_USE_EGL option switches the OpenGL backend from using X11 bindings to Wayland EGL bindings.
This option is only relevant on Linux when running wxWidgets 3.1.5+ with the EGL backend of
the wxGLCanvas (which is the default option, but can be disabled in the wxWidgets build).
By default, setting KICAD_USE_EGL will use a in-tree version of the GLEW library (that is compiled with
the additional flags needed to run on an EGL canvas) staticly linked into KiCad. If the system
version of GLEW supports EGL (it must be compiled with the GLEW_EGL flag), then it can be used instead
by setting KICAD_USE_BUNDLED_GLEW to OFF.
## Development Analysis Tools ## {#dev_tools} ## Development Analysis Tools ## {#dev_tools}
KiCad can be compiled with support for several features to aid in the catching and debugging of KiCad can be compiled with support for several features to aid in the catching and debugging of

View File

@ -239,6 +239,10 @@ wxString GetVersionInfoData( const wxString& aTitle, bool aHtml, bool aBrief )
aMsg << indent4 << "KICAD_USE_OCC=" << ON; aMsg << indent4 << "KICAD_USE_OCC=" << ON;
#endif #endif
#ifdef KICAD_USE_EGL
aMsg << indent4 << "KICAD_USE_EGL=" << ON;
#endif
aMsg << indent4 << "KICAD_SPICE="; aMsg << indent4 << "KICAD_SPICE=";
#ifdef KICAD_SPICE #ifdef KICAD_SPICE
aMsg << ON; aMsg << ON;

View File

@ -24,7 +24,8 @@
#include <confirm.h> // DisplayError #include <confirm.h> // DisplayError
#include <GL/glew.h> #include <gal/opengl/kiglew.h> // Must be included first
#include <stdexcept> #include <stdexcept>
#include <wx/log.h> // wxLogDebug #include <wx/log.h> // wxLogDebug

View File

@ -0,0 +1,68 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* This file is used for including the proper GLEW header for the platform.
*/
#ifndef KIGLEW_H_
#define KIGLEW_H_
// Pull in the configuration options for wxWidgets
#include <wx/setup.h>
// Apple, in their infinite wisdom, has decided to mark OpenGL as deprecated.
// Luckily we can silence warnings about its deprecation. This is needed on the GLEW
// includes since they transitively include the OpenGL headers.
#define GL_SILENCE_DEPRECATION 1
#ifdef __WXGTK__
#ifdef KICAD_USE_EGL
#ifdef wxUSE_GLCANVAS_EGL
// wxWidgets was compiled with the EGL canvas, so use the EGL header for GLEW
#include <GL/eglew.h>
#else
#error "KICAD_USE_EGL can only be used when wxWidgets is compiled with the EGL canvas"
#endif
#else // KICAD_USE_EGL
#ifdef wxUSE_GLCANVAS_EGL
#error "KICAD_USE_EGL must be defined since wxWidgets has been compiled with the EGL canvas"
#else
// wxWidgets wasn't compiled with the EGL canvas, so use the X11 GLEW
#include <GL/glxew.h>
#endif
#endif // KICAD_USE_EGL
#else // __WXGTK__
// Non-GTK platforms only need the normal GLEW include
#include <GL/glew.h>
#endif // __WXGTK__
#endif // KIGLEW_H_

View File

@ -31,10 +31,11 @@
#ifndef OPENGL_COMPOSITOR_H_ #ifndef OPENGL_COMPOSITOR_H_
#define OPENGL_COMPOSITOR_H_ #define OPENGL_COMPOSITOR_H_
#include <gal/opengl/kiglew.h> // Must be included first
#include <gal/compositor.h> #include <gal/compositor.h>
#include <gal/opengl/antialiasing.h> #include <gal/opengl/antialiasing.h>
#include <gal/gal_display_options.h> #include <gal/gal_display_options.h>
#include <GL/glew.h>
#include <deque> #include <deque>
namespace KIGFX namespace KIGFX

View File

@ -29,7 +29,7 @@
#ifndef SHADER_H_ #ifndef SHADER_H_
#define SHADER_H_ #define SHADER_H_
#include <GL/glew.h> #include <gal/opengl/kiglew.h> // Must be included first
#include <math/vector2d.h> #include <math/vector2d.h>

View File

@ -30,8 +30,9 @@
#ifndef VERTEX_COMMON_H_ #ifndef VERTEX_COMMON_H_
#define VERTEX_COMMON_H_ #define VERTEX_COMMON_H_
#include <gal/opengl/kiglew.h> // Must be included first
#include <math/vector2d.h> #include <math/vector2d.h>
#include <GL/glew.h>
#include <cstddef> #include <cstddef>

View File

@ -24,12 +24,12 @@
#ifndef GL_UTILS_H #ifndef GL_UTILS_H
#define GL_UTILS_H #define GL_UTILS_H
#ifdef __linux__ #include <gal/opengl/kiglew.h> // Must be included first
#include <GL/glxew.h>
#endif
#include <limits> #include <limits>
#include <wx/setup.h>
class GL_UTILS class GL_UTILS
{ {
public: public:
@ -40,9 +40,9 @@ public:
*/ */
static int SetSwapInterval( int aVal ) static int SetSwapInterval( int aVal )
{ {
/// This routine is written for Linux only. The equivalent functions under Windows would /// This routine is written for Linux using X11 only. The equivalent functions under Windows would
/// include <wglext.h> and call wglSwapIntervalEXT /// include <wglext.h> and call wglSwapIntervalEXT
#ifdef __linux__ #if defined( __linux__ ) && !defined( KICAD_USE_EGL )
Display *dpy = glXGetCurrentDisplay(); Display *dpy = glXGetCurrentDisplay();
GLXDrawable drawable = glXGetCurrentDrawable(); GLXDrawable drawable = glXGetCurrentDrawable();

View File

@ -21,6 +21,8 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# #
# Note: The glew folder isn't added here because it is added inside the main CMakeLists.txt
add_subdirectory( clipper ) add_subdirectory( clipper )
add_subdirectory( compoundfilereader ) add_subdirectory( compoundfilereader )
add_subdirectory( delaunator ) add_subdirectory( delaunator )

21
thirdparty/glew/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,21 @@
add_library( glew STATIC )
# Mark the include directory as private so that it doesn't get used by other targets
# and is only used when building the actual library.
# The actual include directories will be added to the global include paths as
# system headers
target_include_directories( glew PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include" )
# Definitions for compiling GLEW staticly for EGL (extracted from the main GLEW CMakeLists.txt file)
add_definitions( -DGLEW_STATIC )
add_definitions( -DGLEW_EGL )
add_definitions( -DGLEW_NO_GLU )
target_sources( glew PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/glew.c
)
target_link_libraries( glew PUBLIC
${OPENGL_LIBRARIES}
${OPENGL_egl_LIBRARY}
)

73
thirdparty/glew/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,73 @@
The OpenGL Extension Wrangler Library
Copyright (C) 2002-2007, Milan Ikits <milan ikits[]ieee org>
Copyright (C) 2002-2007, Marcelo E. Magallon <mmagallo[]debian org>
Copyright (C) 2002, Lev Povalahev
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* The name of the author may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
Mesa 3-D graphics library
Version: 7.0
Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2007 The Khronos Group Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and/or associated documentation files (the
"Materials"), to deal in the Materials without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Materials, and to
permit persons to whom the Materials are furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Materials.
THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.

14
thirdparty/glew/README.md vendored Normal file
View File

@ -0,0 +1,14 @@
This directory contains the source code and includes for the GLEW library
(https://github.com/nigels-com/glew). This library is normally dynamically
linked to KiCad on all platforms, but wxWidgets 3.1.5+ on Linux requires
GLEW compiled with EGL support and most distributions do not supply this
(since compiling GLEW for EGL is mutually exclusive with GLEW for X11).
The source files are generated from the GLEW repo, or can be pulled from
a recent GLEW release.
As of November 10, 2020 this GLEW version was pulled from its GitHub
repository and is what should be version upstream version 2.2.0.
This library is licensed under BSD and MIT licenses, with the actual
license text given in the LICENSE file in this directory.

3093
thirdparty/glew/include/GL/eglew.h vendored Normal file

File diff suppressed because it is too large Load Diff

26554
thirdparty/glew/include/GL/glew.h vendored Normal file

File diff suppressed because it is too large Load Diff

1831
thirdparty/glew/include/GL/glxew.h vendored Normal file

File diff suppressed because it is too large Load Diff

1468
thirdparty/glew/include/GL/wglew.h vendored Normal file

File diff suppressed because it is too large Load Diff

32167
thirdparty/glew/src/glew.c vendored Normal file

File diff suppressed because it is too large Load Diff

19147
thirdparty/glew/src/glewinfo.c vendored Normal file

File diff suppressed because it is too large Load Diff

1297
thirdparty/glew/src/visualinfo.c vendored Normal file

File diff suppressed because it is too large Load Diff