[Bf-blender-cvs] [a296b8f694d] master: GPU: replace GLEW with libepoxy

Christian Rauch noreply at git.blender.org
Mon Aug 15 16:14:26 CEST 2022


Commit: a296b8f694d1a93d40da78312758580f69b43be7
Author: Christian Rauch
Date:   Mon Aug 15 14:58:04 2022 +0200
Branches: master
https://developer.blender.org/rBa296b8f694d1a93d40da78312758580f69b43be7

GPU: replace GLEW with libepoxy

With libepoxy we can choose between EGL and GLX at runtime, as well as
dynamically open EGL and GLX libraries without linking to them.

This will make it possible to build with Wayland, EGL, GLVND support while
still running on systems that only have X11, GLX and libGL. It also paves
the way for headless rendering through EGL.

libepoxy is a new library dependency, and is included in the precompiled
libraries. GLEW is no longer a dependency, and WITH_SYSTEM_GLEW was removed.

Includes contributions by Brecht Van Lommel, Ray Molenkamp, Campbell Barton
and Sergey Sharybin.

Ref T76428

Differential Revision: https://developer.blender.org/D15291

===================================================================

M	CMakeLists.txt
M	build_files/build_environment/CMakeLists.txt
M	build_files/build_environment/cmake/check_software.cmake
M	build_files/build_environment/cmake/download.cmake
A	build_files/build_environment/cmake/epoxy.cmake
D	build_files/build_environment/cmake/glew.cmake
M	build_files/build_environment/cmake/harvest.cmake
M	build_files/build_environment/cmake/versions.cmake
D	build_files/build_environment/patches/cmakelists_glew.txt
A	build_files/build_environment/patches/epoxy.diff
A	build_files/cmake/Modules/FindEpoxy.cmake
D	build_files/cmake/Modules/FindGLEW.cmake
A	build_files/cmake/Modules/FindLibEpoxy.cmake
M	build_files/cmake/platform/platform_apple.cmake
M	build_files/cmake/platform/platform_unix.cmake
M	build_files/cmake/platform/platform_win32.cmake
M	extern/CMakeLists.txt
D	extern/glew-es/CMakeLists.txt
D	extern/glew-es/LICENSE.txt
D	extern/glew-es/README.blender
D	extern/glew-es/include/GL/glew.h
D	extern/glew-es/include/GL/glxew.h
D	extern/glew-es/include/GL/wglew.h
D	extern/glew-es/src/glew.c
D	extern/glew/CMakeLists.txt
D	extern/glew/LICENSE.txt
D	extern/glew/README.blender
D	extern/glew/include/GL/eglew.h
D	extern/glew/include/GL/glew.h
D	extern/glew/include/GL/glxew.h
D	extern/glew/include/GL/wglew.h
D	extern/glew/src/glew.c
M	intern/CMakeLists.txt
M	intern/cycles/app/CMakeLists.txt
M	intern/cycles/app/opengl/display_driver.cpp
M	intern/cycles/app/opengl/shader.cpp
M	intern/cycles/app/opengl/window.cpp
M	intern/cycles/blender/CMakeLists.txt
M	intern/cycles/cmake/external_libs.cmake
M	intern/cycles/device/CMakeLists.txt
M	intern/cycles/device/hip/device_impl.cpp
M	intern/cycles/hydra/CMakeLists.txt
M	intern/cycles/hydra/display_driver.cpp
M	intern/cycles/util/CMakeLists.txt
M	intern/cycles/util/opengl.h
M	intern/ghost/CMakeLists.txt
M	intern/ghost/intern/GHOST_Context.cpp
M	intern/ghost/intern/GHOST_Context.h
M	intern/ghost/intern/GHOST_ContextCGL.mm
M	intern/ghost/intern/GHOST_ContextD3D.cpp
M	intern/ghost/intern/GHOST_ContextEGL.cpp
M	intern/ghost/intern/GHOST_ContextEGL.h
M	intern/ghost/intern/GHOST_ContextGLX.cpp
M	intern/ghost/intern/GHOST_ContextGLX.h
M	intern/ghost/intern/GHOST_ContextSDL.cpp
M	intern/ghost/intern/GHOST_ContextWGL.cpp
M	intern/ghost/intern/GHOST_ContextWGL.h
M	intern/ghost/intern/GHOST_SystemX11.cpp
M	intern/ghost/intern/GHOST_WindowSDL.cpp
M	intern/ghost/intern/GHOST_WindowX11.cpp
M	intern/ghost/intern/GHOST_Xr_openxr_includes.h
M	intern/ghost/test/CMakeLists.txt
D	intern/glew-mx/CMakeLists.txt
D	intern/glew-mx/glew-mx.h
D	intern/glew-mx/intern/gl-deprecated.h
D	intern/glew-mx/intern/glew-mx.c
D	intern/glew-mx/intern/symbol-binding.h
M	intern/opencolorio/CMakeLists.txt
M	intern/opensubdiv/CMakeLists.txt
M	intern/opensubdiv/internal/evaluator/gl_compute_evaluator.cc
M	release/license/THIRD-PARTY-LICENSES.txt
M	source/blender/blenfont/CMakeLists.txt
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/draw/CMakeLists.txt
M	source/blender/editors/animation/CMakeLists.txt
M	source/blender/editors/armature/CMakeLists.txt
M	source/blender/editors/curve/CMakeLists.txt
M	source/blender/editors/gizmo_library/CMakeLists.txt
M	source/blender/editors/gpencil/CMakeLists.txt
M	source/blender/editors/interface/CMakeLists.txt
M	source/blender/editors/mask/CMakeLists.txt
M	source/blender/editors/mesh/CMakeLists.txt
M	source/blender/editors/object/CMakeLists.txt
M	source/blender/editors/physics/CMakeLists.txt
M	source/blender/editors/render/CMakeLists.txt
M	source/blender/editors/screen/CMakeLists.txt
M	source/blender/editors/sculpt_paint/CMakeLists.txt
M	source/blender/editors/space_action/CMakeLists.txt
M	source/blender/editors/space_buttons/CMakeLists.txt
M	source/blender/editors/space_clip/CMakeLists.txt
M	source/blender/editors/space_console/CMakeLists.txt
M	source/blender/editors/space_file/CMakeLists.txt
M	source/blender/editors/space_graph/CMakeLists.txt
M	source/blender/editors/space_image/CMakeLists.txt
M	source/blender/editors/space_info/CMakeLists.txt
M	source/blender/editors/space_nla/CMakeLists.txt
M	source/blender/editors/space_node/CMakeLists.txt
M	source/blender/editors/space_outliner/CMakeLists.txt
M	source/blender/editors/space_script/CMakeLists.txt
M	source/blender/editors/space_sequencer/CMakeLists.txt
M	source/blender/editors/space_spreadsheet/CMakeLists.txt
M	source/blender/editors/space_statusbar/CMakeLists.txt
M	source/blender/editors/space_text/CMakeLists.txt
M	source/blender/editors/space_topbar/CMakeLists.txt
M	source/blender/editors/space_view3d/CMakeLists.txt
M	source/blender/editors/transform/CMakeLists.txt
M	source/blender/editors/util/CMakeLists.txt
M	source/blender/editors/uvedit/CMakeLists.txt
M	source/blender/freestyle/CMakeLists.txt
M	source/blender/gpu/CMakeLists.txt
D	source/blender/gpu/GPU_glew.h
D	source/blender/gpu/GPU_legacy_stubs.h
M	source/blender/gpu/intern/gpu_platform.cc
M	source/blender/gpu/opengl/gl_backend.cc
M	source/blender/gpu/opengl/gl_batch.hh
M	source/blender/gpu/opengl/gl_context.cc
M	source/blender/gpu/opengl/gl_context.hh
M	source/blender/gpu/opengl/gl_debug.cc
M	source/blender/gpu/opengl/gl_debug.hh
M	source/blender/gpu/opengl/gl_framebuffer.hh
M	source/blender/gpu/opengl/gl_immediate.hh
M	source/blender/gpu/opengl/gl_index_buffer.hh
M	source/blender/gpu/opengl/gl_primitive.hh
M	source/blender/gpu/opengl/gl_query.hh
M	source/blender/gpu/opengl/gl_shader.cc
M	source/blender/gpu/opengl/gl_shader.hh
M	source/blender/gpu/opengl/gl_shader_interface.hh
M	source/blender/gpu/opengl/gl_state.hh
M	source/blender/gpu/opengl/gl_storage_buffer.hh
M	source/blender/gpu/opengl/gl_texture.hh
M	source/blender/gpu/opengl/gl_uniform_buffer.hh
M	source/blender/gpu/opengl/gl_vertex_array.hh
M	source/blender/gpu/opengl/gl_vertex_buffer.hh
M	source/blender/gpu/tests/gpu_shader_test.cc
M	source/blender/makesrna/intern/CMakeLists.txt
M	source/blender/nodes/CMakeLists.txt
M	source/blender/python/generic/CMakeLists.txt
M	source/blender/python/generic/bgl.c
M	source/blender/python/gpu/CMakeLists.txt
M	source/blender/windowmanager/CMakeLists.txt
M	source/creator/CMakeLists.txt

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9ac3e379f5e..dd14feaeb25 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -546,30 +546,18 @@ if(WITH_GHOST_WAYLAND)
 endif()
 
 if(UNIX AND NOT APPLE)
