Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a74936103 |
@@ -1,7 +0,0 @@
|
|||||||
name: 'Set up dependency versions'
|
|
||||||
runs:
|
|
||||||
using: "composite"
|
|
||||||
steps:
|
|
||||||
- name: Set up dependency versions
|
|
||||||
shell: bash
|
|
||||||
run: cat ./build/common/versions >> $GITHUB_ENV
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
name: 'Linux Preqrequisites'
|
|
||||||
runs:
|
|
||||||
using: "composite"
|
|
||||||
steps:
|
|
||||||
- uses: ./.github/actions/dep-versions
|
|
||||||
- name: Install Linux Prerequisites
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -xe
|
|
||||||
# See https://askubuntu.com/questions/272248/processing-triggers-for-man-db/1476024#1476024
|
|
||||||
echo "set man-db/auto-update false" | sudo debconf-communicate
|
|
||||||
sudo dpkg-reconfigure man-db
|
|
||||||
|
|
||||||
# Install ninja
|
|
||||||
source ./build/common/get-ninja.sh
|
|
||||||
|
|
||||||
# Install CMake
|
|
||||||
mkdir -p cmake
|
|
||||||
cd cmake
|
|
||||||
|
|
||||||
sudo wget https://github.com/Kitware/CMake/releases/download/v$GITHUB_CMAKE_VERSION/cmake-$GITHUB_CMAKE_VERSION-Linux-x86_64.sh
|
|
||||||
sudo chmod +x ./cmake-$GITHUB_CMAKE_VERSION-Linux-x86_64.sh
|
|
||||||
sudo ./cmake-$GITHUB_CMAKE_VERSION-Linux-x86_64.sh --skip-license > /dev/null
|
|
||||||
sudo update-alternatives --install /usr/bin/cmake cmake $(pwd)/bin/cmake 1000 --force
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
sudo wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install clang-$GITHUB_CLANG_VERSION libc++-$GITHUB_CLANG_VERSION-dev libc++abi-$GITHUB_CLANG_VERSION-dev
|
|
||||||
sudo apt-get install mesa-common-dev libxi-dev libxxf86vm-dev
|
|
||||||
|
|
||||||
# For dawn
|
|
||||||
sudo apt-get install libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libx11-xcb-dev
|
|
||||||
|
|
||||||
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-${GITHUB_CLANG_VERSION} 100
|
|
||||||
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-${GITHUB_CLANG_VERSION} 100
|
|
||||||
set +xe
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
name: 'Mac Preqrequisites'
|
|
||||||
runs:
|
|
||||||
using: "composite"
|
|
||||||
steps:
|
|
||||||
- uses: ./.github/actions/dep-versions
|
|
||||||
- name: Set up Homebrew
|
|
||||||
id: set-up-homebrew
|
|
||||||
uses: Homebrew/actions/setup-homebrew@master
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: '3.x'
|
|
||||||
- name: Cache Brew
|
|
||||||
id: brew-cache
|
|
||||||
uses: actions/cache@v4 # Use a specific version
|
|
||||||
with:
|
|
||||||
path: $HOME/Library/Caches/Homebrew
|
|
||||||
key: ${{ runner.os }}-brew-20250424
|
|
||||||
- name: Install Mac Prerequisites
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
# Install ninja
|
|
||||||
source ./build/common/get-ninja.sh
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
name: 'Web Preqrequisites'
|
|
||||||
runs:
|
|
||||||
using: "composite"
|
|
||||||
steps:
|
|
||||||
- uses: ./.github/actions/dep-versions
|
|
||||||
- name: Cache EMSDK
|
|
||||||
id: emsdk-cache
|
|
||||||
uses: actions/cache@v4 # Use a specific version
|
|
||||||
with:
|
|
||||||
path: emsdk
|
|
||||||
key: ${{ runner.os }}-emsdk-${{ env.GITHUB_EMSDK_VERSION }}
|
|
||||||
- name: Install Web Prerequisites
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
bash ./build/common/get-emscripten.sh
|
|
||||||
echo "EMSDK=$PWD/emsdk" >> $GITHUB_ENV
|
|
||||||
@@ -16,9 +16,6 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- uses: ./.github/actions/linux-prereq
|
|
||||||
- name: Run Android Continuous
|
- name: Run Android Continuous
|
||||||
uses: ./.github/actions/android-continuous
|
uses: ./.github/actions/android-continuous
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- uses: ./.github/actions/mac-prereq
|
|
||||||
- name: Run build script
|
- name: Run build script
|
||||||
run: |
|
run: |
|
||||||
cd build/ios && printf "y" | ./build.sh continuous
|
cd build/ios && printf "y" | ./build.sh continuous
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- uses: ./.github/actions/linux-prereq
|
|
||||||
- name: Run build script
|
- name: Run build script
|
||||||
run: |
|
run: |
|
||||||
cd build/linux && printf "y" | ./build.sh continuous
|
cd build/linux && printf "y" | ./build.sh continuous
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- uses: ./.github/actions/mac-prereq
|
|
||||||
- name: Run build script
|
- name: Run build script
|
||||||
run: |
|
run: |
|
||||||
cd build/mac && printf "y" | ./build.sh continuous
|
cd build/mac && printf "y" | ./build.sh continuous
|
||||||
@@ -26,4 +23,4 @@ jobs:
|
|||||||
path: out/filament-release-darwin.tgz
|
path: out/filament-release-darwin.tgz
|
||||||
- name: Check public headers
|
- name: Check public headers
|
||||||
run: |
|
run: |
|
||||||
test/check-headers/test.sh out/release/filament/include
|
build/common/check-headers.sh out/release/filament/include
|
||||||
|
|||||||
@@ -9,43 +9,32 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-desktop-mac:
|
build-desktop:
|
||||||
name: build-mac
|
name: build-desktop
|
||||||
runs-on: macos-14-xlarge
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4.1.6
|
strategy:
|
||||||
with:
|
matrix:
|
||||||
fetch-depth: 0
|
os: [macos-14-xlarge, ubuntu-22.04-16core]
|
||||||
- uses: ./.github/actions/mac-prereq
|
|
||||||
- name: Run build script
|
|
||||||
run: |
|
|
||||||
cd build/mac && printf "y" | ./build.sh presubmit
|
|
||||||
- name: Test material parser
|
|
||||||
run: |
|
|
||||||
out/cmake-release/filament/test/test_material_parser
|
|
||||||
|
|
||||||
build-desktop-linux:
|
|
||||||
name: build-linux
|
|
||||||
runs-on: ubuntu-22.04-16core
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- uses: ./.github/actions/linux-prereq
|
|
||||||
- name: Run build script
|
- name: Run build script
|
||||||
run: |
|
run: |
|
||||||
cd build/linux && printf "y" | ./build.sh presubmit
|
WORKFLOW_OS=`echo \`uname\` | sed "s/Darwin/mac/" | tr [:upper:] [:lower:]`
|
||||||
|
cd build/$WORKFLOW_OS && printf "y" | ./build.sh presubmit
|
||||||
- name: Test material parser
|
- name: Test material parser
|
||||||
run: |
|
run: |
|
||||||
out/cmake-release/filament/test/test_material_parser
|
out/cmake-release/filament/test/test_material_parser
|
||||||
|
|
||||||
build-windows:
|
build-windows:
|
||||||
name: build-windows
|
name: build-windows
|
||||||
runs-on: windows-2022-32core
|
runs-on: win-2019-16core
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- name: Run build script
|
- name: Run build script
|
||||||
run: |
|
run: |
|
||||||
build\windows\build-github.bat presubmit
|
build\windows\build-github.bat presubmit
|
||||||
@@ -59,7 +48,6 @@ jobs:
|
|||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- uses: ./.github/actions/linux-prereq
|
|
||||||
- uses: actions/setup-java@v3
|
- uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
@@ -78,7 +66,6 @@ jobs:
|
|||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- uses: ./.github/actions/mac-prereq
|
|
||||||
- name: Run build script
|
- name: Run build script
|
||||||
run: |
|
run: |
|
||||||
cd build/ios && printf "y" | ./build.sh presubmit
|
cd build/ios && printf "y" | ./build.sh presubmit
|
||||||
@@ -92,10 +79,6 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- uses: ./.github/actions/linux-prereq
|
|
||||||
- uses: ./.github/actions/web-prereq
|
|
||||||
- name: Run build script
|
- name: Run build script
|
||||||
run: |
|
run: |
|
||||||
cd build/web && printf "y" | ./build.sh presubmit
|
cd build/web && printf "y" | ./build.sh presubmit
|
||||||
@@ -118,22 +101,30 @@ jobs:
|
|||||||
runs-on: macos-14-xlarge
|
runs-on: macos-14-xlarge
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
|
- name: Set up Homebrew
|
||||||
|
id: set-up-homebrew
|
||||||
|
uses: Homebrew/actions/setup-homebrew@master
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
python-version: '3.x'
|
||||||
- uses: ./.github/actions/mac-prereq
|
|
||||||
- name: Cache Mesa and deps
|
- name: Cache Mesa and deps
|
||||||
id: mesa-cache
|
id: mesa-cache
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4 # Use a specific version
|
||||||
with:
|
with:
|
||||||
path: mesa
|
path: |
|
||||||
key: ${{ runner.os }}-mesa-deps-2-${{ vars.MESA_VERSION }}
|
$HOME/Library/Caches/Homebrew
|
||||||
- name: Prerequisites
|
mesa
|
||||||
id: prereqs
|
key: ${{ runner.os }}-mesa-deps-${{ vars.MESA_VERSION }}
|
||||||
|
- name: Get Mesa
|
||||||
|
id: mesa-prereq
|
||||||
|
env:
|
||||||
|
MESA_VERSION: ${{ vars.MESA_VERSION }}
|
||||||
run: |
|
run: |
|
||||||
bash build/common/get-mesa.sh
|
bash test/utils/get_mesa.sh
|
||||||
pip install tifffile numpy
|
|
||||||
- name: Run Test
|
- name: Run Test
|
||||||
run: bash test/renderdiff/test.sh
|
run: |
|
||||||
|
bash test/renderdiff/test.sh
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: presubmit-renderdiff-result
|
name: presubmit-renderdiff-result
|
||||||
@@ -142,33 +133,38 @@ jobs:
|
|||||||
validate-wgsl-webgpu:
|
validate-wgsl-webgpu:
|
||||||
name: validate-wgsl-webgpu
|
name: validate-wgsl-webgpu
|
||||||
runs-on: 'ubuntu-24.04-8core'
|
runs-on: 'ubuntu-24.04-8core'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- uses: ./.github/actions/linux-prereq
|
|
||||||
- name: Run build script
|
- name: Run build script
|
||||||
run: ./build.sh -W debug test_filamat filament
|
run: source ./build/linux/ci-common.sh && ./build.sh -W debug test_filamat filament
|
||||||
- name: Run test
|
- name: Run test
|
||||||
run: ./out/cmake-debug/libs/filamat/test_filamat --gtest_filter=MaterialCompiler.Wgsl*
|
run: ./out/cmake-debug/libs/filamat/test_filamat --gtest_filter=MaterialCompiler.Wgsl*
|
||||||
|
|
||||||
test-code-correctness:
|
code-correcteness:
|
||||||
name: test-code-correctness
|
name: code-correctness
|
||||||
runs-on: 'macos-14-xlarge'
|
runs-on: 'macos-14-xlarge'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- uses: ./.github/actions/mac-prereq
|
- name: Set up Homebrew
|
||||||
- name: Install clang-tidy and deps
|
id: set-up-homebrew
|
||||||
|
uses: Homebrew/actions/setup-homebrew@master
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
- name: Install prerequisites
|
||||||
run: |
|
run: |
|
||||||
pip install pyyaml
|
pip install pyyaml
|
||||||
brew install llvm@${GITHUB_LLVM_VERSION}
|
brew install llvm
|
||||||
sudo ln -s "$(brew --prefix llvm)@${GITHUB_LLVM_VERSION}/bin/clang-tidy" "/usr/local/bin/clang-tidy"
|
sudo ln -s "$(brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy"
|
||||||
- name: Run build script
|
- name: Run build script
|
||||||
# We need to build before clang-tidy can run analysis
|
# We need to build before clang-tidy can run analysis
|
||||||
run: |
|
run: |
|
||||||
# This will build for all three desktop backends on mac
|
# This will build for all three desktop backends on mac
|
||||||
./build.sh -p desktop debug gltf_viewer
|
./build.sh -p desktop debug gltf_viewer
|
||||||
- name: Run test
|
- name: Run test
|
||||||
run: bash test/code-correctness/test.sh
|
run: |
|
||||||
|
bash test/code-correctness/test.sh
|
||||||
|
|||||||
@@ -29,11 +29,15 @@ on:
|
|||||||
types: [created]
|
types: [created]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-linux:
|
build-desktop:
|
||||||
name: build-linux
|
name: build-desktop
|
||||||
runs-on: ubuntu-22.04-32core
|
runs-on: ${{ matrix.os }}
|
||||||
if: github.event_name == 'release' || github.event.inputs.platform == 'desktop'
|
if: github.event_name == 'release' || github.event.inputs.platform == 'desktop'
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [macos-14-xlarge, ubuntu-22.04-32core]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Decide Git ref
|
- name: Decide Git ref
|
||||||
id: git_ref
|
id: git_ref
|
||||||
@@ -45,48 +49,15 @@ jobs:
|
|||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
with:
|
with:
|
||||||
ref: ${{ steps.git_ref.outputs.ref }}
|
ref: ${{ steps.git_ref.outputs.ref }}
|
||||||
- uses: ./.github/actions/linux-prereq
|
|
||||||
- name: Run build script
|
- name: Run build script
|
||||||
env:
|
env:
|
||||||
TAG: ${{ steps.git_ref.outputs.tag }}
|
TAG: ${{ steps.git_ref.outputs.tag }}
|
||||||
run: |
|
run: |
|
||||||
cd build/linux && printf "y" | ./build.sh release
|
WORKFLOW_OS=`echo \`uname\` | sed "s/Darwin/mac/" | tr [:upper:] [:lower:]`
|
||||||
|
cd build/$WORKFLOW_OS && printf "y" | ./build.sh release
|
||||||
cd ../..
|
cd ../..
|
||||||
mv out/filament-release-linux.tgz out/filament-${TAG}-linux.tgz
|
if [ -f out/filament-release-darwin.tgz ]; then mv out/filament-release-darwin.tgz out/filament-${TAG}-mac.tgz; fi;
|
||||||
- uses: actions/github-script@v6
|
if [ -f out/filament-release-linux.tgz ]; then mv out/filament-release-linux.tgz out/filament-${TAG}-linux.tgz; fi;
|
||||||
env:
|
|
||||||
TAG: ${{ steps.git_ref.outputs.tag }}
|
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
const upload = require('./build/common/upload-release-assets');
|
|
||||||
const { TAG } = process.env;
|
|
||||||
const globber = await glob.create('out/*.tgz');
|
|
||||||
await upload({ github, context }, await globber.glob(), TAG);
|
|
||||||
|
|
||||||
build-mac:
|
|
||||||
name: build-mac
|
|
||||||
runs-on: macos-14-xlarge
|
|
||||||
if: github.event_name == 'release' || github.event.inputs.platform == 'desktop'
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Decide Git ref
|
|
||||||
id: git_ref
|
|
||||||
run: |
|
|
||||||
REF=${RELEASE_TAG:-${GITHUB_REF}}
|
|
||||||
TAG=${REF##*/}
|
|
||||||
echo "ref=${REF}" >> $GITHUB_OUTPUT
|
|
||||||
echo "tag=${TAG}" >> $GITHUB_OUTPUT
|
|
||||||
- uses: actions/checkout@v4.1.6
|
|
||||||
with:
|
|
||||||
ref: ${{ steps.git_ref.outputs.ref }}
|
|
||||||
- uses: ./.github/actions/mac-prereq
|
|
||||||
- name: Run build script
|
|
||||||
env:
|
|
||||||
TAG: ${{ steps.git_ref.outputs.tag }}
|
|
||||||
run: |
|
|
||||||
cd build/mac && printf "y" | ./build.sh release
|
|
||||||
cd ../..
|
|
||||||
mv out/filament-release-darwin.tgz out/filament-${TAG}-mac.tgz
|
|
||||||
- uses: actions/github-script@v6
|
- uses: actions/github-script@v6
|
||||||
env:
|
env:
|
||||||
TAG: ${{ steps.git_ref.outputs.tag }}
|
TAG: ${{ steps.git_ref.outputs.tag }}
|
||||||
@@ -113,8 +84,6 @@ jobs:
|
|||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
with:
|
with:
|
||||||
ref: ${{ steps.git_ref.outputs.ref }}
|
ref: ${{ steps.git_ref.outputs.ref }}
|
||||||
- uses: ./.github/actions/linux-prereq
|
|
||||||
- uses: ./.github/actions/web-prereq
|
|
||||||
- name: Run build script
|
- name: Run build script
|
||||||
env:
|
env:
|
||||||
TAG: ${{ steps.git_ref.outputs.tag }}
|
TAG: ${{ steps.git_ref.outputs.tag }}
|
||||||
@@ -152,7 +121,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '17'
|
java-version: '17'
|
||||||
- uses: ./.github/actions/linux-prereq
|
|
||||||
- name: Run build script
|
- name: Run build script
|
||||||
env:
|
env:
|
||||||
TAG: ${{ steps.git_ref.outputs.tag }}
|
TAG: ${{ steps.git_ref.outputs.tag }}
|
||||||
@@ -163,9 +131,6 @@ jobs:
|
|||||||
mv out/filamat-android-release.aar out/filamat-${TAG}-android.aar
|
mv out/filamat-android-release.aar out/filamat-${TAG}-android.aar
|
||||||
mv out/gltfio-android-release.aar out/gltfio-${TAG}-android.aar
|
mv out/gltfio-android-release.aar out/gltfio-${TAG}-android.aar
|
||||||
mv out/filament-utils-android-release.aar out/filament-utils-${TAG}-android.aar
|
mv out/filament-utils-android-release.aar out/filament-utils-${TAG}-android.aar
|
||||||
cd out/android-release/filament
|
|
||||||
tar -czf ../../filament-${TAG}-android-native.tgz .
|
|
||||||
cd ../../..
|
|
||||||
- name: Sign sample-gltf-viewer
|
- name: Sign sample-gltf-viewer
|
||||||
run: |
|
run: |
|
||||||
echo "${APK_KEYSTORE_BASE64}" > filament.jks.base64
|
echo "${APK_KEYSTORE_BASE64}" > filament.jks.base64
|
||||||
@@ -187,7 +152,7 @@ jobs:
|
|||||||
script: |
|
script: |
|
||||||
const upload = require('./build/common/upload-release-assets');
|
const upload = require('./build/common/upload-release-assets');
|
||||||
const { TAG } = process.env;
|
const { TAG } = process.env;
|
||||||
const globber = await glob.create(['out/*.aar', 'out/*.apk', 'out/*.tgz'].join('\n'));
|
const globber = await glob.create(['out/*.aar', 'out/*.apk'].join('\n'));
|
||||||
await upload({ github, context }, await globber.glob(), TAG);
|
await upload({ github, context }, await globber.glob(), TAG);
|
||||||
|
|
||||||
build-ios:
|
build-ios:
|
||||||
@@ -206,7 +171,6 @@ jobs:
|
|||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
with:
|
with:
|
||||||
ref: ${{ steps.git_ref.outputs.ref }}
|
ref: ${{ steps.git_ref.outputs.ref }}
|
||||||
- uses: ./.github/actions/mac-prereq
|
|
||||||
- name: Run build script
|
- name: Run build script
|
||||||
env:
|
env:
|
||||||
TAG: ${{ steps.git_ref.outputs.tag }}
|
TAG: ${{ steps.git_ref.outputs.tag }}
|
||||||
@@ -226,7 +190,7 @@ jobs:
|
|||||||
|
|
||||||
build-windows:
|
build-windows:
|
||||||
name: build-windows
|
name: build-windows
|
||||||
runs-on: windows-2022-32core
|
runs-on: windows-2019-32core
|
||||||
if: github.event_name == 'release' || github.event.inputs.platform == 'windows'
|
if: github.event_name == 'release' || github.event.inputs.platform == 'windows'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -14,10 +14,6 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- uses: ./.github/actions/linux-prereq
|
|
||||||
- uses: ./.github/actions/web-prereq
|
|
||||||
- name: Run build script
|
- name: Run build script
|
||||||
run: |
|
run: |
|
||||||
cd build/web && printf "y" | ./build.sh continuous
|
cd build/web && printf "y" | ./build.sh continuous
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build-windows:
|
build-windows:
|
||||||
name: build-windows
|
name: build-windows
|
||||||
runs-on: windows-2022-32core
|
runs-on: windows-2019-32core
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
|
|||||||
+15
@@ -18,3 +18,18 @@ test*.json
|
|||||||
results
|
results
|
||||||
/compile_commands.json
|
/compile_commands.json
|
||||||
/.cache
|
/.cache
|
||||||
|
build/.cmake/
|
||||||
|
build/CMakeCache.txt
|
||||||
|
build/CMakeFiles/
|
||||||
|
build/Makefile
|
||||||
|
build/SPIRV-Tools*
|
||||||
|
build/cmake_install.cmake
|
||||||
|
build/compile_commands.json
|
||||||
|
build/filament/
|
||||||
|
build/include/
|
||||||
|
build/libs/
|
||||||
|
build/mac/ninja
|
||||||
|
build/samples/
|
||||||
|
build/shaders/
|
||||||
|
build/third_party/
|
||||||
|
build/tools/
|
||||||
|
|||||||
@@ -363,8 +363,6 @@ python ./emsdk.py activate latest
|
|||||||
source ./emsdk_env.sh
|
source ./emsdk_env.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
Alternatively, you can try running the script `build/common/get-emscripten.sh`.
|
|
||||||
|
|
||||||
After this you can invoke the [easy build](#easy-build) script as follows:
|
After this you can invoke the [easy build](#easy-build) script as follows:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
|||||||
@@ -49,10 +49,6 @@ option(FILAMENT_SUPPORTS_OSMESA "Enable OSMesa (headless GL context) for Filamen
|
|||||||
|
|
||||||
option(FILAMENT_ENABLE_FGVIEWER "Enable the frame graph viewer" OFF)
|
option(FILAMENT_ENABLE_FGVIEWER "Enable the frame graph viewer" OFF)
|
||||||
|
|
||||||
# This is to disable GTAO for the short-term while we investigate a way to better manage size increases.
|
|
||||||
# On the regular filament build (where size is of less concern), we enable GTAO by default.
|
|
||||||
option(FILAMENT_DISABLE_GTAO "Disable GTAO" OFF)
|
|
||||||
|
|
||||||
set(FILAMENT_NDK_VERSION "" CACHE STRING
|
set(FILAMENT_NDK_VERSION "" CACHE STRING
|
||||||
"Android NDK version or version prefix to be used when building for Android."
|
"Android NDK version or version prefix to be used when building for Android."
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.google.android.filament:filament-android:1.61.0'
|
implementation 'com.google.android.filament:filament-android:1.59.3'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ Here are all the libraries available in the group `com.google.android.filament`:
|
|||||||
iOS projects can use CocoaPods to install the latest release:
|
iOS projects can use CocoaPods to install the latest release:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
pod 'Filament', '~> 1.61.0'
|
pod 'Filament', '~> 1.59.3'
|
||||||
```
|
```
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|||||||
@@ -7,25 +7,6 @@ A new header is inserted each time a *tag* is created.
|
|||||||
Instead, if you are authoring a PR for the main branch, add your release note to
|
Instead, if you are authoring a PR for the main branch, add your release note to
|
||||||
[NEW_RELEASE_NOTES.md](./NEW_RELEASE_NOTES.md).
|
[NEW_RELEASE_NOTES.md](./NEW_RELEASE_NOTES.md).
|
||||||
|
|
||||||
## v1.61.0
|
|
||||||
|
|
||||||
- materials: sampler now export their type in the material binary [⚠️ **New Material Version**]
|
|
||||||
- samples/texturedquad.cpp now has CLI to select backend api
|
|
||||||
- samples/hellopbr.cpp CLI now allows for selecting webgpu
|
|
||||||
|
|
||||||
## v1.60.1
|
|
||||||
|
|
||||||
|
|
||||||
## v1.60.0
|
|
||||||
|
|
||||||
- materials: remove dependence on per-view descset layout from filamat. [⚠️ **New Material Version**]
|
|
||||||
- matc non-functional change: Update GLSL postprocessor to
|
|
||||||
isolate calls to SPVRemap from calls to SPIRV-Cross.
|
|
||||||
|
|
||||||
|
|
||||||
## v1.59.5
|
|
||||||
|
|
||||||
|
|
||||||
## v1.59.4
|
## v1.59.4
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1801,22 +1801,6 @@ public class View {
|
|||||||
* @see setAmbientOcclusionOptions()
|
* @see setAmbientOcclusionOptions()
|
||||||
*/
|
*/
|
||||||
public static class AmbientOcclusionOptions {
|
public static class AmbientOcclusionOptions {
|
||||||
public enum AmbientOcclusionType {
|
|
||||||
/**
|
|
||||||
* use Scalable Ambient Occlusion
|
|
||||||
*/
|
|
||||||
SAO,
|
|
||||||
/**
|
|
||||||
* use Ground Truth-Based Ambient Occlusion
|
|
||||||
*/
|
|
||||||
GTAO,
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type of ambient occlusion algorithm.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
public AmbientOcclusionOptions.AmbientOcclusionType aoType = AmbientOcclusionOptions.AmbientOcclusionType.SAO;
|
|
||||||
/**
|
/**
|
||||||
* Ambient Occlusion radius in meters, between 0 and ~10.
|
* Ambient Occlusion radius in meters, between 0 and ~10.
|
||||||
*/
|
*/
|
||||||
@@ -1826,8 +1810,7 @@ public class View {
|
|||||||
*/
|
*/
|
||||||
public float power = 1.0f;
|
public float power = 1.0f;
|
||||||
/**
|
/**
|
||||||
* Self-occlusion bias in meters. Use to avoid self-occlusion.
|
* Self-occlusion bias in meters. Use to avoid self-occlusion. Between 0 and a few mm.
|
||||||
* Between 0 and a few mm. No effect when aoType set to GTAO
|
|
||||||
*/
|
*/
|
||||||
public float bias = 0.0005f;
|
public float bias = 0.0005f;
|
||||||
/**
|
/**
|
||||||
@@ -1843,12 +1826,12 @@ public class View {
|
|||||||
*/
|
*/
|
||||||
public float bilateralThreshold = 0.05f;
|
public float bilateralThreshold = 0.05f;
|
||||||
/**
|
/**
|
||||||
* affects # of samples used for AO and params for filtering
|
* affects # of samples used for AO.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public QualityLevel quality = QualityLevel.LOW;
|
public QualityLevel quality = QualityLevel.LOW;
|
||||||
/**
|
/**
|
||||||
* affects AO smoothness. Recommend setting to HIGH when aoType set to GTAO.
|
* affects AO smoothness
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public QualityLevel lowPassFilter = QualityLevel.MEDIUM;
|
public QualityLevel lowPassFilter = QualityLevel.MEDIUM;
|
||||||
@@ -1866,7 +1849,7 @@ public class View {
|
|||||||
*/
|
*/
|
||||||
public boolean bentNormals = false;
|
public boolean bentNormals = false;
|
||||||
/**
|
/**
|
||||||
* min angle in radian to consider. No effect when aoType set to GTAO.
|
* min angle in radian to consider
|
||||||
*/
|
*/
|
||||||
public float minHorizonAngleRad = 0.0f;
|
public float minHorizonAngleRad = 0.0f;
|
||||||
/**
|
/**
|
||||||
@@ -1921,19 +1904,6 @@ public class View {
|
|||||||
*/
|
*/
|
||||||
public boolean ssctEnabled = false;
|
public boolean ssctEnabled = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Ground Truth-base Ambient Occlusion (GTAO) options
|
|
||||||
*/
|
|
||||||
public int gtaoSampleSliceCount = 4;
|
|
||||||
/**
|
|
||||||
* Ground Truth-base Ambient Occlusion (GTAO) options
|
|
||||||
*/
|
|
||||||
public int gtaoSampleStepsPerSlice = 3;
|
|
||||||
/**
|
|
||||||
* Ground Truth-base Ambient Occlusion (GTAO) options
|
|
||||||
*/
|
|
||||||
public float gtaoThicknessHeuristic = 0.004f;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2010,7 +1980,7 @@ public class View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reconstruction filter width typically between 1 (sharper) and 2 (smoother)
|
* reconstruction filter width typically between 0.2 (sharper, aliased) and 1.5 (smoother)
|
||||||
*/
|
*/
|
||||||
public float filterWidth = 1.0f;
|
public float filterWidth = 1.0f;
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
GROUP=com.google.android.filament
|
GROUP=com.google.android.filament
|
||||||
VERSION_NAME=1.61.0
|
VERSION_NAME=1.59.3
|
||||||
|
|
||||||
POM_DESCRIPTION=Real-time physically based rendering engine for Android.
|
POM_DESCRIPTION=Real-time physically based rendering engine for Android.
|
||||||
|
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ function print_fgviewer_help {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Unless explicitly specified, NDK version will be selected as highest available version within same major release chain
|
# Unless explicitly specified, NDK version will be selected as highest available version within same major release chain
|
||||||
FILAMENT_NDK_VERSION=${FILAMENT_NDK_VERSION:-$(cat `dirname $0`/build/common/versions | grep GITHUB_NDK_VERSION | sed s/GITHUB_NDK_VERSION=//g | cut -f 1 -d ".")}
|
FILAMENT_NDK_VERSION=${FILAMENT_NDK_VERSION:-$(cat `dirname $0`/build/android/ndk.version | cut -f 1 -d ".")}
|
||||||
|
|
||||||
# Requirements
|
# Requirements
|
||||||
CMAKE_MAJOR=3
|
CMAKE_MAJOR=3
|
||||||
@@ -463,6 +463,16 @@ function ensure_android_build {
|
|||||||
echo "Error: Android NDK side-by-side version ${FILAMENT_NDK_VERSION} or compatible must be installed, exiting"
|
echo "Error: Android NDK side-by-side version ${FILAMENT_NDK_VERSION} or compatible must be installed, exiting"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local cmake_version=$(cmake --version)
|
||||||
|
if [[ "${cmake_version}" =~ ([0-9]+)\.([0-9]+)\.[0-9]+ ]]; then
|
||||||
|
if [[ "${BASH_REMATCH[1]}" -lt "${CMAKE_MAJOR}" ]] || \
|
||||||
|
[[ "${BASH_REMATCH[2]}" -lt "${CMAKE_MINOR}" ]]; then
|
||||||
|
echo "Error: cmake version ${CMAKE_MAJOR}.${CMAKE_MINOR}+ is required," \
|
||||||
|
"${BASH_REMATCH[1]}.${BASH_REMATCH[2]} installed, exiting"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function build_android {
|
function build_android {
|
||||||
|
|||||||
+37
-7
@@ -1,6 +1,28 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
source `dirname $0`/../common/ci-check.sh
|
# Usage: the first argument selects the build type:
|
||||||
|
# - release, to build release only
|
||||||
|
# - debug, to build debug only
|
||||||
|
# - continuous, to build release and debug
|
||||||
|
# - presubmit, for presubmit builds
|
||||||
|
#
|
||||||
|
# The default is release
|
||||||
|
|
||||||
|
echo "This script is intended to run in a CI environment and may modify your current environment."
|
||||||
|
echo "Please refer to BUILDING.md for more information."
|
||||||
|
|
||||||
|
read -r -p "Do you wish to proceed (y/n)? " choice
|
||||||
|
case "${choice}" in
|
||||||
|
y|Y)
|
||||||
|
echo "Build will proceed..."
|
||||||
|
;;
|
||||||
|
n|N)
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
@@ -8,22 +30,30 @@ set -x
|
|||||||
UNAME=`echo $(uname)`
|
UNAME=`echo $(uname)`
|
||||||
LC_UNAME=`echo $UNAME | tr '[:upper:]' '[:lower:]'`
|
LC_UNAME=`echo $UNAME | tr '[:upper:]' '[:lower:]'`
|
||||||
|
|
||||||
|
FILAMENT_ANDROID_CI_BUILD=true
|
||||||
|
|
||||||
|
# build-common.sh will generate the following variables:
|
||||||
|
# $GENERATE_ARCHIVES
|
||||||
|
# $BUILD_DEBUG
|
||||||
|
# $BUILD_RELEASE
|
||||||
|
source `dirname $0`/../common/ci-common.sh
|
||||||
|
if [[ "$LC_UNAME" == "linux" ]]; then
|
||||||
|
source `dirname $0`/../linux/ci-common.sh
|
||||||
|
elif [[ "$LC_UNAME" == "darwin" ]]; then
|
||||||
|
source `dirname $0`/../mac/ci-common.sh
|
||||||
|
fi
|
||||||
source `dirname $0`/../common/build-common.sh
|
source `dirname $0`/../common/build-common.sh
|
||||||
|
|
||||||
if [[ "$GITHUB_WORKFLOW" ]]; then
|
if [[ "$GITHUB_WORKFLOW" ]]; then
|
||||||
java_version=$(java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1)
|
java_version=$(java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1)
|
||||||
if [[ "$java_version" < 17 ]]; then
|
if [[ "$java_version" < 17 ]]; then
|
||||||
echo "Android builds require Java 17, found version ${java_version} instead"
|
echo "Android builds require Java 17, found version ${java_version} instead"
|
||||||
exit 1
|
exit 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Unless explicitly specified, NDK version will be set to match exactly the required one
|
# Unless explicitly specified, NDK version will be set to match exactly the required one
|
||||||
FILAMENT_NDK_VERSION=${GITHUB_NDK_VERSION:-27.0.11718014}
|
FILAMENT_NDK_VERSION=${FILAMENT_NDK_VERSION:-$(cat `dirname $0`/ndk.version)}
|
||||||
|
|
||||||
(! grep "${FILAMENT_NDK_VERSION}" `dirname $0`/../../android/build.gradle > /dev/null) &&
|
|
||||||
echo "Mismatch of NDK versions: want ${FILAMENT_NDK_VERSION} and not found in android/build.gradle" &&
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
# Install the required NDK version specifically (if not present)
|
# Install the required NDK version specifically (if not present)
|
||||||
if [[ ! -d "${ANDROID_HOME}/ndk/$FILAMENT_NDK_VERSION" ]]; then
|
if [[ ! -d "${ANDROID_HOME}/ndk/$FILAMENT_NDK_VERSION" ]]; then
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
27.0.11718014
|
||||||
@@ -1,20 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# build-common.sh will generate the following variables:
|
|
||||||
# $GENERATE_ARCHIVES
|
|
||||||
# $BUILD_DEBUG
|
|
||||||
# $BUILD_RELEASE
|
|
||||||
|
|
||||||
# Typically a build script (build.sh) would source this script. For example,
|
|
||||||
# source `dirname $0`/../common/build-common.sh
|
|
||||||
|
|
||||||
# Usage: the first argument selects the build type:
|
|
||||||
# - release, to build release only
|
|
||||||
# - debug, to build debug only
|
|
||||||
# - continuous, to build release and debug
|
|
||||||
# - presubmit, for presubmit builds
|
|
||||||
#
|
|
||||||
# The default is release
|
|
||||||
if [[ ! "$TARGET" ]]; then
|
if [[ ! "$TARGET" ]]; then
|
||||||
if [[ "$1" ]]; then
|
if [[ "$1" ]]; then
|
||||||
TARGET=$1
|
TARGET=$1
|
||||||
|
|||||||
@@ -56,16 +56,10 @@ popd >/dev/null
|
|||||||
rm -rf out/check-headers
|
rm -rf out/check-headers
|
||||||
mkdir -p out/check-headers
|
mkdir -p out/check-headers
|
||||||
|
|
||||||
TMP_FILE=out/check-headers/temp.cpp
|
|
||||||
echo "Checking that public headers compile independently..."
|
echo "Checking that public headers compile independently..."
|
||||||
for include in "${includes[@]}"; do
|
for include in "${includes[@]}"; do
|
||||||
rm -f ${TMP_FILE}
|
|
||||||
echo "Checking ${include}"
|
echo "Checking ${include}"
|
||||||
if [[ "${include}" == "utils/Systrace.h" ]]; then
|
echo "#include <${include}>" >> out/check-headers/temp.cpp
|
||||||
# A necessary define before we can include utils/Systrace.h
|
clang -std=c++17 -I "${FILAMENT_HEADERS}" out/check-headers/temp.cpp -c -o /dev/null
|
||||||
echo "#define SYSTRACE_TAG SYSTRACE_TAG_DISABLED" >> ${TMP_FILE}
|
|
||||||
fi
|
|
||||||
echo "#include <${include}>" >> ${TMP_FILE}
|
|
||||||
clang -std=c++17 -I "${FILAMENT_HEADERS}" ${TMP_FILE} -c -o /dev/null
|
|
||||||
done
|
done
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
echo "This script is intended to run in a CI environment and may modify your current environment."
|
|
||||||
echo "Please refer to BUILDING.md for more information."
|
|
||||||
|
|
||||||
read -r -p "Do you wish to proceed (y/n)? " choice
|
|
||||||
case "${choice}" in
|
|
||||||
y|Y)
|
|
||||||
echo "Build will proceed..."
|
|
||||||
;;
|
|
||||||
n|N)
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if [[ "$GITHUB_WORKFLOW" ]]; then
|
|
||||||
echo "Running workflow $GITHUB_WORKFLOW (event: $GITHUB_EVENT_NAME, action: $GITHUB_ACTION)"
|
|
||||||
fi
|
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ "$GITHUB_WORKFLOW" ]]; then
|
||||||
|
echo "Running workflow $GITHUB_WORKFLOW (event: $GITHUB_EVENT_NAME, action: $GITHUB_ACTION)"
|
||||||
|
CONTINUOUS_INTEGRATION=true
|
||||||
|
fi
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
if [ -d "./emsdk" ]; then
|
|
||||||
echo "emsdk folder found. Assume emsdk has been installed."
|
|
||||||
cd emsdk
|
|
||||||
./emsdk activate latest
|
|
||||||
source ./emsdk_env.sh
|
|
||||||
export EMSDK="$PWD"
|
|
||||||
cd ..
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Install emscripten.
|
|
||||||
EMSDK_VERSION=${GITHUB_EMSDK_VERSION-3.1.60}
|
|
||||||
curl -L https://github.com/emscripten-core/emsdk/archive/refs/tags/${EMSDK_VERSION}.zip > emsdk.zip
|
|
||||||
unzip emsdk.zip ; mv emsdk-* emsdk ; cd emsdk
|
|
||||||
./emsdk install latest
|
|
||||||
./emsdk activate latest
|
|
||||||
source ./emsdk_env.sh
|
|
||||||
|
|
||||||
export EMSDK="$PWD"
|
|
||||||
cd ..
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
if [[ "$GITHUB_WORKFLOW" ]]; then
|
|
||||||
OS_NAME=$(uname -s)
|
|
||||||
NINJA_DL_DIR=/tmp/ninja-dl
|
|
||||||
NINJA_PLATFORM=
|
|
||||||
if [[ "$OS_NAME" == "Linux" ]]; then
|
|
||||||
NINJA_PLATFORM=linux
|
|
||||||
elif [[ "$OS_NAME" == "Darwin" ]]; then
|
|
||||||
NINJA_PLATFORM=mac
|
|
||||||
fi
|
|
||||||
curl -L -o /tmp/ninja-dl.zip https://github.com/ninja-build/ninja/releases/download/v${GITHUB_NINJA_VERSION}/ninja-${NINJA_PLATFORM}.zip
|
|
||||||
mkdir -p $NINJA_DL_DIR
|
|
||||||
unzip -q /tmp/ninja-dl.zip -d $NINJA_DL_DIR
|
|
||||||
chmod +x ${NINJA_DL_DIR}/ninja
|
|
||||||
# Install ninja globally for AGP
|
|
||||||
sudo cp ${NINJA_DL_DIR}/ninja /usr/local/bin/
|
|
||||||
fi
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
GITHUB_CLANG_VERSION=14
|
|
||||||
GITHUB_CMAKE_VERSION=3.19.5
|
|
||||||
GITHUB_NINJA_VERSION=1.10.2
|
|
||||||
GITHUB_MESA_VERSION=24.2.1
|
|
||||||
GITHUB_LLVM_VERSION=16
|
|
||||||
GITHUB_NDK_VERSION=27.0.11718014
|
|
||||||
GITHUB_EMSDK_VERSION=3.1.60
|
|
||||||
+27
-1
@@ -1,11 +1,36 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
source `dirname $0`/../common/ci-check.sh
|
# Usage: the first argument selects the build type:
|
||||||
|
# - release, to build release only
|
||||||
|
# - debug, to build debug only
|
||||||
|
# - continuous, to build release and debug
|
||||||
|
# - presubmit, for presubmit builds
|
||||||
|
#
|
||||||
|
# The default is release
|
||||||
|
|
||||||
|
echo "This script is intended to run in a CI environment and may modify your current environment."
|
||||||
|
echo "Please refer to BUILDING.md for more information."
|
||||||
|
|
||||||
|
read -r -p "Do you wish to proceed (y/n)? " choice
|
||||||
|
case "${choice}" in
|
||||||
|
y|Y)
|
||||||
|
echo "Build will proceed..."
|
||||||
|
;;
|
||||||
|
n|N)
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
source `dirname $0`/../common/ci-common.sh
|
||||||
|
source `dirname $0`/ci-common.sh
|
||||||
source `dirname $0`/../common/build-common.sh
|
source `dirname $0`/../common/build-common.sh
|
||||||
|
|
||||||
pushd `dirname $0`/../.. > /dev/null
|
pushd `dirname $0`/../.. > /dev/null
|
||||||
|
|
||||||
# If we're generating an archive for release or continuous builds, then we'll also build for the
|
# If we're generating an archive for release or continuous builds, then we'll also build for the
|
||||||
@@ -16,3 +41,4 @@ if [[ "${GENERATE_ARCHIVES}" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
./build.sh -i -p ios -c $BUILD_SIMULATOR $GENERATE_ARCHIVES $BUILD_DEBUG $BUILD_RELEASE
|
./build.sh -i -p ios -c $BUILD_SIMULATOR $GENERATE_ARCHIVES $BUILD_DEBUG $BUILD_RELEASE
|
||||||
|
|
||||||
|
|||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
curl -OL https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-mac.zip
|
||||||
|
unzip -q ninja-mac.zip
|
||||||
|
chmod +x ninja
|
||||||
|
export PATH="$PWD:$PATH"
|
||||||
+30
-2
@@ -1,11 +1,39 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
source `dirname $0`/../common/ci-check.sh
|
# Usage: the first argument selects the build type:
|
||||||
|
# - release, to build release only
|
||||||
|
# - debug, to build debug only
|
||||||
|
# - continuous, to build release and debug
|
||||||
|
# - presubmit, for presubmit builds
|
||||||
|
#
|
||||||
|
# The default is release
|
||||||
|
|
||||||
|
echo "This script is intended to run in a CI environment and may modify your current environment."
|
||||||
|
echo "Please refer to BUILDING.md for more information."
|
||||||
|
|
||||||
|
read -r -p "Do you wish to proceed (y/n)? " choice
|
||||||
|
case "${choice}" in
|
||||||
|
y|Y)
|
||||||
|
echo "Build will proceed..."
|
||||||
|
;;
|
||||||
|
n|N)
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
# build-common.sh will generate the following variables:
|
||||||
|
# $GENERATE_ARCHIVES
|
||||||
|
# $BUILD_DEBUG
|
||||||
|
# $BUILD_RELEASE
|
||||||
|
source `dirname $0`/../common/ci-common.sh
|
||||||
|
source `dirname $0`/ci-common.sh
|
||||||
source `dirname $0`/../common/build-common.sh
|
source `dirname $0`/../common/build-common.sh
|
||||||
pushd `dirname $0`/../.. > /dev/null
|
|
||||||
|
|
||||||
|
pushd `dirname $0`/../.. > /dev/null
|
||||||
./build.sh -c $RUN_TESTS $GENERATE_ARCHIVES $BUILD_DEBUG $BUILD_RELEASE
|
./build.sh -c $RUN_TESTS $GENERATE_ARCHIVES $BUILD_DEBUG $BUILD_RELEASE
|
||||||
|
|||||||
Executable
+38
@@ -0,0 +1,38 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# version of clang we want to use
|
||||||
|
export GITHUB_CLANG_VERSION=14
|
||||||
|
# version of CMake to use instead of the default one
|
||||||
|
export GITHUB_CMAKE_VERSION=3.19.5
|
||||||
|
# version of ninja to use
|
||||||
|
export GITHUB_NINJA_VERSION=1.10.2
|
||||||
|
|
||||||
|
# Steps for GitHub Workflows
|
||||||
|
if [[ "$GITHUB_WORKFLOW" ]]; then
|
||||||
|
# Install ninja
|
||||||
|
wget -q https://github.com/ninja-build/ninja/releases/download/v$GITHUB_NINJA_VERSION/ninja-linux.zip
|
||||||
|
unzip -q ninja-linux.zip
|
||||||
|
export PATH="$PWD:$PATH"
|
||||||
|
|
||||||
|
# Install CMake
|
||||||
|
mkdir -p cmake
|
||||||
|
cd cmake
|
||||||
|
|
||||||
|
sudo wget https://github.com/Kitware/CMake/releases/download/v$GITHUB_CMAKE_VERSION/cmake-$GITHUB_CMAKE_VERSION-Linux-x86_64.sh
|
||||||
|
sudo chmod +x ./cmake-$GITHUB_CMAKE_VERSION-Linux-x86_64.sh
|
||||||
|
sudo ./cmake-$GITHUB_CMAKE_VERSION-Linux-x86_64.sh --skip-license > /dev/null
|
||||||
|
sudo update-alternatives --install /usr/bin/cmake cmake $(pwd)/bin/cmake 1000 --force
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
sudo wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install clang-$GITHUB_CLANG_VERSION libc++-$GITHUB_CLANG_VERSION-dev libc++abi-$GITHUB_CLANG_VERSION-dev
|
||||||
|
sudo apt-get install mesa-common-dev libxi-dev libxxf86vm-dev
|
||||||
|
|
||||||
|
# For dawn
|
||||||
|
sudo apt-get install libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libx11-xcb-dev
|
||||||
|
|
||||||
|
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-${GITHUB_CLANG_VERSION} 100
|
||||||
|
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-${GITHUB_CLANG_VERSION} 100
|
||||||
|
fi
|
||||||
+26
-2
@@ -1,11 +1,35 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
source `dirname $0`/../common/ci-check.sh
|
# Usage: the first argument selects the build type:
|
||||||
|
# - release, to build release only
|
||||||
|
# - debug, to build debug only
|
||||||
|
# - continuous, to build release and debug
|
||||||
|
# - presubmit, for presubmit builds
|
||||||
|
#
|
||||||
|
# The default is release
|
||||||
|
|
||||||
|
echo "This script is intended to run in a CI environment and may modify your current environment."
|
||||||
|
echo "Please refer to BUILDING.md for more information."
|
||||||
|
|
||||||
|
read -r -p "Do you wish to proceed (y/n)? " choice
|
||||||
|
case "${choice}" in
|
||||||
|
y|Y)
|
||||||
|
echo "Build will proceed..."
|
||||||
|
;;
|
||||||
|
n|N)
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
source `dirname $0`/../common/ci-common.sh
|
||||||
|
source `dirname $0`/ci-common.sh
|
||||||
source `dirname $0`/../common/build-common.sh
|
source `dirname $0`/../common/build-common.sh
|
||||||
pushd `dirname $0`/../.. > /dev/null
|
|
||||||
|
|
||||||
|
pushd `dirname $0`/../.. > /dev/null
|
||||||
./build.sh -c $RUN_TESTS $GENERATE_ARCHIVES $BUILD_DEBUG $BUILD_RELEASE
|
./build.sh -c $RUN_TESTS $GENERATE_ARCHIVES $BUILD_DEBUG $BUILD_RELEASE
|
||||||
|
|||||||
Executable
+8
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
curl -OL https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-mac.zip
|
||||||
|
unzip -q ninja-mac.zip
|
||||||
|
chmod +x ninja
|
||||||
|
# Install ninja globally for AGP
|
||||||
|
cp ninja /usr/local/bin
|
||||||
|
export PATH="$PWD:$PATH"
|
||||||
@@ -31,16 +31,10 @@ set(DIST_ARCH arm64-v8a)
|
|||||||
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} HOST_NAME_L)
|
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} HOST_NAME_L)
|
||||||
file(TO_CMAKE_PATH $ENV{ANDROID_HOME} ANDROID_HOME_UNIX)
|
file(TO_CMAKE_PATH $ENV{ANDROID_HOME} ANDROID_HOME_UNIX)
|
||||||
|
|
||||||
message(STATUS "Try using NDK \'${FILAMENT_NDK_VERSION}\'")
|
|
||||||
if (NOT FILAMENT_NDK_VERSION)
|
if (NOT FILAMENT_NDK_VERSION)
|
||||||
file(READ "${CMAKE_CURRENT_LIST_DIR}/common/versions" VERSIONS_STR)
|
file(READ "${CMAKE_CURRENT_LIST_DIR}/android/ndk.version" FILAMENT_NDK_VERSION)
|
||||||
string(REGEX MATCH "GITHUB_NDK_VERSION=(\\d+)" _UNUSED ${VERSIONS_STR})
|
string(REGEX MATCH "^\\d+" FILAMENT_NDK_VERSION ${FILAMENT_NDK_VERSION})
|
||||||
if(CMAKE_MATCH_1)
|
|
||||||
set(FILAMENT_NDK_VERSION "${CMAKE_MATCH_1}")
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
message(STATUS "Using NDK \'${FILAMENT_NDK_VERSION}\'")
|
|
||||||
|
|
||||||
file(GLOB NDK_VERSIONS LIST_DIRECTORIES true ${ANDROID_HOME_UNIX}/ndk/${FILAMENT_NDK_VERSION}*)
|
file(GLOB NDK_VERSIONS LIST_DIRECTORIES true ${ANDROID_HOME_UNIX}/ndk/${FILAMENT_NDK_VERSION}*)
|
||||||
list(SORT NDK_VERSIONS)
|
list(SORT NDK_VERSIONS)
|
||||||
list(GET NDK_VERSIONS -1 NDK_VERSION)
|
list(GET NDK_VERSIONS -1 NDK_VERSION)
|
||||||
|
|||||||
@@ -32,16 +32,10 @@ set(DIST_ARCH armeabi-v7a)
|
|||||||
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} HOST_NAME_L)
|
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} HOST_NAME_L)
|
||||||
file(TO_CMAKE_PATH $ENV{ANDROID_HOME} ANDROID_HOME_UNIX)
|
file(TO_CMAKE_PATH $ENV{ANDROID_HOME} ANDROID_HOME_UNIX)
|
||||||
|
|
||||||
message(STATUS "Try using NDK \'${FILAMENT_NDK_VERSION}\'")
|
|
||||||
if (NOT FILAMENT_NDK_VERSION)
|
if (NOT FILAMENT_NDK_VERSION)
|
||||||
file(READ "${CMAKE_CURRENT_LIST_DIR}/common/versions" VERSIONS_STR)
|
file(READ "${CMAKE_CURRENT_LIST_DIR}/android/ndk.version" FILAMENT_NDK_VERSION)
|
||||||
string(REGEX MATCH "GITHUB_NDK_VERSION=(\\d+)" _UNUSED ${VERSIONS_STR})
|
string(REGEX MATCH "^\\d+" FILAMENT_NDK_VERSION ${FILAMENT_NDK_VERSION})
|
||||||
if(CMAKE_MATCH_1)
|
|
||||||
set(FILAMENT_NDK_VERSION "${CMAKE_MATCH_1}")
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
message(STATUS "Using NDK \'${FILAMENT_NDK_VERSION}\'")
|
|
||||||
|
|
||||||
file(GLOB NDK_VERSIONS LIST_DIRECTORIES true ${ANDROID_HOME_UNIX}/ndk/${FILAMENT_NDK_VERSION}*)
|
file(GLOB NDK_VERSIONS LIST_DIRECTORIES true ${ANDROID_HOME_UNIX}/ndk/${FILAMENT_NDK_VERSION}*)
|
||||||
list(SORT NDK_VERSIONS)
|
list(SORT NDK_VERSIONS)
|
||||||
list(GET NDK_VERSIONS -1 NDK_VERSION)
|
list(GET NDK_VERSIONS -1 NDK_VERSION)
|
||||||
|
|||||||
@@ -31,16 +31,10 @@ set(DIST_ARCH x86)
|
|||||||
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} HOST_NAME_L)
|
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} HOST_NAME_L)
|
||||||
file(TO_CMAKE_PATH $ENV{ANDROID_HOME} ANDROID_HOME_UNIX)
|
file(TO_CMAKE_PATH $ENV{ANDROID_HOME} ANDROID_HOME_UNIX)
|
||||||
|
|
||||||
message(STATUS "Try using NDK \'${FILAMENT_NDK_VERSION}\'")
|
|
||||||
if (NOT FILAMENT_NDK_VERSION)
|
if (NOT FILAMENT_NDK_VERSION)
|
||||||
file(READ "${CMAKE_CURRENT_LIST_DIR}/common/versions" VERSIONS_STR)
|
file(READ "${CMAKE_CURRENT_LIST_DIR}/android/ndk.version" FILAMENT_NDK_VERSION)
|
||||||
string(REGEX MATCH "GITHUB_NDK_VERSION=(\\d+)" _UNUSED ${VERSIONS_STR})
|
string(REGEX MATCH "^\\d+" FILAMENT_NDK_VERSION ${FILAMENT_NDK_VERSION})
|
||||||
if(CMAKE_MATCH_1)
|
|
||||||
set(FILAMENT_NDK_VERSION "${CMAKE_MATCH_1}")
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
message(STATUS "Using NDK \'${FILAMENT_NDK_VERSION}\'")
|
|
||||||
|
|
||||||
file(GLOB NDK_VERSIONS LIST_DIRECTORIES true ${ANDROID_HOME_UNIX}/ndk/${FILAMENT_NDK_VERSION}*)
|
file(GLOB NDK_VERSIONS LIST_DIRECTORIES true ${ANDROID_HOME_UNIX}/ndk/${FILAMENT_NDK_VERSION}*)
|
||||||
list(SORT NDK_VERSIONS)
|
list(SORT NDK_VERSIONS)
|
||||||
list(GET NDK_VERSIONS -1 NDK_VERSION)
|
list(GET NDK_VERSIONS -1 NDK_VERSION)
|
||||||
|
|||||||
@@ -31,16 +31,10 @@ set(DIST_ARCH x86_64)
|
|||||||
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} HOST_NAME_L)
|
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} HOST_NAME_L)
|
||||||
file(TO_CMAKE_PATH $ENV{ANDROID_HOME} ANDROID_HOME_UNIX)
|
file(TO_CMAKE_PATH $ENV{ANDROID_HOME} ANDROID_HOME_UNIX)
|
||||||
|
|
||||||
message(STATUS "Try using NDK \'${FILAMENT_NDK_VERSION}\'")
|
|
||||||
if (NOT FILAMENT_NDK_VERSION)
|
if (NOT FILAMENT_NDK_VERSION)
|
||||||
file(READ "${CMAKE_CURRENT_LIST_DIR}/common/versions" VERSIONS_STR)
|
file(READ "${CMAKE_CURRENT_LIST_DIR}/android/ndk.version" FILAMENT_NDK_VERSION)
|
||||||
string(REGEX MATCH "GITHUB_NDK_VERSION=(\\d+)" _UNUSED ${VERSIONS_STR})
|
string(REGEX MATCH "^\\d+" FILAMENT_NDK_VERSION ${FILAMENT_NDK_VERSION})
|
||||||
if(CMAKE_MATCH_1)
|
|
||||||
set(FILAMENT_NDK_VERSION "${CMAKE_MATCH_1}")
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
message(STATUS "Using NDK \'${FILAMENT_NDK_VERSION}\'")
|
|
||||||
|
|
||||||
file(GLOB NDK_VERSIONS LIST_DIRECTORIES true ${ANDROID_HOME_UNIX}/ndk/${FILAMENT_NDK_VERSION}*)
|
file(GLOB NDK_VERSIONS LIST_DIRECTORIES true ${ANDROID_HOME_UNIX}/ndk/${FILAMENT_NDK_VERSION}*)
|
||||||
list(SORT NDK_VERSIONS)
|
list(SORT NDK_VERSIONS)
|
||||||
list(GET NDK_VERSIONS -1 NDK_VERSION)
|
list(GET NDK_VERSIONS -1 NDK_VERSION)
|
||||||
|
|||||||
+25
-1
@@ -1,10 +1,34 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
source `dirname $0`/../common/ci-check.sh
|
# Usage: the first argument selects the build type:
|
||||||
|
# - release, to build release only
|
||||||
|
# - debug, to build debug only
|
||||||
|
# - continuous, to build release and debug
|
||||||
|
# - presubmit, for presubmit builds
|
||||||
|
#
|
||||||
|
# The default is release
|
||||||
|
|
||||||
|
echo "This script is intended to run in a CI environment and may modify your current environment."
|
||||||
|
echo "Please refer to BUILDING.md for more information."
|
||||||
|
|
||||||
|
read -r -p "Do you wish to proceed (y/n)? " choice
|
||||||
|
case "${choice}" in
|
||||||
|
y|Y)
|
||||||
|
echo "Build will proceed..."
|
||||||
|
;;
|
||||||
|
n|N)
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
source `dirname $0`/../common/ci-common.sh
|
||||||
|
source `dirname $0`/ci-common.sh
|
||||||
source `dirname $0`/../common/build-common.sh
|
source `dirname $0`/../common/build-common.sh
|
||||||
pushd `dirname $0`/../.. > /dev/null
|
pushd `dirname $0`/../.. > /dev/null
|
||||||
|
|
||||||
|
|||||||
Executable
+23
@@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
if [ `uname` == "Linux" ];then
|
||||||
|
source `dirname $0`/../linux/ci-common.sh
|
||||||
|
elif [ `uname` == "Darwin" ];then
|
||||||
|
curl -OL https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-mac.zip
|
||||||
|
unzip -q ninja-mac.zip
|
||||||
|
else
|
||||||
|
echo "Unsupported OS"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
chmod +x ninja
|
||||||
|
export PATH="$PWD:$PATH"
|
||||||
|
|
||||||
|
# Install emscripten.
|
||||||
|
curl -L https://github.com/emscripten-core/emsdk/archive/refs/tags/3.1.60.zip > emsdk.zip
|
||||||
|
unzip emsdk.zip ; mv emsdk-* emsdk ; cd emsdk
|
||||||
|
./emsdk install latest
|
||||||
|
./emsdk activate latest
|
||||||
|
source ./emsdk_env.sh
|
||||||
|
|
||||||
|
export EMSDK="$PWD"
|
||||||
|
cd ..
|
||||||
@@ -47,11 +47,7 @@ if "%RUNNING_LOCALLY%" == "1" (
|
|||||||
set "PATH=%PATH%;C:\Program Files\7-Zip"
|
set "PATH=%PATH%;C:\Program Files\7-Zip"
|
||||||
)
|
)
|
||||||
|
|
||||||
:: Outdated windows-2019 pattern
|
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\%VISUAL_STUDIO_VERSION%\VC\Auxiliary\Build\vcvars64.bat"
|
||||||
:: call "C:\Program Files (x86)\Microsoft Visual Studio\2019\%VISUAL_STUDIO_VERSION%\VC\Auxiliary\Build\vcvars64.bat"
|
|
||||||
|
|
||||||
call "C:\Program Files\Microsoft Visual Studio\2022\%VISUAL_STUDIO_VERSION%\VC\Auxiliary\Build\vcvars64.bat"
|
|
||||||
echo Passed vcvars64.bat
|
|
||||||
if errorlevel 1 exit /b %errorlevel%
|
if errorlevel 1 exit /b %errorlevel%
|
||||||
|
|
||||||
msbuild /version
|
msbuild /version
|
||||||
@@ -111,7 +107,7 @@ cd out\cmake-%variant%
|
|||||||
if errorlevel 1 exit /b %errorlevel%
|
if errorlevel 1 exit /b %errorlevel%
|
||||||
|
|
||||||
cmake ..\.. ^
|
cmake ..\.. ^
|
||||||
-G "Visual Studio 17 2022" ^
|
-G "Visual Studio 16 2019" ^
|
||||||
-A x64 ^
|
-A x64 ^
|
||||||
%flag% ^
|
%flag% ^
|
||||||
-DCMAKE_INSTALL_PREFIX=..\%variant% ^
|
-DCMAKE_INSTALL_PREFIX=..\%variant% ^
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
+20
-37
@@ -166,7 +166,7 @@ This document is part of the <a href="https://github.com/google/filament">Filame
|
|||||||
</p><ul>
|
</p><ul>
|
||||||
<li class="minus"><a href="https://github.com/romainguy">Romain Guy</a>, <a href="https://twitter.com/romainguy">@romainguy</a>
|
<li class="minus"><a href="https://github.com/romainguy">Romain Guy</a>, <a href="https://twitter.com/romainguy">@romainguy</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="minus"><a href="https://github.com/pixelflinger">Mathias Agopian</a>, <a href="https://bsky.app/profile/pixelflinger.bsky.social">@pixelflinger</a></li></ul>
|
<li class="minus"><a href="https://github.com/pixelflinger">Mathias Agopian</a>, <a href="https://twitter.com/darthmoosious">@darthmoosious</a></li></ul>
|
||||||
|
|
||||||
<p></p>
|
<p></p>
|
||||||
<a class="target" name="overview"> </a><a class="target" name="overview"> </a><a class="target" name="toc2"> </a><h1>Overview</h1>
|
<a class="target" name="overview"> </a><a class="target" name="overview"> </a><a class="target" name="toc2"> </a><h1>Overview</h1>
|
||||||
@@ -259,27 +259,26 @@ in <a href="#table_standardproperties">table 1</a>.
|
|||||||
</p><div class="table">
|
</p><div class="table">
|
||||||
<table class="table"><tbody><tr><th style="text-align:right"> Property </th><th style="text-align:left"> Definition </th></tr>
|
<table class="table"><tbody><tr><th style="text-align:right"> Property </th><th style="text-align:left"> Definition </th></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">baseColor</strong> </td><td style="text-align:left"> Diffuse albedo for non-metallic surfaces, and specular color for metallic surfaces </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">baseColor</strong> </td><td style="text-align:left"> Diffuse albedo for non-metallic surfaces, and specular color for metallic surfaces </td></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">roughness</strong> </td><td style="text-align:left"> Perceived smoothness (1.0) or roughness (0.0) of a surface. Smooth surfaces exhibit sharp reflections </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">metallic</strong> </td><td style="text-align:left"> Whether a surface appears to be dielectric (0.0) or conductor (1.0). Often used as a binary value (0 or 1) </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">metallic</strong> </td><td style="text-align:left"> Whether a surface appears to be dielectric (0.0) or conductor (1.0). Often used as a binary value (0 or 1) </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">roughness</strong> </td><td style="text-align:left"> Perceived smoothness (1.0) or roughness (0.0) of a surface. Smooth surfaces exhibit sharp reflections </td></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">reflectance</strong> </td><td style="text-align:left"> Fresnel reflectance at normal incidence for dielectric surfaces. This directly controls the strength of the reflections </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">reflectance</strong> </td><td style="text-align:left"> Fresnel reflectance at normal incidence for dielectric surfaces. This directly controls the strength of the reflections </td></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">ambientOcclusion</strong> </td><td style="text-align:left"> Defines how much of the ambient light is accessible to a surface point. It is a per-pixel shadowing factor between 0.0 and 1.0 </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">clearCoat</strong> </td><td style="text-align:left"> Strength of the clear coat layer </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">clearCoatRoughness</strong> </td><td style="text-align:left"> Perceived smoothness or roughness of the clear coat layer </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">clearCoatNormal</strong> </td><td style="text-align:left"> A detail normal used to perturb the clear coat layer using <em class="underscore">bump mapping</em> (<em class="underscore">normal mapping</em>) </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">anisotropy</strong> </td><td style="text-align:left"> Amount of anisotropy in either the tangent or bitangent direction </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">anisotropyDirection</strong> </td><td style="text-align:left"> Local surface direction in tangent space </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">thickness</strong> </td><td style="text-align:left"> Thickness of the solid volume of refractive objects </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">sheenColor</strong> </td><td style="text-align:left"> Strength of the sheen layer </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">sheenColor</strong> </td><td style="text-align:left"> Strength of the sheen layer </td></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">sheenRoughness</strong> </td><td style="text-align:left"> Perceived smoothness or roughness of the sheen layer </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">sheenRoughness</strong> </td><td style="text-align:left"> Perceived smoothness or roughness of the sheen layer </td></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">emissive</strong> </td><td style="text-align:left"> Additional diffuse albedo to simulate emissive surfaces (such as neons, etc.) This property is mostly useful in an HDR pipeline with a bloom pass </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">clearCoat</strong> </td><td style="text-align:left"> Strength of the clear coat layer </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">clearCoatRoughness</strong> </td><td style="text-align:left"> Perceived smoothness or roughness of the clear coat layer </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">anisotropy</strong> </td><td style="text-align:left"> Amount of anisotropy in either the tangent or bitangent direction </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">anisotropyDirection</strong> </td><td style="text-align:left"> Local surface direction in tangent space </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">ambientOcclusion</strong> </td><td style="text-align:left"> Defines how much of the ambient light is accessible to a surface point. It is a per-pixel shadowing factor between 0.0 and 1.0 </td></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">normal</strong> </td><td style="text-align:left"> A detail normal used to perturb the surface using <em class="underscore">bump mapping</em> (<em class="underscore">normal mapping</em>) </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">normal</strong> </td><td style="text-align:left"> A detail normal used to perturb the surface using <em class="underscore">bump mapping</em> (<em class="underscore">normal mapping</em>) </td></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">postLightingColor</strong> </td><td style="text-align:left"> Additional color that can be blended with the result of the lighting computations. See <code>postLightingBlending</code> </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">absorption</strong> </td><td style="text-align:left"> Absorption factor for refractive objects </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">transmission</strong> </td><td style="text-align:left"> Defines how much of the diffuse light of a dielectric is transmitted through the object, in other words this defines how transparent an object is </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">ior</strong> </td><td style="text-align:left"> Index of refraction, either for refractive objects or as an alternative to reflectance </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">microThickness</strong> </td><td style="text-align:left"> Thickness of the thin layer of refractive objects </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">bentNormal</strong> </td><td style="text-align:left"> A normal pointing in the average unoccluded direction. Can be used to improve indirect lighting quality </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">bentNormal</strong> </td><td style="text-align:left"> A normal pointing in the average unoccluded direction. Can be used to improve indirect lighting quality </td></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">shadowStrength</strong> </td><td style="text-align:left"> Strength factor between 0 and 1 for all shadows received by this material </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">clearCoatNormal</strong> </td><td style="text-align:left"> A detail normal used to perturb the clear coat layer using <em class="underscore">bump mapping</em> (<em class="underscore">normal mapping</em>) </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">emissive</strong> </td><td style="text-align:left"> Additional diffuse albedo to simulate emissive surfaces (such as neons, etc.) This property is mostly useful in an HDR pipeline with a bloom pass </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">postLightingColor</strong> </td><td style="text-align:left"> Additional color that can be blended with the result of the lighting computations. See <code>postLightingBlending</code> </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">ior</strong> </td><td style="text-align:left"> Index of refraction, either for refractive objects or as an alternative to reflectance </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">transmission</strong> </td><td style="text-align:left"> Defines how much of the diffuse light of a dielectric is transmitted through the object, in other words this defines how transparent an object is </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">absorption</strong> </td><td style="text-align:left"> Absorption factor for refractive objects </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">microThickness</strong> </td><td style="text-align:left"> Thickness of the thin layer of refractive objects </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">thickness</strong> </td><td style="text-align:left"> Thickness of the solid volume of refractive objects </td></tr>
|
||||||
</tbody></table><center><div class="tablecaption"><a class="target" name="table_standardproperties"> </a><b style="font-style:normal;">Table 1:</b> Properties of the standard model</div></center></div>
|
</tbody></table><center><div class="tablecaption"><a class="target" name="table_standardproperties"> </a><b style="font-style:normal;">Table 1:</b> Properties of the standard model</div></center></div>
|
||||||
|
|
||||||
<p></p><p>
|
<p></p><p>
|
||||||
@@ -1487,13 +1486,10 @@ non-shader data.
|
|||||||
</p><dl><dt>Type</dt><dd><p> array of parameter objects
|
</p><dl><dt>Type</dt><dd><p> array of parameter objects
|
||||||
|
|
||||||
</p></dd><dt>Value</dt><dd><p> Each entry is an object with the properties <code>name</code> and <code>type</code>, both of <code>string</code> type. The
|
</p></dd><dt>Value</dt><dd><p> Each entry is an object with the properties <code>name</code> and <code>type</code>, both of <code>string</code> type. The
|
||||||
name must be a valid GLSL identifier. Entries have an optional <code>precision</code>, which can be
|
name must be a valid GLSL identifier. Entries also have an optional <code>precision</code>, which can be
|
||||||
one of <code>default</code> (best precision for the platform, typically <code>high</code> on desktop, <code>medium</code> on
|
one of <code>default</code> (best precision for the platform, typically <code>high</code> on desktop, <code>medium</code> on
|
||||||
mobile), <code>low</code>, <code>medium</code>, <code>high</code>. The type must be one of the types described in
|
mobile), <code>low</code>, <code>medium</code>, <code>high</code>. The type must be one of the types described in
|
||||||
<a href="#table_materialparamstypes">table 14</a>. For Android external textures, entries also have an optional
|
<a href="#table_materialparamstypes">table 14</a>.
|
||||||
transformName parameter to specify the name of the material parameter that will be
|
|
||||||
used to expose the transform matrix associated with the external sampler. In iOS and Vulkan,
|
|
||||||
this will always be identity.
|
|
||||||
|
|
||||||
</p></dd></dl><div class="table">
|
</p></dd></dl><div class="table">
|
||||||
<table class="table"><tbody><tr><th style="text-align:left"> Type </th><th style="text-align:left"> Description </th></tr>
|
<table class="table"><tbody><tr><th style="text-align:left"> Type </th><th style="text-align:left"> Description </th></tr>
|
||||||
@@ -1756,13 +1752,7 @@ non-shader data.
|
|||||||
when selecting any shading model that is not <code>unlit</code>. See the shader sections of this document
|
when selecting any shading model that is not <code>unlit</code>. See the shader sections of this document
|
||||||
for more information on how to access these attributes from the shaders.
|
for more information on how to access these attributes from the shaders.
|
||||||
|
|
||||||
</p></dd></dl><div class="admonition note"><div class="admonition-title"> Interaction with custom variables</div>
|
</p></dd></dl><p></p><pre class="listing tilde"><code><span class="line">material {</span>
|
||||||
|
|
||||||
<p></p><p>
|
|
||||||
|
|
||||||
When the <code>color</code> attribute is specified, only four custom variables are available instead of five.</p></div>
|
|
||||||
|
|
||||||
<p></p><pre class="listing tilde"><code><span class="line">material {</span>
|
|
||||||
<span class="line"> parameters : [</span>
|
<span class="line"> parameters : [</span>
|
||||||
<span class="line"> {</span>
|
<span class="line"> {</span>
|
||||||
<span class="line"> type : sampler2d,</span>
|
<span class="line"> type : sampler2d,</span>
|
||||||
@@ -1789,7 +1779,7 @@ non-shader data.
|
|||||||
|
|
||||||
</p><dl><dt>Type</dt><dd><p> array of <code>string</code>
|
</p><dl><dt>Type</dt><dd><p> array of <code>string</code>
|
||||||
|
|
||||||
</p></dd><dt>Value</dt><dd><p> Up to 5 strings, each must be a valid GLSL identifier.
|
</p></dd><dt>Value</dt><dd><p> Up to 4 strings, each must be a valid GLSL identifier.
|
||||||
|
|
||||||
</p></dd><dt>Description</dt><dd><p> Defines custom interpolants (or variables) that are output by the material's vertex shader.
|
</p></dd><dt>Description</dt><dd><p> Defines custom interpolants (or variables) that are output by the material's vertex shader.
|
||||||
Each entry of the array defines the name of an interpolant. The full name in the fragment
|
Each entry of the array defines the name of an interpolant. The full name in the fragment
|
||||||
@@ -1804,14 +1794,7 @@ non-shader data.
|
|||||||
particular if <code>default</code> is specified the default precision is used is the fragment shader
|
particular if <code>default</code> is specified the default precision is used is the fragment shader
|
||||||
(<code>mediump</code>) and in the vertex shader (<code>highp</code>).
|
(<code>mediump</code>) and in the vertex shader (<code>highp</code>).
|
||||||
|
|
||||||
</p></dd></dl><div class="admonition warning"><div class="admonition-title"> Interaction with required attributes</div>
|
</p></dd></dl><p></p><pre class="listing tilde"><code><span class="line">material {</span>
|
||||||
|
|
||||||
<p></p><p>
|
|
||||||
|
|
||||||
If the <code>color</code> attribute is specified in the <code>required</code> list, then only four variables can be used
|
|
||||||
instead of five.</p></div>
|
|
||||||
|
|
||||||
<p></p><pre class="listing tilde"><code><span class="line">material {</span>
|
|
||||||
<span class="line"> name : Skybox,</span>
|
<span class="line"> name : Skybox,</span>
|
||||||
<span class="line"> parameters : [</span>
|
<span class="line"> parameters : [</span>
|
||||||
<span class="line"> {</span>
|
<span class="line"> {</span>
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
+16
-16
@@ -49,7 +49,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="left"><a href="#EntityManager">EntityManager</a></td>
|
<td align="left"><a href="#EntityManager">EntityManager</a></td>
|
||||||
<td align="left">Singleton used for constructing entities in Filament's ECS.</td>
|
<td align="left">Singleton used for constructing entities in Filament's ECS.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="left"><a href="#Frustum">Frustum</a></td>
|
<td align="left"><a href="#Frustum">Frustum</a></td>
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="left"><a href="#Renderer">Renderer</a></td>
|
<td align="left"><a href="#Renderer">Renderer</a></td>
|
||||||
<td align="left">Represents the platform's native window.</td>
|
<td align="left">Represents the platform's native window.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="left"><a href="#Scene">Scene</a></td>
|
<td align="left"><a href="#Scene">Scene</a></td>
|
||||||
@@ -97,7 +97,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="left"><a href="#SwapChain">SwapChain</a></td>
|
<td align="left"><a href="#SwapChain">SwapChain</a></td>
|
||||||
<td align="left">Represents the platform's native rendering surface.</td>
|
<td align="left">Represents the platform's native rendering surface.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="left"><a href="#Texture">Texture</a></td>
|
<td align="left"><a href="#Texture">Texture</a></td>
|
||||||
@@ -604,11 +604,11 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<p>To create an entity with no components, use <a href="#EntityManager">EntityManager</a>.
|
<p>To create an entity with no components, use <a href="#EntityManager">EntityManager</a>.
|
||||||
TODO: It would be better to expose these as JS numbers rather than as JS objects.
|
TODO: It would be better to expose these as JS numbers rather than as JS objects.
|
||||||
This would also be more consistent with Filament's Java bindings.</p>
|
This would also be more consistent with Filament's Java bindings.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class='classdoc'>
|
<div class='classdoc'>
|
||||||
<h2>class <a id='EntityManager' href='#EntityManager'>EntityManager</a></h2>
|
<h2>class <a id='EntityManager' href='#EntityManager'>EntityManager</a></h2>
|
||||||
<p>Singleton used for constructing entities in Filament's ECS.</p>
|
<p>Singleton used for constructing entities in Filament's ECS.</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><strong>entityManager.create()</strong>
|
<li><strong>entityManager.create()</strong>
|
||||||
<ul>
|
<ul>
|
||||||
@@ -742,7 +742,7 @@ properties.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>Be sure to call the instance's <code>delete</code> method when you're done with it.</p>
|
<p>Be sure to call the instance's <code>delete</code> method when you're done with it.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class='classdoc'>
|
<div class='classdoc'>
|
||||||
<h2>class <a id='PixelBufferDescriptor' href='#PixelBufferDescriptor'>PixelBufferDescriptor</a></h2>
|
<h2>class <a id='PixelBufferDescriptor' href='#PixelBufferDescriptor'>PixelBufferDescriptor</a></h2>
|
||||||
@@ -780,11 +780,11 @@ properties.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>Be sure to call the instance's <code>delete</code> method when you're done with it.</p>
|
<p>Be sure to call the instance's <code>delete</code> method when you're done with it.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class='classdoc'>
|
<div class='classdoc'>
|
||||||
<h2>class <a id='Renderer' href='#Renderer'>Renderer</a></h2>
|
<h2>class <a id='Renderer' href='#Renderer'>Renderer</a></h2>
|
||||||
<p>Represents the platform's native window.</p>
|
<p>Represents the platform's native window.</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><strong>renderer.render(swapChain, view)</strong>
|
<li><strong>renderer.render(swapChain, view)</strong>
|
||||||
<ul>
|
<ul>
|
||||||
@@ -803,7 +803,7 @@ properties.</p>
|
|||||||
</div>
|
</div>
|
||||||
<div class='classdoc'>
|
<div class='classdoc'>
|
||||||
<h2>class <a id='SwapChain' href='#SwapChain'>SwapChain</a></h2>
|
<h2>class <a id='SwapChain' href='#SwapChain'>SwapChain</a></h2>
|
||||||
<p>Represents the platform's native rendering surface.</p>
|
<p>Represents the platform's native rendering surface.</p>
|
||||||
<p>See also the <a href="#Engine">Engine</a> methods <code>createSwapChain</code> and <code>destroySwapChain</code>.</p>
|
<p>See also the <a href="#Engine">Engine</a> methods <code>createSwapChain</code> and <code>destroySwapChain</code>.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class='classdoc'>
|
<div class='classdoc'>
|
||||||
@@ -847,7 +847,7 @@ properties.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>Be sure to call the instance's <code>delete</code> method when you're done with it.</p>
|
<p>Be sure to call the instance's <code>delete</code> method when you're done with it.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class='classdoc'>
|
<div class='classdoc'>
|
||||||
<h2>class <a id='VertexBuffer' href='#VertexBuffer'>VertexBuffer</a></h2>
|
<h2>class <a id='VertexBuffer' href='#VertexBuffer'>VertexBuffer</a></h2>
|
||||||
@@ -944,7 +944,7 @@ See also the <a href="#Engine">Engine</a> methods <code>createView</code> and <c
|
|||||||
<ul>
|
<ul>
|
||||||
<li><strong>assets</strong>
|
<li><strong>assets</strong>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Array of strings containing URL's of required assets.</li>
|
<li>Array of strings containing URL's of required assets.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><strong>onDone</strong>
|
<li><strong>onDone</strong>
|
||||||
@@ -954,7 +954,7 @@ See also the <a href="#Engine">Engine</a> methods <code>createView</code> and <c
|
|||||||
</li>
|
</li>
|
||||||
<li><strong>onFetched</strong>
|
<li><strong>onFetched</strong>
|
||||||
<ul>
|
<ul>
|
||||||
<li>optional callback that's invoked after each asset is downloaded.</li>
|
<li>optional callback that's invoked after each asset is downloaded.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -1001,7 +1001,7 @@ useful for compressed textures. For example, some platforms accept ETC and other
|
|||||||
<ul>
|
<ul>
|
||||||
<li><strong>assets</strong>
|
<li><strong>assets</strong>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Array of strings containing URL's of required assets.</li>
|
<li>Array of strings containing URL's of required assets.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><strong>onready</strong>
|
<li><strong>onready</strong>
|
||||||
@@ -1010,12 +1010,12 @@ useful for compressed textures. For example, some platforms accept ETC and other
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>All JavaScript clients must call the init function, passing in a list of asset URL's and a
|
<p>All JavaScript clients must call the init function, passing in a list of asset URL's and a
|
||||||
callback. This callback gets invoked only after all assets have been downloaded and the Filament
|
callback. This callback gets invoked only after all assets have been downloaded and the Filament
|
||||||
WebAssembly module has been loaded. Clients should only pass asset URL's that absolutely must
|
WebAssembly module has been loaded. Clients should only pass asset URL's that absolutely must
|
||||||
be ready at initialization time.
|
be ready at initialization time.
|
||||||
When the callback is called, each downloaded asset is available in the <code>Filament.assets</code> global
|
When the callback is called, each downloaded asset is available in the <code>Filament.assets</code> global
|
||||||
object, which contains a mapping from URL's to Uint8Array objects.</p>
|
object, which contains a mapping from URL's to Uint8Array objects.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class='funcdoc'>
|
<div class='funcdoc'>
|
||||||
<h2>function <a id='loadMathExtensions' href='#loadMathExtensions'>loadMathExtensions</a>()</h2>
|
<h2>function <a id='loadMathExtensions' href='#loadMathExtensions'>loadMathExtensions</a>()</h2>
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
+157
-157
@@ -10,7 +10,7 @@
|
|||||||
textures.</p>
|
textures.</p>
|
||||||
<p>For starters, create a text file called <code>redball.html</code> and copy over the HTML that we used in the
|
<p>For starters, create a text file called <code>redball.html</code> and copy over the HTML that we used in the
|
||||||
<a href="tutorial_triangle.html">previous tutorial</a>. Change the last script tag from <code>triangle.js</code> to <code>redball.js</code>.</p>
|
<a href="tutorial_triangle.html">previous tutorial</a>. Change the last script tag from <code>triangle.js</code> to <code>redball.js</code>.</p>
|
||||||
<p>Next you'll need to get a couple command-line tools: <code>matc</code> and <code>cmgen</code>. You can find these in the
|
<p>Next you'll need to get a couple command-line tools: <code>matc</code> and <code>cmgen</code>. You can find these in the
|
||||||
appropriate <a href="//github.com/google/filament/releases">Filament release</a>. You should choose the
|
appropriate <a href="//github.com/google/filament/releases">Filament release</a>. You should choose the
|
||||||
archive that corresponds to your development machine rather than the one for web, and the version
|
archive that corresponds to your development machine rather than the one for web, and the version
|
||||||
that matches the <code>unpkg.com/filament@x.x.x</code> url in the script tag of <code>redball.html</code> (you may check
|
that matches the <code>unpkg.com/filament@x.x.x</code> url in the script tag of <code>redball.html</code> (you may check
|
||||||
@@ -19,7 +19,7 @@ out the last available release of <a href="https://www.npmjs.com/package/filamen
|
|||||||
<p>The <code>matc</code> tool consumes a text file containing a high-level description of a PBR material, and
|
<p>The <code>matc</code> tool consumes a text file containing a high-level description of a PBR material, and
|
||||||
produces a binary material package that contains shader code and associated metadata. For more
|
produces a binary material package that contains shader code and associated metadata. For more
|
||||||
information, see the official document describing the <a href="https://google.github.io/filament/Materials.md.html">Filament Material System</a>.</p>
|
information, see the official document describing the <a href="https://google.github.io/filament/Materials.md.html">Filament Material System</a>.</p>
|
||||||
<p>Let's try out <code>matc</code>. Create the following file in your favorite text editor and call it
|
<p>Let's try out <code>matc</code>. Create the following file in your favorite text editor and call it
|
||||||
<code>plastic.mat</code>.</p>
|
<code>plastic.mat</code>.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>material {
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>material {
|
||||||
name : Lit,
|
name : Lit,
|
||||||
@@ -44,16 +44,16 @@ fragment {
|
|||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Next, invoke <code>matc</code> as follows.</p>
|
<p>Next, invoke <code>matc</code> as follows.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>matc<span style="color: #BBB"> </span>-a<span style="color: #BBB"> </span>opengl<span style="color: #BBB"> </span>-p<span style="color: #BBB"> </span>mobile<span style="color: #BBB"> </span>-o<span style="color: #BBB"> </span>plastic.filamat<span style="color: #BBB"> </span>plastic.mat
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>matc -a opengl -p mobile -o plastic.filamat plastic.mat
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>You should now have a material archive in your working directory, which we'll use later in the
|
<p>You should now have a material archive in your working directory, which we'll use later in the
|
||||||
tutorial.</p>
|
tutorial.</p>
|
||||||
<h2>Bake environment map</h2>
|
<h2>Bake environment map</h2>
|
||||||
<p>Next we'll use Filament's <code>cmgen</code> tool to consume a HDR environment map in latlong format, and
|
<p>Next we'll use Filament's <code>cmgen</code> tool to consume a HDR environment map in latlong format, and
|
||||||
produce two cubemap files: a mipmapped IBL and a blurry skybox.</p>
|
produce two cubemap files: a mipmapped IBL and a blurry skybox.</p>
|
||||||
<p>Download <a href="//github.com/google/filament/blob/main/third_party/environments/pillars_2k.hdr">pillars_2k.hdr</a>, then invoke the following command in your terminal.</p>
|
<p>Download <a href="//github.com/google/filament/blob/main/third_party/environments/pillars_2k.hdr">pillars_2k.hdr</a>, then invoke the following command in your terminal.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>cmgen<span style="color: #BBB"> </span>-x<span style="color: #BBB"> </span>pillars_2k<span style="color: #BBB"> </span>--format<span style="color: #666">=</span>ktx<span style="color: #BBB"> </span>--size<span style="color: #666">=256</span><span style="color: #BBB"> </span>--extract-blur<span style="color: #666">=0</span>.1<span style="color: #BBB"> </span>pillars_2k.hdr
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>cmgen -x pillars_2k --format<span style="color: #666666">=</span>ktx --size<span style="color: #666666">=256</span> --extract-blur<span style="color: #666666">=0</span>.1 pillars_2k.hdr
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>You should now have a <code>pillars_2k</code> folder containing a couple KTX files for the IBL and skybox, as
|
<p>You should now have a <code>pillars_2k</code> folder containing a couple KTX files for the IBL and skybox, as
|
||||||
@@ -61,84 +61,84 @@ well as a text file with spherical harmonics coefficients. You can discard the t
|
|||||||
IBL KTX contains these coefficients in its metadata.</p>
|
IBL KTX contains these coefficients in its metadata.</p>
|
||||||
<h2>Create JavaScript</h2>
|
<h2>Create JavaScript</h2>
|
||||||
<p>Next, create <code>redball.js</code> with the following content.</p>
|
<p>Next, create <code>redball.js</code> with the following content.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>environ<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">'pillars_2k'</span>;
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>environ<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">'pillars_2k'</span>;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>ibl_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_ibl.ktx`</span>;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>ibl_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_ibl.ktx`</span>;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>sky_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_skybox.ktx`</span>;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>sky_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_skybox.ktx`</span>;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>filamat_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">'plastic.filamat'</span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>filamat_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">'plastic.filamat'</span><span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
Filament.init([<span style="color: #BBB"> </span>filamat_url,<span style="color: #BBB"> </span>ibl_url,<span style="color: #BBB"> </span>sky_url<span style="color: #BBB"> </span>],<span style="color: #BBB"> </span>()<span style="color: #BBB"> </span>=><span style="color: #BBB"> </span>{
|
Filament.init([<span style="color: #bbbbbb"> </span>filamat_url,<span style="color: #bbbbbb"> </span>ibl_url,<span style="color: #bbbbbb"> </span>sky_url<span style="color: #bbbbbb"> </span>],<span style="color: #bbbbbb"> </span>()<span style="color: #bbbbbb"> </span>=><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// Create some global aliases to enums for convenience.</span>
|
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// Create some global aliases to enums for convenience.</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.VertexAttribute<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.VertexAttribute;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.VertexAttribute<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.VertexAttribute;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.AttributeType<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.VertexBuffer$AttributeType;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.AttributeType<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.VertexBuffer$AttributeType;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.PrimitiveType<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.RenderableManager$PrimitiveType;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.PrimitiveType<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.RenderableManager$PrimitiveType;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.IndexType<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.IndexBuffer$IndexType;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.IndexType<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.IndexBuffer$IndexType;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.Fov<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Camera$Fov;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.Fov<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Camera$Fov;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.LightType<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.LightManager$Type;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.LightType<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.LightManager$Type;<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// Obtain the canvas DOM object and pass it to the App.</span>
|
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// Obtain the canvas DOM object and pass it to the App.</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>canvas<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">document</span>.getElementsByTagName(<span style="color: #BA2121">'canvas'</span>)[<span style="color: #666">0</span>];
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>canvas<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">document</span>.getElementsByTagName(<span style="color: #BA2121">'canvas'</span>)[<span style="color: #666666">0</span>];<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.app<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span>App(canvas);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.app<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span>App(canvas);<span style="color: #bbbbbb"></span>
|
||||||
}<span style="color: #BBB"> </span>);
|
}<span style="color: #bbbbbb"> </span>);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">class</span><span style="color: #BBB"> </span>App<span style="color: #BBB"> </span>{
|
<span style="color: #008000; font-weight: bold">class</span><span style="color: #bbbbbb"> </span>App<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">constructor</span>(canvas)<span style="color: #BBB"> </span>{
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">constructor</span>(canvas)<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>canvas;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>canvas;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>engine<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Engine.create(canvas);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>engine<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Engine.create(canvas);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>scene<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createScene();
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>scene<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createScene();<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create material</span>
|
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create material</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create sphere</span>
|
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create sphere</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create lights</span>
|
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create lights</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create IBL</span>
|
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create IBL</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create skybox</span>
|
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create skybox</span><span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.swapChain<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createSwapChain();
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.swapChain<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createSwapChain();<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.renderer<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createRenderer();
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.renderer<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createRenderer();<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.camera<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createCamera(Filament.EntityManager.get().create());
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.camera<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createCamera(Filament.EntityManager.get().create());<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createView();
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createView();<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setCamera(<span style="color: #008000; font-weight: bold">this</span>.camera);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setCamera(<span style="color: #008000; font-weight: bold">this</span>.camera);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setScene(scene);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setScene(scene);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize();
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize();<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.render<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.render.bind(<span style="color: #008000; font-weight: bold">this</span>);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.render<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.render.bind(<span style="color: #008000; font-weight: bold">this</span>);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize.bind(<span style="color: #008000; font-weight: bold">this</span>);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize.bind(<span style="color: #008000; font-weight: bold">this</span>);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.addEventListener(<span style="color: #BA2121">'resize'</span>,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.addEventListener(<span style="color: #BA2121">'resize'</span>,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>}
|
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span>render()<span style="color: #BBB"> </span>{
|
<span style="color: #bbbbbb"> </span>render()<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>eye<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>[<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">4</span>],<span style="color: #BBB"> </span>center<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>[<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>],<span style="color: #BBB"> </span>up<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>[<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>];
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>eye<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">4</span>],<span style="color: #bbbbbb"> </span>center<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>],<span style="color: #bbbbbb"> </span>up<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>];<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>radians<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">Date</span>.now()<span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span><span style="color: #666">10000</span>;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>radians<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">Date</span>.now()<span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span><span style="color: #666666">10000</span>;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>vec3.rotateY(eye,<span style="color: #BBB"> </span>eye,<span style="color: #BBB"> </span>center,<span style="color: #BBB"> </span>radians);
|
<span style="color: #bbbbbb"> </span>vec3.rotateY(eye,<span style="color: #bbbbbb"> </span>eye,<span style="color: #bbbbbb"> </span>center,<span style="color: #bbbbbb"> </span>radians);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.camera.lookAt(eye,<span style="color: #BBB"> </span>center,<span style="color: #BBB"> </span>up);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.camera.lookAt(eye,<span style="color: #bbbbbb"> </span>center,<span style="color: #bbbbbb"> </span>up);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.renderer.render(<span style="color: #008000; font-weight: bold">this</span>.swapChain,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.renderer.render(<span style="color: #008000; font-weight: bold">this</span>.swapChain,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>}
|
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span>resize()<span style="color: #BBB"> </span>{
|
<span style="color: #bbbbbb"> </span>resize()<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>dpr<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.devicePixelRatio;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>dpr<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.devicePixelRatio;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>width<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.width<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.innerWidth<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span>dpr;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>width<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.width<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.innerWidth<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span>dpr;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>height<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.height<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.innerHeight<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span>dpr;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>height<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.height<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.innerHeight<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span>dpr;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setViewport([<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span>width,<span style="color: #BBB"> </span>height]);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setViewport([<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>width,<span style="color: #bbbbbb"> </span>height]);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.camera.setProjectionFov(<span style="color: #666">45</span>,<span style="color: #BBB"> </span>width<span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span>height,<span style="color: #BBB"> </span><span style="color: #666">1.0</span>,<span style="color: #BBB"> </span><span style="color: #666">10.0</span>,<span style="color: #BBB"> </span>Fov.VERTICAL);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.camera.setProjectionFov(<span style="color: #666666">45</span>,<span style="color: #bbbbbb"> </span>width<span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span>height,<span style="color: #bbbbbb"> </span><span style="color: #666666">1.0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">10.0</span>,<span style="color: #bbbbbb"> </span>Fov.VERTICAL);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>}
|
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
||||||
}
|
}<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>The above boilerplate should be familiar to you from the previous tutorial, although it loads in a
|
<p>The above boilerplate should be familiar to you from the previous tutorial, although it loads in a
|
||||||
new set of assets. We also added some animation to the camera.</p>
|
new set of assets. We also added some animation to the camera.</p>
|
||||||
<p>Next let's create a material instance from the package that we built at the beginning the tutorial.
|
<p>Next let's create a material instance from the package that we built at the beginning the tutorial.
|
||||||
Replace the <strong>create material</strong> comment with the following snippet.</p>
|
Replace the <strong>create material</strong> comment with the following snippet.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>material<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createMaterial(filamat_url);
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>material<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createMaterial(filamat_url);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>matinstance<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>material.createInstance();
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>matinstance<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>material.createInstance();<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>red<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>[<span style="color: #666">0.8</span>,<span style="color: #BBB"> </span><span style="color: #666">0.0</span>,<span style="color: #BBB"> </span><span style="color: #666">0.0</span>];
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>red<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">0.8</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0.0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0.0</span>];<span style="color: #bbbbbb"></span>
|
||||||
matinstance.setColor3Parameter(<span style="color: #BA2121">'baseColor'</span>,<span style="color: #BBB"> </span>Filament.RgbType.sRGB,<span style="color: #BBB"> </span>red);
|
matinstance.setColor3Parameter(<span style="color: #BA2121">'baseColor'</span>,<span style="color: #bbbbbb"> </span>Filament.RgbType.sRGB,<span style="color: #bbbbbb"> </span>red);<span style="color: #bbbbbb"></span>
|
||||||
matinstance.setFloatParameter(<span style="color: #BA2121">'roughness'</span>,<span style="color: #BBB"> </span><span style="color: #666">0.5</span>);
|
matinstance.setFloatParameter(<span style="color: #BA2121">'roughness'</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0.5</span>);<span style="color: #bbbbbb"></span>
|
||||||
matinstance.setFloatParameter(<span style="color: #BA2121">'clearCoat'</span>,<span style="color: #BBB"> </span><span style="color: #666">1.0</span>);
|
matinstance.setFloatParameter(<span style="color: #BA2121">'clearCoat'</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1.0</span>);<span style="color: #bbbbbb"></span>
|
||||||
matinstance.setFloatParameter(<span style="color: #BA2121">'clearCoatRoughness'</span>,<span style="color: #BBB"> </span><span style="color: #666">0.3</span>);
|
matinstance.setFloatParameter(<span style="color: #BA2121">'clearCoatRoughness'</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0.3</span>);<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>The next step is to create a renderable for the sphere. To help with this, we'll use the <code>IcoSphere</code>
|
<p>The next step is to create a renderable for the sphere. To help with this, we'll use the <code>IcoSphere</code>
|
||||||
utility class, whose constructor takes a LOD. Its job is to subdivide an icosadedron, producing
|
utility class, whose constructor takes a LOD. Its job is to subdivide an icosadedron, producing
|
||||||
three arrays:</p>
|
three arrays:</p>
|
||||||
<ul>
|
<ul>
|
||||||
@@ -147,137 +147,137 @@ three arrays:</p>
|
|||||||
as quaternions.</li>
|
as quaternions.</li>
|
||||||
<li><code>icosphere.triangles</code> Uint16Array with triangle indices.</li>
|
<li><code>icosphere.triangles</code> Uint16Array with triangle indices.</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>Let's go ahead use these arrays to build the vertex buffer and index buffer. Replace <strong>create
|
<p>Let's go ahead use these arrays to build the vertex buffer and index buffer. Replace <strong>create
|
||||||
sphere</strong> with the following snippet.</p>
|
sphere</strong> with the following snippet.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>renderable<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.EntityManager.get().create();
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>renderable<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.EntityManager.get().create();<span style="color: #bbbbbb"></span>
|
||||||
scene.addEntity(renderable);
|
scene.addEntity(renderable);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>icosphere<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span>Filament.IcoSphere(<span style="color: #666">5</span>);
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>icosphere<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span>Filament.IcoSphere(<span style="color: #666666">5</span>);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>vb<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.VertexBuffer.Builder()
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>vb<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.VertexBuffer.Builder()<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.vertexCount(icosphere.vertices.length<span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span><span style="color: #666">3</span>)
|
<span style="color: #bbbbbb"> </span>.vertexCount(icosphere.vertices.length<span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span><span style="color: #666666">3</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.bufferCount(<span style="color: #666">2</span>)
|
<span style="color: #bbbbbb"> </span>.bufferCount(<span style="color: #666666">2</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.attribute(VertexAttribute.POSITION,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span>AttributeType.FLOAT3,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>)
|
<span style="color: #bbbbbb"> </span>.attribute(VertexAttribute.POSITION,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>AttributeType.FLOAT3,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.attribute(VertexAttribute.TANGENTS,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span>AttributeType.SHORT4,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>)
|
<span style="color: #bbbbbb"> </span>.attribute(VertexAttribute.TANGENTS,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span>AttributeType.SHORT4,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.normalized(VertexAttribute.TANGENTS)
|
<span style="color: #bbbbbb"> </span>.normalized(VertexAttribute.TANGENTS)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.build(engine);
|
<span style="color: #bbbbbb"> </span>.build(engine);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>ib<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.IndexBuffer.Builder()
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>ib<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.IndexBuffer.Builder()<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.indexCount(icosphere.triangles.length)
|
<span style="color: #bbbbbb"> </span>.indexCount(icosphere.triangles.length)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.bufferType(IndexType.USHORT)
|
<span style="color: #bbbbbb"> </span>.bufferType(IndexType.USHORT)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.build(engine);
|
<span style="color: #bbbbbb"> </span>.build(engine);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
vb.setBufferAt(engine,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span>icosphere.vertices);
|
vb.setBufferAt(engine,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>icosphere.vertices);<span style="color: #bbbbbb"></span>
|
||||||
vb.setBufferAt(engine,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span>icosphere.tangents);
|
vb.setBufferAt(engine,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span>icosphere.tangents);<span style="color: #bbbbbb"></span>
|
||||||
ib.setBuffer(engine,<span style="color: #BBB"> </span>icosphere.triangles);
|
ib.setBuffer(engine,<span style="color: #bbbbbb"> </span>icosphere.triangles);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
Filament.RenderableManager.Builder(<span style="color: #666">1</span>)
|
Filament.RenderableManager.Builder(<span style="color: #666666">1</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.boundingBox({<span style="color: #BBB"> </span>center<span style="color: #666">:</span><span style="color: #BBB"> </span>[<span style="color: #666">-1</span>,<span style="color: #BBB"> </span><span style="color: #666">-1</span>,<span style="color: #BBB"> </span><span style="color: #666">-1</span>],<span style="color: #BBB"> </span>halfExtent<span style="color: #666">:</span><span style="color: #BBB"> </span>[<span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>]<span style="color: #BBB"> </span>})
|
<span style="color: #bbbbbb"> </span>.boundingBox({<span style="color: #bbbbbb"> </span>center<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">-1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">-1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">-1</span>],<span style="color: #bbbbbb"> </span>halfExtent<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>]<span style="color: #bbbbbb"> </span>})<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.material(<span style="color: #666">0</span>,<span style="color: #BBB"> </span>matinstance)
|
<span style="color: #bbbbbb"> </span>.material(<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>matinstance)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.geometry(<span style="color: #666">0</span>,<span style="color: #BBB"> </span>PrimitiveType.TRIANGLES,<span style="color: #BBB"> </span>vb,<span style="color: #BBB"> </span>ib)
|
<span style="color: #bbbbbb"> </span>.geometry(<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>PrimitiveType.TRIANGLES,<span style="color: #bbbbbb"> </span>vb,<span style="color: #bbbbbb"> </span>ib)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.build(engine,<span style="color: #BBB"> </span>renderable);
|
<span style="color: #bbbbbb"> </span>.build(engine,<span style="color: #bbbbbb"> </span>renderable);<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>At this point, the app is rendering a sphere, but it is black so it doesn't show up. To prove that
|
<p>At this point, the app is rendering a sphere, but it is black so it doesn't show up. To prove that
|
||||||
the sphere is there, you can try changing the background color to blue via <code>setClearColor</code>, like we
|
the sphere is there, you can try changing the background color to blue via <code>setClearColor</code>, like we
|
||||||
did in the first tutorial.</p>
|
did in the first tutorial.</p>
|
||||||
<h2>Add lighting</h2>
|
<h2>Add lighting</h2>
|
||||||
<p>In this section we will create some directional light sources, as well as an image-based light (IBL)
|
<p>In this section we will create some directional light sources, as well as an image-based light (IBL)
|
||||||
defined by one of the KTX files we built at the start of the demo. First, replace the <strong>create
|
defined by one of the KTX files we built at the start of the demo. First, replace the <strong>create
|
||||||
lights</strong> comment with the following snippet.</p>
|
lights</strong> comment with the following snippet.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>sunlight<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.EntityManager.get().create();
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>sunlight<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.EntityManager.get().create();<span style="color: #bbbbbb"></span>
|
||||||
scene.addEntity(sunlight);
|
scene.addEntity(sunlight);<span style="color: #bbbbbb"></span>
|
||||||
Filament.LightManager.Builder(LightType.SUN)
|
Filament.LightManager.Builder(LightType.SUN)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.color([<span style="color: #666">0.98</span>,<span style="color: #BBB"> </span><span style="color: #666">0.92</span>,<span style="color: #BBB"> </span><span style="color: #666">0.89</span>])
|
<span style="color: #bbbbbb"> </span>.color([<span style="color: #666666">0.98</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0.92</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0.89</span>])<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.intensity(<span style="color: #666">110000.0</span>)
|
<span style="color: #bbbbbb"> </span>.intensity(<span style="color: #666666">110000.0</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.direction([<span style="color: #666">0.6</span>,<span style="color: #BBB"> </span><span style="color: #666">-1.0</span>,<span style="color: #BBB"> </span><span style="color: #666">-0.8</span>])
|
<span style="color: #bbbbbb"> </span>.direction([<span style="color: #666666">0.6</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">-1.0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">-0.8</span>])<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.sunAngularRadius(<span style="color: #666">1.9</span>)
|
<span style="color: #bbbbbb"> </span>.sunAngularRadius(<span style="color: #666666">1.9</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.sunHaloSize(<span style="color: #666">10.0</span>)
|
<span style="color: #bbbbbb"> </span>.sunHaloSize(<span style="color: #666666">10.0</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.sunHaloFalloff(<span style="color: #666">80.0</span>)
|
<span style="color: #bbbbbb"> </span>.sunHaloFalloff(<span style="color: #666666">80.0</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.build(engine,<span style="color: #BBB"> </span>sunlight);
|
<span style="color: #bbbbbb"> </span>.build(engine,<span style="color: #bbbbbb"> </span>sunlight);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>backlight<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.EntityManager.get().create();
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>backlight<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.EntityManager.get().create();<span style="color: #bbbbbb"></span>
|
||||||
scene.addEntity(backlight);
|
scene.addEntity(backlight);<span style="color: #bbbbbb"></span>
|
||||||
Filament.LightManager.Builder(LightType.DIRECTIONAL)
|
Filament.LightManager.Builder(LightType.DIRECTIONAL)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.direction([<span style="color: #666">-1</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>])
|
<span style="color: #bbbbbb"> </span>.direction([<span style="color: #666666">-1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>])<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.intensity(<span style="color: #666">50000.0</span>)
|
<span style="color: #bbbbbb"> </span>.intensity(<span style="color: #666666">50000.0</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.build(engine,<span style="color: #BBB"> </span>backlight);
|
<span style="color: #bbbbbb"> </span>.build(engine,<span style="color: #bbbbbb"> </span>backlight);<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>The <code>SUN</code> light source is similar to the <code>DIRECTIONAL</code> light source, but has some extra
|
<p>The <code>SUN</code> light source is similar to the <code>DIRECTIONAL</code> light source, but has some extra
|
||||||
parameters because Filament will automatically draw a disk into the skybox.</p>
|
parameters because Filament will automatically draw a disk into the skybox.</p>
|
||||||
<p>Next we need to create an <code>IndirectLight</code> object from the KTX IBL. One way of doing this is the
|
<p>Next we need to create an <code>IndirectLight</code> object from the KTX IBL. One way of doing this is the
|
||||||
following (don't type this out, there's an easier way).</p>
|
following (don't type this out, there's an easier way).</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>format<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.PixelDataFormat.RGB;
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>format<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.PixelDataFormat.RGB;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>datatype<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.PixelDataType.UINT_10F_11F_11F_REV;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>datatype<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.PixelDataType.UINT_10F_11F_11F_REV;<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic">// Create a Texture object for the mipmapped cubemap.</span>
|
<span style="color: #3D7B7B; font-style: italic">// Create a Texture object for the mipmapped cubemap.</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>ibl_package<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Buffer(Filament.assets[ibl_url]);
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>ibl_package<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Buffer(Filament.assets[ibl_url]);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>iblktx<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span>Filament.Ktx1Bundle(ibl_package);
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>iblktx<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span>Filament.Ktx1Bundle(ibl_package);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>ibltex<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Texture.Builder()
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>ibltex<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Texture.Builder()<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.width(iblktx.info().pixelWidth)
|
<span style="color: #bbbbbb"> </span>.width(iblktx.info().pixelWidth)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.height(iblktx.info().pixelHeight)
|
<span style="color: #bbbbbb"> </span>.height(iblktx.info().pixelHeight)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.levels(iblktx.getNumMipLevels())
|
<span style="color: #bbbbbb"> </span>.levels(iblktx.getNumMipLevels())<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.sampler(Filament.Texture$Sampler.SAMPLER_CUBEMAP)
|
<span style="color: #bbbbbb"> </span>.sampler(Filament.Texture$Sampler.SAMPLER_CUBEMAP)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.format(Filament.Texture$InternalFormat.RGBA8)
|
<span style="color: #bbbbbb"> </span>.format(Filament.Texture$InternalFormat.RGBA8)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.build(engine);
|
<span style="color: #bbbbbb"> </span>.build(engine);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">for</span><span style="color: #BBB"> </span>(<span style="color: #008000; font-weight: bold">let</span><span style="color: #BBB"> </span>level<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #666">0</span>;<span style="color: #BBB"> </span>level<span style="color: #BBB"> </span><span style="color: #666"><</span><span style="color: #BBB"> </span>iblktx.getNumMipLevels();<span style="color: #BBB"> </span><span style="color: #666">++</span>level)<span style="color: #BBB"> </span>{
|
<span style="color: #008000; font-weight: bold">for</span><span style="color: #bbbbbb"> </span>(<span style="color: #008000; font-weight: bold">let</span><span style="color: #bbbbbb"> </span>level<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>;<span style="color: #bbbbbb"> </span>level<span style="color: #bbbbbb"> </span><span style="color: #666666"><</span><span style="color: #bbbbbb"> </span>iblktx.getNumMipLevels();<span style="color: #bbbbbb"> </span><span style="color: #666666">++</span>level)<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>uint8array<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>iblktx.getCubeBlob(level).getBytes();
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>uint8array<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>iblktx.getCubeBlob(level).getBytes();<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>pixelbuffer<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.PixelBuffer(uint8array,<span style="color: #BBB"> </span>format,<span style="color: #BBB"> </span>datatype);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>pixelbuffer<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.PixelBuffer(uint8array,<span style="color: #bbbbbb"> </span>format,<span style="color: #bbbbbb"> </span>datatype);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>ibltex.setImageCube(engine,<span style="color: #BBB"> </span>level,<span style="color: #BBB"> </span>pixelbuffer);
|
<span style="color: #bbbbbb"> </span>ibltex.setImageCube(engine,<span style="color: #bbbbbb"> </span>level,<span style="color: #bbbbbb"> </span>pixelbuffer);<span style="color: #bbbbbb"></span>
|
||||||
}
|
}<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic">// Parse the spherical harmonics metadata.</span>
|
<span style="color: #3D7B7B; font-style: italic">// Parse the spherical harmonics metadata.</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>shstring<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>iblktx.getMetadata(<span style="color: #BA2121">'sh'</span>);
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>shstring<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>iblktx.getMetadata(<span style="color: #BA2121">'sh'</span>);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>shfloats<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>shstring.split(<span style="color: #A45A77">/\s/</span>,<span style="color: #BBB"> </span><span style="color: #666">9</span><span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span><span style="color: #666">3</span>).map(<span style="color: #008000">parseFloat</span>);
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>shfloats<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>shstring.split(<span style="color: #A45A77">/\s/</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">9</span><span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span><span style="color: #666666">3</span>).map(<span style="color: #008000">parseFloat</span>);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic">// Build the IBL object and insert it into the scene.</span>
|
<span style="color: #3D7B7B; font-style: italic">// Build the IBL object and insert it into the scene.</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>indirectLight<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.IndirectLight.Builder()
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>indirectLight<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.IndirectLight.Builder()<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.reflections(ibltex)
|
<span style="color: #bbbbbb"> </span>.reflections(ibltex)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.irradianceSh(<span style="color: #666">3</span>,<span style="color: #BBB"> </span>shfloats)
|
<span style="color: #bbbbbb"> </span>.irradianceSh(<span style="color: #666666">3</span>,<span style="color: #bbbbbb"> </span>shfloats)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.intensity(<span style="color: #666">50000.0</span>)
|
<span style="color: #bbbbbb"> </span>.intensity(<span style="color: #666666">50000.0</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.build(engine);
|
<span style="color: #bbbbbb"> </span>.build(engine);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
scene.setIndirectLight(indirectLight);
|
scene.setIndirectLight(indirectLight);<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Filament provides a JavaScript utility to make this simpler,
|
<p>Filament provides a JavaScript utility to make this simpler,
|
||||||
simply replace the <strong>create IBL</strong> comment with the following snippet.</p>
|
simply replace the <strong>create IBL</strong> comment with the following snippet.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>indirectLight<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createIblFromKtx1(ibl_url);
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>indirectLight<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createIblFromKtx1(ibl_url);<span style="color: #bbbbbb"></span>
|
||||||
indirectLight.setIntensity(<span style="color: #666">50000</span>);
|
indirectLight.setIntensity(<span style="color: #666666">50000</span>);<span style="color: #bbbbbb"></span>
|
||||||
scene.setIndirectLight(indirectLight);
|
scene.setIndirectLight(indirectLight);<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<h2>Add background</h2>
|
<h2>Add background</h2>
|
||||||
<p>At this point you can run the demo and you should see a red plastic ball against a black background.
|
<p>At this point you can run the demo and you should see a red plastic ball against a black background.
|
||||||
Without a skybox, the reflections on the ball are not representative of its surroundings.
|
Without a skybox, the reflections on the ball are not representative of its surroundings.
|
||||||
Here's one way to create a texture for the skybox:</p>
|
Here's one way to create a texture for the skybox:</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>sky_package<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Buffer(Filament.assets[sky_url]);
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>sky_package<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Buffer(Filament.assets[sky_url]);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>skyktx<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span>Filament.Ktx1Bundle(sky_package);
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>skyktx<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span>Filament.Ktx1Bundle(sky_package);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>skytex<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Texture.Builder()
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>skytex<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Texture.Builder()<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.width(skyktx.info().pixelWidth)
|
<span style="color: #bbbbbb"> </span>.width(skyktx.info().pixelWidth)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.height(skyktx.info().pixelHeight)
|
<span style="color: #bbbbbb"> </span>.height(skyktx.info().pixelHeight)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.levels(<span style="color: #666">1</span>)
|
<span style="color: #bbbbbb"> </span>.levels(<span style="color: #666666">1</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.sampler(Filament.Texture$Sampler.SAMPLER_CUBEMAP)
|
<span style="color: #bbbbbb"> </span>.sampler(Filament.Texture$Sampler.SAMPLER_CUBEMAP)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.format(Filament.Texture$InternalFormat.RGBA8)
|
<span style="color: #bbbbbb"> </span>.format(Filament.Texture$InternalFormat.RGBA8)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.build(engine);
|
<span style="color: #bbbbbb"> </span>.build(engine);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>uint8array<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>skyktx.getCubeBlob(<span style="color: #666">0</span>).getBytes();
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>uint8array<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>skyktx.getCubeBlob(<span style="color: #666666">0</span>).getBytes();<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>pixelbuffer<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.PixelBuffer(uint8array,<span style="color: #BBB"> </span>format,<span style="color: #BBB"> </span>datatype);
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>pixelbuffer<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.PixelBuffer(uint8array,<span style="color: #bbbbbb"> </span>format,<span style="color: #bbbbbb"> </span>datatype);<span style="color: #bbbbbb"></span>
|
||||||
skytex.setImageCube(engine,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span>pixelbuffer);
|
skytex.setImageCube(engine,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>pixelbuffer);<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Filament provides a Javascript utility to make this easier.
|
<p>Filament provides a Javascript utility to make this easier.
|
||||||
Replace <strong>create skybox</strong> with the following.</p>
|
Replace <strong>create skybox</strong> with the following.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>skybox<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createSkyFromKtx1(sky_url);
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>skybox<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createSkyFromKtx1(sky_url);<span style="color: #bbbbbb"></span>
|
||||||
scene.setSkybox(skybox);
|
scene.setSkybox(skybox);<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>That's it, we now have a shiny red ball floating in an environment! The complete JavaScript file is
|
<p>That's it, we now have a shiny red ball floating in an environment! The complete JavaScript file is
|
||||||
available <a href="tutorial_redball.js">here</a>.</p>
|
available <a href="tutorial_redball.js">here</a>.</p>
|
||||||
<p>In the <a href="tutorial_suzanne.html">next tutorial</a>, we'll take a closer look at textures and interaction.</p>
|
<p>In the <a href="tutorial_suzanne.html">next tutorial</a>, we'll take a closer look at textures and interaction.</p>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+121
-121
@@ -8,58 +8,58 @@
|
|||||||
<div class="demo_frame"><iframe src="demo_suzanne.html"></iframe><a href="demo_suzanne.html">🔗</a></div>
|
<div class="demo_frame"><iframe src="demo_suzanne.html"></iframe><a href="demo_suzanne.html">🔗</a></div>
|
||||||
<p>This tutorial will describe how to create the <strong>suzanne</strong> demo, introducing you to compressed
|
<p>This tutorial will describe how to create the <strong>suzanne</strong> demo, introducing you to compressed
|
||||||
textures, mipmap generation, asynchronous texture loading, and trackball rotation.</p>
|
textures, mipmap generation, asynchronous texture loading, and trackball rotation.</p>
|
||||||
<p>Much like the <a href="tutorial_redball.html">previous tutorial</a>, you'll need to use the command-line tools that can be found in
|
<p>Much like the <a href="tutorial_redball.html">previous tutorial</a>, you'll need to use the command-line tools that can be found in
|
||||||
the appropriate <a href="//github.com/google/filament/releases">Filament release</a> for your development machine. In addition to <code>matc</code> and <code>cmgen</code>,
|
the appropriate <a href="//github.com/google/filament/releases">Filament release</a> for your development machine. In addition to <code>matc</code> and <code>cmgen</code>,
|
||||||
we'll also be using <code>filamesh</code> and <code>mipgen</code>.</p>
|
we'll also be using <code>filamesh</code> and <code>mipgen</code>.</p>
|
||||||
<h2>Create filamesh file</h2>
|
<h2>Create filamesh file</h2>
|
||||||
<p>Filament does not have an asset loading system, but it does provide a binary mesh format
|
<p>Filament does not have an asset loading system, but it does provide a binary mesh format
|
||||||
called <code>filamesh</code> for simple use cases. Let's create a compressed filamesh file for suzanne by
|
called <code>filamesh</code> for simple use cases. Let's create a compressed filamesh file for suzanne by
|
||||||
converting <a href="https://github.com/google/filament/blob/main/assets/models/monkey/monkey.obj">this OBJ file</a>:</p>
|
converting <a href="https://github.com/google/filament/blob/main/assets/models/monkey/monkey.obj">this OBJ file</a>:</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>filamesh<span style="color: #BBB"> </span>--compress<span style="color: #BBB"> </span>monkey.obj<span style="color: #BBB"> </span>suzanne.filamesh
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>filamesh --compress monkey.obj suzanne.filamesh
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<h2>Create mipmapped textures</h2>
|
<h2>Create mipmapped textures</h2>
|
||||||
<p>Next, let's create mipmapped KTX files using filament's <code>mipgen</code> tool. We'll create compressed and
|
<p>Next, let's create mipmapped KTX files using filament's <code>mipgen</code> tool. We'll create compressed and
|
||||||
non-compressed variants for each texture, since not all platforms support the same compression
|
non-compressed variants for each texture, since not all platforms support the same compression
|
||||||
formats. First copy over the PNG files from the <a href="https://github.com/google/filament/blob/main/assets/models/monkey">monkey folder</a>, then do:</p>
|
formats. First copy over the PNG files from the <a href="https://github.com/google/filament/blob/main/assets/models/monkey">monkey folder</a>, then do:</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #3D7B7B; font-style: italic"># Create mipmaps for base color</span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #3D7B7B; font-style: italic"># Create mipmaps for base color</span>
|
||||||
mipgen<span style="color: #BBB"> </span>albedo.png<span style="color: #BBB"> </span>albedo.ktx2
|
mipgen albedo.png albedo.ktx2
|
||||||
mipgen<span style="color: #BBB"> </span>--compression<span style="color: #666">=</span>uastc<span style="color: #BBB"> </span>albedo.png<span style="color: #BBB"> </span>albedo.ktx2
|
mipgen --compression<span style="color: #666666">=</span>uastc albedo.png albedo.ktx2
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the normal map and a compressed variant.</span>
|
<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the normal map and a compressed variant.</span>
|
||||||
mipgen<span style="color: #BBB"> </span>--strip-alpha<span style="color: #BBB"> </span>--kernel<span style="color: #666">=</span>NORMALS<span style="color: #BBB"> </span>--linear<span style="color: #BBB"> </span>normal.png<span style="color: #BBB"> </span>normal.ktx
|
mipgen --strip-alpha --kernel<span style="color: #666666">=</span>NORMALS --linear normal.png normal.ktx
|
||||||
mipgen<span style="color: #BBB"> </span>--strip-alpha<span style="color: #BBB"> </span>--kernel<span style="color: #666">=</span>NORMALS<span style="color: #BBB"> </span>--linear<span style="color: #BBB"> </span>--compression<span style="color: #666">=</span>uastc_normals<span style="color: #BBB"> </span><span style="color: #AA5D1F; font-weight: bold">\</span>
|
mipgen --strip-alpha --kernel<span style="color: #666666">=</span>NORMALS --linear --compression<span style="color: #666666">=</span>uastc_normals <span style="color: #AA5D1F; font-weight: bold">\</span>
|
||||||
<span style="color: #BBB"> </span>normal.png<span style="color: #BBB"> </span>normal.ktx2
|
normal.png normal.ktx2
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the single-component roughness map and a compressed variant.</span>
|
<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the single-component roughness map and a compressed variant.</span>
|
||||||
mipgen<span style="color: #BBB"> </span>--grayscale<span style="color: #BBB"> </span>roughness.png<span style="color: #BBB"> </span>roughness.ktx
|
mipgen --grayscale roughness.png roughness.ktx
|
||||||
mipgen<span style="color: #BBB"> </span>--grayscale<span style="color: #BBB"> </span>--compression<span style="color: #666">=</span>uastc<span style="color: #BBB"> </span>roughness.png<span style="color: #BBB"> </span>roughness.ktx2
|
mipgen --grayscale --compression<span style="color: #666666">=</span>uastc roughness.png roughness.ktx2
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the single-component metallic map and a compressed variant.</span>
|
<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the single-component metallic map and a compressed variant.</span>
|
||||||
mipgen<span style="color: #BBB"> </span>--grayscale<span style="color: #BBB"> </span>metallic.png<span style="color: #BBB"> </span>metallic.ktx
|
mipgen --grayscale metallic.png metallic.ktx
|
||||||
mipgen<span style="color: #BBB"> </span>--grayscale<span style="color: #BBB"> </span>--compression<span style="color: #666">=</span>uastc<span style="color: #BBB"> </span>metallic.png<span style="color: #BBB"> </span>metallic.ktx2
|
mipgen --grayscale --compression<span style="color: #666666">=</span>uastc metallic.png metallic.ktx2
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the single-component occlusion map and a compressed variant.</span>
|
<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the single-component occlusion map and a compressed variant.</span>
|
||||||
mipgen<span style="color: #BBB"> </span>--grayscale<span style="color: #BBB"> </span>ao.png<span style="color: #BBB"> </span>ao.ktx
|
mipgen --grayscale ao.png ao.ktx
|
||||||
mipgen<span style="color: #BBB"> </span>--grayscale<span style="color: #BBB"> </span>--compression<span style="color: #666">=</span>uastc<span style="color: #BBB"> </span>ao.png<span style="color: #BBB"> </span>ao.ktx2
|
mipgen --grayscale --compression<span style="color: #666666">=</span>uastc ao.png ao.ktx2
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>For more information on mipgen's arguments and supported formats, do <code>mipgen --help</code>.</p>
|
<p>For more information on mipgen's arguments and supported formats, do <code>mipgen --help</code>.</p>
|
||||||
<p>In a production setting, you'd want to invoke these commands with a script or build system.</p>
|
<p>In a production setting, you'd want to invoke these commands with a script or build system.</p>
|
||||||
<h2>Bake environment map</h2>
|
<h2>Bake environment map</h2>
|
||||||
<p>Much like the <a href="tutorial_redball.html">previous tutorial</a> we need to use Filament's <code>cmgen</code> tool to produce cubemap files.</p>
|
<p>Much like the <a href="tutorial_redball.html">previous tutorial</a> we need to use Filament's <code>cmgen</code> tool to produce cubemap files.</p>
|
||||||
<p>Download <a href="//github.com/google/filament/blob/main/third_party/environments/venetian_crossroads_2k.hdr">venetian_crossroads_2k.hdr</a>, then invoke the following commands in your terminal.</p>
|
<p>Download <a href="//github.com/google/filament/blob/main/third_party/environments/venetian_crossroads_2k.hdr">venetian_crossroads_2k.hdr</a>, then invoke the following commands in your terminal.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>cmgen<span style="color: #BBB"> </span>-x<span style="color: #BBB"> </span>.<span style="color: #BBB"> </span>--format<span style="color: #666">=</span>ktx<span style="color: #BBB"> </span>--size<span style="color: #666">=64</span><span style="color: #BBB"> </span>--extract-blur<span style="color: #666">=0</span>.1<span style="color: #BBB"> </span>venetian_crossroads_2k.hdr
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>cmgen -x . --format<span style="color: #666666">=</span>ktx --size<span style="color: #666666">=64</span> --extract-blur<span style="color: #666666">=0</span>.1 venetian_crossroads_2k.hdr
|
||||||
<span style="color: #008000">cd</span><span style="color: #BBB"> </span>venetian*<span style="color: #BBB"> </span>;<span style="color: #BBB"> </span>mv<span style="color: #BBB"> </span>venetian*_ibl.ktx<span style="color: #BBB"> </span>venetian_crossroads_2k_skybox_tiny.ktx<span style="color: #BBB"> </span>;<span style="color: #BBB"> </span><span style="color: #008000">cd</span><span style="color: #BBB"> </span>-
|
<span style="color: #008000">cd</span> venetian* ; mv venetian*_ibl.ktx venetian_crossroads_2k_skybox_tiny.ktx ; <span style="color: #008000">cd</span> -
|
||||||
|
|
||||||
cmgen<span style="color: #BBB"> </span>-x<span style="color: #BBB"> </span>.<span style="color: #BBB"> </span>--format<span style="color: #666">=</span>ktx<span style="color: #BBB"> </span>--size<span style="color: #666">=256</span><span style="color: #BBB"> </span>--extract-blur<span style="color: #666">=0</span>.1<span style="color: #BBB"> </span>venetian_crossroads_2k.hdr
|
cmgen -x . --format<span style="color: #666666">=</span>ktx --size<span style="color: #666666">=256</span> --extract-blur<span style="color: #666666">=0</span>.1 venetian_crossroads_2k.hdr
|
||||||
cmgen<span style="color: #BBB"> </span>-x<span style="color: #BBB"> </span>.<span style="color: #BBB"> </span>--format<span style="color: #666">=</span>ktx<span style="color: #BBB"> </span>--size<span style="color: #666">=256</span><span style="color: #BBB"> </span>--extract-blur<span style="color: #666">=0</span>.1<span style="color: #BBB"> </span>venetian_crossroads_2k.hdr
|
cmgen -x . --format<span style="color: #666666">=</span>ktx --size<span style="color: #666666">=256</span> --extract-blur<span style="color: #666666">=0</span>.1 venetian_crossroads_2k.hdr
|
||||||
cmgen<span style="color: #BBB"> </span>-x<span style="color: #BBB"> </span>.<span style="color: #BBB"> </span>--format<span style="color: #666">=</span>ktx<span style="color: #BBB"> </span>--size<span style="color: #666">=256</span><span style="color: #BBB"> </span>--extract-blur<span style="color: #666">=0</span>.1<span style="color: #BBB"> </span>venetian_crossroads_2k.hdr
|
cmgen -x . --format<span style="color: #666666">=</span>ktx --size<span style="color: #666666">=256</span> --extract-blur<span style="color: #666666">=0</span>.1 venetian_crossroads_2k.hdr
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<h2>Define textured material</h2>
|
<h2>Define textured material</h2>
|
||||||
<p>You might recall the <code>filamat</code> file we generated in the previous tutorial for red plastic. For this
|
<p>You might recall the <code>filamat</code> file we generated in the previous tutorial for red plastic. For this
|
||||||
demo, we'll create a material that uses textures for several parameters.</p>
|
demo, we'll create a material that uses textures for several parameters.</p>
|
||||||
<p>Create the following text file and call it <code>textured.mat</code>. Note that our material definition now
|
<p>Create the following text file and call it <code>textured.mat</code>. Note that our material definition now
|
||||||
requires a <code>uv0</code> attribute.</p>
|
requires a <code>uv0</code> attribute.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>material {
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>material {
|
||||||
@@ -90,7 +90,7 @@ fragment {
|
|||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Next, invoke <code>matc</code> as follows.</p>
|
<p>Next, invoke <code>matc</code> as follows.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>matc<span style="color: #BBB"> </span>-a<span style="color: #BBB"> </span>opengl<span style="color: #BBB"> </span>-p<span style="color: #BBB"> </span>mobile<span style="color: #BBB"> </span>-o<span style="color: #BBB"> </span>textured.filamat<span style="color: #BBB"> </span>textured.mat
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>matc -a opengl -p mobile -o textured.filamat textured.mat
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>You should now have a material archive in your working directory. For the suzanne asset, the normal
|
<p>You should now have a material archive in your working directory. For the suzanne asset, the normal
|
||||||
@@ -100,65 +100,65 @@ materials, consult the official document describing the <a href="https://google.
|
|||||||
<p>Create a text file called <code>suzanne.html</code> and copy over the HTML that we used in the <a href="tutorial_redball.html">previous
|
<p>Create a text file called <code>suzanne.html</code> and copy over the HTML that we used in the <a href="tutorial_redball.html">previous
|
||||||
tutorial</a>. Change the last script tag from <code>redball.js</code> to <code>suzanne.js</code>. Next, create <code>suzanne.js</code>
|
tutorial</a>. Change the last script tag from <code>redball.js</code> to <code>suzanne.js</code>. Next, create <code>suzanne.js</code>
|
||||||
with the following content.</p>
|
with the following content.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #3D7B7B; font-style: italic">// TODO: declare asset URLs</span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #3D7B7B; font-style: italic">// TODO: declare asset URLs</span><span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
Filament.init([<span style="color: #BBB"> </span>filamat_url,<span style="color: #BBB"> </span>filamesh_url,<span style="color: #BBB"> </span>sky_small_url,<span style="color: #BBB"> </span>ibl_url<span style="color: #BBB"> </span>],<span style="color: #BBB"> </span>()<span style="color: #BBB"> </span>=><span style="color: #BBB"> </span>{
|
Filament.init([<span style="color: #bbbbbb"> </span>filamat_url,<span style="color: #bbbbbb"> </span>filamesh_url,<span style="color: #bbbbbb"> </span>sky_small_url,<span style="color: #bbbbbb"> </span>ibl_url<span style="color: #bbbbbb"> </span>],<span style="color: #bbbbbb"> </span>()<span style="color: #bbbbbb"> </span>=><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.app<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span>App(<span style="color: #008000">document</span>.getElementsByTagName(<span style="color: #BA2121">'canvas'</span>)[<span style="color: #666">0</span>]);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.app<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span>App(<span style="color: #008000">document</span>.getElementsByTagName(<span style="color: #BA2121">'canvas'</span>)[<span style="color: #666666">0</span>]);<span style="color: #bbbbbb"></span>
|
||||||
});
|
});<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">class</span><span style="color: #BBB"> </span>App<span style="color: #BBB"> </span>{
|
<span style="color: #008000; font-weight: bold">class</span><span style="color: #bbbbbb"> </span>App<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">constructor</span>(canvas)<span style="color: #BBB"> </span>{
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">constructor</span>(canvas)<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>canvas;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>canvas;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Engine.create(canvas);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Engine.create(canvas);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.scene<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createScene();
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.scene<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createScene();<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>material<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createMaterial(filamat_url);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>material<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createMaterial(filamat_url);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>material.createInstance();
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>material.createInstance();<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>filamesh<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.loadFilamesh(filamesh_url,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>filamesh<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.loadFilamesh(filamesh_url,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.suzanne<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>filamesh.renderable;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.suzanne<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>filamesh.renderable;<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create sky box and IBL</span>
|
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create sky box and IBL</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: initialize gltumble</span>
|
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: initialize gltumble</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: fetch larger assets</span>
|
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: fetch larger assets</span><span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.swapChain<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createSwapChain();
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.swapChain<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createSwapChain();<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.renderer<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createRenderer();
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.renderer<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createRenderer();<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.camera<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createCamera(Filament.EntityManager.get().create());
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.camera<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createCamera(Filament.EntityManager.get().create());<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createView();
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createView();<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setCamera(<span style="color: #008000; font-weight: bold">this</span>.camera);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setCamera(<span style="color: #008000; font-weight: bold">this</span>.camera);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setScene(<span style="color: #008000; font-weight: bold">this</span>.scene);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setScene(<span style="color: #008000; font-weight: bold">this</span>.scene);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.render<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.render.bind(<span style="color: #008000; font-weight: bold">this</span>);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.render<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.render.bind(<span style="color: #008000; font-weight: bold">this</span>);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize.bind(<span style="color: #008000; font-weight: bold">this</span>);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize.bind(<span style="color: #008000; font-weight: bold">this</span>);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.addEventListener(<span style="color: #BA2121">'resize'</span>,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.addEventListener(<span style="color: #BA2121">'resize'</span>,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>eye<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>[<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">4</span>],<span style="color: #BBB"> </span>center<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>[<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>],<span style="color: #BBB"> </span>up<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>[<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>];
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>eye<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">4</span>],<span style="color: #bbbbbb"> </span>center<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>],<span style="color: #bbbbbb"> </span>up<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>];<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.camera.lookAt(eye,<span style="color: #BBB"> </span>center,<span style="color: #BBB"> </span>up);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.camera.lookAt(eye,<span style="color: #bbbbbb"> </span>center,<span style="color: #bbbbbb"> </span>up);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize();
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize();<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>}
|
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span>render()<span style="color: #BBB"> </span>{
|
<span style="color: #bbbbbb"> </span>render()<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: apply gltumble matrix</span>
|
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: apply gltumble matrix</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.renderer.render(<span style="color: #008000; font-weight: bold">this</span>.swapChain,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.renderer.render(<span style="color: #008000; font-weight: bold">this</span>.swapChain,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>}
|
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span>resize()<span style="color: #BBB"> </span>{
|
<span style="color: #bbbbbb"> </span>resize()<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>dpr<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.devicePixelRatio;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>dpr<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.devicePixelRatio;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>width<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.width<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.innerWidth<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span>dpr;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>width<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.width<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.innerWidth<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span>dpr;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>height<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.height<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.innerHeight<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span>dpr;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>height<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.height<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.innerHeight<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span>dpr;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setViewport([<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span>width,<span style="color: #BBB"> </span>height]);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setViewport([<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>width,<span style="color: #bbbbbb"> </span>height]);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>aspect<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>width<span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span>height;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>aspect<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>width<span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span>height;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>Fov<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Camera$Fov,<span style="color: #BBB"> </span>fov<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>aspect<span style="color: #BBB"> </span><span style="color: #666"><</span><span style="color: #BBB"> </span><span style="color: #666">1</span><span style="color: #BBB"> </span><span style="color: #666">?</span><span style="color: #BBB"> </span>Fov.HORIZONTAL<span style="color: #BBB"> </span><span style="color: #666">:</span><span style="color: #BBB"> </span>Fov.VERTICAL;
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>Fov<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Camera$Fov,<span style="color: #bbbbbb"> </span>fov<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>aspect<span style="color: #bbbbbb"> </span><span style="color: #666666"><</span><span style="color: #bbbbbb"> </span><span style="color: #666666">1</span><span style="color: #bbbbbb"> </span><span style="color: #666666">?</span><span style="color: #bbbbbb"> </span>Fov.HORIZONTAL<span style="color: #bbbbbb"> </span><span style="color: #666666">:</span><span style="color: #bbbbbb"> </span>Fov.VERTICAL;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.camera.setProjectionFov(<span style="color: #666">45</span>,<span style="color: #BBB"> </span>aspect,<span style="color: #BBB"> </span><span style="color: #666">1.0</span>,<span style="color: #BBB"> </span><span style="color: #666">10.0</span>,<span style="color: #BBB"> </span>fov);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.camera.setProjectionFov(<span style="color: #666666">45</span>,<span style="color: #bbbbbb"> </span>aspect,<span style="color: #bbbbbb"> </span><span style="color: #666666">1.0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">10.0</span>,<span style="color: #bbbbbb"> </span>fov);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>}
|
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
||||||
}
|
}<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Our app will only require a subset of assets to be present for <code>App</code> construction. We'll download
|
<p>Our app will only require a subset of assets to be present for <code>App</code> construction. We'll download
|
||||||
the other assets after construction. By using a progressive loading strategy, we can reduce the
|
the other assets after construction. By using a progressive loading strategy, we can reduce the
|
||||||
perceived load time.</p>
|
perceived load time.</p>
|
||||||
<p>Next we need to supply the URLs for various assets. This is actually a bit tricky, because different
|
<p>Next we need to supply the URLs for various assets. This is actually a bit tricky, because different
|
||||||
@@ -171,85 +171,85 @@ string -- which might be empty.</p>
|
|||||||
<p>In our case, we know that our web server will have <code>astc</code> and <code>s3tc</code> variants for albedo, and <code>etc</code>
|
<p>In our case, we know that our web server will have <code>astc</code> and <code>s3tc</code> variants for albedo, and <code>etc</code>
|
||||||
variants for the other textures. The uncompressed variants (empty string) are always available as a
|
variants for the other textures. The uncompressed variants (empty string) are always available as a
|
||||||
last resort. Go ahead and replace the <strong>declare asset URLs</strong> comment with the following snippet.</p>
|
last resort. Go ahead and replace the <strong>declare asset URLs</strong> comment with the following snippet.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>albedo_suffix<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.getSupportedFormatSuffix(<span style="color: #BA2121">'astc s3tc_srgb'</span>);
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>albedo_suffix<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.getSupportedFormatSuffix(<span style="color: #BA2121">'astc s3tc_srgb'</span>);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>texture_suffix<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.getSupportedFormatSuffix(<span style="color: #BA2121">'etc'</span>);
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>texture_suffix<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.getSupportedFormatSuffix(<span style="color: #BA2121">'etc'</span>);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>environ<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">'venetian_crossroads_2k'</span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>environ<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">'venetian_crossroads_2k'</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>ibl_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_ibl.ktx`</span>;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>ibl_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_ibl.ktx`</span>;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>sky_small_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_skybox_tiny.ktx`</span>;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>sky_small_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_skybox_tiny.ktx`</span>;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>sky_large_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_skybox.ktx`</span>;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>sky_large_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_skybox.ktx`</span>;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>albedo_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`albedo</span><span style="color: #A45A77; font-weight: bold">${</span>albedo_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>albedo_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`albedo</span><span style="color: #A45A77; font-weight: bold">${</span>albedo_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>ao_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`ao</span><span style="color: #A45A77; font-weight: bold">${</span>texture_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>ao_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`ao</span><span style="color: #A45A77; font-weight: bold">${</span>texture_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>metallic_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`metallic</span><span style="color: #A45A77; font-weight: bold">${</span>texture_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>metallic_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`metallic</span><span style="color: #A45A77; font-weight: bold">${</span>texture_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>normal_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`normal</span><span style="color: #A45A77; font-weight: bold">${</span>texture_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>normal_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`normal</span><span style="color: #A45A77; font-weight: bold">${</span>texture_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>roughness_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`roughness</span><span style="color: #A45A77; font-weight: bold">${</span>texture_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>roughness_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`roughness</span><span style="color: #A45A77; font-weight: bold">${</span>texture_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>filamat_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">'textured.filamat'</span>;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>filamat_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">'textured.filamat'</span>;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>filamesh_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">'suzanne.filamesh'</span>;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>filamesh_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">'suzanne.filamesh'</span>;<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<h2>Create skybox and IBL</h2>
|
<h2>Create skybox and IBL</h2>
|
||||||
<p>Next, let's create the low-resolution skybox and IBL in the <code>App</code> constructor.</p>
|
<p>Next, let's create the low-resolution skybox and IBL in the <code>App</code> constructor.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.skybox<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createSkyFromKtx1(sky_small_url);
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.skybox<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createSkyFromKtx1(sky_small_url);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.scene.setSkybox(<span style="color: #008000; font-weight: bold">this</span>.skybox);
|
<span style="color: #008000; font-weight: bold">this</span>.scene.setSkybox(<span style="color: #008000; font-weight: bold">this</span>.skybox);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.indirectLight<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createIblFromKtx1(ibl_url);
|
<span style="color: #008000; font-weight: bold">this</span>.indirectLight<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createIblFromKtx1(ibl_url);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.indirectLight.setIntensity(<span style="color: #666">100000</span>);
|
<span style="color: #008000; font-weight: bold">this</span>.indirectLight.setIntensity(<span style="color: #666666">100000</span>);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.scene.setIndirectLight(<span style="color: #008000; font-weight: bold">this</span>.indirectLight);
|
<span style="color: #008000; font-weight: bold">this</span>.scene.setIndirectLight(<span style="color: #008000; font-weight: bold">this</span>.indirectLight);<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>This allows users to see a reasonable background fairly quickly, before larger assets have finished
|
<p>This allows users to see a reasonable background fairly quickly, before larger assets have finished
|
||||||
loading in.</p>
|
loading in.</p>
|
||||||
<h2>Fetch assets asychronously</h2>
|
<h2>Fetch assets asychronously</h2>
|
||||||
<p>Next we'll invoke the <code>Filament.fetch</code> function from within the app constructor. This function is
|
<p>Next we'll invoke the <code>Filament.fetch</code> function from within the app constructor. This function is
|
||||||
very similar to <code>Filament.init</code>. It takes a list of asset URLs and a callback function that triggers
|
very similar to <code>Filament.init</code>. It takes a list of asset URLs and a callback function that triggers
|
||||||
when the assets have finished downloading.</p>
|
when the assets have finished downloading.</p>
|
||||||
<p>In our callback, we'll make several <code>setTextureParameter</code> calls on the material instance, then we'll
|
<p>In our callback, we'll make several <code>setTextureParameter</code> calls on the material instance, then we'll
|
||||||
recreate the skybox using a higher-resolution texture. As a last step we unhide the renderable that
|
recreate the skybox using a higher-resolution texture. As a last step we unhide the renderable that
|
||||||
was created in the app constructor.</p>
|
was created in the app constructor.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>Filament.fetch([sky_large_url,<span style="color: #BBB"> </span>albedo_url,<span style="color: #BBB"> </span>roughness_url,<span style="color: #BBB"> </span>metallic_url,<span style="color: #BBB"> </span>normal_url,<span style="color: #BBB"> </span>ao_url],<span style="color: #BBB"> </span>()<span style="color: #BBB"> </span>=><span style="color: #BBB"> </span>{
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>Filament.fetch([sky_large_url,<span style="color: #bbbbbb"> </span>albedo_url,<span style="color: #bbbbbb"> </span>roughness_url,<span style="color: #bbbbbb"> </span>metallic_url,<span style="color: #bbbbbb"> </span>normal_url,<span style="color: #bbbbbb"> </span>ao_url],<span style="color: #bbbbbb"> </span>()<span style="color: #bbbbbb"> </span>=><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>albedo<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(albedo_url,<span style="color: #BBB"> </span>{srgb<span style="color: #666">:</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">true</span>});
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>albedo<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(albedo_url,<span style="color: #bbbbbb"> </span>{srgb<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">true</span>});<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>roughness<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(roughness_url);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>roughness<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(roughness_url);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>metallic<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(metallic_url);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>metallic<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(metallic_url);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>normal<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(normal_url);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>normal<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(normal_url);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>ao<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(ao_url);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>ao<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(ao_url);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>sampler<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span>Filament.TextureSampler(
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>sampler<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span>Filament.TextureSampler(<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>Filament.MinFilter.LINEAR_MIPMAP_LINEAR,
|
<span style="color: #bbbbbb"> </span>Filament.MinFilter.LINEAR_MIPMAP_LINEAR,<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>Filament.MagFilter.LINEAR,
|
<span style="color: #bbbbbb"> </span>Filament.MagFilter.LINEAR,<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>Filament.WrapMode.CLAMP_TO_EDGE);
|
<span style="color: #bbbbbb"> </span>Filament.WrapMode.CLAMP_TO_EDGE);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'albedo'</span>,<span style="color: #BBB"> </span>albedo,<span style="color: #BBB"> </span>sampler);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'albedo'</span>,<span style="color: #bbbbbb"> </span>albedo,<span style="color: #bbbbbb"> </span>sampler);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'roughness'</span>,<span style="color: #BBB"> </span>roughness,<span style="color: #BBB"> </span>sampler);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'roughness'</span>,<span style="color: #bbbbbb"> </span>roughness,<span style="color: #bbbbbb"> </span>sampler);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'metallic'</span>,<span style="color: #BBB"> </span>metallic,<span style="color: #BBB"> </span>sampler);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'metallic'</span>,<span style="color: #bbbbbb"> </span>metallic,<span style="color: #bbbbbb"> </span>sampler);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'normal'</span>,<span style="color: #BBB"> </span>normal,<span style="color: #BBB"> </span>sampler);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'normal'</span>,<span style="color: #bbbbbb"> </span>normal,<span style="color: #bbbbbb"> </span>sampler);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'ao'</span>,<span style="color: #BBB"> </span>ao,<span style="color: #BBB"> </span>sampler);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'ao'</span>,<span style="color: #bbbbbb"> </span>ao,<span style="color: #bbbbbb"> </span>sampler);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// Replace low-res skybox with high-res skybox.</span>
|
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// Replace low-res skybox with high-res skybox.</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.destroySkybox(<span style="color: #008000; font-weight: bold">this</span>.skybox);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.destroySkybox(<span style="color: #008000; font-weight: bold">this</span>.skybox);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.skybox<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createSkyFromKtx1(sky_large_url);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.skybox<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createSkyFromKtx1(sky_large_url);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.scene.setSkybox(<span style="color: #008000; font-weight: bold">this</span>.skybox);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.scene.setSkybox(<span style="color: #008000; font-weight: bold">this</span>.skybox);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.scene.addEntity(<span style="color: #008000; font-weight: bold">this</span>.suzanne);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.scene.addEntity(<span style="color: #008000; font-weight: bold">this</span>.suzanne);<span style="color: #bbbbbb"></span>
|
||||||
});
|
});<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<h2>Introduce trackball rotation</h2>
|
<h2>Introduce trackball rotation</h2>
|
||||||
<p>Add the following script tag to your HTML file. This imports a small third-party library that
|
<p>Add the following script tag to your HTML file. This imports a small third-party library that
|
||||||
listens for drag events and computes a rotation matrix.</p>
|
listens for drag events and computes a rotation matrix.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><<span style="color: #008000; font-weight: bold">script</span> <span style="color: #687822">src</span><span style="color: #666">=</span><span style="color: #BA2121">"//unpkg.com/gltumble"</span>></<span style="color: #008000; font-weight: bold">script</span>>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><<span style="color: #008000; font-weight: bold">script</span> <span style="color: #687822">src</span><span style="color: #666666">=</span><span style="color: #BA2121">"//unpkg.com/gltumble"</span>></<span style="color: #008000; font-weight: bold">script</span>>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Next, replace the <strong>initialize gltumble</strong> and <strong>apply gltumble matrix</strong> comments with the following
|
<p>Next, replace the <strong>initialize gltumble</strong> and <strong>apply gltumble matrix</strong> comments with the following
|
||||||
two code snippets.</p>
|
two code snippets.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.trackball<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span>Trackball(canvas,<span style="color: #BBB"> </span>{startSpin<span style="color: #666">:</span><span style="color: #BBB"> </span><span style="color: #666">0.035</span>});
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.trackball<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span>Trackball(canvas,<span style="color: #bbbbbb"> </span>{startSpin<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span><span style="color: #666666">0.035</span>});<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>tcm<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.getTransformManager();
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>tcm<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.getTransformManager();<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>inst<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>tcm.getInstance(<span style="color: #008000; font-weight: bold">this</span>.suzanne);
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>inst<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>tcm.getInstance(<span style="color: #008000; font-weight: bold">this</span>.suzanne);<span style="color: #bbbbbb"></span>
|
||||||
tcm.setTransform(inst,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.trackball.getMatrix());
|
tcm.setTransform(inst,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.trackball.getMatrix());<span style="color: #bbbbbb"></span>
|
||||||
inst.<span style="color: #A2F; font-weight: bold">delete</span>();
|
inst.<span style="color: #AA22FF; font-weight: bold">delete</span>();<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>That's it, we now have a fast-loading interactive demo. The complete JavaScript file is available
|
<p>That's it, we now have a fast-loading interactive demo. The complete JavaScript file is available
|
||||||
<a href="tutorial_suzanne.js">here</a>.</p>
|
<a href="tutorial_suzanne.js">here</a>.</p>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
+110
-110
@@ -8,30 +8,30 @@
|
|||||||
<div class="demo_frame"><iframe src="demo_triangle.html"></iframe><a href="demo_triangle.html">🔗</a></div>
|
<div class="demo_frame"><iframe src="demo_triangle.html"></iframe><a href="demo_triangle.html">🔗</a></div>
|
||||||
<h2>Literate programming</h2>
|
<h2>Literate programming</h2>
|
||||||
<p>The markdown source for this tutorial is not only used to generate this
|
<p>The markdown source for this tutorial is not only used to generate this
|
||||||
web page, it's also used to generate the JavaScript for the above demo.
|
web page, it's also used to generate the JavaScript for the above demo.
|
||||||
We use a small Python script for weaving (generating HTML) and tangling
|
We use a small Python script for weaving (generating HTML) and tangling
|
||||||
(generating JS). In the code samples, you'll often see
|
(generating JS). In the code samples, you'll often see
|
||||||
<code>// TODO: <some task></code>. These are special markers that get replaced by
|
<code>// TODO: <some task></code>. These are special markers that get replaced by
|
||||||
subsequent code blocks.</p>
|
subsequent code blocks.</p>
|
||||||
<h2>Start your project</h2>
|
<h2>Start your project</h2>
|
||||||
<p>First, create a text file called <code>triangle.html</code> and fill it with the following HTML. This creates
|
<p>First, create a text file called <code>triangle.html</code> and fill it with the following HTML. This creates
|
||||||
a mobile-friendly page with a full-screen canvas.</p>
|
a mobile-friendly page with a full-screen canvas.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #9C6500"><!DOCTYPE html></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #9C6500"><!DOCTYPE html></span>
|
||||||
<<span style="color: #008000; font-weight: bold">html</span> <span style="color: #687822">lang</span><span style="color: #666">=</span><span style="color: #BA2121">"en"</span>>
|
<<span style="color: #008000; font-weight: bold">html</span> <span style="color: #687822">lang</span><span style="color: #666666">=</span><span style="color: #BA2121">"en"</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">head</span>>
|
<<span style="color: #008000; font-weight: bold">head</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">title</span>>Filament Tutorial</<span style="color: #008000; font-weight: bold">title</span>>
|
<<span style="color: #008000; font-weight: bold">title</span>>Filament Tutorial</<span style="color: #008000; font-weight: bold">title</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">meta</span> <span style="color: #687822">charset</span><span style="color: #666">=</span><span style="color: #BA2121">"utf-8"</span>>
|
<<span style="color: #008000; font-weight: bold">meta</span> <span style="color: #687822">charset</span><span style="color: #666666">=</span><span style="color: #BA2121">"utf-8"</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">meta</span> <span style="color: #687822">name</span><span style="color: #666">=</span><span style="color: #BA2121">"viewport"</span> <span style="color: #687822">content</span><span style="color: #666">=</span><span style="color: #BA2121">"width=device-width,user-scalable=no,initial-scale=1"</span>>
|
<<span style="color: #008000; font-weight: bold">meta</span> <span style="color: #687822">name</span><span style="color: #666666">=</span><span style="color: #BA2121">"viewport"</span> <span style="color: #687822">content</span><span style="color: #666666">=</span><span style="color: #BA2121">"width=device-width,user-scalable=no,initial-scale=1"</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">style</span>>
|
<<span style="color: #008000; font-weight: bold">style</span>><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">body</span><span style="color: #BBB"> </span>{<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">margin</span>:<span style="color: #BBB"> </span><span style="color: #666">0</span>;<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">overflow</span>:<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">hidden</span>;<span style="color: #BBB"> </span>}
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">body</span><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">margin</span>:<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>;<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">overflow</span>:<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">hidden</span>;<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">canvas</span><span style="color: #BBB"> </span>{<span style="color: #BBB"> </span>touch-action:<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">none</span>;<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">width</span>:<span style="color: #BBB"> </span><span style="color: #666">100</span><span style="color: #B00040">%</span>;<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">height</span>:<span style="color: #BBB"> </span><span style="color: #666">100</span><span style="color: #B00040">%</span>;<span style="color: #BBB"> </span>}
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">canvas</span><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"> </span>touch-action:<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">none</span>;<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">width</span>:<span style="color: #bbbbbb"> </span><span style="color: #666666">100</span><span style="color: #B00040">%</span>;<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">height</span>:<span style="color: #bbbbbb"> </span><span style="color: #666666">100</span><span style="color: #B00040">%</span>;<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span></<span style="color: #008000; font-weight: bold">style</span>>
|
<span style="color: #bbbbbb"> </span></<span style="color: #008000; font-weight: bold">style</span>>
|
||||||
</<span style="color: #008000; font-weight: bold">head</span>>
|
</<span style="color: #008000; font-weight: bold">head</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">body</span>>
|
<<span style="color: #008000; font-weight: bold">body</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">canvas</span>></<span style="color: #008000; font-weight: bold">canvas</span>>
|
<<span style="color: #008000; font-weight: bold">canvas</span>></<span style="color: #008000; font-weight: bold">canvas</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">script</span> <span style="color: #687822">src</span><span style="color: #666">=</span><span style="color: #BA2121">"filament.js"</span>></<span style="color: #008000; font-weight: bold">script</span>>
|
<<span style="color: #008000; font-weight: bold">script</span> <span style="color: #687822">src</span><span style="color: #666666">=</span><span style="color: #BA2121">"filament.js"</span>></<span style="color: #008000; font-weight: bold">script</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">script</span> <span style="color: #687822">src</span><span style="color: #666">=</span><span style="color: #BA2121">"//unpkg.com/gl-matrix@2.8.1"</span>></<span style="color: #008000; font-weight: bold">script</span>>
|
<<span style="color: #008000; font-weight: bold">script</span> <span style="color: #687822">src</span><span style="color: #666666">=</span><span style="color: #BA2121">"//unpkg.com/gl-matrix@2.8.1"</span>></<span style="color: #008000; font-weight: bold">script</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">script</span> <span style="color: #687822">src</span><span style="color: #666">=</span><span style="color: #BA2121">"triangle.js"</span>></<span style="color: #008000; font-weight: bold">script</span>>
|
<<span style="color: #008000; font-weight: bold">script</span> <span style="color: #687822">src</span><span style="color: #666666">=</span><span style="color: #BA2121">"triangle.js"</span>></<span style="color: #008000; font-weight: bold">script</span>>
|
||||||
</<span style="color: #008000; font-weight: bold">body</span>>
|
</<span style="color: #008000; font-weight: bold">body</span>>
|
||||||
</<span style="color: #008000; font-weight: bold">html</span>>
|
</<span style="color: #008000; font-weight: bold">html</span>>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
@@ -48,63 +48,63 @@ a mobile-friendly page with a full-screen canvas.</p>
|
|||||||
<li><code>triangle.js</code> will contain your application code.</li>
|
<li><code>triangle.js</code> will contain your application code.</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>Go ahead and create <code>triangle.js</code> with the following content.</p>
|
<p>Go ahead and create <code>triangle.js</code> with the following content.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">class</span><span style="color: #BBB"> </span>App<span style="color: #BBB"> </span>{
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">class</span><span style="color: #bbbbbb"> </span>App<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">constructor</span>()<span style="color: #BBB"> </span>{
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">constructor</span>()<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create entities</span>
|
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create entities</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.render<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.render.bind(<span style="color: #008000; font-weight: bold">this</span>);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.render<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.render.bind(<span style="color: #008000; font-weight: bold">this</span>);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize.bind(<span style="color: #008000; font-weight: bold">this</span>);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize.bind(<span style="color: #008000; font-weight: bold">this</span>);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.addEventListener(<span style="color: #BA2121">'resize'</span>,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.addEventListener(<span style="color: #BA2121">'resize'</span>,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>}
|
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>render()<span style="color: #BBB"> </span>{
|
<span style="color: #bbbbbb"> </span>render()<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: render scene</span>
|
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: render scene</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>}
|
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>resize()<span style="color: #BBB"> </span>{
|
<span style="color: #bbbbbb"> </span>resize()<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: adjust viewport and canvas</span>
|
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: adjust viewport and canvas</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>}
|
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
||||||
}
|
}<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
Filament.init([<span style="color: #BA2121">'triangle.filamat'</span>],<span style="color: #BBB"> </span>()<span style="color: #BBB"> </span>=><span style="color: #BBB"> </span>{<span style="color: #BBB"> </span><span style="color: #008000">window</span>.app<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span>App()<span style="color: #BBB"> </span>}<span style="color: #BBB"> </span>);
|
Filament.init([<span style="color: #BA2121">'triangle.filamat'</span>],<span style="color: #bbbbbb"> </span>()<span style="color: #bbbbbb"> </span>=><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.app<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span>App()<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"> </span>);<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>The two calls to <code>bind()</code> allow us to pass instance methods as callbacks for animation and resize
|
<p>The two calls to <code>bind()</code> allow us to pass instance methods as callbacks for animation and resize
|
||||||
events.</p>
|
events.</p>
|
||||||
<p><code>Filament.init()</code> consumes two things: a list of asset URLs and a callback.</p>
|
<p><code>Filament.init()</code> consumes two things: a list of asset URLs and a callback.</p>
|
||||||
<p>The callback will be triggered only after all assets finish downloading and the Filament module has
|
<p>The callback will be triggered only after all assets finish downloading and the Filament module has
|
||||||
become ready. In our callback, we simply instantiated the <code>App</code> object, since we'll do most of the
|
become ready. In our callback, we simply instantiated the <code>App</code> object, since we'll do most of the
|
||||||
work in its constructor. We also set the app instance into a <code>Window</code> property to make it accessible
|
work in its constructor. We also set the app instance into a <code>Window</code> property to make it accessible
|
||||||
from the developer console.</p>
|
from the developer console.</p>
|
||||||
<p>Go ahead and download <a href="triangle.filamat">triangle.filamat</a> and place it in your project folder.
|
<p>Go ahead and download <a href="triangle.filamat">triangle.filamat</a> and place it in your project folder.
|
||||||
This is a <em>material package</em>, which is a binary file that contains shaders and other bits of data
|
This is a <em>material package</em>, which is a binary file that contains shaders and other bits of data
|
||||||
that define a PBR material. We'll learn more about material packages in the next tutorial.</p>
|
that define a PBR material. We'll learn more about material packages in the next tutorial.</p>
|
||||||
<h2>Spawn a local server</h2>
|
<h2>Spawn a local server</h2>
|
||||||
<p>Because of CORS restrictions, your web app cannot fetch the material package directly from the
|
<p>Because of CORS restrictions, your web app cannot fetch the material package directly from the
|
||||||
file system. One way around this is to create a temporary server using Python or node:</p>
|
file system. One way around this is to create a temporary server using Python or node:</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>python3<span style="color: #BBB"> </span>-m<span style="color: #BBB"> </span>http.server<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic"># Python 3</span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>python3 -m http.server <span style="color: #3D7B7B; font-style: italic"># Python 3</span>
|
||||||
python<span style="color: #BBB"> </span>-m<span style="color: #BBB"> </span>SimpleHTTPServer<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic"># Python 2.7</span>
|
python -m SimpleHTTPServer <span style="color: #3D7B7B; font-style: italic"># Python 2.7</span>
|
||||||
npx<span style="color: #BBB"> </span>http-server<span style="color: #BBB"> </span>-p<span style="color: #BBB"> </span><span style="color: #666">8000</span><span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic"># nodejs</span>
|
npx http-server -p <span style="color: #666666">8000</span> <span style="color: #3D7B7B; font-style: italic"># nodejs</span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>To see if this works, navigate to <a href="http://localhost:8000">http://localhost:8000</a> and check if you
|
<p>To see if this works, navigate to <a href="http://localhost:8000">http://localhost:8000</a> and check if you
|
||||||
can load the page without any errors appearing in the developer console.</p>
|
can load the page without any errors appearing in the developer console.</p>
|
||||||
<p>Take care not to use Python's simple server in production since it does not serve WebAssembly files
|
<p>Take care not to use Python's simple server in production since it does not serve WebAssembly files
|
||||||
with the correct MIME type.</p>
|
with the correct MIME type.</p>
|
||||||
<h2>Create the Engine and Scene</h2>
|
<h2>Create the Engine and Scene</h2>
|
||||||
<p>We now have a basic skeleton that can respond to paint and resize events. Let's start adding
|
<p>We now have a basic skeleton that can respond to paint and resize events. Let's start adding
|
||||||
Filament objects to the app. Insert the following code into the top of the app constructor.</p>
|
Filament objects to the app. Insert the following code into the top of the app constructor.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.canvas<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">document</span>.getElementsByTagName(<span style="color: #BA2121">'canvas'</span>)[<span style="color: #666">0</span>];
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.canvas<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">document</span>.getElementsByTagName(<span style="color: #BA2121">'canvas'</span>)[<span style="color: #666666">0</span>];<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>engine<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Engine.create(<span style="color: #008000; font-weight: bold">this</span>.canvas);
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>engine<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Engine.create(<span style="color: #008000; font-weight: bold">this</span>.canvas);<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>The above snippet creates the <code>Engine</code> by passing it a canvas DOM object. The engine needs the
|
<p>The above snippet creates the <code>Engine</code> by passing it a canvas DOM object. The engine needs the
|
||||||
canvas in order to create a WebGL 2.0 context in its contructor.</p>
|
canvas in order to create a WebGL 2.0 context in its contructor.</p>
|
||||||
<p>The engine is a factory for many Filament entities, including <code>Scene</code>, which is a flat container of
|
<p>The engine is a factory for many Filament entities, including <code>Scene</code>, which is a flat container of
|
||||||
entities. Let's go ahead and create a scene, then add a blank entity called <code>triangle</code> into the
|
entities. Let's go ahead and create a scene, then add a blank entity called <code>triangle</code> into the
|
||||||
scene.</p>
|
scene.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.scene<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createScene();
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.scene<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createScene();<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.triangle<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.EntityManager.get().create();
|
<span style="color: #008000; font-weight: bold">this</span>.triangle<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.EntityManager.get().create();<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.scene.addEntity(<span style="color: #008000; font-weight: bold">this</span>.triangle);
|
<span style="color: #008000; font-weight: bold">this</span>.scene.addEntity(<span style="color: #008000; font-weight: bold">this</span>.triangle);<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Filament uses an <a href="//en.wikipedia.org/wiki/Entity-component-system">Entity-Component System</a>.
|
<p>Filament uses an <a href="//en.wikipedia.org/wiki/Entity-component-system">Entity-Component System</a>.
|
||||||
@@ -112,30 +112,30 @@ The triangle entity in the above snippet does not yet have an associated compone
|
|||||||
tutorial we will make it into a <em>renderable</em>. Renderables are entities that have associated draw
|
tutorial we will make it into a <em>renderable</em>. Renderables are entities that have associated draw
|
||||||
calls.</p>
|
calls.</p>
|
||||||
<h2>Construct typed arrays</h2>
|
<h2>Construct typed arrays</h2>
|
||||||
<p>Next we'll create two typed arrays: a positions array with XY coordinates for each vertex, and a
|
<p>Next we'll create two typed arrays: a positions array with XY coordinates for each vertex, and a
|
||||||
colors array with a 32-bit word for each vertex.</p>
|
colors array with a 32-bit word for each vertex.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>TRIANGLE_POSITIONS<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span><span style="color: #008000">Float32Array</span>([
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>TRIANGLE_POSITIONS<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span><span style="color: #008000">Float32Array</span>([<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,
|
<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">Math</span>.cos(<span style="color: #008000">Math</span>.PI<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span><span style="color: #666">2</span><span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span><span style="color: #666">3</span>),<span style="color: #BBB"> </span><span style="color: #008000">Math</span>.sin(<span style="color: #008000">Math</span>.PI<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span><span style="color: #666">2</span><span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span><span style="color: #666">3</span>),
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">Math</span>.cos(<span style="color: #008000">Math</span>.PI<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span><span style="color: #666666">2</span><span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span><span style="color: #666666">3</span>),<span style="color: #bbbbbb"> </span><span style="color: #008000">Math</span>.sin(<span style="color: #008000">Math</span>.PI<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span><span style="color: #666666">2</span><span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span><span style="color: #666666">3</span>),<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">Math</span>.cos(<span style="color: #008000">Math</span>.PI<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span><span style="color: #666">4</span><span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span><span style="color: #666">3</span>),<span style="color: #BBB"> </span><span style="color: #008000">Math</span>.sin(<span style="color: #008000">Math</span>.PI<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span><span style="color: #666">4</span><span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span><span style="color: #666">3</span>),
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">Math</span>.cos(<span style="color: #008000">Math</span>.PI<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span><span style="color: #666666">4</span><span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span><span style="color: #666666">3</span>),<span style="color: #bbbbbb"> </span><span style="color: #008000">Math</span>.sin(<span style="color: #008000">Math</span>.PI<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span><span style="color: #666666">4</span><span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span><span style="color: #666666">3</span>),<span style="color: #bbbbbb"></span>
|
||||||
]);
|
]);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>TRIANGLE_COLORS<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span><span style="color: #008000">Uint32Array</span>([<span style="color: #666">0xffff0000</span>,<span style="color: #BBB"> </span><span style="color: #666">0xff00ff00</span>,<span style="color: #BBB"> </span><span style="color: #666">0xff0000ff</span>]);
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>TRIANGLE_COLORS<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span><span style="color: #008000">Uint32Array</span>([<span style="color: #666666">0xffff0000</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0xff00ff00</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0xff0000ff</span>]);<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Next we'll use the positions and colors buffers to create a single <code>VertexBuffer</code> object.</p>
|
<p>Next we'll use the positions and colors buffers to create a single <code>VertexBuffer</code> object.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>VertexAttribute<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.VertexAttribute;
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>VertexAttribute<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.VertexAttribute;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>AttributeType<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.VertexBuffer$AttributeType;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>AttributeType<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.VertexBuffer$AttributeType;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.vb<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.VertexBuffer.Builder()
|
<span style="color: #008000; font-weight: bold">this</span>.vb<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.VertexBuffer.Builder()<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.vertexCount(<span style="color: #666">3</span>)
|
<span style="color: #bbbbbb"> </span>.vertexCount(<span style="color: #666666">3</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.bufferCount(<span style="color: #666">2</span>)
|
<span style="color: #bbbbbb"> </span>.bufferCount(<span style="color: #666666">2</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.attribute(VertexAttribute.POSITION,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span>AttributeType.FLOAT2,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">8</span>)
|
<span style="color: #bbbbbb"> </span>.attribute(VertexAttribute.POSITION,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>AttributeType.FLOAT2,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">8</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.attribute(VertexAttribute.COLOR,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span>AttributeType.UBYTE4,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">4</span>)
|
<span style="color: #bbbbbb"> </span>.attribute(VertexAttribute.COLOR,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span>AttributeType.UBYTE4,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">4</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.normalized(VertexAttribute.COLOR)
|
<span style="color: #bbbbbb"> </span>.normalized(VertexAttribute.COLOR)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.build(engine);
|
<span style="color: #bbbbbb"> </span>.build(engine);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.vb.setBufferAt(engine,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span>TRIANGLE_POSITIONS);
|
<span style="color: #008000; font-weight: bold">this</span>.vb.setBufferAt(engine,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>TRIANGLE_POSITIONS);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.vb.setBufferAt(engine,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span>TRIANGLE_COLORS);
|
<span style="color: #008000; font-weight: bold">this</span>.vb.setBufferAt(engine,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span>TRIANGLE_COLORS);<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>The above snippet first creates aliases for two enum types, then constructs the vertex buffer using
|
<p>The above snippet first creates aliases for two enum types, then constructs the vertex buffer using
|
||||||
@@ -147,74 +147,74 @@ self-documenting.</p>
|
|||||||
<p>Our app sets up two buffer slots in the vertex buffer, and each slot is associated with a single
|
<p>Our app sets up two buffer slots in the vertex buffer, and each slot is associated with a single
|
||||||
attribute. Alternatively, we could have interleaved or concatenated these attributes into a single
|
attribute. Alternatively, we could have interleaved or concatenated these attributes into a single
|
||||||
buffer slot.</p>
|
buffer slot.</p>
|
||||||
<p>Next we'll construct an index buffer. The index buffer for our triangle is trivial: it simply holds
|
<p>Next we'll construct an index buffer. The index buffer for our triangle is trivial: it simply holds
|
||||||
the integers 0,1,2.</p>
|
the integers 0,1,2.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.ib<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.IndexBuffer.Builder()
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.ib<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.IndexBuffer.Builder()<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.indexCount(<span style="color: #666">3</span>)
|
<span style="color: #bbbbbb"> </span>.indexCount(<span style="color: #666666">3</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.bufferType(Filament.IndexBuffer$IndexType.USHORT)
|
<span style="color: #bbbbbb"> </span>.bufferType(Filament.IndexBuffer$IndexType.USHORT)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.build(engine);
|
<span style="color: #bbbbbb"> </span>.build(engine);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.ib.setBuffer(engine,<span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span><span style="color: #008000">Uint16Array</span>([<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">2</span>]));
|
<span style="color: #008000; font-weight: bold">this</span>.ib.setBuffer(engine,<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span><span style="color: #008000">Uint16Array</span>([<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">2</span>]));<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Note that constructing an index buffer is similar to constructing a vertex buffer, but it only has
|
<p>Note that constructing an index buffer is similar to constructing a vertex buffer, but it only has
|
||||||
one buffer slot, and it can only contain two types of data (USHORT or UINT).</p>
|
one buffer slot, and it can only contain two types of data (USHORT or UINT).</p>
|
||||||
<h2>Finish up initialization</h2>
|
<h2>Finish up initialization</h2>
|
||||||
<p>Next let's construct an actual <code>Material</code> from the material package that was downloaded (the
|
<p>Next let's construct an actual <code>Material</code> from the material package that was downloaded (the
|
||||||
material is an object; the package is just a binary blob), then extract the default
|
material is an object; the package is just a binary blob), then extract the default
|
||||||
<code>MaterialInstance</code> from the material object. Material instances have concrete values for their
|
<code>MaterialInstance</code> from the material object. Material instances have concrete values for their
|
||||||
parameters, and they can be bound to renderables. We'll learn more about material instances in the
|
parameters, and they can be bound to renderables. We'll learn more about material instances in the
|
||||||
next tutorial.</p>
|
next tutorial.</p>
|
||||||
<p>After extracting the material instance, we can finally create a renderable component for the
|
<p>After extracting the material instance, we can finally create a renderable component for the
|
||||||
triangle by setting up a bounding box and passing in the vertex and index buffers.</p>
|
triangle by setting up a bounding box and passing in the vertex and index buffers.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>mat<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createMaterial(<span style="color: #BA2121">'triangle.filamat'</span>);
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>mat<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createMaterial(<span style="color: #BA2121">'triangle.filamat'</span>);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>matinst<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>mat.getDefaultInstance();
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>matinst<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>mat.getDefaultInstance();<span style="color: #bbbbbb"></span>
|
||||||
Filament.RenderableManager.Builder(<span style="color: #666">1</span>)
|
Filament.RenderableManager.Builder(<span style="color: #666666">1</span>)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.boundingBox({<span style="color: #BBB"> </span>center<span style="color: #666">:</span><span style="color: #BBB"> </span>[<span style="color: #666">-1</span>,<span style="color: #BBB"> </span><span style="color: #666">-1</span>,<span style="color: #BBB"> </span><span style="color: #666">-1</span>],<span style="color: #BBB"> </span>halfExtent<span style="color: #666">:</span><span style="color: #BBB"> </span>[<span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>]<span style="color: #BBB"> </span>})
|
<span style="color: #bbbbbb"> </span>.boundingBox({<span style="color: #bbbbbb"> </span>center<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">-1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">-1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">-1</span>],<span style="color: #bbbbbb"> </span>halfExtent<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>]<span style="color: #bbbbbb"> </span>})<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.material(<span style="color: #666">0</span>,<span style="color: #BBB"> </span>matinst)
|
<span style="color: #bbbbbb"> </span>.material(<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>matinst)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.geometry(<span style="color: #666">0</span>,<span style="color: #BBB"> </span>Filament.RenderableManager$PrimitiveType.TRIANGLES,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.vb,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.ib)
|
<span style="color: #bbbbbb"> </span>.geometry(<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>Filament.RenderableManager$PrimitiveType.TRIANGLES,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.vb,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.ib)<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span>.build(engine,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.triangle);
|
<span style="color: #bbbbbb"> </span>.build(engine,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.triangle);<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Next let's wrap up the initialization routine by creating the swap chain, renderer, camera, and
|
<p>Next let's wrap up the initialization routine by creating the swap chain, renderer, camera, and
|
||||||
view.</p>
|
view.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.swapChain<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createSwapChain();
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.swapChain<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createSwapChain();<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.renderer<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createRenderer();
|
<span style="color: #008000; font-weight: bold">this</span>.renderer<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createRenderer();<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.camera<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createCamera(Filament.EntityManager.get().create());
|
<span style="color: #008000; font-weight: bold">this</span>.camera<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createCamera(Filament.EntityManager.get().create());<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.view<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createView();
|
<span style="color: #008000; font-weight: bold">this</span>.view<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createView();<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.view.setCamera(<span style="color: #008000; font-weight: bold">this</span>.camera);
|
<span style="color: #008000; font-weight: bold">this</span>.view.setCamera(<span style="color: #008000; font-weight: bold">this</span>.camera);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.view.setScene(<span style="color: #008000; font-weight: bold">this</span>.scene);
|
<span style="color: #008000; font-weight: bold">this</span>.view.setScene(<span style="color: #008000; font-weight: bold">this</span>.scene);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic">// Set up a blue-green background:</span>
|
<span style="color: #3D7B7B; font-style: italic">// Set up a blue-green background:</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.renderer.setClearOptions({clearColor<span style="color: #666">:</span><span style="color: #BBB"> </span>[<span style="color: #666">0.0</span>,<span style="color: #BBB"> </span><span style="color: #666">0.1</span>,<span style="color: #BBB"> </span><span style="color: #666">0.2</span>,<span style="color: #BBB"> </span><span style="color: #666">1.0</span>],<span style="color: #BBB"> </span>clear<span style="color: #666">:</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">true</span>});
|
<span style="color: #008000; font-weight: bold">this</span>.renderer.setClearOptions({clearColor<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">0.0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0.1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0.2</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1.0</span>],<span style="color: #bbbbbb"> </span>clear<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">true</span>});<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic">// Adjust the initial viewport:</span>
|
<span style="color: #3D7B7B; font-style: italic">// Adjust the initial viewport:</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.resize();
|
<span style="color: #008000; font-weight: bold">this</span>.resize();<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>At this point, we're done creating all Filament entities, and the code should run without errors.
|
<p>At this point, we're done creating all Filament entities, and the code should run without errors.
|
||||||
However the canvas is still blank!</p>
|
However the canvas is still blank!</p>
|
||||||
<h2>Render and resize handlers</h2>
|
<h2>Render and resize handlers</h2>
|
||||||
<p>Recall that our App class has a skeletal render method, which the browser calls every time it needs
|
<p>Recall that our App class has a skeletal render method, which the browser calls every time it needs
|
||||||
to repaint. Often this is 60 times a second.</p>
|
to repaint. Often this is 60 times a second.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>render()<span style="color: #BBB"> </span>{
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>render()<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: render scene</span>
|
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: render scene</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);
|
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);<span style="color: #bbbbbb"></span>
|
||||||
}
|
}<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Let's flesh this out by rotating the triangle and invoking the Filament renderer. Add the following
|
<p>Let's flesh this out by rotating the triangle and invoking the Filament renderer. Add the following
|
||||||
code to the top of the render method.</p>
|
code to the top of the render method.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #3D7B7B; font-style: italic">// Rotate the triangle.</span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #3D7B7B; font-style: italic">// Rotate the triangle.</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>radians<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">Date</span>.now()<span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span><span style="color: #666">1000</span>;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>radians<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">Date</span>.now()<span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span><span style="color: #666666">1000</span>;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>transform<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>mat4.fromRotation(mat4.create(),<span style="color: #BBB"> </span>radians,<span style="color: #BBB"> </span>[<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>]);
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>transform<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>mat4.fromRotation(mat4.create(),<span style="color: #bbbbbb"> </span>radians,<span style="color: #bbbbbb"> </span>[<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>]);<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>tcm<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.getTransformManager();
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>tcm<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.getTransformManager();<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>inst<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>tcm.getInstance(<span style="color: #008000; font-weight: bold">this</span>.triangle);
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>inst<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>tcm.getInstance(<span style="color: #008000; font-weight: bold">this</span>.triangle);<span style="color: #bbbbbb"></span>
|
||||||
tcm.setTransform(inst,<span style="color: #BBB"> </span>transform);
|
tcm.setTransform(inst,<span style="color: #bbbbbb"> </span>transform);<span style="color: #bbbbbb"></span>
|
||||||
inst.<span style="color: #A2F; font-weight: bold">delete</span>();
|
inst.<span style="color: #AA22FF; font-weight: bold">delete</span>();<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic">// Render the frame.</span>
|
<span style="color: #3D7B7B; font-style: italic">// Render the frame.</span><span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.renderer.render(<span style="color: #008000; font-weight: bold">this</span>.swapChain,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view);
|
<span style="color: #008000; font-weight: bold">this</span>.renderer.render(<span style="color: #008000; font-weight: bold">this</span>.swapChain,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view);<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>The first half of our render method obtains the transform component of the triangle entity and uses
|
<p>The first half of our render method obtains the transform component of the triangle entity and uses
|
||||||
@@ -225,19 +225,19 @@ that it wants to skip a frame, hence the <code>if</code> statement.</p>
|
|||||||
<p>One last step. Add the following code to the resize method. This adjusts the resolution of the
|
<p>One last step. Add the following code to the resize method. This adjusts the resolution of the
|
||||||
rendering surface when the window size changes, taking <code>devicePixelRatio</code> into account for high-DPI
|
rendering surface when the window size changes, taking <code>devicePixelRatio</code> into account for high-DPI
|
||||||
displays. It also adjusts the camera frustum accordingly.</p>
|
displays. It also adjusts the camera frustum accordingly.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>dpr<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.devicePixelRatio;
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>dpr<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.devicePixelRatio;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>width<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.width<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.innerWidth<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span>dpr;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>width<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.width<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.innerWidth<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span>dpr;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>height<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.height<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.innerHeight<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span>dpr;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>height<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.height<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.innerHeight<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span>dpr;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.view.setViewport([<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span>width,<span style="color: #BBB"> </span>height]);
|
<span style="color: #008000; font-weight: bold">this</span>.view.setViewport([<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>width,<span style="color: #bbbbbb"> </span>height]);<span style="color: #bbbbbb"></span>
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>aspect<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>width<span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span>height;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>aspect<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>width<span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span>height;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>Projection<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Camera$Projection;
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>Projection<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Camera$Projection;<span style="color: #bbbbbb"></span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.camera.setProjection(Projection.ORTHO,<span style="color: #BBB"> </span><span style="color: #666">-</span>aspect,<span style="color: #BBB"> </span>aspect,<span style="color: #BBB"> </span><span style="color: #666">-1</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>);
|
<span style="color: #008000; font-weight: bold">this</span>.camera.setProjection(Projection.ORTHO,<span style="color: #bbbbbb"> </span><span style="color: #666666">-</span>aspect,<span style="color: #bbbbbb"> </span>aspect,<span style="color: #bbbbbb"> </span><span style="color: #666666">-1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>);<span style="color: #bbbbbb"></span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>You should now have a spinning triangle! The completed JavaScript is available
|
<p>You should now have a spinning triangle! The completed JavaScript is available
|
||||||
<a href="tutorial_triangle.js">here</a>.</p>
|
<a href="tutorial_triangle.js">here</a>.</p>
|
||||||
<p>In the <a href="tutorial_redball.html">next tutorial</a>, we'll take a closer look at Filament materials and 3D rendering.</p>
|
<p>In the <a href="tutorial_redball.html">next tutorial</a>, we'll take a closer look at Filament materials and 3D rendering.</p>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1023,12 +1023,8 @@ samplerCubemap | Cubemap texture
|
|||||||
[Table [materialParamsTypes]: Material parameter types]
|
[Table [materialParamsTypes]: Material parameter types]
|
||||||
|
|
||||||
Samplers
|
Samplers
|
||||||
: Sampler types can specify additional options:
|
: Sampler types can also specify a `format` which can be either `int` or `float` (defaults to
|
||||||
|
`float`).
|
||||||
- `format`: either `int` or `float` (defaults to `float`).
|
|
||||||
- `stages`: array of strings containing the list of shader stages this
|
|
||||||
sampler can be accessed from. Each entry must be either `vertex` or
|
|
||||||
`fragment` (defaults to both).
|
|
||||||
|
|
||||||
Arrays
|
Arrays
|
||||||
: A parameter can define an array of values by appending `[size]` after the type name, where
|
: A parameter can define an array of values by appending `[size]` after the type name, where
|
||||||
|
|||||||
@@ -18,8 +18,6 @@
|
|||||||
- [Metal](./notes/metal_debugging.md)
|
- [Metal](./notes/metal_debugging.md)
|
||||||
- [Vulkan](./notes/vulkan_debugging.md)
|
- [Vulkan](./notes/vulkan_debugging.md)
|
||||||
- [SPIR-V](./notes/spirv_debugging.md)
|
- [SPIR-V](./notes/spirv_debugging.md)
|
||||||
- [Running with ASAN and UBSAN](./notes/asan_ubsan.md)
|
|
||||||
- [Using Instruments on macOS](./notes/instruments.md)
|
|
||||||
- [Libraries](./notes/libs.md)
|
- [Libraries](./notes/libs.md)
|
||||||
- [bluegl](./dup/bluegl.md)
|
- [bluegl](./dup/bluegl.md)
|
||||||
- [bluevk](./dup/bluevk.md)
|
- [bluevk](./dup/bluevk.md)
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
# Running with ASAN/UBSAN
|
|
||||||
|
|
||||||
## Enabling
|
|
||||||
|
|
||||||
When building though build.sh, pass the `-b` flag. This sets the cmake variable
|
|
||||||
`FILAMENT_ENABLE_ASAN_UBSAN=ON` which eventually passes `"-fsanitize=address -fsanitize=undefined"`
|
|
||||||
to all compile and link operations.
|
|
||||||
|
|
||||||
If building through CMake directly, or an IDE like CLion that doesn't use build.sh, instead pass
|
|
||||||
`-DFILAMENT_ENABLE_ASAN_UBSAN=ON` to cmake in order to get the same result.
|
|
||||||
|
|
||||||
## Getting memory leak detection on Mac
|
|
||||||
|
|
||||||
Memory leak detection isn't enabled by default on MacOS. There are two issues to address, first is
|
|
||||||
using a version of clang that supports memory leak detection and second is enabling it at runtime.
|
|
||||||
|
|
||||||
The version of clang distributed by Apple (with a version like "Apple clang version 16.0.0") doesn't
|
|
||||||
currently support leak detection at all. Instead you will need to get or build a different LLVM,
|
|
||||||
such as the one distributed through homebrew and get CMake to use that instead.
|
|
||||||
|
|
||||||
Then during runtime you'll need to have the environment variable `ASAN_OPTIONS` include the option
|
|
||||||
`detect_leaks=1`. Multiple `ASAN_OPTIONS` values are concatenated with `:`.
|
|
||||||
|
|
||||||
## Getting memory leak output in CLion
|
|
||||||
|
|
||||||
### Setting variables
|
|
||||||
|
|
||||||
Under `Settings | Build, Execution, Deployment | Dynamic Analysis Tools | Sanitizers` there is an
|
|
||||||
ASAN Settings field that overrides whatever other `ASAN_OPTIONS` you might set elsewhere, so you
|
|
||||||
must use that instead of setting it through your Run/Debug Configuration.
|
|
||||||
|
|
||||||
To pass `-DFILAMENT_ENABLE_ASAN_UBSAN=ON` to CMake you'll want to create a new CMake Profile and
|
|
||||||
pass it as a CMake argument.
|
|
||||||
|
|
||||||
### Avoiding losing output
|
|
||||||
|
|
||||||
CMake will consume ASAN output and display it through a separate "Sanitizers" tab. Unfortunately
|
|
||||||
certain leak detection errors that interrupt the executable seem to not show up in this tab, but are
|
|
||||||
still removed from the user-visible console output. If this is happening and you need to see the
|
|
||||||
unfiltered console output you'll need to go to `Settings | Build, Execution, Deployment | Dynamic
|
|
||||||
Analysis Tools | Sanitizers` and uncheck "Use visual representation for Sanitizer's output".
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
# Using Instruments on macOS
|
|
||||||
|
|
||||||
When running a binary under Instruments on macOS, you may run into the following issue when
|
|
||||||
launching or attaching to an executable:
|
|
||||||
|
|
||||||
```
|
|
||||||
Failed to gain authorization
|
|
||||||
Recovery Suggestion: Target binary needs to be debuggable and signed with 'get-task-allow'
|
|
||||||
```
|
|
||||||
|
|
||||||
This is a security precaution; the solution is to code sign the binary with the
|
|
||||||
`com.apple.security.get-task-allow` entitlement.
|
|
||||||
|
|
||||||
1. Create an `entitlements.plist` file with the following contents:
|
|
||||||
|
|
||||||
```
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>com.apple.security.get-task-allow</key>
|
|
||||||
<true/>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Run the following command:
|
|
||||||
|
|
||||||
```
|
|
||||||
codesign -s - --entitlements entitlements.plist <binary>
|
|
||||||
```
|
|
||||||
|
|
||||||
Replace `<binary>` with the name of the binary, for example: `out/cmake-debug/samples/gltf_viewer`.
|
|
||||||
|
|
||||||
Afterwards, you should be able to successfully launch and attach to the executable using
|
|
||||||
Instruments.
|
|
||||||
+2
-35
@@ -265,13 +265,6 @@ set(MATERIAL_SRCS
|
|||||||
src/materials/vsmMipmap.mat
|
src/materials/vsmMipmap.mat
|
||||||
)
|
)
|
||||||
|
|
||||||
if (NOT FILAMENT_DISABLE_GTAO)
|
|
||||||
list(APPEND MATERIAL_SRCS
|
|
||||||
src/materials/ssao/gtao.mat
|
|
||||||
src/materials/ssao/gtaoBentNormals.mat
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(MATERIAL_FL0_SRCS
|
set(MATERIAL_FL0_SRCS
|
||||||
src/materials/defaultMaterial.mat
|
src/materials/defaultMaterial.mat
|
||||||
src/materials/skybox.mat
|
src/materials/skybox.mat
|
||||||
@@ -321,14 +314,12 @@ if (FILAMENT_FORCE_PROFILING_MODE)
|
|||||||
add_definitions(-DFILAMENT_FORCE_PROFILING_MODE)
|
add_definitions(-DFILAMENT_FORCE_PROFILING_MODE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (FILAMENT_DISABLE_GTAO)
|
|
||||||
add_definitions(-DFILAMENT_DISABLE_GTAO)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# ==================================================================================================
|
# ==================================================================================================
|
||||||
# Definitions
|
# Definitions
|
||||||
# ==================================================================================================
|
# ==================================================================================================
|
||||||
|
|
||||||
|
# "2" corresponds to SYSTRACE_TAG_FILEMENT (See: utils/Systrace.h)
|
||||||
|
add_definitions(-DSYSTRACE_TAG=2)
|
||||||
add_definitions(-DFILAMENT_DFG_LUT_SIZE=${DFG_LUT_SIZE})
|
add_definitions(-DFILAMENT_DFG_LUT_SIZE=${DFG_LUT_SIZE})
|
||||||
add_definitions(
|
add_definitions(
|
||||||
-DFILAMENT_PER_RENDER_PASS_ARENA_SIZE_IN_MB=${FILAMENT_PER_RENDER_PASS_ARENA_SIZE_IN_MB}
|
-DFILAMENT_PER_RENDER_PASS_ARENA_SIZE_IN_MB=${FILAMENT_PER_RENDER_PASS_ARENA_SIZE_IN_MB}
|
||||||
@@ -472,30 +463,6 @@ add_custom_command(
|
|||||||
APPEND
|
APPEND
|
||||||
)
|
)
|
||||||
|
|
||||||
if (NOT FILAMENT_DISABLE_GTAO)
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT "${MATERIAL_DIR}/gtao.filamat"
|
|
||||||
DEPENDS src/materials/ssao/ssaoUtils.fs
|
|
||||||
DEPENDS src/materials/ssao/ssct.fs
|
|
||||||
DEPENDS src/materials/utils/depthUtils.fs
|
|
||||||
DEPENDS src/materials/utils/geometry.fs
|
|
||||||
DEPENDS src/materials/ssao/gtaoImpl.fs
|
|
||||||
DEPENDS src/materials/ssao/ssctImpl.fs
|
|
||||||
APPEND
|
|
||||||
)
|
|
||||||
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT "${MATERIAL_DIR}/gtaoBentNormals.filamat"
|
|
||||||
DEPENDS src/materials/ssao/ssaoUtils.fs
|
|
||||||
DEPENDS src/materials/ssao/ssct.fs
|
|
||||||
DEPENDS src/materials/utils/depthUtils.fs
|
|
||||||
DEPENDS src/materials/utils/geometry.fs
|
|
||||||
DEPENDS src/materials/ssao/gtaoImpl.fs
|
|
||||||
DEPENDS src/materials/ssao/ssctImpl.fs
|
|
||||||
APPEND
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT "${MATERIAL_DIR}/bilateralBlur.filamat"
|
OUTPUT "${MATERIAL_DIR}/bilateralBlur.filamat"
|
||||||
DEPENDS src/materials/ssao/ssaoUtils.fs
|
DEPENDS src/materials/ssao/ssaoUtils.fs
|
||||||
|
|||||||
@@ -194,8 +194,6 @@ if (FILAMENT_SUPPORTS_VULKAN)
|
|||||||
src/vulkan/VulkanDriver.cpp
|
src/vulkan/VulkanDriver.cpp
|
||||||
src/vulkan/VulkanDriver.h
|
src/vulkan/VulkanDriver.h
|
||||||
src/vulkan/VulkanDriverFactory.h
|
src/vulkan/VulkanDriverFactory.h
|
||||||
src/vulkan/VulkanExternalImageManager.cpp
|
|
||||||
src/vulkan/VulkanExternalImageManager.h
|
|
||||||
src/vulkan/VulkanFboCache.cpp
|
src/vulkan/VulkanFboCache.cpp
|
||||||
src/vulkan/VulkanFboCache.h
|
src/vulkan/VulkanFboCache.h
|
||||||
src/vulkan/VulkanHandles.cpp
|
src/vulkan/VulkanHandles.cpp
|
||||||
@@ -259,8 +257,6 @@ if (FILAMENT_SUPPORTS_WEBGPU)
|
|||||||
src/webgpu/WebGPUDriver.h
|
src/webgpu/WebGPUDriver.h
|
||||||
src/webgpu/WebGPUHandles.cpp
|
src/webgpu/WebGPUHandles.cpp
|
||||||
src/webgpu/WebGPUHandles.h
|
src/webgpu/WebGPUHandles.h
|
||||||
src/webgpu/WebGPUPipelineCreation.cpp
|
|
||||||
src/webgpu/WebGPUPipelineCreation.h
|
|
||||||
src/webgpu/WebGPUSwapChain.cpp
|
src/webgpu/WebGPUSwapChain.cpp
|
||||||
src/webgpu/WebGPUSwapChain.h
|
src/webgpu/WebGPUSwapChain.h
|
||||||
src/webgpu/WGPUProgram.cpp
|
src/webgpu/WGPUProgram.cpp
|
||||||
@@ -290,6 +286,12 @@ if (ANDROID)
|
|||||||
list(APPEND SRCS src/BackendUtilsAndroid.cpp)
|
list(APPEND SRCS src/BackendUtilsAndroid.cpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# ==================================================================================================
|
||||||
|
# Definitions
|
||||||
|
# ==================================================================================================
|
||||||
|
# "2" corresponds to SYSTRACE_TAG_FILEMENT (See: utils/Systrace.h)
|
||||||
|
add_definitions(-DSYSTRACE_TAG=2 )
|
||||||
|
|
||||||
# ==================================================================================================
|
# ==================================================================================================
|
||||||
# Includes & target definition
|
# Includes & target definition
|
||||||
# ==================================================================================================
|
# ==================================================================================================
|
||||||
|
|||||||
@@ -20,15 +20,10 @@
|
|||||||
#define TNT_FILAMENT_BACKEND_BUFFERDESCRIPTOR_H
|
#define TNT_FILAMENT_BACKEND_BUFFERDESCRIPTOR_H
|
||||||
|
|
||||||
#include <utils/compiler.h>
|
#include <utils/compiler.h>
|
||||||
|
#include <utils/ostream.h>
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
namespace utils::io {
|
|
||||||
class ostream;
|
|
||||||
} // namespace utils::io
|
|
||||||
|
|
||||||
namespace filament::backend {
|
namespace filament::backend {
|
||||||
|
|
||||||
class CallbackHandler;
|
class CallbackHandler;
|
||||||
@@ -94,8 +89,8 @@ public:
|
|||||||
* @param callback A callback used to release the CPU buffer from this BufferDescriptor
|
* @param callback A callback used to release the CPU buffer from this BufferDescriptor
|
||||||
* @param user An opaque user pointer passed to the callback function when it's called
|
* @param user An opaque user pointer passed to the callback function when it's called
|
||||||
*/
|
*/
|
||||||
BufferDescriptor(void const* buffer, size_t const size,
|
BufferDescriptor(void const* buffer, size_t size,
|
||||||
Callback const callback = nullptr, void* user = nullptr) noexcept
|
Callback callback = nullptr, void* user = nullptr) noexcept
|
||||||
: buffer(const_cast<void*>(buffer)), size(size), mCallback(callback), mUser(user) {
|
: buffer(const_cast<void*>(buffer)), size(size), mCallback(callback), mUser(user) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,12 +98,11 @@ public:
|
|||||||
* Creates a BufferDescriptor that references a CPU memory-buffer
|
* Creates a BufferDescriptor that references a CPU memory-buffer
|
||||||
* @param buffer Memory address of the CPU buffer to reference
|
* @param buffer Memory address of the CPU buffer to reference
|
||||||
* @param size Size of the CPU buffer in bytes
|
* @param size Size of the CPU buffer in bytes
|
||||||
* @param handler A custom handler for the callback
|
|
||||||
* @param callback A callback used to release the CPU buffer from this BufferDescriptor
|
* @param callback A callback used to release the CPU buffer from this BufferDescriptor
|
||||||
* @param user An opaque user pointer passed to the callback function when it's called
|
* @param user An opaque user pointer passed to the callback function when it's called
|
||||||
*/
|
*/
|
||||||
BufferDescriptor(void const* buffer, size_t const size,
|
BufferDescriptor(void const* buffer, size_t size,
|
||||||
CallbackHandler* handler, Callback const callback, void* user = nullptr) noexcept
|
CallbackHandler* handler, Callback callback, void* user = nullptr) noexcept
|
||||||
: buffer(const_cast<void*>(buffer)), size(size),
|
: buffer(const_cast<void*>(buffer)), size(size),
|
||||||
mCallback(callback), mUser(user), mHandler(handler) {
|
mCallback(callback), mUser(user), mHandler(handler) {
|
||||||
}
|
}
|
||||||
@@ -122,9 +116,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @param buffer Memory address of the CPU buffer to reference
|
* @param buffer Memory address of the CPU buffer to reference
|
||||||
* @param size Size of the CPU buffer in bytes
|
* @param size Size of the CPU buffer in bytes
|
||||||
* @param data A pointer to the data
|
|
||||||
* @param handler Handler to use to dispatch the callback, or nullptr for the default handler
|
* @param handler Handler to use to dispatch the callback, or nullptr for the default handler
|
||||||
* @return A new BufferDescriptor
|
* @return a new BufferDescriptor
|
||||||
*/
|
*/
|
||||||
template<typename T, void(T::*method)(void const*, size_t)>
|
template<typename T, void(T::*method)(void const*, size_t)>
|
||||||
static BufferDescriptor make(void const* buffer, size_t size, T* data,
|
static BufferDescriptor make(void const* buffer, size_t size, T* data,
|
||||||
@@ -171,7 +164,7 @@ public:
|
|||||||
* @param callback The new callback function
|
* @param callback The new callback function
|
||||||
* @param user An opaque user pointer passed to the callbeck function when it's called
|
* @param user An opaque user pointer passed to the callbeck function when it's called
|
||||||
*/
|
*/
|
||||||
void setCallback(Callback const callback, void* user = nullptr) noexcept {
|
void setCallback(Callback callback, void* user = nullptr) noexcept {
|
||||||
this->mCallback = callback;
|
this->mCallback = callback;
|
||||||
this->mUser = user;
|
this->mUser = user;
|
||||||
this->mHandler = nullptr;
|
this->mHandler = nullptr;
|
||||||
@@ -183,7 +176,7 @@ public:
|
|||||||
* @param callback The new callback function
|
* @param callback The new callback function
|
||||||
* @param user An opaque user pointer passed to the callbeck function when it's called
|
* @param user An opaque user pointer passed to the callbeck function when it's called
|
||||||
*/
|
*/
|
||||||
void setCallback(CallbackHandler* handler, Callback const callback, void* user = nullptr) noexcept {
|
void setCallback(CallbackHandler* handler, Callback callback, void* user = nullptr) noexcept {
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
mUser = user;
|
mUser = user;
|
||||||
mHandler = handler;
|
mHandler = handler;
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include <backend/DriverApiForward.h>
|
#include <backend/DriverApiForward.h>
|
||||||
|
|
||||||
|
#include <utils/ostream.h>
|
||||||
|
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@@ -26,10 +28,6 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
namespace utils::io {
|
|
||||||
class ostream;
|
|
||||||
} // namespace utils::io
|
|
||||||
|
|
||||||
namespace filament::backend {
|
namespace filament::backend {
|
||||||
|
|
||||||
void* allocateFromCommandStream(DriverApi& driver, size_t size, size_t alignment) noexcept;
|
void* allocateFromCommandStream(DriverApi& driver, size_t size, size_t alignment) noexcept;
|
||||||
|
|||||||
@@ -25,26 +25,21 @@
|
|||||||
#include <backend/PresentCallable.h>
|
#include <backend/PresentCallable.h>
|
||||||
|
|
||||||
#include <utils/BitmaskEnum.h>
|
#include <utils/BitmaskEnum.h>
|
||||||
#include <utils/CString.h>
|
|
||||||
#include <utils/FixedCapacityVector.h>
|
#include <utils/FixedCapacityVector.h>
|
||||||
#include <utils/Invocable.h>
|
#include <utils/Invocable.h>
|
||||||
#include <utils/StaticString.h>
|
#include <utils/compiler.h>
|
||||||
#include <utils/debug.h>
|
#include <utils/debug.h>
|
||||||
|
#include <utils/ostream.h>
|
||||||
|
|
||||||
#include <math/vec4.h>
|
#include <math/vec4.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <string_view>
|
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace utils::io {
|
|
||||||
class ostream;
|
|
||||||
} // namespace utils::io
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Types and enums used by filament's driver.
|
* Types and enums used by filament's driver.
|
||||||
*
|
*
|
||||||
@@ -163,7 +158,7 @@ enum class TimerQueryResult : int8_t {
|
|||||||
AVAILABLE = 1, // result is available
|
AVAILABLE = 1, // result is available
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr std::string_view to_string(Backend const backend) noexcept {
|
static constexpr const char* backendToString(Backend backend) {
|
||||||
switch (backend) {
|
switch (backend) {
|
||||||
case Backend::NOOP:
|
case Backend::NOOP:
|
||||||
return "Noop";
|
return "Noop";
|
||||||
@@ -175,10 +170,9 @@ constexpr std::string_view to_string(Backend const backend) noexcept {
|
|||||||
return "Metal";
|
return "Metal";
|
||||||
case Backend::WEBGPU:
|
case Backend::WEBGPU:
|
||||||
return "WebGPU";
|
return "WebGPU";
|
||||||
case Backend::DEFAULT:
|
default:
|
||||||
return "Default";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
return "Unknown";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -195,7 +189,7 @@ enum class ShaderLanguage {
|
|||||||
WGSL = 5,
|
WGSL = 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr const char* shaderLanguageToString(ShaderLanguage shaderLanguage) noexcept {
|
static constexpr const char* shaderLanguageToString(ShaderLanguage shaderLanguage) {
|
||||||
switch (shaderLanguage) {
|
switch (shaderLanguage) {
|
||||||
case ShaderLanguage::ESSL1:
|
case ShaderLanguage::ESSL1:
|
||||||
return "ESSL 1.0";
|
return "ESSL 1.0";
|
||||||
@@ -210,7 +204,6 @@ constexpr const char* shaderLanguageToString(ShaderLanguage shaderLanguage) noex
|
|||||||
case ShaderLanguage::WGSL:
|
case ShaderLanguage::WGSL:
|
||||||
return "WGSL";
|
return "WGSL";
|
||||||
}
|
}
|
||||||
return "UNKNOWN";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class ShaderStage : uint8_t {
|
enum class ShaderStage : uint8_t {
|
||||||
@@ -228,7 +221,7 @@ enum class ShaderStageFlags : uint8_t {
|
|||||||
ALL_SHADER_STAGE_FLAGS = VERTEX | FRAGMENT | COMPUTE
|
ALL_SHADER_STAGE_FLAGS = VERTEX | FRAGMENT | COMPUTE
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr bool hasShaderType(ShaderStageFlags flags, ShaderStage type) noexcept {
|
static inline constexpr bool hasShaderType(ShaderStageFlags flags, ShaderStage type) noexcept {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ShaderStage::VERTEX:
|
case ShaderStage::VERTEX:
|
||||||
return bool(uint8_t(flags) & uint8_t(ShaderStageFlags::VERTEX));
|
return bool(uint8_t(flags) & uint8_t(ShaderStageFlags::VERTEX));
|
||||||
@@ -239,239 +232,14 @@ constexpr bool hasShaderType(ShaderStageFlags flags, ShaderStage type) noexcept
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class TextureType : uint8_t {
|
enum class DescriptorType : uint8_t {
|
||||||
FLOAT,
|
UNIFORM_BUFFER,
|
||||||
INT,
|
SHADER_STORAGE_BUFFER,
|
||||||
UINT,
|
SAMPLER,
|
||||||
DEPTH,
|
INPUT_ATTACHMENT,
|
||||||
STENCIL,
|
SAMPLER_EXTERNAL
|
||||||
DEPTH_STENCIL
|
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr std::string_view to_string(TextureType type) noexcept {
|
|
||||||
switch (type) {
|
|
||||||
case TextureType::FLOAT: return "FLOAT";
|
|
||||||
case TextureType::INT: return "INT";
|
|
||||||
case TextureType::UINT: return "UINT";
|
|
||||||
case TextureType::DEPTH: return "DEPTH";
|
|
||||||
case TextureType::STENCIL: return "STENCIL";
|
|
||||||
case TextureType::DEPTH_STENCIL: return "DEPTH_STENCIL";
|
|
||||||
}
|
|
||||||
return "UNKNOWN";
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class DescriptorType : uint8_t {
|
|
||||||
SAMPLER_2D_FLOAT,
|
|
||||||
SAMPLER_2D_INT,
|
|
||||||
SAMPLER_2D_UINT,
|
|
||||||
SAMPLER_2D_DEPTH,
|
|
||||||
|
|
||||||
SAMPLER_2D_ARRAY_FLOAT,
|
|
||||||
SAMPLER_2D_ARRAY_INT,
|
|
||||||
SAMPLER_2D_ARRAY_UINT,
|
|
||||||
SAMPLER_2D_ARRAY_DEPTH,
|
|
||||||
|
|
||||||
SAMPLER_CUBE_FLOAT,
|
|
||||||
SAMPLER_CUBE_INT,
|
|
||||||
SAMPLER_CUBE_UINT,
|
|
||||||
SAMPLER_CUBE_DEPTH,
|
|
||||||
|
|
||||||
SAMPLER_CUBE_ARRAY_FLOAT,
|
|
||||||
SAMPLER_CUBE_ARRAY_INT,
|
|
||||||
SAMPLER_CUBE_ARRAY_UINT,
|
|
||||||
SAMPLER_CUBE_ARRAY_DEPTH,
|
|
||||||
|
|
||||||
SAMPLER_3D_FLOAT,
|
|
||||||
SAMPLER_3D_INT,
|
|
||||||
SAMPLER_3D_UINT,
|
|
||||||
|
|
||||||
SAMPLER_2D_MS_FLOAT,
|
|
||||||
SAMPLER_2D_MS_INT,
|
|
||||||
SAMPLER_2D_MS_UINT,
|
|
||||||
|
|
||||||
SAMPLER_2D_MS_ARRAY_FLOAT,
|
|
||||||
SAMPLER_2D_MS_ARRAY_INT,
|
|
||||||
SAMPLER_2D_MS_ARRAY_UINT,
|
|
||||||
|
|
||||||
SAMPLER_EXTERNAL,
|
|
||||||
UNIFORM_BUFFER,
|
|
||||||
SHADER_STORAGE_BUFFER,
|
|
||||||
INPUT_ATTACHMENT,
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr bool isDepthDescriptor(DescriptorType const type) noexcept {
|
|
||||||
switch (type) {
|
|
||||||
case DescriptorType::SAMPLER_2D_DEPTH:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_DEPTH:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_DEPTH:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_DEPTH:
|
|
||||||
return true;
|
|
||||||
default: ;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr bool isFloatDescriptor(DescriptorType const type) noexcept {
|
|
||||||
switch (type) {
|
|
||||||
case DescriptorType::SAMPLER_2D_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_3D_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_FLOAT:
|
|
||||||
return true;
|
|
||||||
default: ;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr bool isIntDescriptor(DescriptorType const type) noexcept {
|
|
||||||
switch (type) {
|
|
||||||
case DescriptorType::SAMPLER_2D_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_INT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_INT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_INT:
|
|
||||||
case DescriptorType::SAMPLER_3D_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_INT:
|
|
||||||
return true;
|
|
||||||
default: ;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr bool isUnsignedIntDescriptor(DescriptorType const type) noexcept {
|
|
||||||
switch (type) {
|
|
||||||
case DescriptorType::SAMPLER_2D_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_UINT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_UINT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_UINT:
|
|
||||||
case DescriptorType::SAMPLER_3D_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_UINT:
|
|
||||||
return true;
|
|
||||||
default: ;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr bool is3dTypeDescriptor(DescriptorType const type) noexcept {
|
|
||||||
switch (type) {
|
|
||||||
case DescriptorType::SAMPLER_3D_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_3D_INT:
|
|
||||||
case DescriptorType::SAMPLER_3D_UINT:
|
|
||||||
return true;
|
|
||||||
default: ;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr bool is2dTypeDescriptor(DescriptorType const type) noexcept {
|
|
||||||
switch (type) {
|
|
||||||
case DescriptorType::SAMPLER_2D_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_DEPTH:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_UINT:
|
|
||||||
return true;
|
|
||||||
default: ;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr bool is2dArrayTypeDescriptor(DescriptorType const type) noexcept {
|
|
||||||
switch (type) {
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_DEPTH:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_UINT:
|
|
||||||
return true;
|
|
||||||
default: ;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr bool isCubeTypeDescriptor(DescriptorType const type) noexcept {
|
|
||||||
switch (type) {
|
|
||||||
case DescriptorType::SAMPLER_CUBE_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_INT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_UINT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_DEPTH:
|
|
||||||
return true;
|
|
||||||
default: ;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr bool isCubeArrayTypeDescriptor(DescriptorType const type) noexcept {
|
|
||||||
switch (type) {
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_INT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_UINT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_DEPTH:
|
|
||||||
return true;
|
|
||||||
default: ;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr bool isMultiSampledTypeDescriptor(DescriptorType const type) noexcept {
|
|
||||||
switch (type) {
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_UINT:
|
|
||||||
return true;
|
|
||||||
default: ;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr std::string_view to_string(DescriptorType type) noexcept {
|
|
||||||
#define DESCRIPTOR_TYPE_CASE(TYPE) case DescriptorType::TYPE: return #TYPE;
|
|
||||||
switch (type) {
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_2D_FLOAT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_2D_INT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_2D_UINT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_2D_DEPTH)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_2D_ARRAY_FLOAT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_2D_ARRAY_INT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_2D_ARRAY_UINT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_2D_ARRAY_DEPTH)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_CUBE_FLOAT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_CUBE_INT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_CUBE_UINT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_CUBE_DEPTH)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_CUBE_ARRAY_FLOAT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_CUBE_ARRAY_INT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_CUBE_ARRAY_UINT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_CUBE_ARRAY_DEPTH)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_3D_FLOAT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_3D_INT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_3D_UINT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_2D_MS_FLOAT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_2D_MS_INT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_2D_MS_UINT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_2D_MS_ARRAY_FLOAT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_2D_MS_ARRAY_INT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_2D_MS_ARRAY_UINT)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SAMPLER_EXTERNAL)
|
|
||||||
DESCRIPTOR_TYPE_CASE(UNIFORM_BUFFER)
|
|
||||||
DESCRIPTOR_TYPE_CASE(SHADER_STORAGE_BUFFER)
|
|
||||||
DESCRIPTOR_TYPE_CASE(INPUT_ATTACHMENT)
|
|
||||||
}
|
|
||||||
return "UNKNOWN";
|
|
||||||
#undef DESCRIPTOR_TYPE_CASE
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class DescriptorFlags : uint8_t {
|
enum class DescriptorFlags : uint8_t {
|
||||||
NONE = 0x00,
|
NONE = 0x00,
|
||||||
DYNAMIC_OFFSET = 0x01
|
DYNAMIC_OFFSET = 0x01
|
||||||
@@ -482,13 +250,6 @@ using descriptor_set_t = uint8_t;
|
|||||||
using descriptor_binding_t = uint8_t;
|
using descriptor_binding_t = uint8_t;
|
||||||
|
|
||||||
struct DescriptorSetLayoutBinding {
|
struct DescriptorSetLayoutBinding {
|
||||||
static bool isSampler(DescriptorType type) noexcept {
|
|
||||||
return int(type) <= int(DescriptorType::SAMPLER_EXTERNAL);
|
|
||||||
}
|
|
||||||
static bool isBuffer(DescriptorType type) noexcept {
|
|
||||||
return type == DescriptorType::UNIFORM_BUFFER ||
|
|
||||||
type == DescriptorType::SHADER_STORAGE_BUFFER;
|
|
||||||
}
|
|
||||||
DescriptorType type;
|
DescriptorType type;
|
||||||
ShaderStageFlags stageFlags;
|
ShaderStageFlags stageFlags;
|
||||||
descriptor_binding_t binding;
|
descriptor_binding_t binding;
|
||||||
@@ -499,7 +260,7 @@ struct DescriptorSetLayoutBinding {
|
|||||||
// no uninitialized padding bytes.
|
// no uninitialized padding bytes.
|
||||||
// uint8_t externalSamplerDataIndex = EXTERNAL_SAMPLER_DATA_INDEX_UNUSED;
|
// uint8_t externalSamplerDataIndex = EXTERNAL_SAMPLER_DATA_INDEX_UNUSED;
|
||||||
|
|
||||||
friend bool operator==(DescriptorSetLayoutBinding const& lhs,
|
friend inline bool operator==(DescriptorSetLayoutBinding const& lhs,
|
||||||
DescriptorSetLayoutBinding const& rhs) noexcept {
|
DescriptorSetLayoutBinding const& rhs) noexcept {
|
||||||
return lhs.type == rhs.type &&
|
return lhs.type == rhs.type &&
|
||||||
lhs.flags == rhs.flags &&
|
lhs.flags == rhs.flags &&
|
||||||
@@ -532,7 +293,7 @@ enum class TargetBufferFlags : uint32_t {
|
|||||||
ALL = COLOR_ALL | DEPTH | STENCIL //!< Color, depth and stencil buffer selected.
|
ALL = COLOR_ALL | DEPTH | STENCIL //!< Color, depth and stencil buffer selected.
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr TargetBufferFlags getTargetBufferFlagsAt(size_t index) noexcept {
|
inline constexpr TargetBufferFlags getTargetBufferFlagsAt(size_t index) noexcept {
|
||||||
if (index == 0u) return TargetBufferFlags::COLOR0;
|
if (index == 0u) return TargetBufferFlags::COLOR0;
|
||||||
if (index == 1u) return TargetBufferFlags::COLOR1;
|
if (index == 1u) return TargetBufferFlags::COLOR1;
|
||||||
if (index == 2u) return TargetBufferFlags::COLOR2;
|
if (index == 2u) return TargetBufferFlags::COLOR2;
|
||||||
@@ -689,24 +450,6 @@ enum class SamplerType : uint8_t {
|
|||||||
SAMPLER_CUBEMAP_ARRAY, //!< Cube map array texture (feature level 2)
|
SAMPLER_CUBEMAP_ARRAY, //!< Cube map array texture (feature level 2)
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr std::string_view to_string(SamplerType const type) noexcept {
|
|
||||||
switch (type) {
|
|
||||||
case SamplerType::SAMPLER_2D:
|
|
||||||
return "SAMPLER_2D";
|
|
||||||
case SamplerType::SAMPLER_2D_ARRAY:
|
|
||||||
return "SAMPLER_2D_ARRAY";
|
|
||||||
case SamplerType::SAMPLER_CUBEMAP:
|
|
||||||
return "SAMPLER_CUBEMAP";
|
|
||||||
case SamplerType::SAMPLER_EXTERNAL:
|
|
||||||
return "SAMPLER_EXTERNAL";
|
|
||||||
case SamplerType::SAMPLER_3D:
|
|
||||||
return "SAMPLER_3D";
|
|
||||||
case SamplerType::SAMPLER_CUBEMAP_ARRAY:
|
|
||||||
return "SAMPLER_CUBEMAP_ARRAY";
|
|
||||||
}
|
|
||||||
return "Unknown";
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Subpass type
|
//! Subpass type
|
||||||
enum class SubpassType : uint8_t {
|
enum class SubpassType : uint8_t {
|
||||||
SUBPASS_INPUT
|
SUBPASS_INPUT
|
||||||
@@ -720,20 +463,6 @@ enum class SamplerFormat : uint8_t {
|
|||||||
SHADOW = 3 //!< shadow sampler (PCF)
|
SHADOW = 3 //!< shadow sampler (PCF)
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr std::string_view to_string(SamplerFormat const format) noexcept {
|
|
||||||
switch (format) {
|
|
||||||
case SamplerFormat::INT:
|
|
||||||
return "INT";
|
|
||||||
case SamplerFormat::UINT:
|
|
||||||
return "UINT";
|
|
||||||
case SamplerFormat::FLOAT:
|
|
||||||
return "FLOAT";
|
|
||||||
case SamplerFormat::SHADOW:
|
|
||||||
return "SHADOW";
|
|
||||||
}
|
|
||||||
return "Unknown";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supported element types
|
* Supported element types
|
||||||
*/
|
*/
|
||||||
@@ -773,15 +502,6 @@ enum class BufferObjectBinding : uint8_t {
|
|||||||
SHADER_STORAGE
|
SHADER_STORAGE
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr std::string_view to_string(BufferObjectBinding type) noexcept {
|
|
||||||
switch (type) {
|
|
||||||
case BufferObjectBinding::VERTEX: return "VERTEX";
|
|
||||||
case BufferObjectBinding::UNIFORM: return "UNIFORM";
|
|
||||||
case BufferObjectBinding::SHADER_STORAGE: return "SHADER_STORAGE";
|
|
||||||
}
|
|
||||||
return "UNKNOWN";
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Face culling Mode
|
//! Face culling Mode
|
||||||
enum class CullingMode : uint8_t {
|
enum class CullingMode : uint8_t {
|
||||||
NONE, //!< No culling, front and back faces are visible
|
NONE, //!< No culling, front and back faces are visible
|
||||||
@@ -1043,8 +763,6 @@ enum class TextureFormat : uint16_t {
|
|||||||
SRGB_ALPHA_BPTC_UNORM, // BC7 sRGB
|
SRGB_ALPHA_BPTC_UNORM, // BC7 sRGB
|
||||||
};
|
};
|
||||||
|
|
||||||
TextureType getTextureType(TextureFormat format) noexcept;
|
|
||||||
|
|
||||||
//! Bitmask describing the intended Texture Usage
|
//! Bitmask describing the intended Texture Usage
|
||||||
enum class TextureUsage : uint16_t {
|
enum class TextureUsage : uint16_t {
|
||||||
NONE = 0x0000,
|
NONE = 0x0000,
|
||||||
@@ -1072,7 +790,7 @@ enum class TextureSwizzle : uint8_t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
//! returns whether this format a depth format
|
//! returns whether this format a depth format
|
||||||
constexpr bool isDepthFormat(TextureFormat format) noexcept {
|
static constexpr bool isDepthFormat(TextureFormat format) noexcept {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case TextureFormat::DEPTH32F:
|
case TextureFormat::DEPTH32F:
|
||||||
case TextureFormat::DEPTH24:
|
case TextureFormat::DEPTH24:
|
||||||
@@ -1085,7 +803,7 @@ constexpr bool isDepthFormat(TextureFormat format) noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool isStencilFormat(TextureFormat format) noexcept {
|
static constexpr bool isStencilFormat(TextureFormat format) noexcept {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case TextureFormat::STENCIL8:
|
case TextureFormat::STENCIL8:
|
||||||
case TextureFormat::DEPTH24_STENCIL8:
|
case TextureFormat::DEPTH24_STENCIL8:
|
||||||
@@ -1096,7 +814,7 @@ constexpr bool isStencilFormat(TextureFormat format) noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool isColorFormat(TextureFormat format) noexcept {
|
inline constexpr bool isColorFormat(TextureFormat format) noexcept {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
// Standard color formats
|
// Standard color formats
|
||||||
case TextureFormat::R8:
|
case TextureFormat::R8:
|
||||||
@@ -1123,7 +841,7 @@ constexpr bool isColorFormat(TextureFormat format) noexcept {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool isUnsignedIntFormat(TextureFormat format) {
|
static constexpr bool isUnsignedIntFormat(TextureFormat format) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case TextureFormat::R8UI:
|
case TextureFormat::R8UI:
|
||||||
case TextureFormat::R16UI:
|
case TextureFormat::R16UI:
|
||||||
@@ -1144,7 +862,7 @@ constexpr bool isUnsignedIntFormat(TextureFormat format) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool isSignedIntFormat(TextureFormat format) {
|
static constexpr bool isSignedIntFormat(TextureFormat format) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case TextureFormat::R8I:
|
case TextureFormat::R8I:
|
||||||
case TextureFormat::R16I:
|
case TextureFormat::R16I:
|
||||||
@@ -1166,35 +884,35 @@ constexpr bool isSignedIntFormat(TextureFormat format) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! returns whether this format is a compressed format
|
//! returns whether this format is a compressed format
|
||||||
constexpr bool isCompressedFormat(TextureFormat format) noexcept {
|
static constexpr bool isCompressedFormat(TextureFormat format) noexcept {
|
||||||
return format >= TextureFormat::EAC_R11;
|
return format >= TextureFormat::EAC_R11;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! returns whether this format is an ETC2 compressed format
|
//! returns whether this format is an ETC2 compressed format
|
||||||
constexpr bool isETC2Compression(TextureFormat format) noexcept {
|
static constexpr bool isETC2Compression(TextureFormat format) noexcept {
|
||||||
return format >= TextureFormat::EAC_R11 && format <= TextureFormat::ETC2_EAC_SRGBA8;
|
return format >= TextureFormat::EAC_R11 && format <= TextureFormat::ETC2_EAC_SRGBA8;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! returns whether this format is an S3TC compressed format
|
//! returns whether this format is an S3TC compressed format
|
||||||
constexpr bool isS3TCCompression(TextureFormat format) noexcept {
|
static constexpr bool isS3TCCompression(TextureFormat format) noexcept {
|
||||||
return format >= TextureFormat::DXT1_RGB && format <= TextureFormat::DXT5_SRGBA;
|
return format >= TextureFormat::DXT1_RGB && format <= TextureFormat::DXT5_SRGBA;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool isS3TCSRGBCompression(TextureFormat format) noexcept {
|
static constexpr bool isS3TCSRGBCompression(TextureFormat format) noexcept {
|
||||||
return format >= TextureFormat::DXT1_SRGB && format <= TextureFormat::DXT5_SRGBA;
|
return format >= TextureFormat::DXT1_SRGB && format <= TextureFormat::DXT5_SRGBA;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! returns whether this format is an RGTC compressed format
|
//! returns whether this format is an RGTC compressed format
|
||||||
constexpr bool isRGTCCompression(TextureFormat format) noexcept {
|
static constexpr bool isRGTCCompression(TextureFormat format) noexcept {
|
||||||
return format >= TextureFormat::RED_RGTC1 && format <= TextureFormat::SIGNED_RED_GREEN_RGTC2;
|
return format >= TextureFormat::RED_RGTC1 && format <= TextureFormat::SIGNED_RED_GREEN_RGTC2;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! returns whether this format is an BPTC compressed format
|
//! returns whether this format is an BPTC compressed format
|
||||||
constexpr bool isBPTCCompression(TextureFormat format) noexcept {
|
static constexpr bool isBPTCCompression(TextureFormat format) noexcept {
|
||||||
return format >= TextureFormat::RGB_BPTC_SIGNED_FLOAT && format <= TextureFormat::SRGB_ALPHA_BPTC_UNORM;
|
return format >= TextureFormat::RGB_BPTC_SIGNED_FLOAT && format <= TextureFormat::SRGB_ALPHA_BPTC_UNORM;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool isASTCCompression(TextureFormat format) noexcept {
|
static constexpr bool isASTCCompression(TextureFormat format) noexcept {
|
||||||
return format >= TextureFormat::RGBA_ASTC_4x4 && format <= TextureFormat::SRGB8_ALPHA8_ASTC_12x12;
|
return format >= TextureFormat::RGBA_ASTC_4x4 && format <= TextureFormat::SRGB8_ALPHA8_ASTC_12x12;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1315,23 +1033,19 @@ struct SamplerParams { // NOLINT
|
|||||||
assert_invariant(lhs.padding2 == 0);
|
assert_invariant(lhs.padding2 == 0);
|
||||||
auto* pLhs = reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&lhs));
|
auto* pLhs = reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&lhs));
|
||||||
auto* pRhs = reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&rhs));
|
auto* pRhs = reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&rhs));
|
||||||
return *pLhs < *pRhs;
|
return *pLhs == *pRhs;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool isFiltered() const noexcept {
|
|
||||||
return filterMag != SamplerMagFilter::NEAREST || filterMin != SamplerMinFilter::NEAREST;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend bool operator == (SamplerParams lhs, SamplerParams rhs) noexcept {
|
friend inline bool operator == (SamplerParams lhs, SamplerParams rhs) noexcept {
|
||||||
return EqualTo{}(lhs, rhs);
|
return SamplerParams::EqualTo{}(lhs, rhs);
|
||||||
}
|
}
|
||||||
friend bool operator != (SamplerParams lhs, SamplerParams rhs) noexcept {
|
friend inline bool operator != (SamplerParams lhs, SamplerParams rhs) noexcept {
|
||||||
return !EqualTo{}(lhs, rhs);
|
return !SamplerParams::EqualTo{}(lhs, rhs);
|
||||||
}
|
}
|
||||||
friend bool operator < (SamplerParams lhs, SamplerParams rhs) noexcept {
|
friend inline bool operator < (SamplerParams lhs, SamplerParams rhs) noexcept {
|
||||||
return LessThan{}(lhs, rhs);
|
return SamplerParams::LessThan{}(lhs, rhs);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1381,15 +1095,15 @@ struct SamplerYcbcrConversion {// NOLINT
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend bool operator == (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
|
friend inline bool operator == (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
|
||||||
noexcept {
|
noexcept {
|
||||||
return SamplerYcbcrConversion::EqualTo{}(lhs, rhs);
|
return SamplerYcbcrConversion::EqualTo{}(lhs, rhs);
|
||||||
}
|
}
|
||||||
friend bool operator != (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
|
friend inline bool operator != (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
|
||||||
noexcept {
|
noexcept {
|
||||||
return !SamplerYcbcrConversion::EqualTo{}(lhs, rhs);
|
return !SamplerYcbcrConversion::EqualTo{}(lhs, rhs);
|
||||||
}
|
}
|
||||||
friend bool operator < (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
|
friend inline bool operator < (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
|
||||||
noexcept {
|
noexcept {
|
||||||
return SamplerYcbcrConversion::LessThan{}(lhs, rhs);
|
return SamplerYcbcrConversion::LessThan{}(lhs, rhs);
|
||||||
}
|
}
|
||||||
@@ -1425,7 +1139,6 @@ struct ExternalSamplerDatum {
|
|||||||
static_assert(sizeof(ExternalSamplerDatum) == 12);
|
static_assert(sizeof(ExternalSamplerDatum) == 12);
|
||||||
|
|
||||||
struct DescriptorSetLayout {
|
struct DescriptorSetLayout {
|
||||||
std::variant<utils::StaticString, utils::CString, std::monostate> label;
|
|
||||||
utils::FixedCapacityVector<DescriptorSetLayoutBinding> bindings;
|
utils::FixedCapacityVector<DescriptorSetLayoutBinding> bindings;
|
||||||
|
|
||||||
// TODO: uncomment when needed
|
// TODO: uncomment when needed
|
||||||
@@ -1742,11 +1455,6 @@ enum class Workaround : uint16_t {
|
|||||||
DISABLE_BLIT_INTO_TEXTURE_ARRAY,
|
DISABLE_BLIT_INTO_TEXTURE_ARRAY,
|
||||||
// Multiple workarounds needed for PowerVR GPUs
|
// Multiple workarounds needed for PowerVR GPUs
|
||||||
POWER_VR_SHADER_WORKAROUNDS,
|
POWER_VR_SHADER_WORKAROUNDS,
|
||||||
// Some browsers, such as Firefox on Mac, struggle with slow shader compile/link times when
|
|
||||||
// creating programs for the default material, leading to startup stutters. This workaround
|
|
||||||
// prevents these stutters by not precaching depth variants of the default material for those
|
|
||||||
// particular browsers.
|
|
||||||
DISABLE_DEPTH_PRECACHE_FOR_DEFAULT_MATERIAL,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using StereoscopicType = backend::Platform::StereoscopicType;
|
using StereoscopicType = backend::Platform::StereoscopicType;
|
||||||
|
|||||||
@@ -17,6 +17,9 @@
|
|||||||
#ifndef TNT_FILAMENT_BACKEND_HANDLE_H
|
#ifndef TNT_FILAMENT_BACKEND_HANDLE_H
|
||||||
#define TNT_FILAMENT_BACKEND_HANDLE_H
|
#define TNT_FILAMENT_BACKEND_HANDLE_H
|
||||||
|
|
||||||
|
#if !defined(NDEBUG)
|
||||||
|
#include <utils/ostream.h>
|
||||||
|
#endif
|
||||||
#include <utils/debug.h>
|
#include <utils/debug.h>
|
||||||
|
|
||||||
#include <type_traits> // FIXME: STL headers are not allowed in public headers
|
#include <type_traits> // FIXME: STL headers are not allowed in public headers
|
||||||
@@ -24,10 +27,6 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace utils::io {
|
|
||||||
class ostream;
|
|
||||||
} // namespace utils::io
|
|
||||||
|
|
||||||
namespace filament::backend {
|
namespace filament::backend {
|
||||||
|
|
||||||
struct HwBufferObject;
|
struct HwBufferObject;
|
||||||
|
|||||||
@@ -20,14 +20,12 @@
|
|||||||
#include <backend/DriverEnums.h>
|
#include <backend/DriverEnums.h>
|
||||||
#include <backend/Handle.h>
|
#include <backend/Handle.h>
|
||||||
|
|
||||||
|
#include <utils/ostream.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace utils::io {
|
|
||||||
class ostream;
|
|
||||||
} // namespace utils::io
|
|
||||||
|
|
||||||
namespace filament::backend {
|
namespace filament::backend {
|
||||||
|
|
||||||
//! \privatesection
|
//! \privatesection
|
||||||
|
|||||||
@@ -24,14 +24,11 @@
|
|||||||
|
|
||||||
#include <utils/compiler.h>
|
#include <utils/compiler.h>
|
||||||
#include <utils/debug.h>
|
#include <utils/debug.h>
|
||||||
|
#include <utils/ostream.h>
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace utils::io {
|
|
||||||
class ostream;
|
|
||||||
} // namespace utils::io
|
|
||||||
|
|
||||||
namespace filament::backend {
|
namespace filament::backend {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -149,13 +149,6 @@ public:
|
|||||||
* - PlatformEGLAndroid
|
* - PlatformEGLAndroid
|
||||||
*/
|
*/
|
||||||
bool assertNativeWindowIsValid = false;
|
bool assertNativeWindowIsValid = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* The action to take if a Drawable cannot be acquired. If true, the
|
|
||||||
* frame is aborted instead of panic. This is only supported for:
|
|
||||||
* - PlatformMetal
|
|
||||||
*/
|
|
||||||
bool metalDisablePanicOnDrawableFailure = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Platform() noexcept;
|
Platform() noexcept;
|
||||||
|
|||||||
@@ -20,10 +20,12 @@
|
|||||||
#include <utils/CString.h>
|
#include <utils/CString.h>
|
||||||
#include <utils/FixedCapacityVector.h>
|
#include <utils/FixedCapacityVector.h>
|
||||||
#include <utils/Invocable.h>
|
#include <utils/Invocable.h>
|
||||||
|
#include <utils/ostream.h>
|
||||||
|
|
||||||
#include <backend/DriverEnums.h>
|
#include <backend/DriverEnums.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <unordered_map>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
@@ -31,10 +33,6 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace utils::io {
|
|
||||||
class ostream;
|
|
||||||
} // namespace utils::io
|
|
||||||
|
|
||||||
namespace filament::backend {
|
namespace filament::backend {
|
||||||
|
|
||||||
class Program {
|
class Program {
|
||||||
@@ -46,8 +44,8 @@ public:
|
|||||||
|
|
||||||
struct Descriptor {
|
struct Descriptor {
|
||||||
utils::CString name;
|
utils::CString name;
|
||||||
DescriptorType type;
|
backend::DescriptorType type;
|
||||||
descriptor_binding_t binding;
|
backend::descriptor_binding_t binding;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SpecializationConstant {
|
struct SpecializationConstant {
|
||||||
|
|||||||
@@ -19,26 +19,22 @@
|
|||||||
|
|
||||||
#include <backend/Handle.h>
|
#include <backend/Handle.h>
|
||||||
|
|
||||||
#include <utility>
|
#include <utils/ostream.h>
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace utils::io {
|
|
||||||
class ostream;
|
|
||||||
} // namespace utils::io
|
|
||||||
|
|
||||||
namespace filament::backend {
|
namespace filament::backend {
|
||||||
|
|
||||||
//! \privatesection
|
//! \privatesection
|
||||||
|
|
||||||
struct TargetBufferInfo {
|
struct TargetBufferInfo {
|
||||||
// note: the parameters of this constructor are not in the order of this structure's fields
|
// note: the parameters of this constructor are not in the order of this structure's fields
|
||||||
TargetBufferInfo(Handle<HwTexture> handle, uint8_t const level, uint16_t const layer) noexcept
|
TargetBufferInfo(Handle<HwTexture> handle, uint8_t level, uint16_t layer) noexcept
|
||||||
: handle(std::move(handle)), level(level), layer(layer) {
|
: handle(handle), level(level), layer(layer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetBufferInfo(Handle<HwTexture> handle, uint8_t const level) noexcept
|
TargetBufferInfo(Handle<HwTexture> handle, uint8_t level) noexcept
|
||||||
: handle(handle), level(level) {
|
: handle(handle), level(level) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,11 +70,11 @@ private:
|
|||||||
TargetBufferInfo mInfos[MAX_SUPPORTED_RENDER_TARGET_COUNT];
|
TargetBufferInfo mInfos[MAX_SUPPORTED_RENDER_TARGET_COUNT];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TargetBufferInfo const& operator[](size_t const i) const noexcept {
|
TargetBufferInfo const& operator[](size_t i) const noexcept {
|
||||||
return mInfos[i];
|
return mInfos[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetBufferInfo& operator[](size_t const i) noexcept {
|
TargetBufferInfo& operator[](size_t i) noexcept {
|
||||||
return mInfos[i];
|
return mInfos[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,40 +39,18 @@ public:
|
|||||||
Driver* createDriver(void* sharedContext, const Platform::DriverConfig& driverConfig) noexcept override;
|
Driver* createDriver(void* sharedContext, const Platform::DriverConfig& driverConfig) noexcept override;
|
||||||
int getOSVersion() const noexcept override { return 0; }
|
int getOSVersion() const noexcept override { return 0; }
|
||||||
|
|
||||||
/**
|
|
||||||
* Optionally initializes the Metal platform by acquiring resources necessary for rendering.
|
|
||||||
*
|
|
||||||
* This method attempts to acquire a Metal device and command queue, returning true if both are
|
|
||||||
* successfully obtained, or false otherwise. Typically, these objects are acquired when
|
|
||||||
* the Metal backend is initialized. This method allows clients to check for their availability
|
|
||||||
* earlier.
|
|
||||||
*
|
|
||||||
* Calling initialize() is optional and safe to do so multiple times. After initialize() returns
|
|
||||||
* true, subsequent calls will continue to return true but have no effect.
|
|
||||||
*
|
|
||||||
* initialize() must be called from the main thread.
|
|
||||||
*
|
|
||||||
* @returns true if the device and command queue have been successfully obtained; false
|
|
||||||
* otherwise.
|
|
||||||
*/
|
|
||||||
bool initialize() noexcept;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain the preferred Metal device object for the backend to use.
|
* Obtain the preferred Metal device object for the backend to use.
|
||||||
*
|
*
|
||||||
* On desktop platforms, there may be multiple GPUs suitable for rendering, and this method is
|
* On desktop platforms, there may be multiple GPUs suitable for rendering, and this method is
|
||||||
* free to decide which one to use. On mobile systems with a single GPU, implementations should
|
* free to decide which one to use. On mobile systems with a single GPU, implementations should
|
||||||
* simply return the result of MTLCreateSystemDefaultDevice();
|
* simply return the result of MTLCreateSystemDefaultDevice();
|
||||||
*
|
|
||||||
* createDevice is called by the Metal backend from the backend thread.
|
|
||||||
*/
|
*/
|
||||||
virtual void createDevice(MetalDevice& outDevice) noexcept;
|
virtual void createDevice(MetalDevice& outDevice) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a command submission queue on the Metal device object.
|
* Create a command submission queue on the Metal device object.
|
||||||
*
|
*
|
||||||
* createCommandQueue is called by the Metal backend from the backend thread.
|
|
||||||
*
|
|
||||||
* @param device The device which was returned from createDevice()
|
* @param device The device which was returned from createDevice()
|
||||||
*/
|
*/
|
||||||
virtual void createCommandQueue(
|
virtual void createCommandQueue(
|
||||||
@@ -82,8 +60,6 @@ public:
|
|||||||
* Obtain a MTLCommandBuffer enqueued on this Platform's MTLCommandQueue. The command buffer is
|
* Obtain a MTLCommandBuffer enqueued on this Platform's MTLCommandQueue. The command buffer is
|
||||||
* guaranteed to execute before all subsequent command buffers created either by Filament, or
|
* guaranteed to execute before all subsequent command buffers created either by Filament, or
|
||||||
* further calls to this method.
|
* further calls to this method.
|
||||||
*
|
|
||||||
* createAndEnqueueCommandBuffer must be called from the main thread.
|
|
||||||
*/
|
*/
|
||||||
void createAndEnqueueCommandBuffer(MetalCommandBuffer& outCommandBuffer) noexcept;
|
void createAndEnqueueCommandBuffer(MetalCommandBuffer& outCommandBuffer) noexcept;
|
||||||
|
|
||||||
@@ -92,8 +68,6 @@ public:
|
|||||||
*
|
*
|
||||||
* Each frame rendered requires a CAMetalDrawable texture, which is presented on-screen at the
|
* Each frame rendered requires a CAMetalDrawable texture, which is presented on-screen at the
|
||||||
* completion of each frame. These are limited and provided round-robin style by the system.
|
* completion of each frame. These are limited and provided round-robin style by the system.
|
||||||
*
|
|
||||||
* setDrawableFailureBehavior must be called from the main thread.
|
|
||||||
*/
|
*/
|
||||||
enum class DrawableFailureBehavior : uint8_t {
|
enum class DrawableFailureBehavior : uint8_t {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -27,11 +27,8 @@
|
|||||||
#include <utils/Hash.h>
|
#include <utils/Hash.h>
|
||||||
#include <utils/PrivateImplementation.h>
|
#include <utils/PrivateImplementation.h>
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <functional>
|
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -297,16 +294,6 @@ public:
|
|||||||
VkQueue getProtectedGraphicsQueue() const noexcept;
|
VkQueue getProtectedGraphicsQueue() const noexcept;
|
||||||
|
|
||||||
struct ExternalImageMetadata {
|
struct ExternalImageMetadata {
|
||||||
/**
|
|
||||||
* The Filament texture format.
|
|
||||||
*/
|
|
||||||
TextureFormat filamentFormat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Filament texture usage.
|
|
||||||
*/
|
|
||||||
TextureUsage filamentUsage;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The width of the external image
|
* The width of the external image
|
||||||
*/
|
*/
|
||||||
@@ -317,6 +304,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The layerCount of the external image
|
||||||
|
*/
|
||||||
|
uint32_t layerCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The layer count of the external image
|
* The layer count of the external image
|
||||||
*/
|
*/
|
||||||
@@ -332,6 +324,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
VkFormat format;
|
VkFormat format;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An external buffer can be protected. This tells you if it is.
|
||||||
|
*/
|
||||||
|
bool isProtected;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of external format (opaque int) if used.
|
* The type of external format (opaque int) if used.
|
||||||
*/
|
*/
|
||||||
@@ -351,61 +348,20 @@ public:
|
|||||||
* Heap information
|
* Heap information
|
||||||
*/
|
*/
|
||||||
uint32_t memoryTypeBits;
|
uint32_t memoryTypeBits;
|
||||||
|
|
||||||
/**
|
|
||||||
* Ycbcr conversion components
|
|
||||||
*/
|
|
||||||
VkComponentMapping ycbcrConversionComponents;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ycbcr model
|
|
||||||
*/
|
|
||||||
VkSamplerYcbcrModelConversion ycbcrModel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ycbcr range
|
|
||||||
*/
|
|
||||||
VkSamplerYcbcrRange ycbcrRange;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ycbcr x chroma offset
|
|
||||||
*/
|
|
||||||
VkChromaLocation xChromaOffset;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ycbcr y chroma offset
|
|
||||||
*/
|
|
||||||
VkChromaLocation yChromaOffset;
|
|
||||||
};
|
};
|
||||||
|
virtual ExternalImageMetadata getExternalImageMetadata(ExternalImageHandleRef externalImage);
|
||||||
|
|
||||||
|
using ImageData = std::pair<VkImage, VkDeviceMemory>;
|
||||||
|
virtual ImageData createExternalImageData(ExternalImageHandleRef externalImage,
|
||||||
|
const ExternalImageMetadata& metadata, uint32_t memoryTypeIndex,
|
||||||
|
VkImageUsageFlags usage);
|
||||||
|
|
||||||
// Note that the image metadata might change per-frame, hence we need a method for extracting
|
virtual VkSampler createExternalSampler(SamplerYcbcrConversion chroma,
|
||||||
// it.
|
SamplerParams sampler, uint32_t internalFormat);
|
||||||
virtual ExternalImageMetadata extractExternalImageMetadata(ExternalImageHandleRef image) const {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ImageData {
|
virtual VkImageView createExternalImageView(SamplerYcbcrConversion chroma,
|
||||||
struct Bundle {
|
uint32_t internalFormat, VkImage image, VkImageSubresourceRange range,
|
||||||
VkImage image = VK_NULL_HANDLE;
|
VkImageViewType viewType, VkComponentMapping swizzle);
|
||||||
VkDeviceMemory memory = VK_NULL_HANDLE;
|
|
||||||
|
|
||||||
inline bool valid() const noexcept {
|
|
||||||
return image != VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// It's possible for the external image to also have a known VK format. We need to create an
|
|
||||||
// image for that in case we are not looking to use an external "sampler" with this image.
|
|
||||||
Bundle internal;
|
|
||||||
|
|
||||||
// If we get a externalFormat in the metadata, then we should create an image with
|
|
||||||
// VK_FORMAT_UNDEFINED
|
|
||||||
Bundle external;
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual ImageData createVkImageFromExternal(ExternalImageHandleRef image) const {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ExtensionSet getSwapchainInstanceExtensions() const;
|
virtual ExtensionSet getSwapchainInstanceExtensions() const;
|
||||||
@@ -418,6 +374,20 @@ private:
|
|||||||
// Platform dependent helper methods
|
// Platform dependent helper methods
|
||||||
static ExtensionSet getSwapchainInstanceExtensionsImpl();
|
static ExtensionSet getSwapchainInstanceExtensionsImpl();
|
||||||
|
|
||||||
|
static ExternalImageMetadata getExternalImageMetadataImpl(ExternalImageHandleRef externalImage,
|
||||||
|
VkDevice device);
|
||||||
|
|
||||||
|
static ImageData createExternalImageDataImpl(ExternalImageHandleRef externalImage,
|
||||||
|
VkDevice device, const ExternalImageMetadata& metadata, uint32_t memoryTypeIndex,
|
||||||
|
VkImageUsageFlags usage);
|
||||||
|
static VkSampler createExternalSamplerImpl(VkDevice device,
|
||||||
|
SamplerYcbcrConversion chroma, SamplerParams sampler,
|
||||||
|
uint32_t internalFormat);
|
||||||
|
static VkImageView createExternalImageViewImpl(VkDevice device,
|
||||||
|
SamplerYcbcrConversion chroma, uint32_t internalFormat, VkImage image,
|
||||||
|
VkImageSubresourceRange range, VkImageViewType viewType,
|
||||||
|
VkComponentMapping swizzle);
|
||||||
|
|
||||||
// Platform dependent helper methods
|
// Platform dependent helper methods
|
||||||
static SurfaceBundle createVkSurfaceKHRImpl(void* nativeWindow, VkInstance instance,
|
static SurfaceBundle createVkSurfaceKHRImpl(void* nativeWindow, VkInstance instance,
|
||||||
uint64_t flags) noexcept;
|
uint64_t flags) noexcept;
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace filament::backend {
|
|||||||
|
|
||||||
class VulkanPlatformAndroid : public VulkanPlatform {
|
class VulkanPlatformAndroid : public VulkanPlatform {
|
||||||
public:
|
public:
|
||||||
ExternalImageHandle UTILS_PUBLIC createExternalImage(AHardwareBuffer const* buffer,
|
Platform::ExternalImageHandle UTILS_PUBLIC createExternalImage(AHardwareBuffer const* buffer,
|
||||||
bool sRGB) noexcept;
|
bool sRGB) noexcept;
|
||||||
|
|
||||||
struct UTILS_PUBLIC ExternalImageDescAndroid {
|
struct UTILS_PUBLIC ExternalImageDescAndroid {
|
||||||
@@ -39,26 +39,31 @@ public:
|
|||||||
ExternalImageDescAndroid UTILS_PUBLIC getExternalImageDesc(
|
ExternalImageDescAndroid UTILS_PUBLIC getExternalImageDesc(
|
||||||
ExternalImageHandleRef externalImage) const noexcept;
|
ExternalImageHandleRef externalImage) const noexcept;
|
||||||
|
|
||||||
virtual ExternalImageMetadata extractExternalImageMetadata(
|
|
||||||
ExternalImageHandleRef image) const override;
|
|
||||||
|
|
||||||
virtual ImageData createVkImageFromExternal(ExternalImageHandleRef image) const override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ExtensionSet getSwapchainInstanceExtensions() const override;
|
|
||||||
|
|
||||||
using SurfaceBundle = VulkanPlatform::SurfaceBundle;
|
|
||||||
virtual SurfaceBundle createVkSurfaceKHR(void* nativeWindow, VkInstance instance,
|
|
||||||
uint64_t flags) const noexcept override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
struct ExternalImageVulkanAndroid : public Platform::ExternalImage {
|
struct ExternalImageVulkanAndroid : public Platform::ExternalImage {
|
||||||
AHardwareBuffer* aHardwareBuffer = nullptr;
|
AHardwareBuffer* aHardwareBuffer = nullptr;
|
||||||
bool sRGB = false;
|
bool sRGB = false;
|
||||||
|
unsigned int width; // Texture width
|
||||||
|
unsigned int height; // Texture height
|
||||||
|
TextureFormat format;// Texture format
|
||||||
|
TextureUsage usage; // Texture usage flags
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
~ExternalImageVulkanAndroid() override;
|
~ExternalImageVulkanAndroid() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
virtual ExternalImageMetadata getExternalImageMetadata(ExternalImageHandleRef externalImage);
|
||||||
|
|
||||||
|
using ImageData = VulkanPlatform::ImageData;
|
||||||
|
virtual ImageData createExternalImageData(ExternalImageHandleRef externalImage,
|
||||||
|
const ExternalImageMetadata& metadata, uint32_t memoryTypeIndex,
|
||||||
|
VkImageUsageFlags usage);
|
||||||
|
|
||||||
|
virtual ExtensionSet getSwapchainInstanceExtensions() const;
|
||||||
|
|
||||||
|
using SurfaceBundle = VulkanPlatform::SurfaceBundle;
|
||||||
|
virtual SurfaceBundle createVkSurfaceKHR(void* nativeWindow, VkInstance instance,
|
||||||
|
uint64_t flags) const noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
}// namespace filament::backend
|
}// namespace filament::backend
|
||||||
|
|||||||
@@ -18,8 +18,6 @@
|
|||||||
|
|
||||||
#include "DataReshaper.h"
|
#include "DataReshaper.h"
|
||||||
|
|
||||||
#include <backend/DriverEnums.h>
|
|
||||||
|
|
||||||
#include <utils/CString.h>
|
#include <utils/CString.h>
|
||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
@@ -225,143 +223,6 @@ size_t getFormatSize(TextureFormat format) noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureType getTextureType(TextureFormat const format) noexcept {
|
|
||||||
switch (format) {
|
|
||||||
case TextureFormat::UNUSED:
|
|
||||||
// should not happen
|
|
||||||
return TextureType::FLOAT;
|
|
||||||
|
|
||||||
case TextureFormat::R8:
|
|
||||||
case TextureFormat::R16F:
|
|
||||||
case TextureFormat::RG8:
|
|
||||||
case TextureFormat::RGB565:
|
|
||||||
case TextureFormat::RGB5_A1:
|
|
||||||
case TextureFormat::RGBA4:
|
|
||||||
case TextureFormat::R32F:
|
|
||||||
case TextureFormat::RGB8:
|
|
||||||
case TextureFormat::SRGB8:
|
|
||||||
case TextureFormat::RG16F:
|
|
||||||
case TextureFormat::R11F_G11F_B10F:
|
|
||||||
case TextureFormat::RGB9_E5:
|
|
||||||
case TextureFormat::RGBA8:
|
|
||||||
case TextureFormat::SRGB8_A8:
|
|
||||||
case TextureFormat::RGB10_A2:
|
|
||||||
case TextureFormat::RGB16F:
|
|
||||||
case TextureFormat::RG32F:
|
|
||||||
case TextureFormat::RGBA16F:
|
|
||||||
case TextureFormat::RGB32F:
|
|
||||||
case TextureFormat::RGBA32F:
|
|
||||||
return TextureType::FLOAT;
|
|
||||||
|
|
||||||
case TextureFormat::R8_SNORM:
|
|
||||||
case TextureFormat::RG8_SNORM:
|
|
||||||
case TextureFormat::RGB8_SNORM:
|
|
||||||
case TextureFormat::RGBA8_SNORM:
|
|
||||||
// SNORM are treated as float
|
|
||||||
return TextureType::FLOAT;
|
|
||||||
|
|
||||||
case TextureFormat::R8UI:
|
|
||||||
case TextureFormat::R16UI:
|
|
||||||
case TextureFormat::RG8UI:
|
|
||||||
case TextureFormat::RGB8UI:
|
|
||||||
case TextureFormat::R32UI:
|
|
||||||
case TextureFormat::RG16UI:
|
|
||||||
case TextureFormat::RGBA8UI:
|
|
||||||
case TextureFormat::RGB16UI:
|
|
||||||
case TextureFormat::RG32UI:
|
|
||||||
case TextureFormat::RGBA16UI:
|
|
||||||
case TextureFormat::RGB32UI:
|
|
||||||
case TextureFormat::RGBA32UI:
|
|
||||||
return TextureType::UINT;
|
|
||||||
|
|
||||||
case TextureFormat::R8I:
|
|
||||||
case TextureFormat::R16I:
|
|
||||||
case TextureFormat::RG8I:
|
|
||||||
case TextureFormat::RGB8I:
|
|
||||||
case TextureFormat::R32I:
|
|
||||||
case TextureFormat::RG16I:
|
|
||||||
case TextureFormat::RGBA8I:
|
|
||||||
case TextureFormat::RGB16I:
|
|
||||||
case TextureFormat::RG32I:
|
|
||||||
case TextureFormat::RGBA16I:
|
|
||||||
case TextureFormat::RGB32I:
|
|
||||||
case TextureFormat::RGBA32I:
|
|
||||||
return TextureType::INT;
|
|
||||||
|
|
||||||
case TextureFormat::DEPTH16:
|
|
||||||
case TextureFormat::DEPTH24:
|
|
||||||
case TextureFormat::DEPTH32F:
|
|
||||||
return TextureType::DEPTH;
|
|
||||||
|
|
||||||
case TextureFormat::STENCIL8:
|
|
||||||
return TextureType::STENCIL;
|
|
||||||
|
|
||||||
case TextureFormat::DEPTH24_STENCIL8:
|
|
||||||
case TextureFormat::DEPTH32F_STENCIL8:
|
|
||||||
return TextureType::DEPTH_STENCIL;
|
|
||||||
|
|
||||||
// Compressed formats ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
case TextureFormat::EAC_RG11:
|
|
||||||
case TextureFormat::EAC_RG11_SIGNED:
|
|
||||||
case TextureFormat::ETC2_EAC_RGBA8:
|
|
||||||
case TextureFormat::ETC2_EAC_SRGBA8:
|
|
||||||
case TextureFormat::EAC_R11:
|
|
||||||
case TextureFormat::EAC_R11_SIGNED:
|
|
||||||
case TextureFormat::ETC2_RGB8:
|
|
||||||
case TextureFormat::ETC2_SRGB8:
|
|
||||||
case TextureFormat::ETC2_RGB8_A1:
|
|
||||||
case TextureFormat::ETC2_SRGB8_A1:
|
|
||||||
case TextureFormat::DXT1_RGB:
|
|
||||||
case TextureFormat::DXT1_RGBA:
|
|
||||||
case TextureFormat::DXT1_SRGB:
|
|
||||||
case TextureFormat::DXT1_SRGBA:
|
|
||||||
case TextureFormat::DXT3_RGBA:
|
|
||||||
case TextureFormat::DXT3_SRGBA:
|
|
||||||
case TextureFormat::DXT5_RGBA:
|
|
||||||
case TextureFormat::DXT5_SRGBA:
|
|
||||||
case TextureFormat::RED_RGTC1:
|
|
||||||
case TextureFormat::SIGNED_RED_RGTC1:
|
|
||||||
case TextureFormat::RED_GREEN_RGTC2:
|
|
||||||
case TextureFormat::SIGNED_RED_GREEN_RGTC2:
|
|
||||||
case TextureFormat::RGB_BPTC_SIGNED_FLOAT:
|
|
||||||
case TextureFormat::RGB_BPTC_UNSIGNED_FLOAT:
|
|
||||||
case TextureFormat::RGBA_BPTC_UNORM:
|
|
||||||
case TextureFormat::SRGB_ALPHA_BPTC_UNORM:
|
|
||||||
case TextureFormat::RGBA_ASTC_4x4:
|
|
||||||
case TextureFormat::RGBA_ASTC_5x4:
|
|
||||||
case TextureFormat::RGBA_ASTC_5x5:
|
|
||||||
case TextureFormat::RGBA_ASTC_6x5:
|
|
||||||
case TextureFormat::RGBA_ASTC_6x6:
|
|
||||||
case TextureFormat::RGBA_ASTC_8x5:
|
|
||||||
case TextureFormat::RGBA_ASTC_8x6:
|
|
||||||
case TextureFormat::RGBA_ASTC_8x8:
|
|
||||||
case TextureFormat::RGBA_ASTC_10x5:
|
|
||||||
case TextureFormat::RGBA_ASTC_10x6:
|
|
||||||
case TextureFormat::RGBA_ASTC_10x8:
|
|
||||||
case TextureFormat::RGBA_ASTC_10x10:
|
|
||||||
case TextureFormat::RGBA_ASTC_12x10:
|
|
||||||
case TextureFormat::RGBA_ASTC_12x12:
|
|
||||||
case TextureFormat::SRGB8_ALPHA8_ASTC_4x4:
|
|
||||||
case TextureFormat::SRGB8_ALPHA8_ASTC_5x4:
|
|
||||||
case TextureFormat::SRGB8_ALPHA8_ASTC_5x5:
|
|
||||||
case TextureFormat::SRGB8_ALPHA8_ASTC_6x5:
|
|
||||||
case TextureFormat::SRGB8_ALPHA8_ASTC_6x6:
|
|
||||||
case TextureFormat::SRGB8_ALPHA8_ASTC_8x5:
|
|
||||||
case TextureFormat::SRGB8_ALPHA8_ASTC_8x6:
|
|
||||||
case TextureFormat::SRGB8_ALPHA8_ASTC_8x8:
|
|
||||||
case TextureFormat::SRGB8_ALPHA8_ASTC_10x5:
|
|
||||||
case TextureFormat::SRGB8_ALPHA8_ASTC_10x6:
|
|
||||||
case TextureFormat::SRGB8_ALPHA8_ASTC_10x8:
|
|
||||||
case TextureFormat::SRGB8_ALPHA8_ASTC_10x10:
|
|
||||||
case TextureFormat::SRGB8_ALPHA8_ASTC_12x10:
|
|
||||||
case TextureFormat::SRGB8_ALPHA8_ASTC_12x12:
|
|
||||||
return TextureType::FLOAT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TextureType::FLOAT;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t getFormatComponentCount(TextureFormat format) noexcept {
|
size_t getFormatComponentCount(TextureFormat format) noexcept {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case TextureFormat::R8:
|
case TextureFormat::R8:
|
||||||
|
|||||||
@@ -18,13 +18,12 @@
|
|||||||
#include "private/backend/CircularBuffer.h"
|
#include "private/backend/CircularBuffer.h"
|
||||||
#include "private/backend/CommandStream.h"
|
#include "private/backend/CommandStream.h"
|
||||||
|
|
||||||
#include <private/utils/Tracing.h>
|
|
||||||
|
|
||||||
#include <utils/compiler.h>
|
#include <utils/compiler.h>
|
||||||
#include <utils/Log.h>
|
#include <utils/Log.h>
|
||||||
#include <utils/Mutex.h>
|
#include <utils/Mutex.h>
|
||||||
#include <utils/ostream.h>
|
#include <utils/ostream.h>
|
||||||
#include <utils/Panic.h>
|
#include <utils/Panic.h>
|
||||||
|
#include <utils/Systrace.h>
|
||||||
#include <utils/debug.h>
|
#include <utils/debug.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -80,7 +79,7 @@ bool CommandBufferQueue::isExitRequested() const {
|
|||||||
|
|
||||||
|
|
||||||
void CommandBufferQueue::flush() noexcept {
|
void CommandBufferQueue::flush() noexcept {
|
||||||
FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_CALL();
|
||||||
|
|
||||||
CircularBuffer& circularBuffer = mCircularBuffer;
|
CircularBuffer& circularBuffer = mCircularBuffer;
|
||||||
if (circularBuffer.empty()) {
|
if (circularBuffer.empty()) {
|
||||||
@@ -130,7 +129,7 @@ void CommandBufferQueue::flush() noexcept {
|
|||||||
mHighWatermark = std::max(mHighWatermark, totalUsed);
|
mHighWatermark = std::max(mHighWatermark, totalUsed);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FILAMENT_TRACING_NAME(FILAMENT_TRACING_CATEGORY_FILAMENT, "waiting: CircularBuffer::flush()");
|
SYSTRACE_NAME("waiting: CircularBuffer::flush()");
|
||||||
|
|
||||||
FILAMENT_CHECK_POSTCONDITION(!mPaused) <<
|
FILAMENT_CHECK_POSTCONDITION(!mPaused) <<
|
||||||
"CommandStream is full, but since the rendering thread is paused, "
|
"CommandStream is full, but since the rendering thread is paused, "
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
#include "private/backend/CommandStream.h"
|
#include "private/backend/CommandStream.h"
|
||||||
|
|
||||||
#include <private/utils/Tracing.h>
|
|
||||||
|
|
||||||
#if DEBUG_COMMAND_STREAM
|
#if DEBUG_COMMAND_STREAM
|
||||||
#include <utils/CallStack.h>
|
#include <utils/CallStack.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -26,6 +24,7 @@
|
|||||||
#include <utils/Log.h>
|
#include <utils/Log.h>
|
||||||
#include <utils/ostream.h>
|
#include <utils/ostream.h>
|
||||||
#include <utils/Profiler.h>
|
#include <utils/Profiler.h>
|
||||||
|
#include <utils/Systrace.h>
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -80,13 +79,12 @@ CommandStream::CommandStream(Driver& driver, CircularBuffer& buffer) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CommandStream::execute(void* buffer) {
|
void CommandStream::execute(void* buffer) {
|
||||||
// NOTE: we can't use FILAMENT_TRACING_CALL() or similar here because, execute() below, also
|
// NOTE: we can't use SYSTRACE_CALL() or similar here because, execute() below, also
|
||||||
// uses systrace BEGIN/END and the END is not guaranteed to be happening in this scope.
|
// uses systrace BEGIN/END and the END is not guaranteed to be happening in this scope.
|
||||||
|
|
||||||
Profiler profiler;
|
Profiler profiler;
|
||||||
|
|
||||||
|
if constexpr (SYSTRACE_TAG) {
|
||||||
if constexpr (FILAMENT_TRACING_ENABLED) {
|
|
||||||
if (UTILS_UNLIKELY(mUsePerformanceCounter)) {
|
if (UTILS_UNLIKELY(mUsePerformanceCounter)) {
|
||||||
// we want to remove all this when tracing is completely disabled
|
// we want to remove all this when tracing is completely disabled
|
||||||
profiler.resetEvents(Profiler::EV_CPU_CYCLES | Profiler::EV_BPU_MISSES);
|
profiler.resetEvents(Profiler::EV_CPU_CYCLES | Profiler::EV_BPU_MISSES);
|
||||||
@@ -102,17 +100,17 @@ void CommandStream::execute(void* buffer) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if constexpr (FILAMENT_TRACING_ENABLED) {
|
if constexpr (SYSTRACE_TAG) {
|
||||||
if (UTILS_UNLIKELY(mUsePerformanceCounter)) {
|
if (UTILS_UNLIKELY(mUsePerformanceCounter)) {
|
||||||
// we want to remove all this when tracing is completely disabled
|
// we want to remove all this when tracing is completely disabled
|
||||||
profiler.stop();
|
profiler.stop();
|
||||||
UTILS_UNUSED Profiler::Counters const counters = profiler.readCounters();
|
UTILS_UNUSED Profiler::Counters const counters = profiler.readCounters();
|
||||||
FILAMENT_TRACING_CONTEXT(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_CONTEXT();
|
||||||
FILAMENT_TRACING_VALUE(FILAMENT_TRACING_CATEGORY_FILAMENT, "GLThread (I)", counters.getInstructions());
|
SYSTRACE_VALUE32("GLThread (I)", counters.getInstructions());
|
||||||
FILAMENT_TRACING_VALUE(FILAMENT_TRACING_CATEGORY_FILAMENT, "GLThread (C)", counters.getCpuCycles());
|
SYSTRACE_VALUE32("GLThread (C)", counters.getCpuCycles());
|
||||||
FILAMENT_TRACING_VALUE(FILAMENT_TRACING_CATEGORY_FILAMENT, "GLThread (CPI x10)", counters.getCPI() * 10);
|
SYSTRACE_VALUE32("GLThread (CPI x10)", counters.getCPI() * 10);
|
||||||
FILAMENT_TRACING_VALUE(FILAMENT_TRACING_CATEGORY_FILAMENT, "GLThread (BPU miss)", counters.getBranchMisses());
|
SYSTRACE_VALUE32("GLThread (BPU miss)", counters.getBranchMisses());
|
||||||
FILAMENT_TRACING_VALUE(FILAMENT_TRACING_CATEGORY_FILAMENT, "GLThread (I / BPU miss)",
|
SYSTRACE_VALUE32("GLThread (I / BPU miss)",
|
||||||
counters.getInstructions() / counters.getBranchMisses());
|
counters.getInstructions() / counters.getBranchMisses());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,8 @@
|
|||||||
#include "private/backend/Driver.h"
|
#include "private/backend/Driver.h"
|
||||||
#include "private/backend/CommandStream.h"
|
#include "private/backend/CommandStream.h"
|
||||||
|
|
||||||
#include <private/utils/Tracing.h>
|
|
||||||
|
|
||||||
#include <utils/compiler.h>
|
#include <utils/compiler.h>
|
||||||
|
#include <utils/Systrace.h>
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
@@ -39,7 +38,7 @@
|
|||||||
#if DEBUG_LEVEL == DEBUG_LEVEL_NONE
|
#if DEBUG_LEVEL == DEBUG_LEVEL_NONE
|
||||||
# define SYSTRACE()
|
# define SYSTRACE()
|
||||||
#elif DEBUG_LEVEL == DEBUG_LEVEL_SYSTRACE
|
#elif DEBUG_LEVEL == DEBUG_LEVEL_SYSTRACE
|
||||||
# define SYSTRACE() FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
# define SYSTRACE() SYSTRACE_CALL();
|
||||||
#else
|
#else
|
||||||
# error "invalid debug level"
|
# error "invalid debug level"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#include "CompilerThreadPool.h"
|
#include "CompilerThreadPool.h"
|
||||||
|
|
||||||
#include <private/utils/Tracing.h>
|
#include <utils/Systrace.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ void CompilerThreadPool::init(uint32_t threadCount,
|
|||||||
|
|
||||||
for (size_t i = 0; i < threadCount; i++) {
|
for (size_t i = 0; i < threadCount; i++) {
|
||||||
mCompilerThreads.emplace_back([this, setup, cleanup]() {
|
mCompilerThreads.emplace_back([this, setup, cleanup]() {
|
||||||
FILAMENT_TRACING_CONTEXT(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_CONTEXT();
|
||||||
|
|
||||||
(*setup)();
|
(*setup)();
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ void CompilerThreadPool::init(uint32_t threadCount,
|
|||||||
[](auto&& q) { return q.empty(); }));
|
[](auto&& q) { return q.empty(); }));
|
||||||
});
|
});
|
||||||
|
|
||||||
FILAMENT_TRACING_VALUE(FILAMENT_TRACING_CATEGORY_FILAMENT, "CompilerThreadPool Jobs",
|
SYSTRACE_VALUE32("CompilerThreadPool Jobs",
|
||||||
mQueues[0].size() + mQueues[1].size());
|
mQueues[0].size() + mQueues[1].size());
|
||||||
|
|
||||||
if (UTILS_LIKELY(!mExitRequested)) {
|
if (UTILS_LIKELY(!mExitRequested)) {
|
||||||
|
|||||||
@@ -23,12 +23,11 @@
|
|||||||
#include <backend/BufferDescriptor.h>
|
#include <backend/BufferDescriptor.h>
|
||||||
#include <backend/DriverEnums.h>
|
#include <backend/DriverEnums.h>
|
||||||
|
|
||||||
#include <private/utils/Tracing.h>
|
|
||||||
|
|
||||||
#include <utils/compiler.h>
|
#include <utils/compiler.h>
|
||||||
#include <utils/debug.h>
|
#include <utils/debug.h>
|
||||||
#include <utils/Log.h>
|
#include <utils/Log.h>
|
||||||
#include <utils/ostream.h>
|
#include <utils/ostream.h>
|
||||||
|
#include <utils/Systrace.h>
|
||||||
|
|
||||||
#include <math/half.h>
|
#include <math/half.h>
|
||||||
#include <math/vec2.h>
|
#include <math/vec2.h>
|
||||||
@@ -152,31 +151,30 @@ void DriverBase::debugCommandBegin(CommandStream* cmds, bool synchronous, const
|
|||||||
utils::slog.d << methodName << utils::io::endl;
|
utils::slog.d << methodName << utils::io::endl;
|
||||||
}
|
}
|
||||||
if constexpr (bool(FILAMENT_DEBUG_COMMANDS & FILAMENT_DEBUG_COMMANDS_SYSTRACE)) {
|
if constexpr (bool(FILAMENT_DEBUG_COMMANDS & FILAMENT_DEBUG_COMMANDS_SYSTRACE)) {
|
||||||
FILAMENT_TRACING_CONTEXT(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_CONTEXT();
|
||||||
FILAMENT_TRACING_NAME_BEGIN(FILAMENT_TRACING_CATEGORY_FILAMENT, methodName);
|
SYSTRACE_NAME_BEGIN(methodName);
|
||||||
|
|
||||||
if (!synchronous) {
|
if (!synchronous) {
|
||||||
cmds->queueCommand([=]() {
|
cmds->queueCommand([=]() {
|
||||||
FILAMENT_TRACING_CONTEXT(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_CONTEXT();
|
||||||
FILAMENT_TRACING_NAME_BEGIN(FILAMENT_TRACING_CATEGORY_FILAMENT, methodName);
|
SYSTRACE_NAME_BEGIN(methodName);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DriverBase::debugCommandEnd(CommandStream* cmds, bool synchronous,
|
void DriverBase::debugCommandEnd(CommandStream* cmds, bool synchronous, const char* methodName) noexcept {
|
||||||
const char* methodName) noexcept {
|
|
||||||
if constexpr (bool(FILAMENT_DEBUG_COMMANDS > FILAMENT_DEBUG_COMMANDS_NONE)) {
|
if constexpr (bool(FILAMENT_DEBUG_COMMANDS > FILAMENT_DEBUG_COMMANDS_NONE)) {
|
||||||
if constexpr (bool(FILAMENT_DEBUG_COMMANDS & FILAMENT_DEBUG_COMMANDS_SYSTRACE)) {
|
if constexpr (bool(FILAMENT_DEBUG_COMMANDS & FILAMENT_DEBUG_COMMANDS_SYSTRACE)) {
|
||||||
if (!synchronous) {
|
if (!synchronous) {
|
||||||
cmds->queueCommand([]() {
|
cmds->queueCommand([]() {
|
||||||
FILAMENT_TRACING_CONTEXT(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_CONTEXT();
|
||||||
FILAMENT_TRACING_NAME_END(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_NAME_END();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
FILAMENT_TRACING_CONTEXT(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_CONTEXT();
|
||||||
FILAMENT_TRACING_NAME_END(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_NAME_END();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
#include <backend/Platform.h>
|
#include <backend/Platform.h>
|
||||||
|
|
||||||
#include <utils/compiler.h>
|
#include <utils/compiler.h>
|
||||||
#include <utils/ostream.h>
|
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|||||||
@@ -16,8 +16,7 @@
|
|||||||
|
|
||||||
#include <private/backend/PlatformFactory.h>
|
#include <private/backend/PlatformFactory.h>
|
||||||
|
|
||||||
#include <private/utils/Tracing.h>
|
#include <utils/Systrace.h>
|
||||||
|
|
||||||
#include <utils/debug.h>
|
#include <utils/debug.h>
|
||||||
|
|
||||||
// We need to keep this up top for the linux (X11) name collisions.
|
// We need to keep this up top for the linux (X11) name collisions.
|
||||||
@@ -86,7 +85,7 @@ namespace filament::backend {
|
|||||||
// responsible for destroying it. Initialization of the backend API is deferred until
|
// responsible for destroying it. Initialization of the backend API is deferred until
|
||||||
// createDriver(). The passed-in backend hint is replaced with the resolved backend.
|
// createDriver(). The passed-in backend hint is replaced with the resolved backend.
|
||||||
Platform* PlatformFactory::create(Backend* backend) noexcept {
|
Platform* PlatformFactory::create(Backend* backend) noexcept {
|
||||||
FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_CALL();
|
||||||
assert_invariant(backend);
|
assert_invariant(backend);
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
#ifndef TNT_FILAMENT_BACKEND_SYSTRACEPROFILE_H
|
#ifndef TNT_FILAMENT_BACKEND_SYSTRACEPROFILE_H
|
||||||
#define TNT_FILAMENT_BACKEND_SYSTRACEPROFILE_H
|
#define TNT_FILAMENT_BACKEND_SYSTRACEPROFILE_H
|
||||||
|
|
||||||
#include <private/utils/Tracing.h>
|
#include <utils/Systrace.h>
|
||||||
|
|
||||||
#define PROFILE_SCOPE(marker) SYSTRACE_NAME(marker)
|
#define PROFILE_SCOPE(marker) SYSTRACE_NAME(marker)
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
#include "MetalContext.h"
|
#include "MetalContext.h"
|
||||||
|
|
||||||
#include <utils/Panic.h>
|
|
||||||
|
|
||||||
namespace filament {
|
namespace filament {
|
||||||
namespace backend {
|
namespace backend {
|
||||||
|
|
||||||
|
|||||||
@@ -672,8 +672,22 @@ void MetalDriver::createTimerQueryR(Handle<HwTimerQuery> tqh, int) {
|
|||||||
// nothing to do, timer query was constructed in createTimerQueryS
|
// nothing to do, timer query was constructed in createTimerQueryS
|
||||||
}
|
}
|
||||||
|
|
||||||
UTILS_UNUSED
|
const char* toString(DescriptorType type) {
|
||||||
static const char* toString(ShaderStageFlags flags) {
|
switch (type) {
|
||||||
|
case DescriptorType::UNIFORM_BUFFER:
|
||||||
|
return "UNIFORM_BUFFER";
|
||||||
|
case DescriptorType::SHADER_STORAGE_BUFFER:
|
||||||
|
return "SHADER_STORAGE_BUFFER";
|
||||||
|
case DescriptorType::SAMPLER:
|
||||||
|
return "SAMPLER";
|
||||||
|
case DescriptorType::INPUT_ATTACHMENT:
|
||||||
|
return "INPUT_ATTACHMENT";
|
||||||
|
case DescriptorType::SAMPLER_EXTERNAL:
|
||||||
|
return "SAMPLER_EXTERNAL";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* toString(ShaderStageFlags flags) {
|
||||||
std::vector<const char*> stages;
|
std::vector<const char*> stages;
|
||||||
if (any(flags & ShaderStageFlags::VERTEX)) {
|
if (any(flags & ShaderStageFlags::VERTEX)) {
|
||||||
stages.push_back("VERTEX");
|
stages.push_back("VERTEX");
|
||||||
@@ -707,25 +721,15 @@ const char* toString(DescriptorFlags flags) {
|
|||||||
|
|
||||||
void MetalDriver::createDescriptorSetLayoutR(
|
void MetalDriver::createDescriptorSetLayoutR(
|
||||||
Handle<HwDescriptorSetLayout> dslh, DescriptorSetLayout&& info) {
|
Handle<HwDescriptorSetLayout> dslh, DescriptorSetLayout&& info) {
|
||||||
#if FILAMENT_METAL_DEBUG_LOG == 1
|
|
||||||
const char* labelStr = "";
|
|
||||||
std::visit([&labelStr](auto&& arg) {
|
|
||||||
using T = std::decay_t<decltype(arg)>;
|
|
||||||
if constexpr (std::is_same_v<T, utils::CString> || std::is_same_v<T, utils::StaticString>) {
|
|
||||||
labelStr = arg.c_str();
|
|
||||||
}
|
|
||||||
}, info.label);
|
|
||||||
std::sort(info.bindings.begin(), info.bindings.end(),
|
std::sort(info.bindings.begin(), info.bindings.end(),
|
||||||
[](const auto& a, const auto& b) { return a.binding < b.binding; });
|
[](const auto& a, const auto& b) { return a.binding < b.binding; });
|
||||||
DEBUG_LOG("createDescriptorSetLayoutR(dslh = %d, info = { label = %s,\n", dslh.getId(),
|
DEBUG_LOG("createDescriptorSetLayoutR(dslh = %d, info = {\n", dslh.getId());
|
||||||
labelStr);
|
|
||||||
for (size_t i = 0; i < info.bindings.size(); i++) {
|
for (size_t i = 0; i < info.bindings.size(); i++) {
|
||||||
DEBUG_LOG(" {binding = %d, type = %s, count = %d, stage = %s, flags = %s},\n",
|
DEBUG_LOG(" {binding = %d, type = %s, count = %d, stage = %s, flags = %s},\n",
|
||||||
info.bindings[i].binding, toString(info.bindings[i].type), info.bindings[i].count,
|
info.bindings[i].binding, toString(info.bindings[i].type), info.bindings[i].count,
|
||||||
toString(info.bindings[i].stageFlags), toString(info.bindings[i].flags));
|
toString(info.bindings[i].stageFlags), toString(info.bindings[i].flags));
|
||||||
}
|
}
|
||||||
DEBUG_LOG("})\n");
|
DEBUG_LOG("})\n");
|
||||||
#endif
|
|
||||||
construct_handle<MetalDescriptorSetLayout>(dslh, std::move(info));
|
construct_handle<MetalDescriptorSetLayout>(dslh, std::move(info));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1404,8 +1408,8 @@ void MetalDriver::setRenderPrimitiveBuffer(Handle<HwRenderPrimitive> rph, Primit
|
|||||||
auto primitive = handle_cast<MetalRenderPrimitive>(rph);
|
auto primitive = handle_cast<MetalRenderPrimitive>(rph);
|
||||||
auto vertexBuffer = handle_cast<MetalVertexBuffer>(vbh);
|
auto vertexBuffer = handle_cast<MetalVertexBuffer>(vbh);
|
||||||
auto indexBuffer = handle_cast<MetalIndexBuffer>(ibh);
|
auto indexBuffer = handle_cast<MetalIndexBuffer>(ibh);
|
||||||
primitive->vertexBuffer = vertexBuffer;
|
MetalVertexBufferInfo const* const vbi = handle_cast<MetalVertexBufferInfo>(vertexBuffer->vbih);
|
||||||
primitive->indexBuffer = indexBuffer;
|
primitive->setBuffers(vbi, vertexBuffer, indexBuffer);
|
||||||
primitive->type = pt;
|
primitive->type = pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -185,7 +185,6 @@ inline MTLPixelFormat getMetalFormat(PixelDataFormat format, PixelDataType type)
|
|||||||
CONVERT(RGBA_INTEGER, UINT, RGBA32Uint);
|
CONVERT(RGBA_INTEGER, UINT, RGBA32Uint);
|
||||||
CONVERT(RGBA_INTEGER, INT, RGBA32Sint);
|
CONVERT(RGBA_INTEGER, INT, RGBA32Sint);
|
||||||
CONVERT(RGBA, FLOAT, RGBA32Float);
|
CONVERT(RGBA, FLOAT, RGBA32Float);
|
||||||
CONVERT(DEPTH_COMPONENT, FLOAT, Depth32Float);
|
|
||||||
#undef CONVERT
|
#undef CONVERT
|
||||||
|
|
||||||
return MTLPixelFormatInvalid;
|
return MTLPixelFormatInvalid;
|
||||||
|
|||||||
@@ -194,8 +194,12 @@ struct MetalIndexBuffer : public HwIndexBuffer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct MetalRenderPrimitive : public HwRenderPrimitive {
|
struct MetalRenderPrimitive : public HwRenderPrimitive {
|
||||||
|
MetalRenderPrimitive();
|
||||||
|
void setBuffers(MetalVertexBufferInfo const* const vbi,
|
||||||
|
MetalVertexBuffer* vertexBuffer, MetalIndexBuffer* indexBuffer);
|
||||||
// The pointers to MetalVertexBuffer and MetalIndexBuffer are "weak".
|
// The pointers to MetalVertexBuffer and MetalIndexBuffer are "weak".
|
||||||
// The MetalVertexBuffer and MetalIndexBuffer must outlive the MetalRenderPrimitive.
|
// The MetalVertexBuffer and MetalIndexBuffer must outlive the MetalRenderPrimitive.
|
||||||
|
|
||||||
MetalVertexBuffer* vertexBuffer = nullptr;
|
MetalVertexBuffer* vertexBuffer = nullptr;
|
||||||
MetalIndexBuffer* indexBuffer = nullptr;
|
MetalIndexBuffer* indexBuffer = nullptr;
|
||||||
};
|
};
|
||||||
@@ -376,6 +380,7 @@ public:
|
|||||||
|
|
||||||
math::uint2 getAttachmentSize() noexcept;
|
math::uint2 getAttachmentSize() noexcept;
|
||||||
|
|
||||||
|
bool isDefaultRenderTarget() const { return defaultRenderTarget; }
|
||||||
uint8_t getSamples() const { return samples; }
|
uint8_t getSamples() const { return samples; }
|
||||||
|
|
||||||
Attachment getDrawColorAttachment(size_t index);
|
Attachment getDrawColorAttachment(size_t index);
|
||||||
|
|||||||
@@ -536,6 +536,15 @@ MetalIndexBuffer::MetalIndexBuffer(MetalContext& context, BufferUsage usage, uin
|
|||||||
uint32_t indexCount) : HwIndexBuffer(elementSize, indexCount),
|
uint32_t indexCount) : HwIndexBuffer(elementSize, indexCount),
|
||||||
buffer(context, BufferObjectBinding::VERTEX, usage, elementSize * indexCount, true) { }
|
buffer(context, BufferObjectBinding::VERTEX, usage, elementSize * indexCount, true) { }
|
||||||
|
|
||||||
|
MetalRenderPrimitive::MetalRenderPrimitive() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void MetalRenderPrimitive::setBuffers(MetalVertexBufferInfo const* const vbi,
|
||||||
|
MetalVertexBuffer* vertexBuffer, MetalIndexBuffer* indexBuffer) {
|
||||||
|
this->vertexBuffer = vertexBuffer;
|
||||||
|
this->indexBuffer = indexBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
MetalProgram::MetalProgram(MetalContext& context, Program&& program) noexcept
|
MetalProgram::MetalProgram(MetalContext& context, Program&& program) noexcept
|
||||||
: HwProgram(program.getName()), mContext(context) {
|
: HwProgram(program.getName()), mContext(context) {
|
||||||
mToken = context.shaderCompiler->createProgram(program.getName(), std::move(program));
|
mToken = context.shaderCompiler->createProgram(program.getName(), std::move(program));
|
||||||
@@ -1356,31 +1365,7 @@ id<MTLArgumentEncoder> MetalDescriptorSetLayout::getArgumentEncoderSlow(id<MTLDe
|
|||||||
[arguments addObject:bufferArgument];
|
[arguments addObject:bufferArgument];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DescriptorType::SAMPLER_2D_FLOAT:
|
case DescriptorType::SAMPLER:
|
||||||
case DescriptorType::SAMPLER_2D_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_DEPTH:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_DEPTH:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_INT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_UINT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_DEPTH:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_INT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_UINT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_DEPTH:
|
|
||||||
case DescriptorType::SAMPLER_3D_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_3D_INT:
|
|
||||||
case DescriptorType::SAMPLER_3D_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_UINT:
|
|
||||||
case DescriptorType::SAMPLER_EXTERNAL: {
|
case DescriptorType::SAMPLER_EXTERNAL: {
|
||||||
MTLArgumentDescriptor* textureArgument = [MTLArgumentDescriptor argumentDescriptor];
|
MTLArgumentDescriptor* textureArgument = [MTLArgumentDescriptor argumentDescriptor];
|
||||||
textureArgument.index = binding.binding * 2;
|
textureArgument.index = binding.binding * 2;
|
||||||
@@ -1406,9 +1391,6 @@ id<MTLArgumentEncoder> MetalDescriptorSetLayout::getArgumentEncoderSlow(id<MTLDe
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (arguments.count == 0) {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
return [device newArgumentEncoderWithArguments:arguments];
|
return [device newArgumentEncoderWithArguments:arguments];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1469,9 +1451,6 @@ id<MTLBuffer> MetalDescriptorSet::finalizeAndGetBuffer(MetalDriver* driver, Shad
|
|||||||
|
|
||||||
id<MTLArgumentEncoder> encoder =
|
id<MTLArgumentEncoder> encoder =
|
||||||
layout->getArgumentEncoder(context.device, stage, textureTypes);
|
layout->getArgumentEncoder(context.device, stage, textureTypes);
|
||||||
if (!encoder) {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
ScopedAllocationTimer timer("descriptor_set");
|
ScopedAllocationTimer timer("descriptor_set");
|
||||||
@@ -1502,31 +1481,7 @@ id<MTLBuffer> MetalDescriptorSet::finalizeAndGetBuffer(MetalDriver* driver, Shad
|
|||||||
atIndex:binding.binding * 2];
|
atIndex:binding.binding * 2];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DescriptorType::SAMPLER_2D_FLOAT:
|
case DescriptorType::SAMPLER:
|
||||||
case DescriptorType::SAMPLER_2D_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_DEPTH:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_DEPTH:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_INT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_UINT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_DEPTH:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_INT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_UINT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_DEPTH:
|
|
||||||
case DescriptorType::SAMPLER_3D_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_3D_INT:
|
|
||||||
case DescriptorType::SAMPLER_3D_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_UINT:
|
|
||||||
case DescriptorType::SAMPLER_EXTERNAL: {
|
case DescriptorType::SAMPLER_EXTERNAL: {
|
||||||
auto found = textures.find(binding.binding);
|
auto found = textures.find(binding.binding);
|
||||||
if (found == textures.end()) {
|
if (found == textures.end()) {
|
||||||
|
|||||||
@@ -20,18 +20,17 @@
|
|||||||
#include <Metal/Metal.h>
|
#include <Metal/Metal.h>
|
||||||
|
|
||||||
#include "private/backend/Driver.h"
|
#include "private/backend/Driver.h"
|
||||||
|
#include "backend/Program.h"
|
||||||
|
|
||||||
#include <backend/DriverEnums.h>
|
#include <backend/DriverEnums.h>
|
||||||
#include <backend/Program.h>
|
|
||||||
|
|
||||||
#include <utils/bitset.h>
|
|
||||||
#include <utils/FixedCapacityVector.h>
|
#include <utils/FixedCapacityVector.h>
|
||||||
#include <utils/Hash.h>
|
|
||||||
#include <utils/Invocable.h>
|
|
||||||
|
|
||||||
#include <tsl/robin_map.h>
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <tsl/robin_map.h>
|
||||||
|
|
||||||
|
#include <utils/Hash.h>
|
||||||
|
#include <utils/Invocable.h>
|
||||||
|
|
||||||
namespace filament {
|
namespace filament {
|
||||||
namespace backend {
|
namespace backend {
|
||||||
|
|||||||
@@ -24,22 +24,14 @@
|
|||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
namespace filament::backend {
|
namespace filament::backend {
|
||||||
|
|
||||||
struct PlatformMetalImpl {
|
struct PlatformMetalImpl {
|
||||||
std::mutex mLock; // locks mDevice and mCommandQueue
|
|
||||||
id<MTLDevice> mDevice = nil;
|
|
||||||
id<MTLCommandQueue> mCommandQueue = nil;
|
id<MTLCommandQueue> mCommandQueue = nil;
|
||||||
|
|
||||||
// read form driver thread, read/written to from client thread
|
// read form driver thread, read/written to from client thread
|
||||||
std::atomic<PlatformMetal::DrawableFailureBehavior> mDrawableFailureBehavior =
|
std::atomic<PlatformMetal::DrawableFailureBehavior> mDrawableFailureBehavior =
|
||||||
PlatformMetal::DrawableFailureBehavior::PANIC;
|
PlatformMetal::DrawableFailureBehavior::PANIC;
|
||||||
|
|
||||||
// These methods must be called with mLock held
|
|
||||||
void createDeviceImpl(MetalDevice& outDevice);
|
|
||||||
void createCommandQueueImpl(MetalDevice& device, MetalCommandQueue& outCommandQueue);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Platform* createDefaultMetalPlatform() {
|
Platform* createDefaultMetalPlatform() {
|
||||||
@@ -53,65 +45,10 @@ PlatformMetal::~PlatformMetal() noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Driver* PlatformMetal::createDriver(void* /*sharedContext*/, const Platform::DriverConfig& driverConfig) noexcept {
|
Driver* PlatformMetal::createDriver(void* /*sharedContext*/, const Platform::DriverConfig& driverConfig) noexcept {
|
||||||
pImpl->mDrawableFailureBehavior = driverConfig.metalDisablePanicOnDrawableFailure
|
|
||||||
? DrawableFailureBehavior::ABORT_FRAME
|
|
||||||
: DrawableFailureBehavior::PANIC;
|
|
||||||
return MetalDriverFactory::create(this, driverConfig);
|
return MetalDriverFactory::create(this, driverConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PlatformMetal::initialize() noexcept {
|
|
||||||
std::lock_guard<std::mutex> lock(pImpl->mLock);
|
|
||||||
|
|
||||||
MetalDevice device{};
|
|
||||||
pImpl->createDeviceImpl(device);
|
|
||||||
if (device.device == nil) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
MetalCommandQueue commandQueue{};
|
|
||||||
pImpl->createCommandQueueImpl(device, commandQueue);
|
|
||||||
if (commandQueue.commandQueue == nil) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlatformMetal::createDevice(MetalDevice& outDevice) noexcept {
|
void PlatformMetal::createDevice(MetalDevice& outDevice) noexcept {
|
||||||
std::lock_guard<std::mutex> lock(pImpl->mLock);
|
|
||||||
pImpl->createDeviceImpl(outDevice);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlatformMetal::createCommandQueue(
|
|
||||||
MetalDevice& device, MetalCommandQueue& outCommandQueue) noexcept {
|
|
||||||
std::lock_guard<std::mutex> lock(pImpl->mLock);
|
|
||||||
pImpl->createCommandQueueImpl(device, outCommandQueue);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlatformMetal::createAndEnqueueCommandBuffer(MetalCommandBuffer& outCommandBuffer) noexcept {
|
|
||||||
std::lock_guard<std::mutex> lock(pImpl->mLock);
|
|
||||||
id<MTLCommandBuffer> commandBuffer = [pImpl->mCommandQueue commandBuffer];
|
|
||||||
[commandBuffer enqueue];
|
|
||||||
outCommandBuffer.commandBuffer = commandBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlatformMetal::setDrawableFailureBehavior(DrawableFailureBehavior behavior) noexcept {
|
|
||||||
pImpl->mDrawableFailureBehavior = behavior;
|
|
||||||
}
|
|
||||||
|
|
||||||
PlatformMetal::DrawableFailureBehavior PlatformMetal::getDrawableFailureBehavior() const noexcept {
|
|
||||||
return pImpl->mDrawableFailureBehavior;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void PlatformMetalImpl::createDeviceImpl(MetalDevice& outDevice) {
|
|
||||||
if (mDevice) {
|
|
||||||
outDevice.device = mDevice;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
id<MTLDevice> result;
|
id<MTLDevice> result;
|
||||||
|
|
||||||
#if !defined(FILAMENT_IOS)
|
#if !defined(FILAMENT_IOS)
|
||||||
@@ -137,17 +74,27 @@ void PlatformMetalImpl::createDeviceImpl(MetalDevice& outDevice) {
|
|||||||
<< utils::io::endl;
|
<< utils::io::endl;
|
||||||
|
|
||||||
outDevice.device = result;
|
outDevice.device = result;
|
||||||
mDevice = result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlatformMetalImpl::createCommandQueueImpl(MetalDevice& device, MetalCommandQueue& outCommandQueue) {
|
void PlatformMetal::createCommandQueue(
|
||||||
if (mCommandQueue) {
|
MetalDevice& device, MetalCommandQueue& outCommandQueue) noexcept {
|
||||||
outCommandQueue.commandQueue = mCommandQueue;
|
pImpl->mCommandQueue = [device.device newCommandQueue];
|
||||||
return;
|
pImpl->mCommandQueue.label = @"Filament";
|
||||||
}
|
outCommandQueue.commandQueue = pImpl->mCommandQueue;
|
||||||
mCommandQueue = [device.device newCommandQueue];
|
}
|
||||||
mCommandQueue.label = @"Filament";
|
|
||||||
outCommandQueue.commandQueue = mCommandQueue;
|
void PlatformMetal::createAndEnqueueCommandBuffer(MetalCommandBuffer& outCommandBuffer) noexcept {
|
||||||
|
id<MTLCommandBuffer> commandBuffer = [pImpl->mCommandQueue commandBuffer];
|
||||||
|
[commandBuffer enqueue];
|
||||||
|
outCommandBuffer.commandBuffer = commandBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlatformMetal::setDrawableFailureBehavior(DrawableFailureBehavior behavior) noexcept {
|
||||||
|
pImpl->mDrawableFailureBehavior = behavior;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlatformMetal::DrawableFailureBehavior PlatformMetal::getDrawableFailureBehavior() const noexcept {
|
||||||
|
return pImpl->mDrawableFailureBehavior;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace filament
|
} // namespace filament
|
||||||
|
|||||||
@@ -69,8 +69,9 @@ public:
|
|||||||
assert_invariant(set < MAX_DESCRIPTOR_SET_COUNT);
|
assert_invariant(set < MAX_DESCRIPTOR_SET_COUNT);
|
||||||
assert_invariant(binding < MAX_DESCRIPTOR_COUNT);
|
assert_invariant(binding < MAX_DESCRIPTOR_COUNT);
|
||||||
assert_invariant(entry.binding < 128); // we reserve 1 bit for the type right now
|
assert_invariant(entry.binding < 128); // we reserve 1 bit for the type right now
|
||||||
mStorage[set][binding] = { uint8_t(entry.binding),
|
mStorage[set][binding] = { (uint8_t)entry.binding,
|
||||||
DescriptorSetLayoutBinding::isSampler(entry.type) };
|
entry.type == DescriptorType::SAMPLER ||
|
||||||
|
entry.type == DescriptorType::SAMPLER_EXTERNAL };
|
||||||
mActiveDescriptors[set].set(binding);
|
mActiveDescriptors[set].set(binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,32 +95,7 @@ GLDescriptorSet::GLDescriptorSet(OpenGLContext& gl, DescriptorSetLayoutHandle ds
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case DescriptorType::SAMPLER:
|
||||||
case DescriptorType::SAMPLER_2D_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_DEPTH:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_ARRAY_DEPTH:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_INT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_UINT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_DEPTH:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_INT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_UINT:
|
|
||||||
case DescriptorType::SAMPLER_CUBE_ARRAY_DEPTH:
|
|
||||||
case DescriptorType::SAMPLER_3D_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_3D_INT:
|
|
||||||
case DescriptorType::SAMPLER_3D_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_UINT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_FLOAT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_INT:
|
|
||||||
case DescriptorType::SAMPLER_2D_MS_ARRAY_UINT:
|
|
||||||
case DescriptorType::SAMPLER_EXTERNAL:
|
case DescriptorType::SAMPLER_EXTERNAL:
|
||||||
if (UTILS_UNLIKELY(gl.isES2())) {
|
if (UTILS_UNLIKELY(gl.isES2())) {
|
||||||
desc.emplace<SamplerGLES2>();
|
desc.emplace<SamplerGLES2>();
|
||||||
@@ -162,11 +137,8 @@ void GLDescriptorSet::update(OpenGLContext&,
|
|||||||
}, descriptors[binding].desc);
|
}, descriptors[binding].desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLDescriptorSet::update(OpenGLContext& gl, HandleAllocatorGL& handleAllocator,
|
void GLDescriptorSet::update(OpenGLContext& gl,
|
||||||
descriptor_binding_t binding, TextureHandle th, SamplerParams params) noexcept {
|
descriptor_binding_t binding, GLTexture* t, SamplerParams params) noexcept {
|
||||||
|
|
||||||
GLTexture* t = th ? handleAllocator.handle_cast<GLTexture*>(th) : nullptr;
|
|
||||||
|
|
||||||
assert_invariant(binding < descriptors.size());
|
assert_invariant(binding < descriptors.size());
|
||||||
std::visit([=, &gl](auto&& arg) mutable {
|
std::visit([=, &gl](auto&& arg) mutable {
|
||||||
using T = std::decay_t<decltype(arg)>;
|
using T = std::decay_t<decltype(arg)>;
|
||||||
@@ -199,12 +171,20 @@ void GLDescriptorSet::update(OpenGLContext& gl, HandleAllocatorGL& handleAllocat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
arg.handle = th;
|
arg.target = t ? t->gl.target : 0;
|
||||||
|
arg.id = t ? t->gl.id : 0;
|
||||||
|
arg.external = t ? t->gl.external : false;
|
||||||
if constexpr (std::is_same_v<T, Sampler> ||
|
if constexpr (std::is_same_v<T, Sampler> ||
|
||||||
std::is_same_v<T, SamplerWithAnisotropyWorkaround>) {
|
std::is_same_v<T, SamplerWithAnisotropyWorkaround>) {
|
||||||
if constexpr (std::is_same_v<T, SamplerWithAnisotropyWorkaround>) {
|
if constexpr (std::is_same_v<T, SamplerWithAnisotropyWorkaround>) {
|
||||||
arg.anisotropy = float(1u << params.anisotropyLog2);
|
arg.anisotropy = float(1u << params.anisotropyLog2);
|
||||||
}
|
}
|
||||||
|
if (t) {
|
||||||
|
arg.ref = t->ref;
|
||||||
|
arg.baseLevel = t->gl.baseLevel;
|
||||||
|
arg.maxLevel = t->gl.maxLevel;
|
||||||
|
arg.swizzle = t->gl.swizzle;
|
||||||
|
}
|
||||||
#ifndef FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2
|
#ifndef FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2
|
||||||
arg.sampler = gl.getSampler(params);
|
arg.sampler = gl.getSampler(params);
|
||||||
#else
|
#else
|
||||||
@@ -220,39 +200,39 @@ void GLDescriptorSet::update(OpenGLContext& gl, HandleAllocatorGL& handleAllocat
|
|||||||
}, descriptors[binding].desc);
|
}, descriptors[binding].desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
void GLDescriptorSet::updateTextureView(OpenGLContext& gl,
|
void GLDescriptorSet::updateTextureView(OpenGLContext& gl,
|
||||||
HandleAllocatorGL& handleAllocator, GLuint unit, GLTexture const* t) noexcept {
|
HandleAllocatorGL& handleAllocator, GLuint unit, T const& desc) noexcept {
|
||||||
// The common case is that we don't have a ref handle (we only have one if
|
// The common case is that we don't have a ref handle (we only have one if
|
||||||
// the texture ever had a View on it).
|
// the texture ever had a View on it).
|
||||||
assert_invariant(t);
|
assert_invariant(desc.ref);
|
||||||
assert_invariant(t->ref);
|
GLTextureRef* const ref = handleAllocator.handle_cast<GLTextureRef*>(desc.ref);
|
||||||
GLTextureRef* const ref = handleAllocator.handle_cast<GLTextureRef*>(t->ref);
|
if (UTILS_UNLIKELY((desc.baseLevel != ref->baseLevel || desc.maxLevel != ref->maxLevel))) {
|
||||||
if (UTILS_UNLIKELY((t->gl.baseLevel != ref->baseLevel || t->gl.maxLevel != ref->maxLevel))) {
|
|
||||||
// If we have views, then it's still uncommon that we'll switch often
|
// If we have views, then it's still uncommon that we'll switch often
|
||||||
// handle the case where we reset to the original texture
|
// handle the case where we reset to the original texture
|
||||||
GLint baseLevel = GLint(t->gl.baseLevel); // NOLINT(*-signed-char-misuse)
|
GLint baseLevel = GLint(desc.baseLevel); // NOLINT(*-signed-char-misuse)
|
||||||
GLint maxLevel = GLint(t->gl.maxLevel); // NOLINT(*-signed-char-misuse)
|
GLint maxLevel = GLint(desc.maxLevel); // NOLINT(*-signed-char-misuse)
|
||||||
if (baseLevel > maxLevel) {
|
if (baseLevel > maxLevel) {
|
||||||
baseLevel = 0;
|
baseLevel = 0;
|
||||||
maxLevel = 1000; // per OpenGL spec
|
maxLevel = 1000; // per OpenGL spec
|
||||||
}
|
}
|
||||||
// that is very unfortunate that we have to call activeTexture here
|
// that is very unfortunate that we have to call activeTexture here
|
||||||
gl.activeTexture(unit);
|
gl.activeTexture(unit);
|
||||||
glTexParameteri(t->gl.target, GL_TEXTURE_BASE_LEVEL, baseLevel);
|
glTexParameteri(desc.target, GL_TEXTURE_BASE_LEVEL, baseLevel);
|
||||||
glTexParameteri(t->gl.target, GL_TEXTURE_MAX_LEVEL, maxLevel);
|
glTexParameteri(desc.target, GL_TEXTURE_MAX_LEVEL, maxLevel);
|
||||||
ref->baseLevel = t->gl.baseLevel;
|
ref->baseLevel = desc.baseLevel;
|
||||||
ref->maxLevel = t->gl.maxLevel;
|
ref->maxLevel = desc.maxLevel;
|
||||||
}
|
}
|
||||||
if (UTILS_UNLIKELY(t->gl.swizzle != ref->swizzle)) {
|
if (UTILS_UNLIKELY(desc.swizzle != ref->swizzle)) {
|
||||||
using namespace GLUtils;
|
using namespace GLUtils;
|
||||||
gl.activeTexture(unit);
|
gl.activeTexture(unit);
|
||||||
#if !defined(__EMSCRIPTEN__) && !defined(FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2)
|
#if !defined(__EMSCRIPTEN__) && !defined(FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2)
|
||||||
glTexParameteri(t->gl.target, GL_TEXTURE_SWIZZLE_R, (GLint)getSwizzleChannel(t->gl.swizzle[0]));
|
glTexParameteri(desc.target, GL_TEXTURE_SWIZZLE_R, (GLint)getSwizzleChannel(desc.swizzle[0]));
|
||||||
glTexParameteri(t->gl.target, GL_TEXTURE_SWIZZLE_G, (GLint)getSwizzleChannel(t->gl.swizzle[1]));
|
glTexParameteri(desc.target, GL_TEXTURE_SWIZZLE_G, (GLint)getSwizzleChannel(desc.swizzle[1]));
|
||||||
glTexParameteri(t->gl.target, GL_TEXTURE_SWIZZLE_B, (GLint)getSwizzleChannel(t->gl.swizzle[2]));
|
glTexParameteri(desc.target, GL_TEXTURE_SWIZZLE_B, (GLint)getSwizzleChannel(desc.swizzle[2]));
|
||||||
glTexParameteri(t->gl.target, GL_TEXTURE_SWIZZLE_A, (GLint)getSwizzleChannel(t->gl.swizzle[3]));
|
glTexParameteri(desc.target, GL_TEXTURE_SWIZZLE_A, (GLint)getSwizzleChannel(desc.swizzle[3]));
|
||||||
#endif
|
#endif
|
||||||
ref->swizzle = t->gl.swizzle;
|
ref->swizzle = desc.swizzle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,31 +285,27 @@ void GLDescriptorSet::bind(
|
|||||||
}
|
}
|
||||||
} else if constexpr (std::is_same_v<T, Sampler>) {
|
} else if constexpr (std::is_same_v<T, Sampler>) {
|
||||||
GLuint const unit = p.getTextureUnit(set, binding);
|
GLuint const unit = p.getTextureUnit(set, binding);
|
||||||
|
if (arg.target) {
|
||||||
|
gl.bindTexture(unit, arg.target, arg.id, arg.external);
|
||||||
if (arg.handle) {
|
|
||||||
GLTexture const* const t = handleAllocator.handle_cast<GLTexture*>(arg.handle);
|
|
||||||
gl.bindTexture(unit, t->gl.target, t->gl.id, t->gl.external);
|
|
||||||
gl.bindSampler(unit, arg.sampler);
|
gl.bindSampler(unit, arg.sampler);
|
||||||
if (UTILS_UNLIKELY(t->ref)) {
|
if (UTILS_UNLIKELY(arg.ref)) {
|
||||||
updateTextureView(gl, handleAllocator, unit, t);
|
updateTextureView(gl, handleAllocator, unit, arg);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
gl.unbindTextureUnit(unit);
|
gl.unbindTextureUnit(unit);
|
||||||
}
|
}
|
||||||
} else if constexpr (std::is_same_v<T, SamplerWithAnisotropyWorkaround>) {
|
} else if constexpr (std::is_same_v<T, SamplerWithAnisotropyWorkaround>) {
|
||||||
GLuint const unit = p.getTextureUnit(set, binding);
|
GLuint const unit = p.getTextureUnit(set, binding);
|
||||||
if (arg.handle) {
|
if (arg.target) {
|
||||||
GLTexture const* const t = handleAllocator.handle_cast<GLTexture*>(arg.handle);
|
gl.bindTexture(unit, arg.target, arg.id, arg.external);
|
||||||
gl.bindTexture(unit, t->gl.target, t->gl.id, t->gl.external);
|
|
||||||
gl.bindSampler(unit, arg.sampler);
|
gl.bindSampler(unit, arg.sampler);
|
||||||
if (UTILS_UNLIKELY(t->ref)) {
|
if (UTILS_UNLIKELY(arg.ref)) {
|
||||||
updateTextureView(gl, handleAllocator, unit, t);
|
updateTextureView(gl, handleAllocator, unit, arg);
|
||||||
}
|
}
|
||||||
#if defined(GL_EXT_texture_filter_anisotropic)
|
#if defined(GL_EXT_texture_filter_anisotropic)
|
||||||
// Driver claims to support anisotropic filtering, but it fails when set on
|
// Driver claims to support anisotropic filtering, but it fails when set on
|
||||||
// the sampler, we have to set it on the texture instead.
|
// the sampler, we have to set it on the texture instead.
|
||||||
glTexParameterf(t->gl.target, GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
glTexParameterf(arg.target, GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
||||||
std::min(gl.gets.max_anisotropy, float(arg.anisotropy)));
|
std::min(gl.gets.max_anisotropy, float(arg.anisotropy)));
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
@@ -338,20 +314,19 @@ void GLDescriptorSet::bind(
|
|||||||
} else if constexpr (std::is_same_v<T, SamplerGLES2>) {
|
} else if constexpr (std::is_same_v<T, SamplerGLES2>) {
|
||||||
// in ES2 the sampler parameters need to be set on the texture itself
|
// in ES2 the sampler parameters need to be set on the texture itself
|
||||||
GLuint const unit = p.getTextureUnit(set, binding);
|
GLuint const unit = p.getTextureUnit(set, binding);
|
||||||
if (arg.handle) {
|
if (arg.target) {
|
||||||
GLTexture const* const t = handleAllocator.handle_cast<GLTexture*>(arg.handle);
|
gl.bindTexture(unit, arg.target, arg.id, arg.external);
|
||||||
gl.bindTexture(unit, t->gl.target, t->gl.id, t->gl.external);
|
|
||||||
SamplerParams const params = arg.params;
|
SamplerParams const params = arg.params;
|
||||||
glTexParameteri(t->gl.target, GL_TEXTURE_MIN_FILTER,
|
glTexParameteri(arg.target, GL_TEXTURE_MIN_FILTER,
|
||||||
(GLint)GLUtils::getTextureFilter(params.filterMin));
|
(GLint)GLUtils::getTextureFilter(params.filterMin));
|
||||||
glTexParameteri(t->gl.target, GL_TEXTURE_MAG_FILTER,
|
glTexParameteri(arg.target, GL_TEXTURE_MAG_FILTER,
|
||||||
(GLint)GLUtils::getTextureFilter(params.filterMag));
|
(GLint)GLUtils::getTextureFilter(params.filterMag));
|
||||||
glTexParameteri(t->gl.target, GL_TEXTURE_WRAP_S,
|
glTexParameteri(arg.target, GL_TEXTURE_WRAP_S,
|
||||||
(GLint)GLUtils::getWrapMode(params.wrapS));
|
(GLint)GLUtils::getWrapMode(params.wrapS));
|
||||||
glTexParameteri(t->gl.target, GL_TEXTURE_WRAP_T,
|
glTexParameteri(arg.target, GL_TEXTURE_WRAP_T,
|
||||||
(GLint)GLUtils::getWrapMode(params.wrapT));
|
(GLint)GLUtils::getWrapMode(params.wrapT));
|
||||||
#if defined(GL_EXT_texture_filter_anisotropic)
|
#if defined(GL_EXT_texture_filter_anisotropic)
|
||||||
glTexParameterf(t->gl.target, GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
glTexParameterf(arg.target, GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
||||||
std::min(gl.gets.max_anisotropy, arg.anisotropy));
|
std::min(gl.gets.max_anisotropy, arg.anisotropy));
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ struct GLDescriptorSet : public HwDescriptorSet {
|
|||||||
descriptor_binding_t binding, GLBufferObject* bo, size_t offset, size_t size) noexcept;
|
descriptor_binding_t binding, GLBufferObject* bo, size_t offset, size_t size) noexcept;
|
||||||
|
|
||||||
// update a sampler descriptor in the set
|
// update a sampler descriptor in the set
|
||||||
void update(OpenGLContext& gl, HandleAllocatorGL& handleAllocator,
|
void update(OpenGLContext& gl,
|
||||||
descriptor_binding_t binding, TextureHandle th, SamplerParams params) noexcept;
|
descriptor_binding_t binding, GLTexture* t, SamplerParams params) noexcept;
|
||||||
|
|
||||||
// conceptually bind the set to the command buffer
|
// conceptually bind the set to the command buffer
|
||||||
void bind(
|
void bind(
|
||||||
@@ -111,19 +111,46 @@ private:
|
|||||||
|
|
||||||
// A sampler descriptor
|
// A sampler descriptor
|
||||||
struct Sampler {
|
struct Sampler {
|
||||||
TextureHandle handle; // 4
|
uint16_t target; // 2 (GLenum)
|
||||||
|
bool external = false; // 1
|
||||||
|
bool reserved = false; // 1
|
||||||
|
GLuint id = 0; // 4
|
||||||
GLuint sampler = 0; // 4
|
GLuint sampler = 0; // 4
|
||||||
|
Handle<GLTextureRef> ref; // 4
|
||||||
|
int8_t baseLevel = 0x7f; // 1
|
||||||
|
int8_t maxLevel = -1; // 1
|
||||||
|
std::array<TextureSwizzle, 4> swizzle{ // 4
|
||||||
|
TextureSwizzle::CHANNEL_0,
|
||||||
|
TextureSwizzle::CHANNEL_1,
|
||||||
|
TextureSwizzle::CHANNEL_2,
|
||||||
|
TextureSwizzle::CHANNEL_3
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SamplerWithAnisotropyWorkaround {
|
struct SamplerWithAnisotropyWorkaround {
|
||||||
TextureHandle handle; // 4
|
uint16_t target; // 2 (GLenum)
|
||||||
|
bool external = false; // 1
|
||||||
|
bool reserved = false; // 1
|
||||||
|
GLuint id = 0; // 4
|
||||||
GLuint sampler = 0; // 4
|
GLuint sampler = 0; // 4
|
||||||
|
Handle<GLTextureRef> ref; // 4
|
||||||
math::half anisotropy = 1.0f; // 2
|
math::half anisotropy = 1.0f; // 2
|
||||||
|
int8_t baseLevel = 0x7f; // 1
|
||||||
|
int8_t maxLevel = -1; // 1
|
||||||
|
std::array<TextureSwizzle, 4> swizzle{ // 4
|
||||||
|
TextureSwizzle::CHANNEL_0,
|
||||||
|
TextureSwizzle::CHANNEL_1,
|
||||||
|
TextureSwizzle::CHANNEL_2,
|
||||||
|
TextureSwizzle::CHANNEL_3
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// A sampler descriptor for ES2
|
// A sampler descriptor for ES2
|
||||||
struct SamplerGLES2 {
|
struct SamplerGLES2 {
|
||||||
TextureHandle handle; // 4
|
uint16_t target; // 2 (GLenum)
|
||||||
|
bool external = false; // 1
|
||||||
|
bool reserved = false; // 1
|
||||||
|
GLuint id = 0; // 4
|
||||||
SamplerParams params{}; // 4
|
SamplerParams params{}; // 4
|
||||||
float anisotropy = 1.0f; // 4
|
float anisotropy = 1.0f; // 4
|
||||||
};
|
};
|
||||||
@@ -138,8 +165,9 @@ private:
|
|||||||
};
|
};
|
||||||
static_assert(sizeof(Descriptor) <= 32);
|
static_assert(sizeof(Descriptor) <= 32);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
static void updateTextureView(OpenGLContext& gl,
|
static void updateTextureView(OpenGLContext& gl,
|
||||||
HandleAllocatorGL& handleAllocator, GLuint unit, GLTexture const* t) noexcept;
|
HandleAllocatorGL& handleAllocator, GLuint unit, T const& desc) noexcept;
|
||||||
|
|
||||||
utils::FixedCapacityVector<Descriptor> descriptors; // 16
|
utils::FixedCapacityVector<Descriptor> descriptors; // 16
|
||||||
utils::bitset64 dynamicBuffers; // 8
|
utils::bitset64 dynamicBuffers; // 8
|
||||||
|
|||||||
@@ -16,15 +16,9 @@
|
|||||||
|
|
||||||
#include "GLUtils.h"
|
#include "GLUtils.h"
|
||||||
|
|
||||||
#include "private/backend/Driver.h"
|
|
||||||
|
|
||||||
#include <utils/compiler.h>
|
|
||||||
#include <utils/ostream.h>
|
|
||||||
#include <utils/trap.h>
|
#include <utils/trap.h>
|
||||||
|
|
||||||
#include <string_view>
|
#include "private/backend/Driver.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
namespace filament::backend {
|
namespace filament::backend {
|
||||||
|
|
||||||
@@ -34,31 +28,38 @@ using namespace utils;
|
|||||||
namespace GLUtils {
|
namespace GLUtils {
|
||||||
|
|
||||||
UTILS_NOINLINE
|
UTILS_NOINLINE
|
||||||
std::string_view getGLErrorString(GLenum error) noexcept {
|
const char* getGLError(GLenum error) noexcept {
|
||||||
|
const char* string = "unknown";
|
||||||
switch (error) {
|
switch (error) {
|
||||||
case GL_NO_ERROR:
|
case GL_NO_ERROR:
|
||||||
return "GL_NO_ERROR";
|
string = "GL_NO_ERROR";
|
||||||
|
break;
|
||||||
case GL_INVALID_ENUM:
|
case GL_INVALID_ENUM:
|
||||||
return "GL_INVALID_ENUM";
|
string = "GL_INVALID_ENUM";
|
||||||
|
break;
|
||||||
case GL_INVALID_VALUE:
|
case GL_INVALID_VALUE:
|
||||||
return "GL_INVALID_VALUE";
|
string = "GL_INVALID_VALUE";
|
||||||
|
break;
|
||||||
case GL_INVALID_OPERATION:
|
case GL_INVALID_OPERATION:
|
||||||
return "GL_INVALID_OPERATION";
|
string = "GL_INVALID_OPERATION";
|
||||||
|
break;
|
||||||
case GL_INVALID_FRAMEBUFFER_OPERATION:
|
case GL_INVALID_FRAMEBUFFER_OPERATION:
|
||||||
return "GL_INVALID_FRAMEBUFFER_OPERATION";
|
string = "GL_INVALID_FRAMEBUFFER_OPERATION";
|
||||||
|
break;
|
||||||
case GL_OUT_OF_MEMORY:
|
case GL_OUT_OF_MEMORY:
|
||||||
return "GL_OUT_OF_MEMORY";
|
string = "GL_OUT_OF_MEMORY";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return "unknown";
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
UTILS_NOINLINE
|
UTILS_NOINLINE
|
||||||
GLenum checkGLError(io::ostream& out, const char* function, size_t line) noexcept {
|
GLenum checkGLError(io::ostream& out, const char* function, size_t line) noexcept {
|
||||||
GLenum const error = glGetError();
|
GLenum const error = glGetError();
|
||||||
if (UTILS_VERY_UNLIKELY(error != GL_NO_ERROR)) {
|
if (error != GL_NO_ERROR) {
|
||||||
auto const string = getGLErrorString(error);
|
const char* string = getGLError(error);
|
||||||
out << "OpenGL error " << io::hex << error << " (" << string << ") in \""
|
out << "OpenGL error " << io::hex << error << " (" << string << ") in \""
|
||||||
<< function << "\" at line " << io::dec << line << io::endl;
|
<< function << "\" at line " << io::dec << line << io::endl;
|
||||||
}
|
}
|
||||||
@@ -68,39 +69,46 @@ GLenum checkGLError(io::ostream& out, const char* function, size_t line) noexcep
|
|||||||
UTILS_NOINLINE
|
UTILS_NOINLINE
|
||||||
void assertGLError(io::ostream& out, const char* function, size_t line) noexcept {
|
void assertGLError(io::ostream& out, const char* function, size_t line) noexcept {
|
||||||
GLenum const err = checkGLError(out, function, line);
|
GLenum const err = checkGLError(out, function, line);
|
||||||
if (UTILS_VERY_UNLIKELY(err != GL_NO_ERROR)) {
|
if (err != GL_NO_ERROR) {
|
||||||
debug_trap();
|
debug_trap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UTILS_NOINLINE
|
UTILS_NOINLINE
|
||||||
std::string_view getFramebufferStatusString(GLenum status) noexcept {
|
const char* getFramebufferStatus(GLenum status) noexcept {
|
||||||
|
const char* string = "unknown";
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case GL_FRAMEBUFFER_COMPLETE:
|
case GL_FRAMEBUFFER_COMPLETE:
|
||||||
return "GL_FRAMEBUFFER_COMPLETE";
|
string = "GL_FRAMEBUFFER_COMPLETE";
|
||||||
|
break;
|
||||||
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
||||||
return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
|
string = "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
|
||||||
|
break;
|
||||||
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
|
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
|
||||||
return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
|
string = "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
|
||||||
|
break;
|
||||||
case GL_FRAMEBUFFER_UNSUPPORTED:
|
case GL_FRAMEBUFFER_UNSUPPORTED:
|
||||||
return "GL_FRAMEBUFFER_UNSUPPORTED";
|
string = "GL_FRAMEBUFFER_UNSUPPORTED";
|
||||||
|
break;
|
||||||
#ifndef FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2
|
#ifndef FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2
|
||||||
case GL_FRAMEBUFFER_UNDEFINED:
|
case GL_FRAMEBUFFER_UNDEFINED:
|
||||||
return "GL_FRAMEBUFFER_UNDEFINED";
|
string = "GL_FRAMEBUFFER_UNDEFINED";
|
||||||
|
break;
|
||||||
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
|
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
|
||||||
return "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE";
|
string = "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE";
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return "unknown";
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
UTILS_NOINLINE
|
UTILS_NOINLINE
|
||||||
GLenum checkFramebufferStatus(io::ostream& out, GLenum target, const char* function, size_t line) noexcept {
|
GLenum checkFramebufferStatus(io::ostream& out, GLenum target, const char* function, size_t line) noexcept {
|
||||||
GLenum const status = glCheckFramebufferStatus(target);
|
GLenum const status = glCheckFramebufferStatus(target);
|
||||||
if (UTILS_VERY_UNLIKELY(status != GL_FRAMEBUFFER_COMPLETE)) {
|
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
auto const string = getFramebufferStatusString(status);
|
const char* string = getFramebufferStatus(status);
|
||||||
out << "OpenGL framebuffer error " << io::hex << status << " (" << string << ") in \""
|
out << "OpenGL framebuffer error " << io::hex << status << " (" << string << ") in \""
|
||||||
<< function << "\" at line " << io::dec << line << io::endl;
|
<< function << "\" at line " << io::dec << line << io::endl;
|
||||||
}
|
}
|
||||||
@@ -110,7 +118,7 @@ GLenum checkFramebufferStatus(io::ostream& out, GLenum target, const char* funct
|
|||||||
UTILS_NOINLINE
|
UTILS_NOINLINE
|
||||||
void assertFramebufferStatus(io::ostream& out, GLenum target, const char* function, size_t line) noexcept {
|
void assertFramebufferStatus(io::ostream& out, GLenum target, const char* function, size_t line) noexcept {
|
||||||
GLenum const status = checkFramebufferStatus(out, target, function, line);
|
GLenum const status = checkFramebufferStatus(out, target, function, line);
|
||||||
if (UTILS_VERY_UNLIKELY(status != GL_FRAMEBUFFER_COMPLETE)) {
|
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
debug_trap();
|
debug_trap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,26 +17,29 @@
|
|||||||
#ifndef TNT_FILAMENT_BACKEND_OPENGL_GLUTILS_H
|
#ifndef TNT_FILAMENT_BACKEND_OPENGL_GLUTILS_H
|
||||||
#define TNT_FILAMENT_BACKEND_OPENGL_GLUTILS_H
|
#define TNT_FILAMENT_BACKEND_OPENGL_GLUTILS_H
|
||||||
|
|
||||||
|
#include <utils/compiler.h>
|
||||||
#include <utils/debug.h>
|
#include <utils/debug.h>
|
||||||
#include <utils/ostream.h>
|
#include <utils/Log.h>
|
||||||
|
|
||||||
#include <backend/DriverEnums.h>
|
#include <backend/DriverEnums.h>
|
||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "gl_headers.h"
|
#include "gl_headers.h"
|
||||||
|
|
||||||
namespace filament::backend::GLUtils {
|
namespace filament::backend {
|
||||||
|
namespace GLUtils {
|
||||||
|
|
||||||
std::string_view getGLErrorString(GLenum error) noexcept;
|
const char* getGLError(GLenum error) noexcept;
|
||||||
GLenum checkGLError(utils::io::ostream& out, const char* function, size_t line) noexcept;
|
GLenum checkGLError(utils::io::ostream& out, const char* function, size_t line) noexcept;
|
||||||
void assertGLError(utils::io::ostream& out, const char* function, size_t line) noexcept;
|
void assertGLError(utils::io::ostream& out, const char* function, size_t line) noexcept;
|
||||||
|
|
||||||
std::string_view getFramebufferStatusString(GLenum err) noexcept;
|
const char* getFramebufferStatus(GLenum err) noexcept;
|
||||||
GLenum checkFramebufferStatus(utils::io::ostream& out, GLenum target, const char* function, size_t line) noexcept;
|
GLenum checkFramebufferStatus(utils::io::ostream& out, GLenum target, const char* function, size_t line) noexcept;
|
||||||
void assertFramebufferStatus(utils::io::ostream& out, GLenum target, const char* function, size_t line) noexcept;
|
void assertFramebufferStatus(utils::io::ostream& out, GLenum target, const char* function, size_t line) noexcept;
|
||||||
|
|
||||||
@@ -50,7 +53,7 @@ void assertFramebufferStatus(utils::io::ostream& out, GLenum target, const char*
|
|||||||
# define CHECK_GL_FRAMEBUFFER_STATUS(out, target) { GLUtils::checkFramebufferStatus(out, target, __func__, __LINE__); }
|
# define CHECK_GL_FRAMEBUFFER_STATUS(out, target) { GLUtils::checkFramebufferStatus(out, target, __func__, __LINE__); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
constexpr GLuint getComponentCount(ElementType const type) noexcept {
|
constexpr GLuint getComponentCount(ElementType type) noexcept {
|
||||||
using ElementType = ElementType;
|
using ElementType = ElementType;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ElementType::BYTE:
|
case ElementType::BYTE:
|
||||||
@@ -84,29 +87,27 @@ constexpr GLuint getComponentCount(ElementType const type) noexcept {
|
|||||||
case ElementType::USHORT4:
|
case ElementType::USHORT4:
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
// should never happen
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Our enums to GLenum conversions
|
// Our enums to GLenum conversions
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
constexpr GLbitfield getAttachmentBitfield(TargetBufferFlags const flags) noexcept {
|
constexpr GLbitfield getAttachmentBitfield(TargetBufferFlags flags) noexcept {
|
||||||
GLbitfield mask = 0;
|
GLbitfield mask = 0;
|
||||||
if (any(flags & TargetBufferFlags::COLOR_ALL)) {
|
if (any(flags & TargetBufferFlags::COLOR_ALL)) {
|
||||||
mask |= GLbitfield(GL_COLOR_BUFFER_BIT);
|
mask |= (GLbitfield)GL_COLOR_BUFFER_BIT;
|
||||||
}
|
}
|
||||||
if (any(flags & TargetBufferFlags::DEPTH)) {
|
if (any(flags & TargetBufferFlags::DEPTH)) {
|
||||||
mask |= GLbitfield(GL_DEPTH_BUFFER_BIT);
|
mask |= (GLbitfield)GL_DEPTH_BUFFER_BIT;
|
||||||
}
|
}
|
||||||
if (any(flags & TargetBufferFlags::STENCIL)) {
|
if (any(flags & TargetBufferFlags::STENCIL)) {
|
||||||
mask |= GLbitfield(GL_STENCIL_BUFFER_BIT);
|
mask |= (GLbitfield)GL_STENCIL_BUFFER_BIT;
|
||||||
}
|
}
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr GLenum getBufferUsage(BufferUsage const usage) noexcept {
|
constexpr GLenum getBufferUsage(BufferUsage usage) noexcept {
|
||||||
switch (usage) {
|
switch (usage) {
|
||||||
case BufferUsage::STATIC:
|
case BufferUsage::STATIC:
|
||||||
return GL_STATIC_DRAW;
|
return GL_STATIC_DRAW;
|
||||||
@@ -115,7 +116,7 @@ constexpr GLenum getBufferUsage(BufferUsage const usage) noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr GLenum getBufferBindingType(BufferObjectBinding const bindingType) noexcept {
|
constexpr GLenum getBufferBindingType(BufferObjectBinding bindingType) noexcept {
|
||||||
switch (bindingType) {
|
switch (bindingType) {
|
||||||
case BufferObjectBinding::VERTEX:
|
case BufferObjectBinding::VERTEX:
|
||||||
return GL_ARRAY_BUFFER;
|
return GL_ARRAY_BUFFER;
|
||||||
@@ -134,15 +135,13 @@ constexpr GLenum getBufferBindingType(BufferObjectBinding const bindingType) noe
|
|||||||
return 0x90D2; // just to return something
|
return 0x90D2; // just to return something
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
// should never happen
|
|
||||||
return GL_ARRAY_BUFFER;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr GLboolean getNormalization(bool const normalized) noexcept {
|
constexpr GLboolean getNormalization(bool normalized) noexcept {
|
||||||
return GLboolean(normalized ? GL_TRUE : GL_FALSE);
|
return GLboolean(normalized ? GL_TRUE : GL_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr GLenum getComponentType(ElementType const type) noexcept {
|
constexpr GLenum getComponentType(ElementType type) noexcept {
|
||||||
using ElementType = ElementType;
|
using ElementType = ElementType;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ElementType::BYTE:
|
case ElementType::BYTE:
|
||||||
@@ -185,11 +184,9 @@ constexpr GLenum getComponentType(ElementType const type) noexcept {
|
|||||||
return GL_HALF_FLOAT_OES;
|
return GL_HALF_FLOAT_OES;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
// should never happen
|
|
||||||
return GL_INT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr GLenum getTextureTargetNotExternal(SamplerType const target) noexcept {
|
constexpr GLenum getTextureTargetNotExternal(SamplerType target) noexcept {
|
||||||
switch (target) {
|
switch (target) {
|
||||||
case SamplerType::SAMPLER_2D:
|
case SamplerType::SAMPLER_2D:
|
||||||
return GL_TEXTURE_2D;
|
return GL_TEXTURE_2D;
|
||||||
@@ -205,16 +202,14 @@ constexpr GLenum getTextureTargetNotExternal(SamplerType const target) noexcept
|
|||||||
// we should never be here
|
// we should never be here
|
||||||
return GL_TEXTURE_2D;
|
return GL_TEXTURE_2D;
|
||||||
}
|
}
|
||||||
// should never happen
|
|
||||||
return GL_TEXTURE_2D;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr GLenum getCubemapTarget(uint16_t const layer) noexcept {
|
constexpr GLenum getCubemapTarget(uint16_t layer) noexcept {
|
||||||
assert_invariant(layer <= 5);
|
assert_invariant(layer <= 5);
|
||||||
return GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer;
|
return GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr GLenum getWrapMode(SamplerWrapMode const mode) noexcept {
|
constexpr GLenum getWrapMode(SamplerWrapMode mode) noexcept {
|
||||||
using SamplerWrapMode = SamplerWrapMode;
|
using SamplerWrapMode = SamplerWrapMode;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case SamplerWrapMode::REPEAT:
|
case SamplerWrapMode::REPEAT:
|
||||||
@@ -224,8 +219,6 @@ constexpr GLenum getWrapMode(SamplerWrapMode const mode) noexcept {
|
|||||||
case SamplerWrapMode::MIRRORED_REPEAT:
|
case SamplerWrapMode::MIRRORED_REPEAT:
|
||||||
return GL_MIRRORED_REPEAT;
|
return GL_MIRRORED_REPEAT;
|
||||||
}
|
}
|
||||||
// should never happen
|
|
||||||
return GL_CLAMP_TO_EDGE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr GLenum getTextureFilter(SamplerMinFilter filter) noexcept {
|
constexpr GLenum getTextureFilter(SamplerMinFilter filter) noexcept {
|
||||||
@@ -241,8 +234,6 @@ constexpr GLenum getTextureFilter(SamplerMinFilter filter) noexcept {
|
|||||||
return GL_NEAREST_MIPMAP_NEAREST
|
return GL_NEAREST_MIPMAP_NEAREST
|
||||||
- GLenum(SamplerMinFilter::NEAREST_MIPMAP_NEAREST) + GLenum(filter);
|
- GLenum(SamplerMinFilter::NEAREST_MIPMAP_NEAREST) + GLenum(filter);
|
||||||
}
|
}
|
||||||
// should never happen
|
|
||||||
return GL_NEAREST;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr GLenum getTextureFilter(SamplerMagFilter filter) noexcept {
|
constexpr GLenum getTextureFilter(SamplerMagFilter filter) noexcept {
|
||||||
@@ -250,7 +241,7 @@ constexpr GLenum getTextureFilter(SamplerMagFilter filter) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
constexpr GLenum getBlendEquationMode(BlendEquation const mode) noexcept {
|
constexpr GLenum getBlendEquationMode(BlendEquation mode) noexcept {
|
||||||
using BlendEquation = BlendEquation;
|
using BlendEquation = BlendEquation;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case BlendEquation::ADD: return GL_FUNC_ADD;
|
case BlendEquation::ADD: return GL_FUNC_ADD;
|
||||||
@@ -259,11 +250,9 @@ constexpr GLenum getBlendEquationMode(BlendEquation const mode) noexcept {
|
|||||||
case BlendEquation::MIN: return GL_MIN;
|
case BlendEquation::MIN: return GL_MIN;
|
||||||
case BlendEquation::MAX: return GL_MAX;
|
case BlendEquation::MAX: return GL_MAX;
|
||||||
}
|
}
|
||||||
// should never happen
|
|
||||||
return GL_FUNC_ADD;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr GLenum getBlendFunctionMode(BlendFunction const mode) noexcept {
|
constexpr GLenum getBlendFunctionMode(BlendFunction mode) noexcept {
|
||||||
using BlendFunction = BlendFunction;
|
using BlendFunction = BlendFunction;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case BlendFunction::ZERO: return GL_ZERO;
|
case BlendFunction::ZERO: return GL_ZERO;
|
||||||
@@ -278,11 +267,9 @@ constexpr GLenum getBlendFunctionMode(BlendFunction const mode) noexcept {
|
|||||||
case BlendFunction::ONE_MINUS_DST_ALPHA: return GL_ONE_MINUS_DST_ALPHA;
|
case BlendFunction::ONE_MINUS_DST_ALPHA: return GL_ONE_MINUS_DST_ALPHA;
|
||||||
case BlendFunction::SRC_ALPHA_SATURATE: return GL_SRC_ALPHA_SATURATE;
|
case BlendFunction::SRC_ALPHA_SATURATE: return GL_SRC_ALPHA_SATURATE;
|
||||||
}
|
}
|
||||||
// should never happen
|
|
||||||
return GL_ONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr GLenum getCompareFunc(SamplerCompareFunc const func) noexcept {
|
constexpr GLenum getCompareFunc(SamplerCompareFunc func) noexcept {
|
||||||
switch (func) {
|
switch (func) {
|
||||||
case SamplerCompareFunc::LE: return GL_LEQUAL;
|
case SamplerCompareFunc::LE: return GL_LEQUAL;
|
||||||
case SamplerCompareFunc::GE: return GL_GEQUAL;
|
case SamplerCompareFunc::GE: return GL_GEQUAL;
|
||||||
@@ -293,30 +280,28 @@ constexpr GLenum getCompareFunc(SamplerCompareFunc const func) noexcept {
|
|||||||
case SamplerCompareFunc::A: return GL_ALWAYS;
|
case SamplerCompareFunc::A: return GL_ALWAYS;
|
||||||
case SamplerCompareFunc::N: return GL_NEVER;
|
case SamplerCompareFunc::N: return GL_NEVER;
|
||||||
}
|
}
|
||||||
// should never happen
|
|
||||||
return GL_LEQUAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2
|
#ifndef FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2
|
||||||
constexpr GLenum getTextureCompareMode(SamplerCompareMode const mode) noexcept {
|
constexpr GLenum getTextureCompareMode(SamplerCompareMode mode) noexcept {
|
||||||
return mode == SamplerCompareMode::NONE ?
|
return mode == SamplerCompareMode::NONE ?
|
||||||
GL_NONE : GL_COMPARE_REF_TO_TEXTURE;
|
GL_NONE : GL_COMPARE_REF_TO_TEXTURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr GLenum getTextureCompareFunc(SamplerCompareFunc const func) noexcept {
|
constexpr GLenum getTextureCompareFunc(SamplerCompareFunc func) noexcept {
|
||||||
return getCompareFunc(func);
|
return getCompareFunc(func);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
constexpr GLenum getDepthFunc(SamplerCompareFunc const func) noexcept {
|
constexpr GLenum getDepthFunc(SamplerCompareFunc func) noexcept {
|
||||||
return getCompareFunc(func);
|
return getCompareFunc(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr GLenum getStencilFunc(SamplerCompareFunc const func) noexcept {
|
constexpr GLenum getStencilFunc(SamplerCompareFunc func) noexcept {
|
||||||
return getCompareFunc(func);
|
return getCompareFunc(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr GLenum getStencilOp(StencilOperation const op) noexcept {
|
constexpr GLenum getStencilOp(StencilOperation op) noexcept {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case StencilOperation::KEEP: return GL_KEEP;
|
case StencilOperation::KEEP: return GL_KEEP;
|
||||||
case StencilOperation::ZERO: return GL_ZERO;
|
case StencilOperation::ZERO: return GL_ZERO;
|
||||||
@@ -327,11 +312,9 @@ constexpr GLenum getStencilOp(StencilOperation const op) noexcept {
|
|||||||
case StencilOperation::DECR_WRAP: return GL_DECR_WRAP;
|
case StencilOperation::DECR_WRAP: return GL_DECR_WRAP;
|
||||||
case StencilOperation::INVERT: return GL_INVERT;
|
case StencilOperation::INVERT: return GL_INVERT;
|
||||||
}
|
}
|
||||||
// should never happen
|
|
||||||
return GL_KEEP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr GLenum getFormat(PixelDataFormat const format) noexcept {
|
constexpr GLenum getFormat(PixelDataFormat format) noexcept {
|
||||||
using PixelDataFormat = PixelDataFormat;
|
using PixelDataFormat = PixelDataFormat;
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case PixelDataFormat::RGB: return GL_RGB;
|
case PixelDataFormat::RGB: return GL_RGB;
|
||||||
@@ -353,11 +336,9 @@ constexpr GLenum getFormat(PixelDataFormat const format) noexcept {
|
|||||||
default: return GL_NONE;
|
default: return GL_NONE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
// should never happen
|
|
||||||
return GL_RGBA;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr GLenum getType(PixelDataType const type) noexcept {
|
constexpr GLenum getType(PixelDataType type) noexcept {
|
||||||
using PixelDataType = PixelDataType;
|
using PixelDataType = PixelDataType;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PixelDataType::UBYTE: return GL_UNSIGNED_BYTE;
|
case PixelDataType::UBYTE: return GL_UNSIGNED_BYTE;
|
||||||
@@ -379,12 +360,10 @@ constexpr GLenum getType(PixelDataType const type) noexcept {
|
|||||||
default: return GL_NONE;
|
default: return GL_NONE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
// should never happen
|
|
||||||
return GL_UNSIGNED_INT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(__EMSCRIPTEN__) && !defined(FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2)
|
#if !defined(__EMSCRIPTEN__) && !defined(FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2)
|
||||||
constexpr GLenum getSwizzleChannel(TextureSwizzle const c) noexcept {
|
constexpr GLenum getSwizzleChannel(TextureSwizzle c) noexcept {
|
||||||
using TextureSwizzle = TextureSwizzle;
|
using TextureSwizzle = TextureSwizzle;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case TextureSwizzle::SUBSTITUTE_ZERO: return GL_ZERO;
|
case TextureSwizzle::SUBSTITUTE_ZERO: return GL_ZERO;
|
||||||
@@ -394,12 +373,10 @@ constexpr GLenum getSwizzleChannel(TextureSwizzle const c) noexcept {
|
|||||||
case TextureSwizzle::CHANNEL_2: return GL_BLUE;
|
case TextureSwizzle::CHANNEL_2: return GL_BLUE;
|
||||||
case TextureSwizzle::CHANNEL_3: return GL_ALPHA;
|
case TextureSwizzle::CHANNEL_3: return GL_ALPHA;
|
||||||
}
|
}
|
||||||
// should never happen
|
|
||||||
return GL_RED;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
constexpr GLenum getCullingMode(CullingMode const mode) noexcept {
|
constexpr GLenum getCullingMode(CullingMode mode) noexcept {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case CullingMode::NONE:
|
case CullingMode::NONE:
|
||||||
// should never happen
|
// should never happen
|
||||||
@@ -411,13 +388,11 @@ constexpr GLenum getCullingMode(CullingMode const mode) noexcept {
|
|||||||
case CullingMode::FRONT_AND_BACK:
|
case CullingMode::FRONT_AND_BACK:
|
||||||
return GL_FRONT_AND_BACK;
|
return GL_FRONT_AND_BACK;
|
||||||
}
|
}
|
||||||
// should never happen
|
|
||||||
return GL_FRONT_AND_BACK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ES2 supported internal formats for texturing and how they map to a format/type
|
// ES2 supported internal formats for texturing and how they map to a format/type
|
||||||
constexpr std::pair<GLenum, GLenum> textureFormatToFormatAndType(
|
constexpr std::pair<GLenum, GLenum> textureFormatToFormatAndType(
|
||||||
TextureFormat const format) noexcept {
|
TextureFormat format) noexcept {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case TextureFormat::R8: return { 0x1909 /*GL_LUMINANCE*/, GL_UNSIGNED_BYTE };
|
case TextureFormat::R8: return { 0x1909 /*GL_LUMINANCE*/, GL_UNSIGNED_BYTE };
|
||||||
case TextureFormat::RGB8: return { GL_RGB, GL_UNSIGNED_BYTE };
|
case TextureFormat::RGB8: return { GL_RGB, GL_UNSIGNED_BYTE };
|
||||||
@@ -438,7 +413,7 @@ constexpr std::pair<GLenum, GLenum> textureFormatToFormatAndType(
|
|||||||
// clang loses it on this one, and generates a huge jump table when
|
// clang loses it on this one, and generates a huge jump table when
|
||||||
// inlined. So we don't mark it as inline (only constexpr) which solves the problem,
|
// inlined. So we don't mark it as inline (only constexpr) which solves the problem,
|
||||||
// strangely, when not inlined, clang simply generates an array lookup.
|
// strangely, when not inlined, clang simply generates an array lookup.
|
||||||
constexpr /* inline */ GLenum getInternalFormat(TextureFormat const format) noexcept {
|
constexpr /* inline */ GLenum getInternalFormat(TextureFormat format) noexcept {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
|
|
||||||
/* Formats supported by our ES2 implementations */
|
/* Formats supported by our ES2 implementations */
|
||||||
@@ -686,7 +661,7 @@ public:
|
|||||||
|
|
||||||
unordered_string_set split(const char* extensions) noexcept;
|
unordered_string_set split(const char* extensions) noexcept;
|
||||||
|
|
||||||
} // namespace filament::backend::GLUtils
|
} // namespace GLUtils
|
||||||
|
} // namespace filament::backend
|
||||||
|
|
||||||
#endif // TNT_FILAMENT_BACKEND_OPENGL_GLUTILS_H
|
#endif // TNT_FILAMENT_BACKEND_OPENGL_GLUTILS_H
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
#include <backend/Platform.h>
|
#include <backend/Platform.h>
|
||||||
#include <backend/Program.h>
|
#include <backend/Program.h>
|
||||||
|
|
||||||
#include <private/utils/Tracing.h>
|
#include <utils/Systrace.h>
|
||||||
|
|
||||||
namespace filament::backend {
|
namespace filament::backend {
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ OpenGLBlobCache::OpenGLBlobCache(OpenGLContext& gl) noexcept
|
|||||||
|
|
||||||
GLuint OpenGLBlobCache::retrieve(BlobCacheKey* outKey, Platform& platform,
|
GLuint OpenGLBlobCache::retrieve(BlobCacheKey* outKey, Platform& platform,
|
||||||
Program const& program) const noexcept {
|
Program const& program) const noexcept {
|
||||||
FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_CALL();
|
||||||
if (!mCachingSupported || !platform.hasRetrieveBlobFunc()) {
|
if (!mCachingSupported || !platform.hasRetrieveBlobFunc()) {
|
||||||
// the key is never updated in that case
|
// the key is never updated in that case
|
||||||
return 0;
|
return 0;
|
||||||
@@ -68,7 +68,7 @@ GLuint OpenGLBlobCache::retrieve(BlobCacheKey* outKey, Platform& platform,
|
|||||||
programId = glCreateProgram();
|
programId = glCreateProgram();
|
||||||
|
|
||||||
{ // scope for systrace
|
{ // scope for systrace
|
||||||
FILAMENT_TRACING_NAME(FILAMENT_TRACING_CATEGORY_FILAMENT, "glProgramBinary");
|
SYSTRACE_NAME("glProgramBinary");
|
||||||
glProgramBinary(programId, blob->format, blob->data, programBinarySize);
|
glProgramBinary(programId, blob->format, blob->data, programBinarySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ GLuint OpenGLBlobCache::retrieve(BlobCacheKey* outKey, Platform& platform,
|
|||||||
|
|
||||||
void OpenGLBlobCache::insert(Platform& platform,
|
void OpenGLBlobCache::insert(Platform& platform,
|
||||||
BlobCacheKey const& key, GLuint program) noexcept {
|
BlobCacheKey const& key, GLuint program) noexcept {
|
||||||
FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_CALL();
|
||||||
if (!mCachingSupported || !platform.hasInsertBlobFunc()) {
|
if (!mCachingSupported || !platform.hasInsertBlobFunc()) {
|
||||||
// the key is never updated in that case
|
// the key is never updated in that case
|
||||||
return;
|
return;
|
||||||
@@ -100,7 +100,7 @@ void OpenGLBlobCache::insert(Platform& platform,
|
|||||||
GLenum format;
|
GLenum format;
|
||||||
GLint programBinarySize = 0;
|
GLint programBinarySize = 0;
|
||||||
{ // scope for systrace
|
{ // scope for systrace
|
||||||
FILAMENT_TRACING_NAME(FILAMENT_TRACING_CATEGORY_FILAMENT, "glGetProgramiv");
|
SYSTRACE_NAME("glGetProgramiv");
|
||||||
glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &programBinarySize);
|
glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &programBinarySize);
|
||||||
}
|
}
|
||||||
if (programBinarySize) {
|
if (programBinarySize) {
|
||||||
@@ -108,7 +108,7 @@ void OpenGLBlobCache::insert(Platform& platform,
|
|||||||
std::unique_ptr<Blob, decltype(&::free)> blob{ (Blob*)malloc(size), &::free };
|
std::unique_ptr<Blob, decltype(&::free)> blob{ (Blob*)malloc(size), &::free };
|
||||||
if (UTILS_LIKELY(blob)) {
|
if (UTILS_LIKELY(blob)) {
|
||||||
{ // scope for systrace
|
{ // scope for systrace
|
||||||
FILAMENT_TRACING_NAME(FILAMENT_TRACING_CATEGORY_FILAMENT, "glGetProgramBinary");
|
SYSTRACE_NAME("glGetProgramBinary");
|
||||||
glGetProgramBinary(program, programBinarySize,
|
glGetProgramBinary(program, programBinarySize,
|
||||||
&programBinarySize, &format, blob->data);
|
&programBinarySize, &format, blob->data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -340,7 +340,7 @@ void OpenGLContext::setDefaultState() noexcept {
|
|||||||
GL_DITHER,
|
GL_DITHER,
|
||||||
GL_SAMPLE_ALPHA_TO_COVERAGE,
|
GL_SAMPLE_ALPHA_TO_COVERAGE,
|
||||||
GL_SAMPLE_COVERAGE,
|
GL_SAMPLE_COVERAGE,
|
||||||
GL_POLYGON_OFFSET_FILL,
|
GL_POLYGON_OFFSET_FILL,
|
||||||
};
|
};
|
||||||
|
|
||||||
UTILS_NOUNROLL
|
UTILS_NOUNROLL
|
||||||
@@ -542,13 +542,6 @@ void OpenGLContext::initBugs(Bugs* bugs, Extensions const& exts,
|
|||||||
} else if (strstr(renderer, "Intel")) {
|
} else if (strstr(renderer, "Intel")) {
|
||||||
// Intel GPU
|
// Intel GPU
|
||||||
bugs->vao_doesnt_store_element_array_buffer_binding = true;
|
bugs->vao_doesnt_store_element_array_buffer_binding = true;
|
||||||
|
|
||||||
if (strstr(renderer, "Mesa")) {
|
|
||||||
// Mesa Intel driver on Linux/Android
|
|
||||||
// Renderer of the form [Mesa Intel(R) HD Graphics 505 (APL 3)]
|
|
||||||
// b/405252622
|
|
||||||
bugs->disable_invalidate_framebuffer = true;
|
|
||||||
}
|
|
||||||
} else if (strstr(renderer, "PowerVR")) {
|
} else if (strstr(renderer, "PowerVR")) {
|
||||||
// PowerVR GPU
|
// PowerVR GPU
|
||||||
// On PowerVR (Rogue GE8320) glFlush doesn't seem to do anything, in particular,
|
// On PowerVR (Rogue GE8320) glFlush doesn't seem to do anything, in particular,
|
||||||
@@ -607,12 +600,6 @@ void OpenGLContext::initBugs(Bugs* bugs, Extensions const& exts,
|
|||||||
// For Mozilla, the issue appears to be observed regardless of whether the renderer is
|
// For Mozilla, the issue appears to be observed regardless of whether the renderer is
|
||||||
// ANGLE or not. (b/376125497)
|
// ANGLE or not. (b/376125497)
|
||||||
bugs->rebind_buffer_after_deletion = true;
|
bugs->rebind_buffer_after_deletion = true;
|
||||||
|
|
||||||
// We disable depth precache for the default material on Mozilla FireFox. It struggles with
|
|
||||||
// slow shader compile/link times if the shader contains large arrays of uniform. Some depth
|
|
||||||
// program variants have skinning-related data, which incurs this slowness and end up
|
|
||||||
// causing an initial startup stalls. (b/392917621)
|
|
||||||
bugs->disable_depth_precache_for_default_material = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BACKEND_OPENGL_VERSION_GLES
|
#ifdef BACKEND_OPENGL_VERSION_GLES
|
||||||
@@ -1082,41 +1069,41 @@ void OpenGLContext::resetState() noexcept {
|
|||||||
glCullFace(state.raster.cullFace);
|
glCullFace(state.raster.cullFace);
|
||||||
glBlendEquationSeparate(state.raster.blendEquationRGB, state.raster.blendEquationA);
|
glBlendEquationSeparate(state.raster.blendEquationRGB, state.raster.blendEquationA);
|
||||||
glBlendFuncSeparate(
|
glBlendFuncSeparate(
|
||||||
state.raster.blendFunctionSrcRGB,
|
state.raster.blendFunctionSrcRGB,
|
||||||
state.raster.blendFunctionDstRGB,
|
state.raster.blendFunctionDstRGB,
|
||||||
state.raster.blendFunctionSrcA,
|
state.raster.blendFunctionSrcA,
|
||||||
state.raster.blendFunctionDstA
|
state.raster.blendFunctionDstA
|
||||||
);
|
);
|
||||||
glColorMask(
|
glColorMask(
|
||||||
state.raster.colorMask,
|
state.raster.colorMask,
|
||||||
state.raster.colorMask,
|
state.raster.colorMask,
|
||||||
state.raster.colorMask,
|
state.raster.colorMask,
|
||||||
state.raster.colorMask
|
state.raster.colorMask
|
||||||
);
|
);
|
||||||
glDepthMask(state.raster.depthMask);
|
glDepthMask(state.raster.depthMask);
|
||||||
glDepthFunc(state.raster.depthFunc);
|
glDepthFunc(state.raster.depthFunc);
|
||||||
|
|
||||||
// state.stencil
|
// state.stencil
|
||||||
glStencilFuncSeparate(
|
glStencilFuncSeparate(
|
||||||
GL_FRONT,
|
GL_FRONT,
|
||||||
state.stencil.front.func.func,
|
state.stencil.front.func.func,
|
||||||
state.stencil.front.func.ref,
|
state.stencil.front.func.ref,
|
||||||
state.stencil.front.func.mask
|
state.stencil.front.func.mask
|
||||||
);
|
);
|
||||||
glStencilFuncSeparate(
|
glStencilFuncSeparate(
|
||||||
GL_BACK,
|
GL_BACK,
|
||||||
state.stencil.back.func.func,
|
state.stencil.back.func.func,
|
||||||
state.stencil.back.func.ref,
|
state.stencil.back.func.ref,
|
||||||
state.stencil.back.func.mask
|
state.stencil.back.func.mask
|
||||||
);
|
);
|
||||||
glStencilOpSeparate(
|
glStencilOpSeparate(
|
||||||
GL_FRONT,
|
GL_FRONT,
|
||||||
state.stencil.front.op.sfail,
|
state.stencil.front.op.sfail,
|
||||||
state.stencil.front.op.dpfail,
|
state.stencil.front.op.dpfail,
|
||||||
state.stencil.front.op.dppass
|
state.stencil.front.op.dppass
|
||||||
);
|
);
|
||||||
glStencilOpSeparate(
|
glStencilOpSeparate(
|
||||||
GL_BACK,
|
GL_BACK,
|
||||||
state.stencil.back.op.sfail,
|
state.stencil.back.op.sfail,
|
||||||
state.stencil.back.op.dpfail,
|
state.stencil.back.op.dpfail,
|
||||||
state.stencil.back.op.dppass
|
state.stencil.back.op.dppass
|
||||||
@@ -1219,9 +1206,9 @@ void OpenGLContext::resetState() noexcept {
|
|||||||
|
|
||||||
// state.window
|
// state.window
|
||||||
glScissor(
|
glScissor(
|
||||||
state.window.scissor.x,
|
state.window.scissor.x,
|
||||||
state.window.scissor.y,
|
state.window.scissor.y,
|
||||||
state.window.scissor.z,
|
state.window.scissor.z,
|
||||||
state.window.scissor.w
|
state.window.scissor.w
|
||||||
);
|
);
|
||||||
glViewport(
|
glViewport(
|
||||||
|
|||||||
@@ -328,11 +328,6 @@ public:
|
|||||||
// bugs or performance issues.
|
// bugs or performance issues.
|
||||||
bool force_feature_level0;
|
bool force_feature_level0;
|
||||||
|
|
||||||
// Some browsers, such as Firefox on Mac, struggle with slow shader compile/link times when
|
|
||||||
// creating programs for the default material, leading to startup stutters. This workaround
|
|
||||||
// prevents these stutters by not precaching depth variants of the default material for
|
|
||||||
// those particular browsers.
|
|
||||||
bool disable_depth_precache_for_default_material;
|
|
||||||
|
|
||||||
} bugs = {};
|
} bugs = {};
|
||||||
|
|
||||||
@@ -574,9 +569,6 @@ private:
|
|||||||
{ bugs.force_feature_level0,
|
{ bugs.force_feature_level0,
|
||||||
"force_feature_level0",
|
"force_feature_level0",
|
||||||
""},
|
""},
|
||||||
{ bugs.disable_depth_precache_for_default_material,
|
|
||||||
"disable_depth_precache_for_default_material",
|
|
||||||
""},
|
|
||||||
}};
|
}};
|
||||||
|
|
||||||
// this is chosen to minimize code size
|
// this is chosen to minimize code size
|
||||||
|
|||||||
@@ -44,8 +44,6 @@
|
|||||||
#include "private/backend/Dispatcher.h"
|
#include "private/backend/Dispatcher.h"
|
||||||
#include "private/backend/DriverApi.h"
|
#include "private/backend/DriverApi.h"
|
||||||
|
|
||||||
#include <private/utils/Tracing.h>
|
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utils/BitmaskEnum.h>
|
#include <utils/BitmaskEnum.h>
|
||||||
#include <utils/FixedCapacityVector.h>
|
#include <utils/FixedCapacityVector.h>
|
||||||
@@ -53,6 +51,7 @@
|
|||||||
#include <utils/Invocable.h>
|
#include <utils/Invocable.h>
|
||||||
#include <utils/Log.h>
|
#include <utils/Log.h>
|
||||||
#include <utils/Panic.h>
|
#include <utils/Panic.h>
|
||||||
|
#include <utils/Systrace.h>
|
||||||
#include <utils/Slice.h>
|
#include <utils/Slice.h>
|
||||||
#include <utils/compiler.h>
|
#include <utils/compiler.h>
|
||||||
#include <utils/debug.h>
|
#include <utils/debug.h>
|
||||||
@@ -99,13 +98,13 @@
|
|||||||
|
|
||||||
#define DEBUG_GROUP_MARKER_NONE 0x00 // no debug marker
|
#define DEBUG_GROUP_MARKER_NONE 0x00 // no debug marker
|
||||||
#define DEBUG_GROUP_MARKER_OPENGL 0x01 // markers in the gl command queue (req. driver support)
|
#define DEBUG_GROUP_MARKER_OPENGL 0x01 // markers in the gl command queue (req. driver support)
|
||||||
#define DEBUG_GROUP_MARKER_BACKEND 0x02 // markers on the backend side (perfetto)
|
#define DEBUG_GROUP_MARKER_BACKEND 0x02 // markers on the backend side (systrace)
|
||||||
#define DEBUG_GROUP_MARKER_ALL 0xFF // all markers
|
#define DEBUG_GROUP_MARKER_ALL 0xFF // all markers
|
||||||
|
|
||||||
#define DEBUG_MARKER_NONE 0x00 // no debug marker
|
#define DEBUG_MARKER_NONE 0x00 // no debug marker
|
||||||
#define DEBUG_MARKER_OPENGL 0x01 // markers in the gl command queue (req. driver support)
|
#define DEBUG_MARKER_OPENGL 0x01 // markers in the gl command queue (req. driver support)
|
||||||
#define DEBUG_MARKER_BACKEND 0x02 // markers on the backend side (perfetto)
|
#define DEBUG_MARKER_BACKEND 0x02 // markers on the backend side (systrace)
|
||||||
#define DEBUG_MARKER_PROFILE 0x04 // profiling on the backend side (perfetto)
|
#define DEBUG_MARKER_PROFILE 0x04 // profiling on the backend side (systrace)
|
||||||
#define DEBUG_MARKER_ALL (0xFF & ~DEBUG_MARKER_PROFILE) // all markers
|
#define DEBUG_MARKER_ALL (0xFF & ~DEBUG_MARKER_PROFILE) // all markers
|
||||||
|
|
||||||
// set to the desired debug marker level (for user markers [default: All])
|
// set to the desired debug marker level (for user markers [default: All])
|
||||||
@@ -249,8 +248,8 @@ OpenGLDriver::DebugMarker::DebugMarker(OpenGLDriver& driver, const char* string)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if DEBUG_MARKER_LEVEL & DEBUG_MARKER_BACKEND
|
#if DEBUG_MARKER_LEVEL & DEBUG_MARKER_BACKEND
|
||||||
FILAMENT_TRACING_CONTEXT(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_CONTEXT();
|
||||||
FILAMENT_TRACING_NAME_BEGIN(FILAMENT_TRACING_CATEGORY_FILAMENT, string);
|
SYSTRACE_NAME_BEGIN(string);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -266,8 +265,8 @@ OpenGLDriver::DebugMarker::~DebugMarker() noexcept {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if DEBUG_MARKER_LEVEL & DEBUG_MARKER_BACKEND
|
#if DEBUG_MARKER_LEVEL & DEBUG_MARKER_BACKEND
|
||||||
FILAMENT_TRACING_CONTEXT(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_CONTEXT();
|
||||||
FILAMENT_TRACING_NAME_END(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_NAME_END();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -2099,7 +2098,6 @@ void OpenGLDriver::setAcquiredImage(Handle<HwStream> sh, void* hwbuffer, const m
|
|||||||
|
|
||||||
glstream->user_thread.pending = mPlatform.transformAcquiredImage({
|
glstream->user_thread.pending = mPlatform.transformAcquiredImage({
|
||||||
hwbuffer, cb, userData, handler });
|
hwbuffer, cb, userData, handler });
|
||||||
glstream->user_thread.transform = transform;
|
|
||||||
|
|
||||||
if (glstream->user_thread.pending.image != nullptr) {
|
if (glstream->user_thread.pending.image != nullptr) {
|
||||||
// If there's no pending image, do nothing. Note that GL_OES_EGL_image does not let you pass
|
// If there's no pending image, do nothing. Note that GL_OES_EGL_image does not let you pass
|
||||||
@@ -2436,8 +2434,6 @@ bool OpenGLDriver::isWorkaroundNeeded(Workaround workaround) {
|
|||||||
return mContext.bugs.disable_blit_into_texture_array;
|
return mContext.bugs.disable_blit_into_texture_array;
|
||||||
case Workaround::POWER_VR_SHADER_WORKAROUNDS:
|
case Workaround::POWER_VR_SHADER_WORKAROUNDS:
|
||||||
return mContext.bugs.powervr_shader_workarounds;
|
return mContext.bugs.powervr_shader_workarounds;
|
||||||
case Workaround::DISABLE_DEPTH_PRECACHE_FOR_DEFAULT_MATERIAL:
|
|
||||||
return mContext.bugs.disable_depth_precache_for_default_material;
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2514,33 +2510,10 @@ void OpenGLDriver::makeCurrent(Handle<HwSwapChain> schDraw, Handle<HwSwapChain>
|
|||||||
|
|
||||||
mPlatform.makeCurrent(scDraw->swapChain, scRead->swapChain,
|
mPlatform.makeCurrent(scDraw->swapChain, scRead->swapChain,
|
||||||
[this]() {
|
[this]() {
|
||||||
for (auto t: mTexturesWithStreamsAttached) {
|
|
||||||
if (t->hwStream->streamType == StreamType::NATIVE) {
|
|
||||||
mPlatform.detach(t->hwStream->stream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// OpenGL context is about to change, unbind everything
|
// OpenGL context is about to change, unbind everything
|
||||||
mContext.unbindEverything();
|
mContext.unbindEverything();
|
||||||
},
|
},
|
||||||
[this](size_t index) {
|
[this](size_t index) {
|
||||||
for (auto t: mTexturesWithStreamsAttached) {
|
|
||||||
if (t->hwStream->streamType == StreamType::NATIVE) {
|
|
||||||
if (t->externalTexture) {
|
|
||||||
glGenTextures(1, &t->externalTexture->id);
|
|
||||||
t->gl.id = t->externalTexture->id;
|
|
||||||
} else {
|
|
||||||
glGenTextures(1, &t->gl.id);
|
|
||||||
}
|
|
||||||
mPlatform.attach(t->hwStream->stream, t->gl.id);
|
|
||||||
mContext.updateTexImage(GL_TEXTURE_EXTERNAL_OES, t->gl.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// force invalidation of all bound descriptor sets
|
|
||||||
decltype(mInvalidDescriptorSetBindings) changed;
|
|
||||||
changed.setValue((1 << MAX_DESCRIPTOR_SET_COUNT) - 1);
|
|
||||||
mInvalidDescriptorSetBindings |= changed;
|
|
||||||
|
|
||||||
// OpenGL context has changed, resynchronize the state with the cache
|
// OpenGL context has changed, resynchronize the state with the cache
|
||||||
mContext.synchronizeStateAndCache(index);
|
mContext.synchronizeStateAndCache(index);
|
||||||
slog.d << "*** OpenGL context change : " << (index ? "protected" : "default") << io::endl;
|
slog.d << "*** OpenGL context change : " << (index ? "protected" : "default") << io::endl;
|
||||||
@@ -3015,7 +2988,6 @@ void OpenGLDriver::attachStream(GLTexture* t, GLStream* hwStream) noexcept {
|
|||||||
switch (hwStream->streamType) {
|
switch (hwStream->streamType) {
|
||||||
case StreamType::NATIVE:
|
case StreamType::NATIVE:
|
||||||
mPlatform.attach(hwStream->stream, t->gl.id);
|
mPlatform.attach(hwStream->stream, t->gl.id);
|
||||||
mContext.updateTexImage(GL_TEXTURE_EXTERNAL_OES, t->gl.id);
|
|
||||||
break;
|
break;
|
||||||
case StreamType::ACQUIRED:
|
case StreamType::ACQUIRED:
|
||||||
break;
|
break;
|
||||||
@@ -3044,12 +3016,7 @@ void OpenGLDriver::detachStream(GLTexture* t) noexcept {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t->externalTexture) {
|
glGenTextures(1, &t->gl.id);
|
||||||
glGenTextures(1, &t->externalTexture->id);
|
|
||||||
t->gl.id = t->externalTexture->id;
|
|
||||||
} else {
|
|
||||||
glGenTextures(1, &t->gl.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
t->hwStream = nullptr;
|
t->hwStream = nullptr;
|
||||||
}
|
}
|
||||||
@@ -3073,14 +3040,8 @@ void OpenGLDriver::replaceStream(GLTexture* texture, GLStream* newStream) noexce
|
|||||||
|
|
||||||
switch (newStream->streamType) {
|
switch (newStream->streamType) {
|
||||||
case StreamType::NATIVE:
|
case StreamType::NATIVE:
|
||||||
if (texture->externalTexture) {
|
glGenTextures(1, &texture->gl.id);
|
||||||
glGenTextures(1, &texture->externalTexture->id);
|
|
||||||
texture->gl.id = texture->externalTexture->id;
|
|
||||||
} else {
|
|
||||||
glGenTextures(1, &texture->gl.id);
|
|
||||||
}
|
|
||||||
mPlatform.attach(newStream->stream, texture->gl.id);
|
mPlatform.attach(newStream->stream, texture->gl.id);
|
||||||
mContext.updateTexImage(GL_TEXTURE_EXTERNAL_OES, texture->gl.id);
|
|
||||||
break;
|
break;
|
||||||
case StreamType::ACQUIRED:
|
case StreamType::ACQUIRED:
|
||||||
// Just re-use the old texture id.
|
// Just re-use the old texture id.
|
||||||
@@ -3384,8 +3345,8 @@ void OpenGLDriver::pushGroupMarker(char const* string) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if DEBUG_GROUP_MARKER_LEVEL & DEBUG_GROUP_MARKER_BACKEND
|
#if DEBUG_GROUP_MARKER_LEVEL & DEBUG_GROUP_MARKER_BACKEND
|
||||||
FILAMENT_TRACING_CONTEXT(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_CONTEXT();
|
||||||
FILAMENT_TRACING_NAME_BEGIN(FILAMENT_TRACING_CATEGORY_FILAMENT, string);
|
SYSTRACE_NAME_BEGIN(string);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -3401,8 +3362,8 @@ void OpenGLDriver::popGroupMarker(int) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if DEBUG_GROUP_MARKER_LEVEL & DEBUG_GROUP_MARKER_BACKEND
|
#if DEBUG_GROUP_MARKER_LEVEL & DEBUG_GROUP_MARKER_BACKEND
|
||||||
FILAMENT_TRACING_CONTEXT(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_CONTEXT();
|
||||||
FILAMENT_TRACING_NAME_END(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
SYSTRACE_NAME_END();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -3721,7 +3682,7 @@ void OpenGLDriver::endFrame(UTILS_UNUSED uint32_t frameId) {
|
|||||||
gl.depthFunc(GL_LESS);
|
gl.depthFunc(GL_LESS);
|
||||||
gl.disable(GL_SCISSOR_TEST);
|
gl.disable(GL_SCISSOR_TEST);
|
||||||
#endif
|
#endif
|
||||||
//FILAMENT_TRACING_NAME(FILAMENT_TRACING_CATEGORY_FILAMENT, "glFinish");
|
//SYSTRACE_NAME("glFinish");
|
||||||
//glFinish();
|
//glFinish();
|
||||||
mPlatform.endFrame(frameId);
|
mPlatform.endFrame(frameId);
|
||||||
insertEventMarker("endFrame");
|
insertEventMarker("endFrame");
|
||||||
@@ -3743,7 +3704,8 @@ void OpenGLDriver::updateDescriptorSetTexture(
|
|||||||
TextureHandle th,
|
TextureHandle th,
|
||||||
SamplerParams params) {
|
SamplerParams params) {
|
||||||
GLDescriptorSet* ds = handle_cast<GLDescriptorSet*>(dsh);
|
GLDescriptorSet* ds = handle_cast<GLDescriptorSet*>(dsh);
|
||||||
ds->update(mContext, mHandleAllocator, binding, th, params);
|
GLTexture* t = th ? handle_cast<GLTexture*>(th) : nullptr;
|
||||||
|
ds->update(mContext, binding, t, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLDriver::flush(int) {
|
void OpenGLDriver::flush(int) {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user