diff --git a/.gitattributes b/.gitattributes index dde21f78733..11d91b35b01 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,6 @@ +* -text *.bin binary diff=hex + *.c eol=lf *.cpp eol=lf *.h eol=lf diff --git a/.github/workflows/lwjgl.yml b/.github/workflows/lwjgl.yml new file mode 100644 index 00000000000..e67c7a33afa --- /dev/null +++ b/.github/workflows/lwjgl.yml @@ -0,0 +1,304 @@ +name: LWJGL Build + +on: + push: + branches: + - master + +env: + AWS_DEFAULT_REGION: us-east-1 + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + S3_PARAMS: --cache-control "public,must-revalidate,proxy-revalidate,max-age=0" + +jobs: + linux: + name: Linux + runs-on: ubuntu-latest + container: + image: centos:7 + strategy: + fail-fast: false + matrix: + ARCH: [x64] + include: + - ARCH: x64 + PACKAGES: mesa-libGL-devel xorg-x11-proto-devel libX11-devel + OUTPUT_DIR: linux64_gcc + env: + LWJGL_ARCH: ${{matrix.ARCH}} + steps: + - run: | + yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm + yum -y install git + name: Upgrade git + - uses: actions/checkout@v3 + with: + fetch-depth: 3 + - run: | + yum -y install epel-release + yum -y update + name: Configure yum + - run: | + yum -y install centos-release-scl + yum -y install devtoolset-11-gcc-c++ + yum -y install awscli + name: Install build dependencies + - run: | + git clone https://github.com/LWJGL-CI/bx.git ../bx + git clone https://github.com/LWJGL-CI/bimg.git ../bimg + name: Clone bx & bimg + - run: | + source scl_source enable devtoolset-11 || true + git clone https://github.com/bkaradzic/GENie.git ../GENie + cd ../GENie + make + name: Clone and build GENie + - run: | + yum -y install ${{matrix.PACKAGES}} + name: Install bgfx dependencies + - run: | #sudo ln -s /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 /usr/lib/libGL.so + source scl_source enable devtoolset-11 || true + ../GENie/bin/linux/genie --with-shared-lib --with-tools --gcc=linux-gcc gmake + make -R -C .build/projects/gmake-linux config=release64 CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0" bgfx-shared-lib + strip .build/linux64_gcc/bin/libbgfx-shared-libRelease.so + name: Build + - run: | + source scl_source enable devtoolset-11 || true + make -R -C .build/projects/gmake-linux config=release64 geometryc + name: Build geometryc + - run: | + source scl_source enable devtoolset-11 || true + make -R -C .build/projects/gmake-linux config=release64 texturec + name: Build texturec + - run: | + source scl_source enable devtoolset-11 || true + make -R -C .build/projects/gmake-linux config=release64 texturev + name: Build texturev + - run: | + source scl_source enable devtoolset-11 || true + make -R -C .build/projects/gmake-linux config=release64 shaderc + name: Build shaderc + - run: aws s3 cp .build/${{matrix.OUTPUT_DIR}}/bin/libbgfx-shared-libRelease.so s3://lwjgl-build/nightly/linux/${{matrix.ARCH}}/libbgfx.so $S3_PARAMS + name: Upload artifact + - run: | + aws s3 cp .build/linux64_gcc/bin/geometrycRelease s3://lwjgl-build/nightly/linux/x64/bgfx-tools/geometryc $S3_PARAMS + aws s3 cp .build/linux64_gcc/bin/texturecRelease s3://lwjgl-build/nightly/linux/x64/bgfx-tools/texturec $S3_PARAMS + aws s3 cp .build/linux64_gcc/bin/texturevRelease s3://lwjgl-build/nightly/linux/x64/bgfx-tools/texturev $S3_PARAMS + aws s3 cp .build/linux64_gcc/bin/shadercRelease s3://lwjgl-build/nightly/linux/x64/bgfx-tools/shaderc $S3_PARAMS + name: Upload tools + - run: | + git config --global --add safe.directory $PWD + git log --first-parent --pretty=format:%H HEAD~2..HEAD~1 > libbgfx.so.git + aws s3 cp libbgfx.so.git s3://lwjgl-build/nightly/linux/${{matrix.ARCH}}/ $S3_PARAMS + name: Upload git revision + + linux-cross: + name: Linux Cross + runs-on: ubuntu-latest + container: + image: ubuntu:18.04 + strategy: + fail-fast: false + matrix: + ARCH: [arm32, arm64] + include: + # ----- + - ARCH: arm32 + CROSS_ARCH: armhf + PACKAGES: gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libc6-dev-armhf-cross + CROSS_PACKAGES: libgl1-mesa-dev:armhf x11proto-dev:armhf libx11-dev:armhf + OUTPUT_DIR: linux32_arm_gcc + # ----- + - ARCH: arm64 + CROSS_ARCH: arm64 + PACKAGES: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross + CROSS_PACKAGES: libgl1-mesa-dev:arm64 x11proto-dev:arm64 libx11-dev:arm64 + OUTPUT_DIR: linux64_arm_gcc + env: + LWJGL_ARCH: ${{matrix.ARCH}} + steps: + - run: | + apt-get -y update + apt-get -y install software-properties-common wget + apt-get -y install --reinstall ca-certificates + apt-get -y update + apt-get -y upgrade + wget https://apt.kitware.com/keys/kitware-archive-latest.asc + apt-key add kitware-archive-latest.asc + add-apt-repository -y 'deb https://apt.kitware.com/ubuntu/ bionic main' + add-apt-repository -y ppa:git-core/ppa + apt-get -y update + DEBIAN_FRONTEND=noninteractive apt-get -yq install awscli git + name: Upgrade git + - uses: actions/checkout@v3 + with: + fetch-depth: 3 + - run: DEBIAN_FRONTEND=noninteractive apt-get -yq install cmake ${{matrix.PACKAGES}} + name: Install dependencies + - run: | + git clone https://github.com/LWJGL-CI/bx.git ../bx + git clone https://github.com/LWJGL-CI/bimg.git ../bimg + name: Clone bx & bimg + - run: | + git clone https://github.com/bkaradzic/GENie.git ../GENie + cd ../GENie + make + name: Clone and build GENie + - run: | + sed -i 's/deb http/deb [arch=amd64,i386] http/' /etc/apt/sources.list + grep "ubuntu.com/ubuntu" /etc/apt/sources.list | tee /etc/apt/sources.list.d/ports.list + sed -i 's/amd64,i386/armhf,arm64/' /etc/apt/sources.list.d/ports.list + sed -i 's#http://.*/ubuntu#http://ports.ubuntu.com/ubuntu-ports#' /etc/apt/sources.list.d/ports.list + dpkg --add-architecture ${{matrix.CROSS_ARCH}} + apt-get update || true + name: Prepare cross-compilation + - run: apt-get -yq --allow-unauthenticated --no-install-suggests --no-install-recommends install ${{matrix.CROSS_PACKAGES}} -o Dpkg::Options::="--force-overwrite" + name: Install cross-compilation dependencies + - run: | #sudo ln -s /usr/lib/arm-linux-gnueabihf/mesa/libGL.so.1 /usr/lib/libGL.so + sed -i 's/strip -s/arm-linux-gnueabihf-strip/' ../bx/scripts/toolchain.lua + ../GENie/bin/linux/genie --with-shared-lib --gcc=linux-arm-gcc gmake + make -R -C .build/projects/gmake-linux-arm-gcc config=release CXX="arm-linux-gnueabihf-g++" CC="arm-linux-gnueabihf-gcc" CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0" bgfx-shared-lib + arm-linux-gnueabihf-strip .build/linux32_arm_gcc/bin/libbgfx-shared-libRelease.so + name: Build bgfx (arm32) + if: contains(matrix.ARCH, 'arm32') + - run: | #sudo ln -s /usr/lib/aarch64-linux-gnu/mesa/libGL.so.1 /usr/lib/libGL.so + sed -i 's/strip -s/aarch64-linux-gnu-strip/' ../bx/scripts/toolchain.lua + ../GENie/bin/linux/genie --with-shared-lib --gcc=linux-arm-gcc gmake + sed -i 's/ -m64//' .build/projects/gmake-linux-arm-gcc/bgfx.make + sed -i 's/ -m64//' .build/projects/gmake-linux-arm-gcc/bgfx-shared-lib.make + sed -i 's/ -m64//' .build/projects/gmake-linux-arm-gcc/bimg.make + sed -i 's/ -m64//' .build/projects/gmake-linux-arm-gcc/bimg_decode.make + sed -i 's/ -m64//' .build/projects/gmake-linux-arm-gcc/bx.make + sed -i 's/linux32/linux64/g' .build/projects/gmake-linux-arm-gcc/bgfx.make + sed -i 's/linux32/linux64/g' .build/projects/gmake-linux-arm-gcc/bgfx-shared-lib.make + sed -i 's/linux32/linux64/g' .build/projects/gmake-linux-arm-gcc/bimg.make + sed -i 's/linux32/linux64/g' .build/projects/gmake-linux-arm-gcc/bimg_decode.make + sed -i 's/linux32/linux64/g' .build/projects/gmake-linux-arm-gcc/bx.make + make -R -C .build/projects/gmake-linux-arm-gcc config=release64 CXX="aarch64-linux-gnu-g++" CC="aarch64-linux-gnu-gcc" CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0" bgfx-shared-lib + aarch64-linux-gnu-strip .build/linux64_arm_gcc/bin/libbgfx-shared-libRelease.so + name: Build bgfx (arm64) + if: contains(matrix.ARCH, 'arm64') + - run: aws s3 cp .build/${{matrix.OUTPUT_DIR}}/bin/libbgfx-shared-libRelease.so s3://lwjgl-build/nightly/linux/${{matrix.ARCH}}/libbgfx.so $S3_PARAMS + name: Upload artifact + - run: | + git config --global --add safe.directory $(pwd) + git log --first-parent --pretty=format:%H HEAD~2..HEAD~1 > libbgfx.so.git + aws s3 cp libbgfx.so.git s3://lwjgl-build/nightly/linux/${{matrix.ARCH}}/ $S3_PARAMS + name: Upload git revision + + macos: + name: macOS + runs-on: macos-latest + strategy: + fail-fast: false + matrix: + ARCH: [x64, arm64] + include: + - ARCH: x64 + PLATFORM: osx-x64 + GENIE_PARAMS: --with-macos=10.9 + CC: MACOSX_DEPLOYMENT_TARGET=10.9 CFLAGS=-mmacosx-version-min=10.9 LDFLAGS=-mmacosx-version-min=10.9 + - ARCH: arm64 + PLATFORM: osx-arm64 + GENIE_PARAMS: --with-macos=11.0 + CC: MACOSX_DEPLOYMENT_TARGET=11.0 CFLAGS=-mmacosx-version-min=11.0 LDFLAGS=-mmacosx-version-min=11.0 + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 3 + - run: | + git clone https://github.com/LWJGL-CI/bx.git ../bx + git clone https://github.com/LWJGL-CI/bimg.git ../bimg + name: Clone bx & bimg + - run: ${{matrix.CC}} ../bx/tools/bin/darwin/genie --with-shared-lib --with-tools ${{matrix.GENIE_PARAMS}} --gcc=${{matrix.PLATFORM}} gmake + name: Configure build + - run: | + ${{matrix.CC}} make -C .build/projects/gmake-${{matrix.PLATFORM}} config=release64 CFLAGS="-D BGFX_CONFIG_RENDERER_METAL=1 -D BGFX_CONFIG_RENDERER_OPENGL=1" bgfx-shared-lib + strip -u -r .build/${{matrix.PLATFORM}}/bin/libbgfx-shared-libRelease.dylib + name: Build bgfx + - run: ${{matrix.CC}} make -C .build/projects/gmake-${{matrix.PLATFORM}} config=release64 geometryc + name: Build geometryc + - run: ${{matrix.CC}} make -C .build/projects/gmake-${{matrix.PLATFORM}} config=release64 texturec + name: Build texturec + - run: ${{matrix.CC}} make -C .build/projects/gmake-${{matrix.PLATFORM}} config=release64 texturev + name: Build texturev + - run: ${{matrix.CC}} make -C .build/projects/gmake-${{matrix.PLATFORM}} config=release64 shaderc + name: Build shaderc + - run: | + aws s3 cp .build/${{matrix.PLATFORM}}/bin/libbgfx-shared-libRelease.dylib s3://lwjgl-build/nightly/macosx/${{matrix.ARCH}}/libbgfx.dylib $S3_PARAMS + aws s3 cp .build/${{matrix.PLATFORM}}/bin/geometrycRelease s3://lwjgl-build/nightly/macosx/${{matrix.ARCH}}/bgfx-tools/geometryc $S3_PARAMS + aws s3 cp .build/${{matrix.PLATFORM}}/bin/texturecRelease s3://lwjgl-build/nightly/macosx/${{matrix.ARCH}}/bgfx-tools/texturec $S3_PARAMS + aws s3 cp .build/${{matrix.PLATFORM}}/bin/texturevRelease s3://lwjgl-build/nightly/macosx/${{matrix.ARCH}}/bgfx-tools/texturev $S3_PARAMS + aws s3 cp .build/${{matrix.PLATFORM}}/bin/shadercRelease s3://lwjgl-build/nightly/macosx/${{matrix.ARCH}}/bgfx-tools/shaderc $S3_PARAMS + name: Upload artifacts + - run: | + git log --first-parent --pretty=format:%H HEAD~2..HEAD~1 > libbgfx.dylib.git + aws s3 cp libbgfx.dylib.git s3://lwjgl-build/nightly/macosx/${{matrix.ARCH}}/ $S3_PARAMS + name: Upload git revision + + windows: + name: Windows + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + ARCH: [x86, x64] + include: + - ARCH: x86 + MSVC_ARCH: amd64_x86 + PLATFORM: x32 + BUILD: Win32 + OUTPUT_DIR: win32_vs2022 + - ARCH: x64 + MSVC_ARCH: amd64 + PLATFORM: x64 + BUILD: x64 + OUTPUT_DIR: win64_vs2022 +# - ARCH: arm64 +# MSVC_ARCH: amd64_arm64 +# PLATFORM: arm64 +# BUILD: arm64 +# OUTPUT_DIR: win64_vs2022 + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 3 + - uses: ilammy/msvc-dev-cmd@v1 + with: + arch: ${{ matrix.MSVC_ARCH }} + - run: | + git clone https://github.com/LWJGL-CI/bx.git ../bx + git clone https://github.com/LWJGL-CI/bimg.git ../bimg + name: Clone bx & bimg + - run: ..\bx\tools\bin\windows\genie --with-shared-lib --with-tools vs2022 --platform ${{matrix.PLATFORM}} + shell: cmd + name: Configure build + - run: devenv .build\projects\vs2022\bgfx.sln /Project bgfx-shared-lib /Build "Release|${{matrix.BUILD}}" + shell: cmd + name: Build bgfx + - run: devenv .build\projects\vs2022\bgfx.sln /Project geometryc /Build "Release|${{matrix.BUILD}}" + shell: cmd + name: Build geometryc + - run: devenv .build\projects\vs2022\bgfx.sln /Project texturec /Build "Release|${{matrix.BUILD}}" + shell: cmd + name: Build texturec + - run: devenv .build\projects\vs2022\bgfx.sln /Project texturev /Build "Release|${{matrix.BUILD}}" + shell: cmd + name: Build texturev + - run: devenv .build\projects\vs2022\bgfx.sln /Project "shaderc (tools\shaderc\shaderc)" /Build "Release|${{matrix.BUILD}}" + shell: cmd + name: Build shaderc + - run: | + aws s3 cp .build/${{matrix.OUTPUT_DIR}}/bin/bgfx-shared-libRelease.dll s3://lwjgl-build/nightly/windows/${{matrix.ARCH}}/bgfx.dll ${{env.S3_PARAMS}} + aws s3 cp .build/${{matrix.OUTPUT_DIR}}/bin/geometrycRelease.exe s3://lwjgl-build/nightly/windows/${{matrix.ARCH}}/bgfx-tools/geometryc.exe ${{env.S3_PARAMS}} + aws s3 cp .build/${{matrix.OUTPUT_DIR}}/bin/texturecRelease.exe s3://lwjgl-build/nightly/windows/${{matrix.ARCH}}/bgfx-tools/texturec.exe ${{env.S3_PARAMS}} + aws s3 cp .build/${{matrix.OUTPUT_DIR}}/bin/texturevRelease.exe s3://lwjgl-build/nightly/windows/${{matrix.ARCH}}/bgfx-tools/texturev.exe ${{env.S3_PARAMS}} + aws s3 cp .build/${{matrix.OUTPUT_DIR}}/bin/shadercRelease.exe s3://lwjgl-build/nightly/windows/${{matrix.ARCH}}/bgfx-tools/shaderc.exe ${{env.S3_PARAMS}} + shell: cmd + name: Upload artifacts + - run: | + git log --first-parent --pretty=format:%%H HEAD~2..HEAD~1 > bgfx.dll.git + aws s3 cp bgfx.dll.git s3://lwjgl-build/nightly/windows/${{matrix.ARCH}}/ ${{env.S3_PARAMS}} + shell: cmd + name: Upload git revision diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 2c55b27554c..00000000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,247 +0,0 @@ -name: CI - -concurrency: - group: ${{ github.ref }} - cancel-in-progress: true - -on: - push: - pull_request: - -jobs: - msvc: - strategy: - fail-fast: true - matrix: - include: [ - { config: Debug, platform: Win32, bindir: 'win32_vs2019' }, - { config: Debug, platform: x64, bindir: 'win64_vs2019' }, - { config: Release, platform: Win32, bindir: 'win32_vs2019' }, - { config: Release, platform: x64, bindir: 'win64_vs2019' }, - ] - name: msvc-${{ matrix.config }}-${{ matrix.platform }} - runs-on: windows-2019 - steps: - - name: Checkout bgfx - uses: actions/checkout@v3 - with: - path: bgfx - - name: Checkout bx - uses: actions/checkout@v3 - with: - repository: bkaradzic/bx - path: bx - - name: Checkout bimg - uses: actions/checkout@v3 - with: - repository: bkaradzic/bimg - path: bimg - - name: Prepare - uses: microsoft/setup-msbuild@v1.1 - - name: Build - shell: cmd - run: | - cd bgfx - ..\bx\tools\bin\windows\genie.exe --with-tools --with-combined-examples --with-shared-lib vs2019 - msbuild ".build/projects/vs2019/bgfx.sln" /m /v:minimal /p:Configuration=${{ matrix.config }} /p:Platform=${{ matrix.platform }} - - name: Check - shell: cmd - run: | - cd bgfx - dir /s ".build\${{ matrix.bindir }}\bin" - ".build\${{ matrix.bindir }}\bin\geometryc${{ matrix.config }}.exe" --version - ".build\${{ matrix.bindir }}\bin\shaderc${{ matrix.config }}.exe" --version - ".build\${{ matrix.bindir }}\bin\texturec${{ matrix.config }}.exe" --version - mingw: - strategy: - fail-fast: true - matrix: - include: [ - { msystem: MINGW64, project: 'mingw-gcc', bindir: 'win64_mingw-gcc' }, - { msystem: CLANG64, project: 'mingw-clang', bindir: 'win64_mingw-clang' }, - ] - name: mingw-${{ matrix.msystem }} - runs-on: windows-latest - steps: - - name: Checkout bgfx - uses: actions/checkout@v3 - with: - path: bgfx - - name: Checkout bx - uses: actions/checkout@v3 - with: - repository: bkaradzic/bx - path: bx - - name: Checkout bimg - uses: actions/checkout@v3 - with: - repository: bkaradzic/bimg - path: bimg - - name: Prepare - uses: msys2/setup-msys2@v2 - with: - msystem: ${{ matrix.msystem }} - update: true - install: make - pacboy: cc:p - - name: Build - shell: msys2 {0} - run: | - cd bgfx - make ${{ matrix.project }}-release64 -j$(nproc) AR=ar CC=cc CXX=c++ MINGW=$MINGW_PREFIX - - name: Check - shell: cmd - run: | - cd bgfx - dir /s ".build\${{ matrix.bindir }}\bin" - ".build\${{ matrix.bindir }}\bin\geometrycRelease.exe" --version - ".build\${{ matrix.bindir }}\bin\shadercRelease.exe" --version - ".build\${{ matrix.bindir }}\bin\texturecRelease.exe" --version - linux: - strategy: - fail-fast: true - matrix: - include: [ - { config: debug, binsuffix: Debug }, - { config: release, binsuffix: Release }, - ] - name: linux-${{ matrix.config }}64 - runs-on: ubuntu-22.04 - steps: - - name: Checkout bgfx - uses: actions/checkout@v3 - with: - path: bgfx - - name: Checkout bx - uses: actions/checkout@v3 - with: - repository: bkaradzic/bx - path: bx - - name: Checkout bimg - uses: actions/checkout@v3 - with: - repository: bkaradzic/bimg - path: bimg - - name: Build - run: | - sudo apt install libgl-dev - cd bgfx - make -j$(nproc) linux-${{ matrix.config }}64 - - name: Check - run: | - cd bgfx - ls -lash ".build/linux64_gcc/bin" - ".build/linux64_gcc/bin/geometryc${{ matrix.binsuffix}}" --version - ".build/linux64_gcc/bin/shaderc${{ matrix.binsuffix}}" --version - ".build/linux64_gcc/bin/texturec${{ matrix.binsuffix}}" --version - wasm: - strategy: - fail-fast: true - matrix: - config: [ debug, release] - name: wasm-${{ matrix.config }} - runs-on: ubuntu-22.04 - steps: - - name: Checkout bgfx - uses: actions/checkout@v3 - with: - path: bgfx - - name: Checkout bx - uses: actions/checkout@v3 - with: - repository: bkaradzic/bx - path: bx - - name: Checkout bimg - uses: actions/checkout@v3 - with: - repository: bkaradzic/bimg - path: bimg - - name: Prepare - run: | - docker pull emscripten/emsdk - docker run --rm emscripten/emsdk which emcc em++ emar - cd bgfx - EMSCRIPTEN=/emsdk/upstream/emscripten ../bx/tools/bin/linux/genie --with-examples --gcc=wasm gmake - - name: Build - run: > - docker run --rm -u $(id -u):$(id -g) -v $(pwd):/bgfx emscripten/emsdk - make -C /bgfx/bgfx wasm-${{ matrix.config }} -j$(nproc) EMSCRIPTEN=/emsdk/upstream/emscripten - - name: Check - run: | - cd bgfx - ls -lash ".build/wasm/bin" - osx: - strategy: - fail-fast: true - matrix: - include: [ - { config: debug, binsuffix: Debug }, - { config: release, binsuffix: Release }, - ] - name: osx-x64-${{ matrix.config }} - runs-on: macos-latest - steps: - - name: Checkout bgfx - uses: actions/checkout@v3 - with: - path: bgfx - - name: Checkout bx - uses: actions/checkout@v3 - with: - repository: bkaradzic/bx - path: bx - - name: Checkout bimg - uses: actions/checkout@v3 - with: - repository: bkaradzic/bimg - path: bimg - - name: Build - run: | - cd bgfx - make -j$(sysctl -n hw.physicalcpu) osx-x64-${{ matrix.config }} - - name: Check - run: | - cd bgfx - ls -lash ".build/osx-x64/bin" - ".build/osx-x64/bin/geometryc${{ matrix.binsuffix}}" --version - ".build/osx-x64/bin/shaderc${{ matrix.binsuffix}}" --version - ".build/osx-x64/bin/texturec${{ matrix.binsuffix}}" --version - android: - strategy: - fail-fast: true - matrix: - include: [ - { platform: arm64 }, - ] - name: android-${{ matrix.platform }} - runs-on: ubuntu-22.04 - steps: - - uses: nttld/setup-ndk@v1 - id: setup-ndk - with: - ndk-version: r25b - add-to-path: false - - name: Checkout bgfx - uses: actions/checkout@v3 - with: - path: bgfx - - name: Checkout bx - uses: actions/checkout@v3 - with: - repository: bkaradzic/bx - path: bx - - name: Checkout bimg - uses: actions/checkout@v3 - with: - repository: bkaradzic/bimg - path: bimg - - name: Build - run: | - cd bgfx - make -j$(sysctl -n hw.physicalcpu) android-${{ matrix.platform }} - env: - ANDROID_NDK_ROOT: ${{ steps.setup-ndk.outputs.ndk-path }} - - name: Check - run: | - cd bgfx - ls -lash ".build/android-${{ matrix.platform }}/bin" diff --git a/examples/common/nanovg/nanovg_bgfx.cpp b/examples/common/nanovg/nanovg_bgfx.cpp index 3446e405834..23692ef1b91 100644 --- a/examples/common/nanovg/nanovg_bgfx.cpp +++ b/examples/common/nanovg/nanovg_bgfx.cpp @@ -27,12 +27,22 @@ #include "nanovg.h" #include +#include #include #include #include #include +typedef void* (*reallocPROC) (void *ptr, size_t size); +typedef void (*freePROC) (void *ptr); + +static reallocPROC org_lwjgl_realloc; +static freePROC org_lwjgl_free; + +#define NVG_REALLOC(p,sz) org_lwjgl_realloc(p,sz) +#define NVG_FREE(p) org_lwjgl_free(p) + BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4244); // warning C4244: '=' : conversion from '' to '', possible loss of data #include "vs_nanovg_fill.bin.h" @@ -192,7 +202,7 @@ namespace { int old = gl->ctextures; gl->ctextures = (gl->ctextures == 0) ? 2 : gl->ctextures*2; - gl->textures = (struct GLNVGtexture*)bx::realloc(gl->allocator, gl->textures, sizeof(struct GLNVGtexture)*gl->ctextures); + gl->textures = (struct GLNVGtexture*)NVG_REALLOC(gl->textures, sizeof(struct GLNVGtexture)*gl->ctextures); bx::memSet(&gl->textures[old], 0xff, (gl->ctextures-old)*sizeof(struct GLNVGtexture) ); if (gl->textures == NULL) @@ -435,6 +445,29 @@ namespace return c; } + static void nvgTransformIdentity(float* t) + { + t[0] = 1.0f; t[1] = 0.0f; + t[2] = 0.0f; t[3] = 1.0f; + t[4] = 0.0f; t[5] = 0.0f; + } + static int nvgTransformInverse(float* inv, const float* t) + { + double invdet, det = (double)t[0] * t[3] - (double)t[2] * t[1]; + if (det > -1e-6 && det < 1e-6) { + nvgTransformIdentity(inv); + return 0; + } + invdet = 1.0 / det; + inv[0] = (float)(t[3] * invdet); + inv[2] = (float)(-t[2] * invdet); + inv[4] = (float)(((double)t[2] * t[5] - (double)t[3] * t[4]) * invdet); + inv[1] = (float)(-t[1] * invdet); + inv[3] = (float)(t[0] * invdet); + inv[5] = (float)(((double)t[1] * t[4] - (double)t[0] * t[5]) * invdet); + return 1; + } + static int glnvg__convertPaint( struct GLNVGcontext* gl , struct GLNVGfragUniforms* frag @@ -847,7 +880,7 @@ namespace if (gl->ncalls+1 > gl->ccalls) { gl->ccalls = gl->ccalls == 0 ? 32 : gl->ccalls * 2; - gl->calls = (struct GLNVGcall*)bx::realloc(gl->allocator, gl->calls, sizeof(struct GLNVGcall) * gl->ccalls); + gl->calls = (struct GLNVGcall*)NVG_REALLOC(gl->calls, sizeof(struct GLNVGcall) * gl->ccalls); } ret = &gl->calls[gl->ncalls++]; bx::memSet(ret, 0, sizeof(struct GLNVGcall) ); @@ -860,7 +893,7 @@ namespace if (gl->npaths + n > gl->cpaths) { GLNVGpath* paths; int cpaths = glnvg__maxi(gl->npaths + n, 128) + gl->cpaths / 2; // 1.5x Overallocate - paths = (GLNVGpath*)bx::realloc(gl->allocator, gl->paths, sizeof(GLNVGpath) * cpaths); + paths = (GLNVGpath*)NVG_REALLOC(gl->paths, sizeof(GLNVGpath) * cpaths); if (paths == NULL) return -1; gl->paths = paths; gl->cpaths = cpaths; @@ -877,7 +910,7 @@ namespace { NVGvertex* verts; int cverts = glnvg__maxi(gl->nverts + n, 4096) + gl->cverts/2; // 1.5x Overallocate - verts = (NVGvertex*)bx::realloc(gl->allocator, gl->verts, sizeof(NVGvertex) * cverts); + verts = (NVGvertex*)NVG_REALLOC(gl->verts, sizeof(NVGvertex) * cverts); if (verts == NULL) return -1; gl->verts = verts; gl->cverts = cverts; @@ -893,7 +926,7 @@ namespace if (gl->nuniforms+n > gl->cuniforms) { gl->cuniforms = gl->cuniforms == 0 ? glnvg__maxi(n, 32) : gl->cuniforms * 2; - gl->uniforms = (unsigned char*)bx::realloc(gl->allocator, gl->uniforms, gl->cuniforms * structSize); + gl->uniforms = (unsigned char*)NVG_REALLOC(gl->uniforms, gl->cuniforms * structSize); } ret = gl->nuniforms * structSize; gl->nuniforms += n; @@ -1098,17 +1131,39 @@ namespace } } - bx::free(gl->allocator, gl->uniforms); - bx::free(gl->allocator, gl->verts); - bx::free(gl->allocator, gl->paths); - bx::free(gl->allocator, gl->calls); - bx::free(gl->allocator, gl->textures); + NVG_FREE(gl->uniforms); + NVG_FREE(gl->verts); + NVG_FREE(gl->paths); + NVG_FREE(gl->calls); + NVG_FREE(gl->textures); bx::free(gl->allocator, gl); } } // namespace -NVGcontext* nvgCreate(int32_t _edgeaa, bgfx::ViewId _viewId, bx::AllocatorI* _allocator) +typedef NVGcontext* (*nvgCreateInternalPROC) (NVGparams*); +typedef NVGparams* (*nvgInternalParamsPROC) (NVGcontext*); +typedef void (*nvgDeleteInternalPROC) (NVGcontext*); + +static nvgCreateInternalPROC org_lwjgl_nvgCreateInternal; +static nvgInternalParamsPROC org_lwjgl_nvgInternalParams; +static nvgDeleteInternalPROC org_lwjgl_nvgDeleteInternal; + +BGFX_C_API void org_lwjgl_nanovg_setup( + reallocPROC realloc, + freePROC free, + nvgCreateInternalPROC nvgCreateInternal, + nvgInternalParamsPROC nvgInternalParams, + nvgDeleteInternalPROC nvgDeleteInternal +) { + org_lwjgl_realloc = realloc; + org_lwjgl_free = free; + org_lwjgl_nvgCreateInternal = nvgCreateInternal; + org_lwjgl_nvgInternalParams = nvgInternalParams; + org_lwjgl_nvgDeleteInternal = nvgDeleteInternal; +} + +BGFX_C_API NVGcontext* nvgCreate(int32_t _edgeaa, bgfx::ViewId _viewId, bx::AllocatorI* _allocator) { if (NULL == _allocator) { @@ -1145,7 +1200,7 @@ NVGcontext* nvgCreate(int32_t _edgeaa, bgfx::ViewId _viewId, bx::AllocatorI* _al gl->edgeAntiAlias = _edgeaa; gl->viewId = _viewId; - ctx = nvgCreateInternal(¶ms); + ctx = org_lwjgl_nvgCreateInternal(¶ms); if (ctx == NULL) goto error; return ctx; @@ -1154,7 +1209,7 @@ NVGcontext* nvgCreate(int32_t _edgeaa, bgfx::ViewId _viewId, bx::AllocatorI* _al // 'gl' is freed by nvgDeleteInternal. if (ctx != NULL) { - nvgDeleteInternal(ctx); + org_lwjgl_nvgDeleteInternal(ctx); } return NULL; @@ -1164,28 +1219,28 @@ NVGcontext* nvgCreate(int32_t _edgeaa, bgfx::ViewId _viewId) { return nvgCreate(_edgeaa, _viewId, NULL); } -void nvgDelete(NVGcontext* _ctx) +BGFX_C_API void nvgDelete(NVGcontext* _ctx) { - nvgDeleteInternal(_ctx); + org_lwjgl_nvgDeleteInternal(_ctx); } -void nvgSetViewId(NVGcontext* _ctx, bgfx::ViewId _viewId) +BGFX_C_API void nvgSetViewId(NVGcontext* _ctx, bgfx::ViewId _viewId) { - struct NVGparams* params = nvgInternalParams(_ctx); + struct NVGparams* params = org_lwjgl_nvgInternalParams(_ctx); struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr; gl->viewId = _viewId; } -uint16_t nvgGetViewId(struct NVGcontext* _ctx) +BGFX_C_API uint16_t nvgGetViewId(struct NVGcontext* _ctx) { - struct NVGparams* params = nvgInternalParams(_ctx); + struct NVGparams* params = org_lwjgl_nvgInternalParams(_ctx); struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr; return gl->viewId; } bgfx::TextureHandle nvglImageHandle(NVGcontext* _ctx, int32_t _image) { - GLNVGcontext* gl = (GLNVGcontext*)nvgInternalParams(_ctx)->userPtr; + GLNVGcontext* gl = (GLNVGcontext*)org_lwjgl_nvgInternalParams(_ctx)->userPtr; GLNVGtexture* tex = glnvg__findTexture(gl, _image); return tex->id; } @@ -1202,7 +1257,7 @@ NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int32_t width, int32_t return framebuffer; } -NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _width, int32_t _height, int32_t _imageFlags) +BGFX_C_API NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _width, int32_t _height, int32_t _imageFlags) { BX_UNUSED(_imageFlags); BX_ASSERT(_width >= 0 && _width <= bx::max(), "Invalid tex width %d (max: %u)", _width, bx::max()); @@ -1225,7 +1280,7 @@ NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _width, int32 return NULL; } - struct NVGparams* params = nvgInternalParams(_ctx); + struct NVGparams* params = org_lwjgl_nvgInternalParams(_ctx); struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr; struct GLNVGtexture* tex = glnvg__allocTexture(gl); @@ -1249,62 +1304,7 @@ NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _width, int32 return framebuffer; } -NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int32_t imageFlags, bgfx::ViewId viewId) -{ - NVGLUframebuffer* framebuffer = nvgluCreateFramebuffer(ctx, imageFlags); - - if (framebuffer != NULL) - { - nvgluSetViewFramebuffer(viewId, framebuffer); - } - - return framebuffer; -} - -NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _imageFlags) -{ - BX_UNUSED(_imageFlags); - bgfx::TextureHandle textures[] = - { - bgfx::createTexture2D(bgfx::BackbufferRatio::Equal, false, 1, bgfx::TextureFormat::RGBA8, BGFX_TEXTURE_RT), - bgfx::createTexture2D(bgfx::BackbufferRatio::Equal, false, 1, bgfx::TextureFormat::D24S8, BGFX_TEXTURE_RT | BGFX_TEXTURE_RT_WRITE_ONLY) - }; - bgfx::FrameBufferHandle fbh = bgfx::createFrameBuffer( - BX_COUNTOF(textures) - , textures - , true - ); - - if (!bgfx::isValid(fbh) ) - { - return NULL; - } - - struct NVGparams* params = nvgInternalParams(_ctx); - struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr; - struct GLNVGtexture* tex = glnvg__allocTexture(gl); - - if (NULL == tex) - { - bgfx::destroy(fbh); - return NULL; - } - - tex->width = 0; - tex->height = 0; - tex->type = NVG_TEXTURE_RGBA; - tex->flags = _imageFlags | NVG_IMAGE_PREMULTIPLIED; - tex->id = bgfx::getTexture(fbh); - - NVGLUframebuffer* framebuffer = BX_NEW(gl->allocator, NVGLUframebuffer); - framebuffer->ctx = _ctx; - framebuffer->image = tex->id.idx; - framebuffer->handle = fbh; - - return framebuffer; -} - -void nvgluBindFramebuffer(NVGLUframebuffer* _framebuffer) +BGFX_C_API void nvgluBindFramebuffer(NVGLUframebuffer* _framebuffer) { static NVGcontext* s_prevCtx = NULL; static bgfx::ViewId s_prevViewId; @@ -1320,7 +1320,7 @@ void nvgluBindFramebuffer(NVGLUframebuffer* _framebuffer) } } -void nvgluDeleteFramebuffer(NVGLUframebuffer* _framebuffer) +BGFX_C_API void nvgluDeleteFramebuffer(NVGLUframebuffer* _framebuffer) { if (_framebuffer == NULL) { @@ -1332,25 +1332,25 @@ void nvgluDeleteFramebuffer(NVGLUframebuffer* _framebuffer) bgfx::destroy(_framebuffer->handle); } - struct NVGparams* params = nvgInternalParams(_framebuffer->ctx); + struct NVGparams* params = org_lwjgl_nvgInternalParams(_framebuffer->ctx); struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr; glnvg__deleteTexture(gl, _framebuffer->image); bx::deleteObject(gl->allocator, _framebuffer); } -void nvgluSetViewFramebuffer(bgfx::ViewId _viewId, NVGLUframebuffer* _framebuffer) +BGFX_C_API void nvgluSetViewFramebuffer(bgfx::ViewId _viewId, NVGLUframebuffer* _framebuffer) { _framebuffer->viewId = _viewId; bgfx::setViewFrameBuffer(_viewId, _framebuffer->handle); bgfx::setViewMode(_viewId, bgfx::ViewMode::Sequential); } -int nvgCreateBgfxTexture(struct NVGcontext *_ctx, - bgfx::TextureHandle _id, - int _width, - int _height, - int _flags) { - struct NVGparams *params = nvgInternalParams(_ctx); +BGFX_C_API int nvgCreateBgfxTexture(struct NVGcontext *_ctx, + bgfx::TextureHandle _id, + int _width, + int _height, + int _flags) { + struct NVGparams *params = org_lwjgl_nvgInternalParams(_ctx); struct GLNVGcontext *gl = (struct GLNVGcontext *)params->userPtr; struct GLNVGtexture *tex = glnvg__allocTexture(gl); tex->id = _id; diff --git a/examples/common/nanovg/nanovg_bgfx.h b/examples/common/nanovg/nanovg_bgfx.h index a0beb926103..a8f9b1b6ba1 100644 --- a/examples/common/nanovg/nanovg_bgfx.h +++ b/examples/common/nanovg/nanovg_bgfx.h @@ -7,6 +7,7 @@ #define NANOVG_BGFX_H_HEADER_GUARD #include +#include namespace bx { struct AllocatorI; } @@ -26,19 +27,19 @@ enum NVGimageFlagsGL { }; /// -NVGcontext* nvgCreate(int32_t _edgeaa, bgfx::ViewId _viewId, bx::AllocatorI* _allocator); +BGFX_C_API NVGcontext* nvgCreate(int32_t _edgeaa, bgfx::ViewId _viewId, bx::AllocatorI* _allocator); /// NVGcontext* nvgCreate(int32_t _edgeaa, bgfx::ViewId _viewId); /// -void nvgDelete(NVGcontext* _ctx); +BGFX_C_API void nvgDelete(NVGcontext* _ctx); /// -void nvgSetViewId(NVGcontext* _ctx, bgfx::ViewId _viewId); +BGFX_C_API void nvgSetViewId(NVGcontext* _ctx, bgfx::ViewId _viewId); /// -uint16_t nvgGetViewId(struct NVGcontext* _ctx); +BGFX_C_API uint16_t nvgGetViewId(struct NVGcontext* _ctx); // Helper functions to create bgfx framebuffer to render to. // Example: @@ -64,22 +65,19 @@ uint16_t nvgGetViewId(struct NVGcontext* _ctx); NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _width, int32_t _height, int32_t _imageFlags, bgfx::ViewId _viewId); /// -NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _width, int32_t _height, int32_t _imageFlags); +BGFX_C_API NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _width, int32_t _height, int32_t _imageFlags); /// -NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _imageFlags, bgfx::ViewId _viewId); +BGFX_C_API void nvgluBindFramebuffer(NVGLUframebuffer* _framebuffer); /// -NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _imageFlags); +BGFX_C_API void nvgluDeleteFramebuffer(NVGLUframebuffer* _framebuffer); /// -void nvgluBindFramebuffer(NVGLUframebuffer* _framebuffer); +BGFX_C_API void nvgluSetViewFramebuffer(bgfx::ViewId _viewId, NVGLUframebuffer* _framebuffer); /// -void nvgluDeleteFramebuffer(NVGLUframebuffer* _framebuffer); - -/// -void nvgluSetViewFramebuffer(bgfx::ViewId _viewId, NVGLUframebuffer* _framebuffer); +BGFX_C_API int nvgCreateBgfxTexture(NVGcontext * _ctx, bgfx::TextureHandle _id, int _width, int _height, int _flags); /// int nvgCreateBgfxTexture(struct NVGcontext *_ctx, bgfx::TextureHandle _id, int _width, int _height, int _flags); diff --git a/scripts/bgfx.lua b/scripts/bgfx.lua index 1117b9eee2e..9913485e41a 100644 --- a/scripts/bgfx.lua +++ b/scripts/bgfx.lua @@ -138,14 +138,21 @@ function bgfxProjectBase(_kind, _defines) configuration { "osx*" } buildoptions { "-x objective-c++" } -- additional build option for osx + defines { + "BGFX_CONFIG_RENDERER_OPENGL=0", + "BGFX_CONFIG_RENDERER_OPENGLES=0", + } linkoptions { "-framework Cocoa", "-framework IOKit", - "-framework OpenGL", + --"-framework OpenGL", "-framework QuartzCore", "-weak_framework Metal", "-weak_framework MetalKit", } + --removefiles { + --path.join(BGFX_DIR, "src/glcontext**"), + --} configuration { "not NX32", "not NX64" } includedirs { @@ -164,10 +171,14 @@ function bgfxProjectBase(_kind, _defines) path.join(BGFX_DIR, "src/**.cpp"), path.join(BGFX_DIR, "src/**.h"), path.join(BGFX_DIR, "scripts/**.natvis"), + path.join(BGFX_DIR, "examples/common/nanovg/**.cpp"), + path.join(BGFX_DIR, "examples/common/nanovg/**.h"), } removefiles { path.join(BGFX_DIR, "src/**.bin.h"), + path.join(BGFX_DIR, "examples/common/nanovg/nanovg.cpp"), + path.join(BGFX_DIR, "examples/common/nanovg/**.bin.h"), } overridefiles(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-agc"), {