-  if(WITH_GL_EGL)
-    # GLEW can only be built with either GLX or EGL support. Most binary distributions are
-    # built with GLX support and we have no automated way to detect this. So always build
-    # GLEW from source to be sure it has EGL support.
-    set(WITH_SYSTEM_GLEW OFF)
-  else()
-    option(WITH_SYSTEM_GLEW "Use GLEW OpenGL wrapper library provided by the operating system" OFF)
-  endif()
-
   option(WITH_SYSTEM_GLES "Use OpenGL ES library provided by the operating system" ON)
 else()
-  # System GLEW and GLES not an option on other platforms.
-  set(WITH_SYSTEM_GLEW OFF)
+  # System GLES not an option on other platforms.
   set(WITH_SYSTEM_GLES OFF)
 endif()
 
 option(WITH_OPENGL              "When off limits visibility of the opengl headers to just bf_gpu and gawain (temporary option for development purposes)" ON)
-option(WITH_GLEW_ES             "Switches to experimental copy of GLEW that has support for OpenGL ES. (temporary option for development purposes)" OFF)
 option(WITH_GL_PROFILE_ES20     "Support using OpenGL ES 2.0. (through either EGL or the AGL/WGL/XGL 'es20' profile)"                               OFF)
 option(WITH_GPU_BUILDTIME_SHADER_BUILDER  "Shader builder is a developer option enabling linting on GLSL during compilation"                                  OFF)
 
 mark_as_advanced(
   WITH_OPENGL
-  WITH_GLEW_ES
   WITH_GL_PROFILE_ES20
   WITH_GPU_BUILDTIME_SHADER_BUILDER
 )
