Windows构建Google的Angle图形库并使用

2024年2月17日 0 By Majjcom

参考链接

源码链接
源码链接(Github)
chrome源码链接
另一篇相关文章
最佳参考 Github

编译Angle库

准备源码

直接克隆

前往chrome源码链接,准备depot_tools,将其添加到PATH中

配置git代理和系统代理,参考以下shell:

git config --global http.proxy socks://127.0.0.1:10808
git config --global https.proxy socks://127.0.0.1:10808
set http_proxy=http://127.0.0.1:10809
set https_proxy=http://127.0.0.1:10809

运行一遍gclient来更新depot_tools

运行以下shell来拉取angle源码:

fetch --nohooks angle

找到合适的版本并切换到对应分支:

gclient sync --revision chromium/xxxx --nohooks

运行hook:

gclient runhooks

通过git克隆

git clone --depth 100 -b chromium/xxxx https://chromium.googlesource.com/angle/angle

创建信息文件:

gclient config --unmanaged https://chromium.googlesource.com/angle/angle

同步子仓库:

gclient sync --nohooks
gclient runhooks

可以考虑使用--no-history--shallow,减少下载代码时间

注意,可能需要对windows进行一些设置

打开设置->应用->高级应用设置->应用执行名将python打开微软商店的应用安装程序关闭

配置项目

参考以下配置:

is_component_build = false
target_cpu = "x64"
is_debug = false
angle_assert_always_on = false
is_clang = true
symbol_level = 0
libcxx_is_shared = true

对于仅构建ANGLE动态库,为SDL使用,参考:

is_component_build = false           (false forces static links of dependencies)
target_cpu = "x64"                   (the default is "x64")
is_debug = false                     (use false for release builds. is_debug = true is the default)
angle_assert_always_on = false       (enables release asserts and runtime debug layers)
is_clang = false                     (to use system default compiler instead of clang)

补充,Github上的参考构建命令:

target_cpu = "x64"
is_component_build = false
angle_build_all = false
is_debug = false
is_clang = true
angle_has_frame_capture = false
angle_enable_gl = false
angle_enable_vulkan = false
angle_enable_wgpu = false
angle_enable_d3d9 = false
angle_enable_null = false
use_siso = false
gn gen out\Static --args="is_component_build = false target_cpu = \"x64\" is_debug = false angle_assert_always_on = false is_clang = true symbol_level = 0 libcxx_is_shared = true"

编译项目

可以只编译angle_samples

autoninja -C out\Static angle_samples

最佳构建目标:

autoninja -C out\Release libEGL libGLESv2

使用项目

以下内容使用xmake配置

准备LLVM工具链

下载LLVM工具链,windows上下载安装包,可以直接通过7zip打开解压出来使用

项目微调

找到构建目录下的obj/angle_common.ninja

将最下方的alink配置的/clangminlib去除,重新运行编译命令

项目配置

xmake项目配置可以参考以下文件:

add_rules("mode.debug", "mode.release")

target("OpenGLES-Test")
    set_kind("binary")

    add_files("src/**.cpp")

    add_includedirs(
        "G:/builds/angle/third_party/libc++/src/include",
        "G:/builds/angle/buildtools/third_party/libc++",
        "G:/builds/angle",
        "G:/builds/angle/include",
        "G:/builds/angle/src",
        "G:/builds/angle/src/common/base",
        "G:/builds/angle/third_party/abseil-cpp"
    )

    add_defines(
        "NOMINMAX",
        "ANGLE_USE_UTIL_LOADER",
        "ANGLE_USE_ABSEIL",
        "ABSL_CONSUME_DLL",
        "ANGLE_OUTSIDE_WEBKIT",
        "ANGLE_HAS_ASTCENC",
        "ANGLE_IS_WIN",
        "NVALGRIND",
        "ABSL_ALLOCATOR_NOTHROW=1",
        "EGL_EGL_PROTOTYPES=0",
        "GL_GLES_PROTOTYPES=0",
        "ANGLE_ENABLE_CONTEXT_MUTEX=1",
        "ANGLE_ENABLE_SHARE_CONTEXT_LOCK=1",
        "ANGLE_VMA_VERSION=3000000",
        "DYNAMIC_ANNOTATIONS_ENABLED=0"
    )

    add_linkdirs(
        "G:/builds/angle/out/Static",
        "G:/builds/angle/out/Static/obj"
    )
    add_links(
        "angle_util.dll",
        "libc++.dll",
        "libEGL.dll",
        "angle_common"
    )

配置命令:xmake r -m release –toolchain=llvm –sdk=/path/to/llvm

然后复制以下dll到构建目录:

  • angle_util.dll
  • libc++.dll
  • libEGL.dll
  • libGLESv2.dll

完整构建示例

set vs2022_install=VS_PATH
set PATH=/path/to/depot_tools;%PATH%
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
set http_proxy=http://127.0.0.1:10808
set https_proxy=http://127.0.0.1:10808

git config --global http.proxy socks://127.0.0.1:10808
git config --global https.proxy socks://127.0.0.1:10808
git config --global core.autocrlf false
git config --global core.safecrlf true
git config --global core.filemode false
git config --global core.fscache true
git config --global core.preloadindex true

gclient config --unmanaged https://chromium.googlesource.com/angle/angle

gclient sync --revision angle@chromium/7258 --no-history -–nohooks

gn gen out\Release --args="target_cpu = \"x64\" is_component_build = false angle_build_all = false is_debug = false is_clang = true angle_has_frame_capture = false angle_enable_gl = false angle_enable_vulkan = false angle_enable_wgpu = false angle_enable_d3d9 = false angle_enable_null = false use_siso = false"

gn gen out\ReleaseVk --args="target_cpu = \"x64\" is_component_build = false angle_build_all = false is_debug = false is_clang = true angle_has_frame_capture = false angle_enable_gl = false angle_enable_vulkan = true angle_enable_wgpu = false angle_enable_d3d9 = false angle_enable_d3d11 = false angle_enable_null = false use_siso = false"

autoninja -C out\Release libEGL libGLESv2
autoninja -C out\ReleaseVk libEGL libGLESv2