@@ -596,11 +584,6 @@ if(WIN32)
   mark_as_advanced(WITH_GL_ANGLE)
 endif()
 
-if(WITH_GLEW_ES AND WITH_SYSTEM_GLEW)
-  message(WARNING Ignoring WITH_SYSTEM_GLEW and using WITH_GLEW_ES)
-  set(WITH_SYSTEM_GLEW OFF)
-endif()
-
 if(WIN32)
   getDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
   set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
@@ -1295,7 +1278,7 @@ if(WITH_GL_EGL)
   find_package(OpenGL REQUIRED EGL)
   list(APPEND BLENDER_GL_LIBRARIES OpenGL::EGL)
 
-  list(APPEND GL_DEFINITIONS -DWITH_GL_EGL -DGLEW_EGL -DGLEW_INC_EGL)
+  list(APPEND GL_DEFINITIONS -DWITH_GL_EGL)
 
   if(WITH_SYSTEM_GLES)
     if(NOT OPENGLES_EGL_LIBRARY)
@@ -1388,66 +1371,6 @@ if(WITH_OPENMP)
   )
 endif()
 
-#-----------------------------------------------------------------------------
-# Configure GLEW
-
-if(WITH_SYSTEM_GLEW)
-  find_package(GLEW)
-
-  # Note: There is an assumption here that the system GLEW is not a static library.
-
-  if(NOT GLEW_FOUND)
-    message(FATAL_ERROR "GLEW is required to build Blender. Install it or disable WITH_SYSTEM_GLEW.")
-  endif()
-
-  set(GLEW_INCLUDE_PATH "${GLEW_INCLUDE_DIR}")
-  set(BLENDER_GLEW_LIBRARIES ${GLEW_LIBRARY})
-else()
-  if(WITH_GLEW_ES)
-    set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew-es/include")
-
-    list(APPEND GL_DEFINITIONS -DGLEW_STATIC -DWITH_GLEW_ES)
-
-    # These definitions remove APIs from glew.h, making GLEW smaller, and catching unguarded API usage
-    if(WITH_GL_PROFILE_ES20)
-      list(APPEND GL_DEFINITIONS -DGLEW_ES_ONLY)
-    else()
-      # No ES functions are needed
-      list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
-    endif()
-
-    if(WITH_GL_PROFILE_ES20)
-      if(WITH_GL_EGL)
-        list(APPEND GL_DEFINITIONS -DGLEW_USE_LIB_ES20)
-      endif()
-
-      # ToDo: This is an experiment to eliminate ES 1 symbols,
-      # GLEW doesn't really properly provide this level of control
-      # (for example, without modification it eliminates too many symbols)
-      # so there are lots of modifications to GLEW to make this work,
-      # and no attempt to make it work beyond Blender at this point.
-      list(APPEND GL_DEFINITIONS -DGL_ES_VERSION_1_0=0 -DGL_ES_VERSION_CL_1_1=0 -DGL_ES_VERSION_CM_1_1=0)
-    endif()
-
-    set(BLENDER_GLEW_LIBRARIES extern_glew_es bf_intern_glew_mx)
-
-  else()
-    set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
-
-    list(APPEND GL_DEFINITIONS -DGLEW_STATIC)
-
-    # This won't affect the non-experimental glew library,
-    # but is used for conditional compilation elsewhere.
-    list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
-
-    set(BLENDER_GLEW_LIBRARIES extern_glew)
-
-  endif()
-
-endif()
-
-list(APPEND GL_DEFINITIONS -DGLEW_NO_GLU)
-
 #-----------------------------------------------------------------------------
 # Configure Bullet
 
@@ -1973,7 +1896,6 @@ if(WITH_BLENDER)
   # internal and external library information first, for test linking
   add_subdirectory(source)
 elseif(WITH_CYCLES_STANDALONE OR WITH_CYCLES_HYDRA_RENDER_DELEGATE)
-  add_subdirectory(intern/glew-mx)
   add_subdirectory(intern/guardedalloc)
   add_subdirectory(intern/libc_compat)
   add_subdirectory(intern/sky)
@@ -1991,9 +1913,6 @@ elseif(WITH_CYCLES_STANDALONE OR WITH_CYCLES_HYDRA_RENDER_DELEGATE)
   if(WITH_HIP_DYNLOAD)
     add_subdirectory(extern/hipew)
   endif()
-  if(NOT WITH_SYSTEM_GLEW)
-    add_subdirectory(extern/glew)
-  endif()
 endif()
 
 #-----------------------------------------------------------------------------
@@ -2086,7 +2005,6 @@ if(FIRST_RUN)
   info_cfg_option(WITH_INSTALL_PORTABLE)
   info_cfg_option(WITH_MEM_JEMALLOC)
   info_cfg_option(WITH_MEM_VALGRIND)
-  info_cfg_option(WITH_SYSTEM_GLEW)
   info_cfg_option(WITH_X11_ALPHA)
   info_cfg_option(WITH_X11_XF86VMODE)
   info_cfg_option(WITH_X11_XFIXES)
@@ -2140,7 +2058,6 @@ if(FIRST_RUN)
   endif()
   info_cfg_option(WITH_GL_EGL)
   info_cfg_option(WITH_GL_PROFILE_ES20)
-  info_cfg_option(WITH_GLEW_ES)
 
   info_cfg_text("")
 
diff --git a/build_files/build_environment/CMakeLists.txt b/build_files/build_environment/CMakeLists.txt
index 856fe7b32ff..ee8a9a26c53 100644
--- a/build_files/build_environment/CMakeLists.txt
+++ b/build_files/build_environment/CMakeLists.txt
@@ -53,8 +53,8 @@ include(cmake/imath.cmake)
 include(cmake/openexr.cmake)
 include(cmake/brotli.cmake)
 include(cmake/freetype.cmake)
+include(cmake/epoxy.cmake)
 include(cmake/freeglut.cmake)
-include(cmake/glew.cmake)
 include(cmake/alembic.cmake)
 include(cmake/opensubdiv.cmake)
 include(cmake/sdl.cmake)
diff --git a/build_files/build_environment/cmake/check_software.cmake b/build_files/build_environment/cmake/check_software.cmake
index 080c1e52973..cc8fead6f81 100644
--- a/build_files/build_environment/cmake/check_software.cmake
+++ b/build_files/build_environment/cmake/check_software.cmake
@@ -12,21 +12,13 @@ if(UNIX)
     automake
     bison
     ${_libtoolize_name}
+    meson
+    ninja
     pkg-config
     tclsh
     yasm
   )
 
-  if(NOT APPLE)
-    set(_required_software
-      ${_required_software}
-
-      # Needed for Mesa.
-      meson
-      ninja
-    )
-  endif()
-
   foreach(_software ${_required_software})
     find_program(_software_find NAMES ${_software})
     if(NOT _software_find)
@@ -57,7 +49,7 @@ if(UNIX)
       "  apt install autoconf automake libtool yasm tcl ninja-build meson python3-mako\n"
       "\n"
       "On macOS (with homebrew):\n"
-      "  brew install autoconf automake bison flex libtool pkg-config yasm\n"
+      "  brew install autoconf automake bison flex libtool meson ninja pkg-config yasm\n"
       "\n"
       "Other platforms:\n"
       "  Install equivalent packages.\n")
diff --git a/build_files/build_environment/cmake/download.cmake b/build_files/build_environment/cmake/download.cmake
index 547bf77f8dd..938a140194a 100644
--- a/build_files/build_environment/cmake/download.cmake
+++ b/build_files/build_environment/cmake/download.cmake
@@ -36,7 +36,7 @@ download_source(BLOSC)
 download_source(PTHREADS)
 download_source(OPENEXR)
 download_source(FREETYPE)
-download_source(GLEW)
+download_source(EPOXY)
 download_source(FREEGLUT)
 download_source(ALEMBIC)
 download_source(OPENSUBDIV)
diff --git a/build_files/build_environment/cmake/epoxy.cmake b/build_files/build_environment/cmake/epoxy.cmake
new file mode 100644
index 00000000000..4cd9158f2ac
--- /dev/null
+++ b/build_files/build_environment/cmake/epoxy.cmake
@@ -0,0 +1,25 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+if(WIN32)
+  set(EPOXY_LIB_TYPE shared)
+else()
+  set(EPOXY_LIB_TYPE static)
+endif()
+ExternalProject_Add(external_epoxy
+  URL file://${PACKAGE_DIR}/${EPOXY_FILE}
+  DOWNLOAD_DIR ${DOWNLOAD_DIR}
+  URL_HASH ${EPOXY_HASH_TYPE}=${EPOXY_HASH}
+  PREFIX ${BUILD_DIR}/epoxy
+  PATCH_COMMAND ${PATCH_CMD} -p 1 -N -d ${BUILD_DIR}/epoxy/src/external_epoxy/ < ${PATCH_DIR}/epoxy.diff
+  CONFIGURE_COMMAND ${CONFIGURE_ENV} && meson setup --prefix ${LIBDIR}/epoxy --default-library ${EPOXY_LIB_TYPE} --libdir lib ${BUILD_DIR}/epoxy/src/external_epoxy-build ${BUILD_DIR}/epoxy/src/external_epoxy -Dtests=false
+  BUILD_COMMAND ninja
+  INSTALL_COMMAND ninja install
+)
+
+if(BUILD_MODE STREQUAL Release AND WIN32)
+  ExternalProject_Add_Step(external_epoxy after_install
+    COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBDIR}/epoxy/include ${HARVEST_TARGET}/epoxy/include
+    COMMAND ${CMAKE_COMMAND} -E copy ${LIBDIR}/epoxy/bin/epoxy-0.dll ${HARVEST_TARGET}/epoxy/bin/epoxy-0.dll
+    COMMAND ${CMAKE_COMMAND} -E copy ${LIBDIR}/epoxy/lib/epoxy.lib ${HARVEST_TARGET}/epoxy/lib/epoxy.lib
+    DEPENDEES install
+  )
+endif()
diff --git a/build_files/build_environment/cmake/glew.cmake b/build_files/build_environment/cmake/glew.cmake
deleted file mode 100644
index 0745ad01533..00000000000
--- a/build_files/build_environment/cmake/glew.cmake
+++ /dev/null
@@ -1,16 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-set(GLEW_EXTRA_ARGS
-  -DBUILD_UTILS=Off
-  -DBUILD_SHARED_LIBS=Off
-)
-
-ExternalProject_Add(external_glew
-  URL file://${PACKAGE_DIR}/${GLEW_FILE}
-  DOWNLOAD_DIR ${DOWNLOAD_DIR}
-  URL_HASH ${GLEW_HASH_TYPE}=${GLEW_HASH}
-  PATCH_COMMAND COMMAND ${CMAKE_COMMAND} -E copy ${PATCH_DIR}/cmakelists_glew.txt ${BUILD_DIR}/glew/src/external_glew/CMakeLists.txt
-  PREFIX ${BUILD_DIR}/glew
-  CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=${LIBDIR}/glew ${DEFAULT_CMAKE_FLAGS} ${GLEW_EXTRA_ARGS}
-  INSTALL_DIR ${LIBDIR}/glew
-)
diff --git a/build_files/build_environment/cmake/harvest.cmake b/build_files/build_environment/cmake/harvest.cmake
index 7ebad7a3da2..6ed98398fde 10

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list