Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c645cc9068 | ||
|
|
4637f6097b |
@@ -150,20 +150,13 @@ jobs:
|
||||
pushd .
|
||||
cd build/android && printf "y" | ./build.sh presubmit-with-archive arm64-v8a
|
||||
popd
|
||||
- id: get_commit_msg
|
||||
uses: ./.github/actions/get-commit-msg
|
||||
- name: Check artifact sizes
|
||||
run: |
|
||||
python3 test/sizeguard/dump_artifact_size.py out/*.aar > current_size.json
|
||||
BYPASS_ARG=""
|
||||
if python3 test/sizeguard/check_bypass.py ${{ steps.get_commit_msg.outputs.hash }}; then
|
||||
BYPASS_ARG="--bypass"
|
||||
fi
|
||||
python3 test/sizeguard/check_size.py current_size.json \
|
||||
--target-branch origin/main \
|
||||
--threshold 20480 \
|
||||
--artifacts filament-android-release.aar/jni/arm64-v8a/libfilament-jni.so \
|
||||
$BYPASS_ARG
|
||||
--artifacts filament-android-release.aar/jni/arm64-v8a/libfilament-jni.so
|
||||
|
||||
build-ios:
|
||||
name: build-iOS
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
name: Android
|
||||
run-name: ${{ github.event.workflow_run.display_title }}
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Postsubmit CI"]
|
||||
types: [completed]
|
||||
|
||||
jobs:
|
||||
status:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.workflow_run.conclusion != 'skipped' }}
|
||||
steps:
|
||||
- uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const { data: { jobs } } = await github.rest.actions.listJobsForWorkflowRun({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: ${{ github.event.workflow_run.id }}
|
||||
});
|
||||
const job = jobs.find(j => j.name === 'build-android');
|
||||
if (job && job.conclusion !== 'success') {
|
||||
core.setFailed(`Android build failed: ${job.conclusion}`);
|
||||
} else if (!job) {
|
||||
core.warning(`Job build-android not found in the workflow run.`);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
name: iOS
|
||||
run-name: ${{ github.event.workflow_run.display_title }}
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Postsubmit CI"]
|
||||
types: [completed]
|
||||
|
||||
jobs:
|
||||
status:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.workflow_run.conclusion != 'skipped' }}
|
||||
steps:
|
||||
- uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const { data: { jobs } } = await github.rest.actions.listJobsForWorkflowRun({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: ${{ github.event.workflow_run.id }}
|
||||
});
|
||||
const job = jobs.find(j => j.name === 'build-ios');
|
||||
if (job && job.conclusion !== 'success') {
|
||||
core.setFailed(`iOS build failed: ${job.conclusion}`);
|
||||
} else if (!job) {
|
||||
core.warning(`Job build-ios not found in the workflow run.`);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
name: Linux
|
||||
run-name: ${{ github.event.workflow_run.display_title }}
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Postsubmit CI"]
|
||||
types: [completed]
|
||||
|
||||
jobs:
|
||||
status:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.workflow_run.conclusion != 'skipped' }}
|
||||
steps:
|
||||
- uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const { data: { jobs } } = await github.rest.actions.listJobsForWorkflowRun({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: ${{ github.event.workflow_run.id }}
|
||||
});
|
||||
const job = jobs.find(j => j.name === 'build-linux');
|
||||
if (job && job.conclusion !== 'success') {
|
||||
core.setFailed(`Linux build failed: ${job.conclusion}`);
|
||||
} else if (!job) {
|
||||
core.warning(`Job build-linux not found in the workflow run.`);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
name: macOS
|
||||
run-name: ${{ github.event.workflow_run.display_title }}
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Postsubmit CI"]
|
||||
types: [completed]
|
||||
|
||||
jobs:
|
||||
status:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.workflow_run.conclusion != 'skipped' }}
|
||||
steps:
|
||||
- uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const { data: { jobs } } = await github.rest.actions.listJobsForWorkflowRun({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: ${{ github.event.workflow_run.id }}
|
||||
});
|
||||
const job = jobs.find(j => j.name === 'build-mac');
|
||||
if (job && job.conclusion !== 'success') {
|
||||
core.setFailed(`macOS build failed: ${job.conclusion}`);
|
||||
} else if (!job) {
|
||||
core.warning(`Job build-mac not found in the workflow run.`);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
name: Web
|
||||
run-name: ${{ github.event.workflow_run.display_title }}
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Postsubmit CI"]
|
||||
types: [completed]
|
||||
|
||||
jobs:
|
||||
status:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.workflow_run.conclusion != 'skipped' }}
|
||||
steps:
|
||||
- uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const { data: { jobs } } = await github.rest.actions.listJobsForWorkflowRun({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: ${{ github.event.workflow_run.id }}
|
||||
});
|
||||
const job = jobs.find(j => j.name === 'build-web');
|
||||
if (job && job.conclusion !== 'success') {
|
||||
core.setFailed(`Web build failed: ${job.conclusion}`);
|
||||
} else if (!job) {
|
||||
core.warning(`Job build-web not found in the workflow run.`);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
name: Windows
|
||||
run-name: ${{ github.event.workflow_run.display_title }}
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Postsubmit CI"]
|
||||
types: [completed]
|
||||
|
||||
jobs:
|
||||
status:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.workflow_run.conclusion != 'skipped' }}
|
||||
steps:
|
||||
- uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const { data: { jobs } } = await github.rest.actions.listJobsForWorkflowRun({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: ${{ github.event.workflow_run.id }}
|
||||
});
|
||||
const job = jobs.find(j => j.name === 'build-windows');
|
||||
if (job && job.conclusion !== 'success') {
|
||||
core.setFailed(`Windows build failed: ${job.conclusion}`);
|
||||
} else if (!job) {
|
||||
core.warning(`Job build-windows not found in the workflow run.`);
|
||||
}
|
||||
+1
-5
@@ -79,10 +79,6 @@ The following CMake options are boolean options specific to Filament:
|
||||
- `FILAMENT_INSTALL_BACKEND_TEST`: Install the backend test library so it can be consumed on iOS
|
||||
- `FILAMENT_USE_EXTERNAL_GLES3`: Experimental: Compile Filament against OpenGL ES 3
|
||||
- `FILAMENT_SKIP_SAMPLES`: Don't build sample apps
|
||||
- `FILAMENT_ENABLE_EXCEPTIONS`: Enable C++ exceptions (default: ON, OFF for iOS). Required for JNI bindings.
|
||||
- `FILAMENT_ENABLE_RTTI`: Enable C++ RTTI (default: OFF).
|
||||
|
||||
Note: If you intend to use the JNI library (Android/Java build), you need to have `FILAMENT_ENABLE_EXCEPTIONS` enabled. If you are using Filament on Android as a pure native library and want to save space, you can disable it (e.g., using `./build.sh -E`).
|
||||
|
||||
To turn an option on or off:
|
||||
|
||||
@@ -412,7 +408,7 @@ same version that our continuous builds use.
|
||||
|
||||
```shell
|
||||
cd <your chosen parent folder for the emscripten SDK>
|
||||
curl -L https://github.com/emscripten-core/emsdk/archive/refs/tags/5.0.4.zip > emsdk.zip
|
||||
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
|
||||
python ./emsdk.py install latest
|
||||
python ./emsdk.py activate latest
|
||||
|
||||
+26
-43
@@ -20,12 +20,9 @@ endif()
|
||||
# Project declaration
|
||||
# ==================================================================================================
|
||||
set(EXTRA_LANGS)
|
||||
|
||||
# This is only needed for the webgpu on MacOS build.
|
||||
if (APPLE AND NOT IOS)
|
||||
if (APPLE)
|
||||
set(EXTRA_LANGS OBJC OBJCXX)
|
||||
endif()
|
||||
|
||||
project(TNT C CXX ${EXTRA_LANGS})
|
||||
|
||||
# ==================================================================================================
|
||||
@@ -33,20 +30,6 @@ project(TNT C CXX ${EXTRA_LANGS})
|
||||
# ==================================================================================================
|
||||
option(FILAMENT_USE_EXTERNAL_GLES3 "Experimental: Compile Filament against OpenGL ES 3" OFF)
|
||||
|
||||
# Note: If you intend to use the JNI library (Android/Java build), you need to have
|
||||
# exceptions enabled (the default). If you are using Filament on Android as a pure
|
||||
# native library and want to save space, you can disable them.
|
||||
# We disable exceptions on iOS by default. This fixes an availability error we see when using
|
||||
# std::visit and std::get, which are not supported on iOS 11.0 when exceptions are enabled.
|
||||
if (IOS)
|
||||
set(FILAMENT_ENABLE_EXCEPTIONS_DEFAULT OFF)
|
||||
else()
|
||||
set(FILAMENT_ENABLE_EXCEPTIONS_DEFAULT ON)
|
||||
endif()
|
||||
option(FILAMENT_ENABLE_EXCEPTIONS "Enable C++ exceptions" ${FILAMENT_ENABLE_EXCEPTIONS_DEFAULT})
|
||||
|
||||
option(FILAMENT_ENABLE_RTTI "Enable C++ RTTI" OFF)
|
||||
|
||||
option(FILAMENT_ENABLE_LTO "Enable link-time optimizations if supported by the compiler" OFF)
|
||||
option(FILAMENT_SKIP_SAMPLES "Don't build samples" OFF)
|
||||
|
||||
@@ -121,15 +104,6 @@ set(FILAMENT_OSMESA_PATH "" CACHE STRING
|
||||
# Enable exceptions by default in spirv-cross.
|
||||
set(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS OFF)
|
||||
|
||||
if (NOT FILAMENT_ENABLE_EXCEPTIONS)
|
||||
add_compile_options(-fno-exceptions)
|
||||
set(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS ON)
|
||||
endif()
|
||||
|
||||
if (NOT FILAMENT_ENABLE_RTTI)
|
||||
add_compile_options(-fno-rtti)
|
||||
endif()
|
||||
|
||||
# ==================================================================================================
|
||||
# CMake policies
|
||||
# ==================================================================================================
|
||||
@@ -367,14 +341,8 @@ endif()
|
||||
# ==================================================================================================
|
||||
# General compiler flags
|
||||
# ==================================================================================================
|
||||
|
||||
# This is only needed for the webgpu on MacOS build.
|
||||
# Don't enable for iOS because we need to support ios min target 11.0
|
||||
if (APPLE AND NOT IOS)
|
||||
set(CMAKE_OBJCXX_STANDARD 20)
|
||||
set(CMAKE_OBJCXX_STANDARD_REQUIRED ON)
|
||||
endif()
|
||||
|
||||
set(CMAKE_OBJCXX_STANDARD 20)
|
||||
set(CMAKE_OBJCXX_STANDARD_REQUIRED ON)
|
||||
set(CXX_STANDARD "-std=c++20")
|
||||
if (WIN32)
|
||||
set(CXX_STANDARD "/std:c++20")
|
||||
@@ -391,8 +359,8 @@ else()
|
||||
endif()
|
||||
if (APPLE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nullability-extension")
|
||||
set(CMAKE_OBJCXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
endif()
|
||||
set(CMAKE_OBJCXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
endif()
|
||||
|
||||
if (FILAMENT_USE_EXTERNAL_GLES3)
|
||||
@@ -439,7 +407,8 @@ if (ANDROID)
|
||||
endif()
|
||||
|
||||
if (CYGWIN)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
|
||||
set(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS ON)
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
@@ -473,17 +442,30 @@ if (NOT MSVC)
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ffunction-sections -fdata-sections")
|
||||
endif()
|
||||
|
||||
if (ANDROID OR WEBGL)
|
||||
# On Android and WebGL RELEASE builds, we omit unwind info to save space.
|
||||
# (We keep unwind info on iOS to allow readable stack traces in crash reports.)
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-unwind-tables -fno-asynchronous-unwind-tables")
|
||||
# On Android RELEASE builds, we disable exceptions and RTTI to save some space (about 75 KiB
|
||||
# saved by -fno-exception and 10 KiB saved by -fno-rtti).
|
||||
if (ANDROID OR IOS OR WEBGL)
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-exceptions -fno-rtti")
|
||||
set(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS ON)
|
||||
|
||||
if (ANDROID OR WEBGL)
|
||||
# Omitting unwind info prevents the generation of readable stack traces in crash reports on iOS
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-unwind-tables -fno-asynchronous-unwind-tables")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# With WebGL, we disable RTTI because we pass emscripten::val back and forth
|
||||
# Turn off exceptions on iOS debug as well. This fixes an availability error we see when using
|
||||
# std::visit, which is not supported on iOS 11.0 when exceptions are enabled.
|
||||
if (IOS)
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-exceptions")
|
||||
set(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS ON)
|
||||
endif()
|
||||
|
||||
# With WebGL, we disable RTTI even for debug builds because we pass emscripten::val back and forth
|
||||
# between C++ and JavaScript in order to efficiently access typed arrays, which are unbound.
|
||||
# NOTE: This is not documented in emscripten so we should consider a different approach.
|
||||
if (WEBGL)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-rtti")
|
||||
endif()
|
||||
|
||||
if (WEBGL_PTHREADS)
|
||||
@@ -684,6 +666,7 @@ if (FILAMENT_SUPPORTS_METAL)
|
||||
set(MATC_API_FLAGS ${MATC_API_FLAGS} -a metal)
|
||||
endif()
|
||||
|
||||
# With WebGPU, push constants are not supported. Skinning uses them.
|
||||
# WebGPU has a proposal to add push constants at https://github.com/gpuweb/gpuweb/blob/main/proposals/push-constants.md
|
||||
# With WebGPU, Tint does not support ClipDistance which is used in Stereo. Mentioned in comment
|
||||
# https://github.com/google/dawn/blob/855d17b08abdf02f9142bf5a8f14d0ea088810a4/src/tint/lang/spirv/reader/ast_parser/function.cc#L4434
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# Filament
|
||||
|
||||
[](https://github.com/google/filament/actions/workflows/status-android.yml)
|
||||
[](https://github.com/google/filament/actions/workflows/status-ios.yml)
|
||||
[](https://github.com/google/filament/actions/workflows/status-linux.yml)
|
||||
[](https://github.com/google/filament/actions/workflows/status-macos.yml)
|
||||
[](https://github.com/google/filament/actions/workflows/status-windows.yml)
|
||||
[](https://github.com/google/filament/actions/workflows/status-web.yml)
|
||||
[](https://github.com/google/filament/actions?query=workflow%3AAndroid)
|
||||
[](https://github.com/google/filament/actions?query=workflow%3AiOS)
|
||||
[](https://github.com/google/filament/actions?query=workflow%3ALinux)
|
||||
[](https://github.com/google/filament/actions?query=workflow%3AmacOS)
|
||||
[](https://github.com/google/filament/actions?query=workflow%3AWindows)
|
||||
[](https://github.com/google/filament/actions?query=workflow%3AWeb)
|
||||
|
||||
Filament is a real-time physically based rendering engine for Android, iOS, Linux, macOS, Windows,
|
||||
and WebGL. It is designed to be as small as possible and as efficient as possible on Android.
|
||||
@@ -31,7 +31,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.google.android.filament:filament-android:1.71.3'
|
||||
implementation 'com.google.android.filament:filament-android:1.71.0'
|
||||
}
|
||||
```
|
||||
|
||||
@@ -50,7 +50,7 @@ Here are all the libraries available in the group `com.google.android.filament`:
|
||||
iOS projects can use CocoaPods to install the latest release:
|
||||
|
||||
```shell
|
||||
pod 'Filament', '~> 1.71.3'
|
||||
pod 'Filament', '~> 1.71.0'
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
@@ -7,13 +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
|
||||
[NEW_RELEASE_NOTES.md](./NEW_RELEASE_NOTES.md).
|
||||
|
||||
## v1.71.3
|
||||
|
||||
- Metal: add support for asynchronous resource loading
|
||||
|
||||
## v1.71.2
|
||||
|
||||
|
||||
## v1.71.1
|
||||
|
||||
|
||||
|
||||
@@ -145,6 +145,7 @@ buildscript {
|
||||
ext.cppFlags = [
|
||||
"-std=c++17",
|
||||
"-fno-stack-protector",
|
||||
"-fno-exceptions",
|
||||
"-fno-unwind-tables",
|
||||
"-fno-asynchronous-unwind-tables",
|
||||
"-fno-rtti",
|
||||
|
||||
@@ -75,17 +75,6 @@ void JniCallback::postToJavaAndDestroy(JniCallback* callback) {
|
||||
delete callback;
|
||||
}
|
||||
|
||||
void JniCallback::destroy(JniCallback* callback) {
|
||||
JNIEnv* env = filament::VirtualMachineEnv::get().getEnvironment();
|
||||
env->DeleteGlobalRef(callback->mHandler);
|
||||
env->DeleteGlobalRef(callback->mCallback);
|
||||
#ifdef __ANDROID__
|
||||
env->DeleteGlobalRef(callback->mCallbackUtils.handlerClass);
|
||||
#endif
|
||||
env->DeleteGlobalRef(callback->mCallbackUtils.executorClass);
|
||||
delete callback;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
|
||||
JniBufferCallback* JniBufferCallback::make(filament::Engine*,
|
||||
|
||||
@@ -48,9 +48,6 @@ struct JniCallback : private filament::backend::CallbackHandler {
|
||||
// execute the callback on the java thread and destroy ourselves
|
||||
static void postToJavaAndDestroy(JniCallback* callback);
|
||||
|
||||
// destroy ourselves without executing the callback
|
||||
static void destroy(JniCallback* callback);
|
||||
|
||||
// CallbackHandler interface.
|
||||
void post(void* user, Callback callback) override;
|
||||
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2026 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "JniUtils.h"
|
||||
|
||||
namespace filament {
|
||||
namespace android {
|
||||
|
||||
#ifdef __EXCEPTIONS
|
||||
|
||||
UTILS_NOINLINE void wrapJniHelper(JNIEnv* env, void (*invoker)(void*), void* userData) {
|
||||
try {
|
||||
invoker(userData);
|
||||
} catch (const utils::PreconditionPanic& e) {
|
||||
jclass exClass = env->FindClass("java/lang/IllegalArgumentException");
|
||||
env->ThrowNew(exClass, e.what());
|
||||
} catch (const utils::PostconditionPanic& e) {
|
||||
jclass exClass = env->FindClass("java/lang/RuntimeException");
|
||||
env->ThrowNew(exClass, e.what());
|
||||
} catch (const std::exception& e) {
|
||||
jclass exClass = env->FindClass("java/lang/RuntimeException");
|
||||
env->ThrowNew(exClass, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
UTILS_NOINLINE void wrapJniBackendHelper(JNIEnv* env, void (*invoker)(void*), void* userData) {
|
||||
try {
|
||||
invoker(userData);
|
||||
} catch (const std::exception& e) {
|
||||
jclass exClass = env->FindClass("java/lang/RuntimeException");
|
||||
env->ThrowNew(exClass, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace android
|
||||
} // namespace filament
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2026 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_ANDROID_COMMON_JNIUTILS_H
|
||||
#define TNT_ANDROID_COMMON_JNIUTILS_H
|
||||
|
||||
#include <jni.h>
|
||||
#include <exception>
|
||||
#include <type_traits>
|
||||
#include <utils/Panic.h>
|
||||
#include <utils/compiler.h>
|
||||
|
||||
namespace filament {
|
||||
namespace android {
|
||||
|
||||
#ifdef __EXCEPTIONS
|
||||
|
||||
// Non-templated helpers implemented in JniUtils.cpp
|
||||
void wrapJniHelper(JNIEnv* env, void (*invoker)(void*), void* userData);
|
||||
void wrapJniBackendHelper(JNIEnv* env, void (*invoker)(void*), void* userData);
|
||||
|
||||
// For JNI methods that return a value
|
||||
template<typename R, typename F>
|
||||
R wrapJni(JNIEnv* env, F const& f) {
|
||||
if constexpr (std::is_void_v<R>) {
|
||||
auto invoker = [](void* data) {
|
||||
auto& f_ref = *reinterpret_cast<const F*>(data);
|
||||
f_ref();
|
||||
};
|
||||
wrapJniHelper(env, invoker, (void*)&f);
|
||||
} else {
|
||||
struct Context {
|
||||
const F& f;
|
||||
R result;
|
||||
};
|
||||
Context ctx{ f, R{} };
|
||||
auto invoker = [](void* data) {
|
||||
auto& context = *reinterpret_cast<Context*>(data);
|
||||
context.result = context.f();
|
||||
};
|
||||
wrapJniHelper(env, invoker, &ctx);
|
||||
return ctx.result;
|
||||
}
|
||||
}
|
||||
|
||||
// Overload for JNI methods that return void
|
||||
template<typename F>
|
||||
inline void wrapJni(JNIEnv* env, F const& f) {
|
||||
wrapJni<void, F>(env, f);
|
||||
}
|
||||
|
||||
// For JNI methods that can return backend errors (mapped to java.lang.Error)
|
||||
template<typename R, typename F>
|
||||
R wrapJniBackend(JNIEnv* env, F const& f) {
|
||||
if constexpr (std::is_void_v<R>) {
|
||||
auto invoker = [](void* data) {
|
||||
auto& f_ref = *reinterpret_cast<const F*>(data);
|
||||
f_ref();
|
||||
};
|
||||
wrapJniBackendHelper(env, invoker, (void*)&f);
|
||||
} else {
|
||||
struct Context {
|
||||
const F& f;
|
||||
R result;
|
||||
};
|
||||
Context ctx{ f, R{} };
|
||||
auto invoker = [](void* data) {
|
||||
auto& context = *reinterpret_cast<Context*>(data);
|
||||
context.result = context.f();
|
||||
};
|
||||
wrapJniBackendHelper(env, invoker, &ctx);
|
||||
return ctx.result;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
inline void wrapJniBackend(JNIEnv* env, F const& f) {
|
||||
wrapJniBackend<void, F>(env, f);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// For JNI methods that return a value
|
||||
template<typename R, typename F>
|
||||
R wrapJni(JNIEnv* env, F const& f) {
|
||||
return f();
|
||||
}
|
||||
|
||||
// Overload for JNI methods that return void
|
||||
template<typename F>
|
||||
inline void wrapJni(JNIEnv* env, F const& f) {
|
||||
f();
|
||||
}
|
||||
|
||||
template<typename R, typename F>
|
||||
R wrapJniBackend(JNIEnv* env, F const& f) {
|
||||
return f();
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
inline void wrapJniBackend(JNIEnv* env, F const& f) {
|
||||
f();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace android
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_ANDROID_COMMON_JNIUTILS_H
|
||||
@@ -126,7 +126,6 @@ add_library(filament-jni SHARED
|
||||
# Common utils
|
||||
../common/CallbackUtils.cpp
|
||||
../common/NioUtils.cpp
|
||||
../common/JniUtils.cpp
|
||||
)
|
||||
|
||||
target_include_directories(filament-jni PRIVATE
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <functional>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -25,7 +26,6 @@
|
||||
|
||||
#include "common/CallbackUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace backend;
|
||||
@@ -63,9 +63,7 @@ Java_com_google_android_filament_BufferObject_nBuilderBuild(JNIEnv *env, jclass
|
||||
jlong nativeBuilder, jlong nativeEngine) {
|
||||
BufferObject::Builder* builder = (BufferObject::Builder *) nativeBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return filament::android::wrapJni<jlong>(env, [=]() {
|
||||
return (jlong) builder->build(*engine);
|
||||
});
|
||||
return (jlong) builder->build(*engine);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
@@ -83,22 +81,20 @@ Java_com_google_android_filament_BufferObject_nSetBuffer(JNIEnv *env, jclass typ
|
||||
BufferObject *bufferObject = (BufferObject *) nativeBufferObject;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
|
||||
return filament::android::wrapJni<int>(env, [=]() {
|
||||
AutoBuffer nioBuffer(env, buffer, count);
|
||||
void* data = nioBuffer.getData();
|
||||
size_t sizeInBytes = nioBuffer.getSize();
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
AutoBuffer nioBuffer(env, buffer, count);
|
||||
void* data = nioBuffer.getData();
|
||||
size_t sizeInBytes = nioBuffer.getSize();
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto* callback = JniBufferCallback::make(engine, env, handler, runnable, std::move(nioBuffer));
|
||||
auto* callback = JniBufferCallback::make(engine, env, handler, runnable, std::move(nioBuffer));
|
||||
|
||||
BufferDescriptor desc(data, sizeInBytes,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
BufferDescriptor desc(data, sizeInBytes,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
bufferObject->setBuffer(*engine, std::move(desc), (uint32_t) destOffsetInBytes);
|
||||
bufferObject->setBuffer(*engine, std::move(desc), (uint32_t) destOffsetInBytes);
|
||||
|
||||
return 0;
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <jni.h>
|
||||
|
||||
#include <filament/Camera.h>
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
|
||||
#include <utils/Entity.h>
|
||||
@@ -25,26 +24,21 @@
|
||||
#include <math/mat4.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace filament::android;
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Camera_nSetProjection(JNIEnv* env, jclass, jlong nativeCamera,
|
||||
Java_com_google_android_filament_Camera_nSetProjection(JNIEnv*, jclass, jlong nativeCamera,
|
||||
jint projection, jdouble left, jdouble right, jdouble bottom, jdouble top, jdouble near,
|
||||
jdouble far) {
|
||||
Camera *camera = (Camera *) nativeCamera;
|
||||
wrapJni(env, [=]() {
|
||||
camera->setProjection((Camera::Projection) projection, left, right, bottom, top, near, far);
|
||||
});
|
||||
camera->setProjection((Camera::Projection) projection, left, right, bottom, top, near, far);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Camera_nSetProjectionFov(JNIEnv* env, jclass ,
|
||||
Java_com_google_android_filament_Camera_nSetProjectionFov(JNIEnv*, jclass ,
|
||||
jlong nativeCamera, jdouble fovInDegrees, jdouble aspect, jdouble near, jdouble far,
|
||||
jint fov) {
|
||||
Camera *camera = (Camera *) nativeCamera;
|
||||
wrapJni(env, [=]() {
|
||||
camera->setProjection(fovInDegrees, aspect, near, far, (Camera::Fov) fov);
|
||||
});
|
||||
camera->setProjection(fovInDegrees, aspect, near, far, (Camera::Fov) fov);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jdouble JNICALL
|
||||
@@ -55,12 +49,10 @@ Java_com_google_android_filament_Camera_nGetFieldOfViewInDegrees(JNIEnv*, jclass
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Camera_nSetLensProjection(JNIEnv* env, jclass,
|
||||
Java_com_google_android_filament_Camera_nSetLensProjection(JNIEnv*, jclass,
|
||||
jlong nativeCamera, jdouble focalLength, jdouble aspect, jdouble near, jdouble far) {
|
||||
Camera *camera = (Camera *) nativeCamera;
|
||||
wrapJni(env, [=]() {
|
||||
camera->setLensProjection(focalLength, aspect, near, far);
|
||||
});
|
||||
camera->setLensProjection(focalLength, aspect, near, far);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
@@ -70,12 +62,10 @@ Java_com_google_android_filament_Camera_nSetCustomProjection(JNIEnv *env, jclass
|
||||
Camera *camera = (Camera *) nativeCamera;
|
||||
jdouble *inProjection = env->GetDoubleArrayElements(inProjection_, NULL);
|
||||
jdouble *inProjectionForCulling = env->GetDoubleArrayElements(inProjectionForCulling_, NULL);
|
||||
wrapJni(env, [=]() {
|
||||
camera->setCustomProjection(
|
||||
*reinterpret_cast<const filament::math::mat4 *>(inProjection),
|
||||
*reinterpret_cast<const filament::math::mat4 *>(inProjectionForCulling),
|
||||
near, far);
|
||||
});
|
||||
camera->setCustomProjection(
|
||||
*reinterpret_cast<const filament::math::mat4 *>(inProjection),
|
||||
*reinterpret_cast<const filament::math::mat4 *>(inProjectionForCulling),
|
||||
near, far);
|
||||
env->ReleaseDoubleArrayElements(inProjection_, inProjection, JNI_ABORT);
|
||||
env->ReleaseDoubleArrayElements(inProjectionForCulling_, inProjectionForCulling, JNI_ABORT);
|
||||
}
|
||||
@@ -87,12 +77,10 @@ Java_com_google_android_filament_Camera_nSetCustomEyeProjection(JNIEnv *env, jcl
|
||||
Camera *camera = (Camera *) nativeCamera;
|
||||
jdouble *inProjection = env->GetDoubleArrayElements(inProjection_, NULL);
|
||||
jdouble *inProjectionForCulling = env->GetDoubleArrayElements(inProjectionForCulling_, NULL);
|
||||
wrapJni(env, [=]() {
|
||||
camera->setCustomEyeProjection(
|
||||
reinterpret_cast<const filament::math::mat4 *>(inProjection), (size_t) count,
|
||||
*reinterpret_cast<const filament::math::mat4 *>(inProjectionForCulling),
|
||||
near, far);
|
||||
});
|
||||
camera->setCustomEyeProjection(
|
||||
reinterpret_cast<const filament::math::mat4 *>(inProjection), (size_t) count,
|
||||
*reinterpret_cast<const filament::math::mat4 *>(inProjectionForCulling),
|
||||
near, far);
|
||||
env->ReleaseDoubleArrayElements(inProjection_, inProjection, JNI_ABORT);
|
||||
env->ReleaseDoubleArrayElements(inProjectionForCulling_, inProjectionForCulling, JNI_ABORT);
|
||||
}
|
||||
@@ -166,9 +154,7 @@ Java_com_google_android_filament_Camera_nSetEyeModelMatrix(JNIEnv *env, jclass,
|
||||
jlong nativeCamera, jint eyeId, jdoubleArray model_) {
|
||||
Camera* camera = (Camera *) nativeCamera;
|
||||
jdouble *model = env->GetDoubleArrayElements(model_, NULL);
|
||||
wrapJni(env, [=]() {
|
||||
camera->setEyeModelMatrix((uint8_t)eyeId, *reinterpret_cast<const filament::math::mat4 *>(model));
|
||||
});
|
||||
camera->setEyeModelMatrix((uint8_t)eyeId, *reinterpret_cast<const filament::math::mat4*>(model));
|
||||
env->ReleaseDoubleArrayElements(model_, model, JNI_ABORT);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace math;
|
||||
@@ -38,12 +37,10 @@ Java_com_google_android_filament_ColorGrading_nDestroyBuilder(JNIEnv*, jclass, j
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_ColorGrading_nBuilderBuild(JNIEnv* env, jclass, jlong nativeBuilder, jlong nativeEngine) {
|
||||
Java_com_google_android_filament_ColorGrading_nBuilderBuild(JNIEnv*, jclass, jlong nativeBuilder, jlong nativeEngine) {
|
||||
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return filament::android::wrapJni<jlong>(env, [=]() {
|
||||
return (jlong) builder->build(*engine);
|
||||
});
|
||||
return (jlong) builder->build(*engine);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <exception>
|
||||
|
||||
#include <filament/Camera.h>
|
||||
#include <filament/Engine.h>
|
||||
#include <filament/MorphTargetBuffer.h>
|
||||
@@ -30,18 +28,14 @@
|
||||
#include <filament/View.h>
|
||||
|
||||
#include "common/CallbackUtils.h"
|
||||
#include "common/JniUtils.h"
|
||||
|
||||
using namespace filament;
|
||||
using namespace utils;
|
||||
using namespace filament::android;
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyEngine(JNIEnv *env, jclass, jlong nativeEngine) {
|
||||
wrapJni(env, [=]() {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
Engine::destroy(&engine);
|
||||
});
|
||||
Java_com_google_android_filament_Engine_nDestroyEngine(JNIEnv*, jclass, jlong nativeEngine) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
Engine::destroy(&engine);
|
||||
}
|
||||
|
||||
// SwapChain
|
||||
@@ -83,13 +77,11 @@ Java_com_google_android_filament_Engine_nCreateSwapChainFromRawPointer(JNIEnv*,
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroySwapChain(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroySwapChain(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeSwapChain) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
SwapChain* swapChain = (SwapChain*) nativeSwapChain;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->destroy(swapChain);
|
||||
});
|
||||
return engine->destroy(swapChain);
|
||||
}
|
||||
|
||||
// View
|
||||
@@ -102,13 +94,11 @@ Java_com_google_android_filament_Engine_nCreateView(JNIEnv*, jclass,
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyView(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroyView(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeView) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
View* view = (View*) nativeView;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->destroy(view);
|
||||
});
|
||||
return engine->destroy(view);
|
||||
}
|
||||
|
||||
// Renderer
|
||||
@@ -121,13 +111,11 @@ Java_com_google_android_filament_Engine_nCreateRenderer(JNIEnv*, jclass,
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyRenderer(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroyRenderer(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeRenderer) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
Renderer* renderer = (Renderer*) nativeRenderer;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->destroy(renderer);
|
||||
});
|
||||
return engine->destroy(renderer);
|
||||
}
|
||||
|
||||
// Camera
|
||||
@@ -149,13 +137,11 @@ Java_com_google_android_filament_Engine_nGetCameraComponent(JNIEnv*, jclass,
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyCameraComponent(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroyCameraComponent(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jint entity_) {
|
||||
wrapJni(env, [=]() {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
Entity entity = *reinterpret_cast<const Entity*>(&entity_);
|
||||
engine->destroyCameraComponent(entity);
|
||||
});
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
Entity& entity = *reinterpret_cast<Entity*>(&entity_);
|
||||
engine->destroyCameraComponent(entity);
|
||||
}
|
||||
|
||||
// Scene
|
||||
@@ -168,13 +154,11 @@ Java_com_google_android_filament_Engine_nCreateScene(JNIEnv*, jclass,
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyScene(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroyScene(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeScene) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
Scene* scene = (Scene*) nativeScene;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->destroy(scene);
|
||||
});
|
||||
return engine->destroy(scene);
|
||||
}
|
||||
|
||||
// Fence
|
||||
@@ -187,147 +171,119 @@ Java_com_google_android_filament_Engine_nCreateFence(JNIEnv*, jclass,
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyFence(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroyFence(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeFence) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
Fence* fence = (Fence*) nativeFence;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->destroy(fence);
|
||||
});
|
||||
return engine->destroy(fence);
|
||||
}
|
||||
|
||||
// Stream
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyStream(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroyStream(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeStream) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
Stream* stream = (Stream*) nativeStream;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->destroy(stream);
|
||||
});
|
||||
return engine->destroy(stream);
|
||||
}
|
||||
|
||||
// Others...
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyIndexBuffer(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroyIndexBuffer(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeIndexBuffer) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
IndexBuffer* indexBuffer = (IndexBuffer*) nativeIndexBuffer;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->destroy(indexBuffer);
|
||||
});
|
||||
return engine->destroy(indexBuffer);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyVertexBuffer(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroyVertexBuffer(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeVertexBuffer) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
VertexBuffer* vertexBuffer = (VertexBuffer*) nativeVertexBuffer;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->destroy(vertexBuffer);
|
||||
});
|
||||
return engine->destroy(vertexBuffer);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroySkinningBuffer(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroySkinningBuffer(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeSkinningBuffer) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
SkinningBuffer* skinningBuffer = (SkinningBuffer*) nativeSkinningBuffer;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->destroy(skinningBuffer);
|
||||
});
|
||||
return engine->destroy(skinningBuffer);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyMorphTargetBuffer(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroyMorphTargetBuffer(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeMorphTargetBuffer) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
MorphTargetBuffer* mtb = (MorphTargetBuffer*) nativeMorphTargetBuffer;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->destroy(mtb);
|
||||
});
|
||||
return engine->destroy(mtb);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyIndirectLight(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroyIndirectLight(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeIndirectLight) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
IndirectLight* indirectLight = (IndirectLight*) nativeIndirectLight;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->destroy(indirectLight);
|
||||
});
|
||||
return engine->destroy(indirectLight);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyMaterial(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroyMaterial(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeMaterial) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
Material* material = (Material*) nativeMaterial;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->destroy(material);
|
||||
});
|
||||
return engine->destroy(material);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyMaterialInstance(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroyMaterialInstance(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeMaterialInstance) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
MaterialInstance* materialInstance = (MaterialInstance*) nativeMaterialInstance;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->destroy(materialInstance);
|
||||
});
|
||||
return engine->destroy(materialInstance);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroySkybox(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroySkybox(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeSkybox) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
Skybox* skybox = (Skybox*) nativeSkybox;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->destroy(skybox);
|
||||
});
|
||||
return engine->destroy(skybox);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyColorGrading(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroyColorGrading(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeColorGrading) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
ColorGrading* colorGrading = (ColorGrading*) nativeColorGrading;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->destroy(colorGrading);
|
||||
});
|
||||
return engine->destroy(colorGrading);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyTexture(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroyTexture(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeTexture) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
Texture* texture = (Texture*) nativeTexture;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->destroy(texture);
|
||||
});
|
||||
return engine->destroy(texture);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyRenderTarget(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroyRenderTarget(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong nativeTarget) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
RenderTarget* target = (RenderTarget*) nativeTarget;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->destroy(target);
|
||||
});
|
||||
return engine->destroy(target);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Engine_nDestroyEntity(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nDestroyEntity(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jint entity_) {
|
||||
wrapJni(env, [=]() {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
Entity entity = *reinterpret_cast<const Entity*>(&entity_);
|
||||
engine->destroy(entity);
|
||||
});
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
Entity& entity = *reinterpret_cast<Entity*>(&entity_);
|
||||
engine->destroy(entity);
|
||||
}
|
||||
|
||||
|
||||
@@ -459,21 +415,17 @@ Java_com_google_android_filament_Engine_nIsValidSwapChain(JNIEnv*, jclass,
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nFlushAndWait(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nFlushAndWait(JNIEnv*, jclass,
|
||||
jlong nativeEngine, jlong timeout) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return engine->flushAndWait((uint64_t)timeout);
|
||||
});
|
||||
return engine->flushAndWait((uint64_t)timeout);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Engine_nFlush(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nFlush(JNIEnv*, jclass,
|
||||
jlong nativeEngine) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
wrapJni(env, [=]() {
|
||||
engine->flush();
|
||||
});
|
||||
engine->flush();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
@@ -484,32 +436,21 @@ Java_com_google_android_filament_Engine_nIsPaused(JNIEnv*, jclass,
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Engine_nCompile(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nCompile(JNIEnv* env, jclass,
|
||||
jlong nativeEngine, jint priority, jlong nativeMaterial, jlong nativeView,
|
||||
jint shadowReceiver, jint skinning, jobject handler, jobject runnable) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
Material* material = (Material*) nativeMaterial;
|
||||
View* view = (View*) nativeView;
|
||||
JniCallback* jniCallback = JniCallback::make(env, handler, runnable);
|
||||
wrapJni(env, [=]() {
|
||||
#if defined(__EXCEPTIONS)
|
||||
try {
|
||||
#endif
|
||||
engine->compile(
|
||||
(backend::CompilerPriorityQueue) priority,
|
||||
material, view,
|
||||
(utils::tribool::value_t) shadowReceiver,
|
||||
(utils::tribool::value_t) skinning,
|
||||
jniCallback->getHandler(), [jniCallback](Material*){
|
||||
JniCallback::postToJavaAndDestroy(jniCallback);
|
||||
});
|
||||
#if defined(__EXCEPTIONS)
|
||||
} catch (...) {
|
||||
JniCallback::destroy(jniCallback);
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
});
|
||||
engine->compile(
|
||||
(backend::CompilerPriorityQueue) priority,
|
||||
material, view,
|
||||
(utils::tribool::value_t) shadowReceiver,
|
||||
(utils::tribool::value_t) skinning,
|
||||
jniCallback->getHandler(), [jniCallback](Material*){
|
||||
JniCallback::postToJavaAndDestroy(jniCallback);
|
||||
});
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
@@ -570,12 +511,6 @@ Java_com_google_android_filament_Engine_nIsAutomaticInstancingEnabled(JNIEnv*, j
|
||||
return (jboolean)engine->isAutomaticInstancingEnabled();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Engine_nHasUnrecoverableFailure(JNIEnv*, jclass, jlong nativeEngine) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
return (jboolean)engine->hasUnrecoverableFailure();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_Engine_nGetMaxStereoscopicEyes(JNIEnv*, jclass, jlong nativeEngine) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
@@ -591,12 +526,10 @@ Java_com_google_android_filament_Engine_nGetSupportedFeatureLevel(JNIEnv *, jcla
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_Engine_nSetActiveFeatureLevel(JNIEnv *env, jclass,
|
||||
Java_com_google_android_filament_Engine_nSetActiveFeatureLevel(JNIEnv *, jclass,
|
||||
jlong nativeEngine, jint ordinal) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
return wrapJni<jint>(env, [=]() {
|
||||
return (jint)engine->setActiveFeatureLevel((Engine::FeatureLevel)ordinal);
|
||||
});
|
||||
return (jint)engine->setActiveFeatureLevel((Engine::FeatureLevel)ordinal);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
@@ -718,11 +651,9 @@ Java_com_google_android_filament_Engine_nSetBuilderFeature(JNIEnv *env, jclass c
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_Engine_nBuilderBuild(JNIEnv *env, jclass, jlong nativeBuilder) {
|
||||
Java_com_google_android_filament_Engine_nBuilderBuild(JNIEnv*, jclass, jlong nativeBuilder) {
|
||||
Engine::Builder* builder = (Engine::Builder*) nativeBuilder;
|
||||
return wrapJniBackend<jlong>(env, [=]() {
|
||||
return (jlong) builder->build();
|
||||
});
|
||||
return (jlong) builder->build();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <jni.h>
|
||||
|
||||
#include <filament/Fence.h>
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
using namespace filament;
|
||||
|
||||
@@ -25,17 +24,13 @@ extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_Fence_nWait(JNIEnv *env, jclass type, jlong nativeFence, jint mode,
|
||||
jlong timeoutNanoSeconds) {
|
||||
Fence *fence = (Fence *) nativeFence;
|
||||
return filament::android::wrapJniBackend<jint>(env, [=]() {
|
||||
return (jint) fence->wait((Fence::Mode) mode, (uint64_t) timeoutNanoSeconds);
|
||||
});
|
||||
return (jint) fence->wait((Fence::Mode) mode, (uint64_t) timeoutNanoSeconds);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_Fence_nWaitAndDestroy(JNIEnv *env, jclass type, jlong nativeFence,
|
||||
jint mode) {
|
||||
Fence *fence = (Fence *) nativeFence;
|
||||
return filament::android::wrapJniBackend<jint>(env, [=]() {
|
||||
return (jint) Fence::waitAndDestroy(fence, (Fence::Mode) mode);
|
||||
});
|
||||
return (jint) Fence::waitAndDestroy(fence, (Fence::Mode) mode);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <functional>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <filament/IndexBuffer.h>
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
#include <backend/BufferDescriptor.h>
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
using namespace filament;
|
||||
using namespace backend;
|
||||
using namespace filament::android;
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_IndexBuffer_nCreateBuilder(JNIEnv *env, jclass type) {
|
||||
@@ -64,9 +63,7 @@ Java_com_google_android_filament_IndexBuffer_nBuilderBuild(JNIEnv *env, jclass t
|
||||
jlong nativeBuilder, jlong nativeEngine) {
|
||||
IndexBuffer::Builder* builder = (IndexBuffer::Builder *) nativeBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return wrapJni<jlong>(env, [=]() {
|
||||
return (jlong) builder->build(*engine);
|
||||
});
|
||||
return (jlong) builder->build(*engine);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
@@ -97,9 +94,7 @@ Java_com_google_android_filament_IndexBuffer_nSetBuffer(JNIEnv *env, jclass type
|
||||
BufferDescriptor desc(data, sizeInBytes,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
wrapJni(env, [&]() {
|
||||
indexBuffer->setBuffer(*engine, std::move(desc), (uint32_t) destOffsetInBytes);
|
||||
});
|
||||
indexBuffer->setBuffer(*engine, std::move(desc), (uint32_t) destOffsetInBytes);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include <common/NioUtils.h>
|
||||
#include <common/CallbackUtils.h>
|
||||
#include <math/mat4.h>
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
using namespace filament;
|
||||
|
||||
@@ -38,13 +37,11 @@ Java_com_google_android_filament_IndirectLight_nDestroyBuilder(JNIEnv*, jclass,
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_IndirectLight_nBuilderBuild(JNIEnv* env, jclass,
|
||||
Java_com_google_android_filament_IndirectLight_nBuilderBuild(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jlong nativeEngine) {
|
||||
IndirectLight::Builder* builder = (IndirectLight::Builder*) nativeBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return filament::android::wrapJni<jlong>(env, [=]() {
|
||||
return (jlong) builder->build(*engine);
|
||||
});
|
||||
return (jlong) builder->build(*engine);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <jni.h>
|
||||
|
||||
#include <filament/LightManager.h>
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
#include <utils/Entity.h>
|
||||
|
||||
@@ -25,7 +24,6 @@
|
||||
|
||||
using namespace filament;
|
||||
using namespace utils;
|
||||
using namespace filament::android;
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_LightManager_nGetComponentCount(JNIEnv*, jclass,
|
||||
@@ -212,13 +210,11 @@ Java_com_google_android_filament_LightManager_nBuilderLightChannel(JNIEnv*, jcla
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_LightManager_nBuilderBuild(JNIEnv* env, jclass,
|
||||
Java_com_google_android_filament_LightManager_nBuilderBuild(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jlong nativeEngine, jint entity) {
|
||||
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return jboolean(builder->build(*engine, (Entity &) entity) == LightManager::Builder::Success);
|
||||
});
|
||||
return jboolean(builder->build(*engine, (Entity &) entity) == LightManager::Builder::Success);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -227,9 +223,7 @@ extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nComputeUniformSplits(JNIEnv* env, jclass,
|
||||
jfloatArray splitPositions, jint cascades) {
|
||||
jfloat *nativeSplits = env->GetFloatArrayElements(splitPositions, NULL);
|
||||
wrapJni(env, [=]() {
|
||||
LightManager::ShadowCascades::computeUniformSplits(nativeSplits, (uint8_t) cascades);
|
||||
});
|
||||
LightManager::ShadowCascades::computeUniformSplits(nativeSplits, (uint8_t) cascades);
|
||||
env->ReleaseFloatArrayElements(splitPositions, nativeSplits, 0);
|
||||
}
|
||||
|
||||
@@ -237,9 +231,7 @@ extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nComputeLogSplits(JNIEnv* env, jclass,
|
||||
jfloatArray splitPositions, jint cascades, jfloat near, jfloat far) {
|
||||
jfloat *nativeSplits = env->GetFloatArrayElements(splitPositions, NULL);
|
||||
wrapJni(env, [=]() {
|
||||
LightManager::ShadowCascades::computeLogSplits(nativeSplits, (uint8_t) cascades, near, far);
|
||||
});
|
||||
LightManager::ShadowCascades::computeLogSplits(nativeSplits, (uint8_t) cascades, near, far);
|
||||
env->ReleaseFloatArrayElements(splitPositions, nativeSplits, 0);
|
||||
}
|
||||
|
||||
@@ -247,9 +239,7 @@ extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_LightManager_nComputePracticalSplits(JNIEnv* env, jclass,
|
||||
jfloatArray splitPositions, jint cascades, jfloat near, jfloat far, jfloat lambda) {
|
||||
jfloat *nativeSplits = env->GetFloatArrayElements(splitPositions, NULL);
|
||||
wrapJni(env, [=]() {
|
||||
LightManager::ShadowCascades::computePracticalSplits(nativeSplits, (uint8_t) cascades, near, far, lambda);
|
||||
});
|
||||
LightManager::ShadowCascades::computePracticalSplits(nativeSplits, (uint8_t) cascades, near, far, lambda);
|
||||
env->ReleaseFloatArrayElements(splitPositions, nativeSplits, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,28 +20,25 @@
|
||||
|
||||
#include "common/NioUtils.h"
|
||||
#include "common/CallbackUtils.h"
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace filament::android;
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_Material_nBuilderBuild(JNIEnv *env, jclass,
|
||||
jlong nativeEngine, jobject buffer_, jint size, jint shBandCount, jint shadowQuality, jint uboBatchingMode) {
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
return wrapJni<jlong>(env, [=]() {
|
||||
AutoBuffer buffer(env, buffer_, size);
|
||||
auto builder = Material::Builder();
|
||||
if (shBandCount) {
|
||||
builder.sphericalHarmonicsBandCount(shBandCount);
|
||||
}
|
||||
builder.shadowSamplingQuality((Material::Builder::ShadowSamplingQuality)shadowQuality);
|
||||
builder.uboBatching((Material::UboBatchingMode)uboBatchingMode);
|
||||
Material* material = builder
|
||||
.package(buffer.getData(), buffer.getSize())
|
||||
.build(*engine);
|
||||
return (jlong) material;
|
||||
});
|
||||
AutoBuffer buffer(env, buffer_, size);
|
||||
auto builder = Material::Builder();
|
||||
if (shBandCount) {
|
||||
builder.sphericalHarmonicsBandCount(shBandCount);
|
||||
}
|
||||
builder.shadowSamplingQuality((Material::Builder::ShadowSamplingQuality)shadowQuality);
|
||||
builder.uboBatching((Material::UboBatchingMode)uboBatchingMode);
|
||||
Material* material = builder
|
||||
.package(buffer.getData(), buffer.getSize())
|
||||
.build(*engine);
|
||||
|
||||
return (jlong) material;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
|
||||
@@ -25,11 +25,9 @@
|
||||
#include <math/vec2.h>
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace filament::math;
|
||||
using namespace filament::android;
|
||||
|
||||
enum BooleanElement {
|
||||
BOOL,
|
||||
@@ -58,9 +56,7 @@ template<typename T>
|
||||
static void setParameter(JNIEnv* env, jlong nativeMaterialInstance, jstring name_, T v) {
|
||||
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
|
||||
const char *name = env->GetStringUTFChars(name_, 0);
|
||||
wrapJni(env, [=]() {
|
||||
instance->setParameter(name, v);
|
||||
});
|
||||
instance->setParameter(name, v);
|
||||
env->ReleaseStringUTFChars(name_, name);
|
||||
}
|
||||
|
||||
@@ -164,22 +160,20 @@ Java_com_google_android_filament_MaterialInstance_nSetBooleanParameterArray(JNIE
|
||||
// NOTE: In C++, bool has an implementation-defined size. Here we assume
|
||||
// it has the same size as jboolean, which is 1 byte.
|
||||
|
||||
wrapJni(env, [=]() {
|
||||
switch ((BooleanElement) element) {
|
||||
case BOOL:
|
||||
instance->setParameter(name, ((const bool*) v) + offset, count);
|
||||
break;
|
||||
case BOOL2:
|
||||
instance->setParameter(name, ((const bool2*) v) + offset, count);
|
||||
break;
|
||||
case BOOL3:
|
||||
instance->setParameter(name, ((const bool3*) v) + offset, count);
|
||||
break;
|
||||
case BOOL4:
|
||||
instance->setParameter(name, ((const bool4*) v) + offset, count);
|
||||
break;
|
||||
}
|
||||
});
|
||||
switch ((BooleanElement) element) {
|
||||
case BOOL:
|
||||
instance->setParameter(name, ((const bool*) v) + offset, count);
|
||||
break;
|
||||
case BOOL2:
|
||||
instance->setParameter(name, ((const bool2*) v) + offset, count);
|
||||
break;
|
||||
case BOOL3:
|
||||
instance->setParameter(name, ((const bool3*) v) + offset, count);
|
||||
break;
|
||||
case BOOL4:
|
||||
instance->setParameter(name, ((const bool4*) v) + offset, count);
|
||||
break;
|
||||
}
|
||||
|
||||
env->ReleaseBooleanArrayElements(v_, v, 0);
|
||||
|
||||
@@ -196,22 +190,20 @@ Java_com_google_android_filament_MaterialInstance_nSetIntParameterArray(JNIEnv *
|
||||
const char* name = env->GetStringUTFChars(name_, 0);
|
||||
jint* v = env->GetIntArrayElements(v_, NULL);
|
||||
|
||||
wrapJni(env, [=]() {
|
||||
switch ((IntElement) element) {
|
||||
case INT:
|
||||
instance->setParameter(name, ((const int32_t*) v) + offset, count);
|
||||
break;
|
||||
case INT2:
|
||||
instance->setParameter(name, ((const int2*) v) + offset, count);
|
||||
break;
|
||||
case INT3:
|
||||
instance->setParameter(name, ((const int3*) v) + offset, count);
|
||||
break;
|
||||
case INT4:
|
||||
instance->setParameter(name, ((const int4*) v) + offset, count);
|
||||
break;
|
||||
}
|
||||
});
|
||||
switch ((IntElement) element) {
|
||||
case INT:
|
||||
instance->setParameter(name, ((const int32_t*) v) + offset, count);
|
||||
break;
|
||||
case INT2:
|
||||
instance->setParameter(name, ((const int2*) v) + offset, count);
|
||||
break;
|
||||
case INT3:
|
||||
instance->setParameter(name, ((const int3*) v) + offset, count);
|
||||
break;
|
||||
case INT4:
|
||||
instance->setParameter(name, ((const int4*) v) + offset, count);
|
||||
break;
|
||||
}
|
||||
|
||||
env->ReleaseIntArrayElements(v_, v, JNI_ABORT);
|
||||
|
||||
@@ -228,28 +220,26 @@ Java_com_google_android_filament_MaterialInstance_nSetFloatParameterArray(JNIEnv
|
||||
const char* name = env->GetStringUTFChars(name_, 0);
|
||||
jfloat* v = env->GetFloatArrayElements(v_, NULL);
|
||||
|
||||
wrapJni(env, [=]() {
|
||||
switch ((FloatElement) element) {
|
||||
case FLOAT:
|
||||
instance->setParameter(name, ((const float*) v) + offset, count);
|
||||
break;
|
||||
case FLOAT2:
|
||||
instance->setParameter(name, ((const float2*) v) + offset, count);
|
||||
break;
|
||||
case FLOAT3:
|
||||
instance->setParameter(name, ((const float3*) v) + offset, count);
|
||||
break;
|
||||
case FLOAT4:
|
||||
instance->setParameter(name, ((const float4*) v) + offset, count);
|
||||
break;
|
||||
case MAT3:
|
||||
instance->setParameter(name, ((const mat3f*) v) + offset, count);
|
||||
break;
|
||||
case MAT4:
|
||||
instance->setParameter(name, ((const mat4f*) v) + offset, count);
|
||||
break;
|
||||
}
|
||||
});
|
||||
switch ((FloatElement) element) {
|
||||
case FLOAT:
|
||||
instance->setParameter(name, ((const float*) v) + offset, count);
|
||||
break;
|
||||
case FLOAT2:
|
||||
instance->setParameter(name, ((const float2*) v) + offset, count);
|
||||
break;
|
||||
case FLOAT3:
|
||||
instance->setParameter(name, ((const float3*) v) + offset, count);
|
||||
break;
|
||||
case FLOAT4:
|
||||
instance->setParameter(name, ((const float4*) v) + offset, count);
|
||||
break;
|
||||
case MAT3:
|
||||
instance->setParameter(name, ((const mat3f*) v) + offset, count);
|
||||
break;
|
||||
case MAT4:
|
||||
instance->setParameter(name, ((const mat4f*) v) + offset, count);
|
||||
break;
|
||||
}
|
||||
|
||||
env->ReleaseFloatArrayElements(v_, v, 0);
|
||||
|
||||
@@ -270,9 +260,7 @@ Java_com_google_android_filament_MaterialInstance_nSetParameterTexture(
|
||||
Texture* texture = (Texture*) nativeTexture;
|
||||
|
||||
const char *name = env->GetStringUTFChars(name_, 0);
|
||||
wrapJni(env, [=]() {
|
||||
instance->setParameter(name, texture, JniUtils::from_long(sampler_));
|
||||
});
|
||||
instance->setParameter(name, texture, JniUtils::from_long(sampler_));
|
||||
env->ReleaseStringUTFChars(name_, name);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <functional>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -23,7 +24,6 @@
|
||||
|
||||
#include "common/CallbackUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace backend;
|
||||
@@ -81,13 +81,11 @@ extern "C" JNIEXPORT void JNICALL
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_MorphTargetBuffer_nBuilderBuild(JNIEnv* env, jclass,
|
||||
Java_com_google_android_filament_MorphTargetBuffer_nBuilderBuild(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jlong nativeEngine) {
|
||||
MorphTargetBuffer::Builder* builder = (MorphTargetBuffer::Builder *) nativeBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return filament::android::wrapJni<jlong>(env, [=]() {
|
||||
return (jlong) builder->build(*engine);
|
||||
});
|
||||
return (jlong) builder->build(*engine);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -99,13 +97,11 @@ Java_com_google_android_filament_MorphTargetBuffer_nSetPositionsAt(JNIEnv* env,
|
||||
jint targetIndex, jfloatArray positions, jint count) {
|
||||
MorphTargetBuffer *morphTargetBuffer = (MorphTargetBuffer *) nativeObject;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return filament::android::wrapJni<jint>(env, [=]() {
|
||||
jfloat* data = env->GetFloatArrayElements(positions, NULL);
|
||||
morphTargetBuffer->setPositionsAt(*engine, targetIndex,
|
||||
(math::float4*) data, size_t(count));
|
||||
env->ReleaseFloatArrayElements(positions, data, JNI_ABORT);
|
||||
return 0;
|
||||
});
|
||||
jfloat* data = env->GetFloatArrayElements(positions, NULL);
|
||||
morphTargetBuffer->setPositionsAt(*engine, targetIndex,
|
||||
(math::float4*) data, size_t(count));
|
||||
env->ReleaseFloatArrayElements(positions, data, JNI_ABORT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
@@ -115,13 +111,11 @@ Java_com_google_android_filament_MorphTargetBuffer_nSetTangentsAt(JNIEnv* env, j
|
||||
jint targetIndex, jshortArray tangents, jint count) {
|
||||
MorphTargetBuffer *morphTargetBuffer = (MorphTargetBuffer *) nativeObject;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return filament::android::wrapJni<jint>(env, [=]() {
|
||||
jshort* data = env->GetShortArrayElements(tangents, NULL);
|
||||
morphTargetBuffer->setTangentsAt(*engine, targetIndex,
|
||||
(math::short4*) data, size_t(count));
|
||||
env->ReleaseShortArrayElements(tangents, data, JNI_ABORT);
|
||||
return 0;
|
||||
});
|
||||
jshort* data = env->GetShortArrayElements(tangents, NULL);
|
||||
morphTargetBuffer->setTangentsAt(*engine, targetIndex,
|
||||
(math::short4*) data, size_t(count));
|
||||
env->ReleaseShortArrayElements(tangents, data, JNI_ABORT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <filament/RenderTarget.h>
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace backend;
|
||||
@@ -73,9 +72,7 @@ Java_com_google_android_filament_RenderTarget_nBuilderBuild(JNIEnv *env, jclass
|
||||
jlong nativeBuilder, jlong nativeEngine) {
|
||||
RenderTarget::Builder* builder = (RenderTarget::Builder*) nativeBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return filament::android::wrapJni<jlong>(env, [=]() {
|
||||
return (jlong) builder->build(*engine);
|
||||
});
|
||||
return (jlong) builder->build(*engine);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
#include <filament/RenderableManager.h>
|
||||
#include <filament/MaterialInstance.h>
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
#include <utils/Entity.h>
|
||||
|
||||
@@ -26,7 +25,6 @@
|
||||
|
||||
using namespace filament;
|
||||
using namespace utils;
|
||||
using namespace filament::android;
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nHasComponent(JNIEnv*, jclass,
|
||||
@@ -65,13 +63,11 @@ Java_com_google_android_filament_RenderableManager_nDestroyBuilder(JNIEnv*, jcla
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nBuilderBuild(JNIEnv* env, jclass,
|
||||
Java_com_google_android_filament_RenderableManager_nBuilderBuild(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jlong nativeEngine, jint entity) {
|
||||
RenderableManager::Builder *builder = (RenderableManager::Builder *) nativeBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
return jboolean(builder->build(*engine, (Entity &) entity) == RenderableManager::Builder::Success);
|
||||
});
|
||||
return jboolean(builder->build(*engine, (Entity &) entity) == RenderableManager::Builder::Success);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
@@ -280,13 +276,11 @@ Java_com_google_android_filament_RenderableManager_nBuilderInstances(JNIEnv*, jc
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nSetSkinningBuffer(JNIEnv* env, jclass,
|
||||
Java_com_google_android_filament_RenderableManager_nSetSkinningBuffer(JNIEnv*, jclass,
|
||||
jlong nativeRenderableManager, jint i, jlong nativeSkinningBuffer, jint count, jint offset) {
|
||||
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
|
||||
SkinningBuffer *sb = (SkinningBuffer *) nativeSkinningBuffer;
|
||||
wrapJni(env, [=]() {
|
||||
rm->setSkinningBuffer(i, sb, count, offset);
|
||||
});
|
||||
rm->setSkinningBuffer(i, sb, count, offset);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
@@ -301,12 +295,9 @@ Java_com_google_android_filament_RenderableManager_nSetBonesAsMatrices(JNIEnv* e
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
jint result = 0;
|
||||
wrapJni(env, [=]() {
|
||||
rm->setBones((RenderableManager::Instance)i,
|
||||
static_cast<filament::math::mat4f const *>(data), (size_t)boneCount, (size_t)offset);
|
||||
});
|
||||
return result;
|
||||
rm->setBones((RenderableManager::Instance)i,
|
||||
static_cast<filament::math::mat4f const *>(data), (size_t)boneCount, (size_t)offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
@@ -321,12 +312,9 @@ Java_com_google_android_filament_RenderableManager_nSetBonesAsQuaternions(JNIEnv
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
jint result = 0;
|
||||
wrapJni(env, [=]() {
|
||||
rm->setBones((RenderableManager::Instance)i,
|
||||
static_cast<RenderableManager::Bone const *>(data), (size_t)boneCount, (size_t)offset);
|
||||
});
|
||||
return result;
|
||||
rm->setBones((RenderableManager::Instance)i,
|
||||
static_cast<RenderableManager::Bone const *>(data), (size_t)boneCount, (size_t)offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
@@ -335,21 +323,17 @@ Java_com_google_android_filament_RenderableManager_nSetMorphWeights(JNIEnv* env,
|
||||
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
|
||||
jfloat* vec = env->GetFloatArrayElements(weights, NULL);
|
||||
jsize count = env->GetArrayLength(weights);
|
||||
wrapJni(env, [=]() {
|
||||
rm->setMorphWeights((RenderableManager::Instance)instance, vec, count, offset);
|
||||
});
|
||||
rm->setMorphWeights((RenderableManager::Instance)instance, vec, count, offset);
|
||||
env->ReleaseFloatArrayElements(weights, vec, JNI_ABORT);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nSetMorphTargetBufferOffsetAt(JNIEnv* env,
|
||||
Java_com_google_android_filament_RenderableManager_nSetMorphTargetBufferOffsetAt(JNIEnv*,
|
||||
jclass, jlong nativeRenderableManager, jint i, int level, jint primitiveIndex,
|
||||
jlong, jint offset) {
|
||||
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
|
||||
wrapJni(env, [=]() {
|
||||
rm->setMorphTargetBufferOffsetAt((RenderableManager::Instance) i, (uint8_t) level,
|
||||
(size_t) primitiveIndex, (size_t) offset);
|
||||
});
|
||||
rm->setMorphTargetBufferOffsetAt((RenderableManager::Instance) i, (uint8_t) level,
|
||||
(size_t) primitiveIndex, (size_t) offset);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
@@ -360,14 +344,12 @@ Java_com_google_android_filament_RenderableManager_nGetMorphTargetCount(JNIEnv*
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nSetAxisAlignedBoundingBox(JNIEnv* env,
|
||||
Java_com_google_android_filament_RenderableManager_nSetAxisAlignedBoundingBox(JNIEnv*,
|
||||
jclass, jlong nativeRenderableManager, jint i, jfloat cx, jfloat cy, jfloat cz,
|
||||
jfloat ex, jfloat ey, jfloat ez) {
|
||||
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
|
||||
wrapJni(env, [=]() {
|
||||
rm->setAxisAlignedBoundingBox((RenderableManager::Instance) i, {{cx, cy, cz},
|
||||
{ex, ey, ez}});
|
||||
});
|
||||
rm->setAxisAlignedBoundingBox((RenderableManager::Instance) i, {{cx, cy, cz},
|
||||
{ex, ey, ez}});
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
@@ -504,23 +486,19 @@ Java_com_google_android_filament_RenderableManager_nGetInstanceCount(JNIEnv*, jc
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nSetMaterialInstanceAt(JNIEnv* env, jclass,
|
||||
Java_com_google_android_filament_RenderableManager_nSetMaterialInstanceAt(JNIEnv*, jclass,
|
||||
jlong nativeRenderableManager, jint i, jint primitiveIndex, jlong nativeMaterialInstance) {
|
||||
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
|
||||
const MaterialInstance *materialInstance = (const MaterialInstance *) nativeMaterialInstance;
|
||||
wrapJni(env, [=]() {
|
||||
rm->setMaterialInstanceAt((RenderableManager::Instance) i, (size_t) primitiveIndex,
|
||||
materialInstance);
|
||||
});
|
||||
rm->setMaterialInstanceAt((RenderableManager::Instance) i, (size_t) primitiveIndex,
|
||||
materialInstance);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_RenderableManager_nClearMaterialInstanceAt(JNIEnv* env, jclass,
|
||||
Java_com_google_android_filament_RenderableManager_nClearMaterialInstanceAt(JNIEnv*, jclass,
|
||||
jlong nativeRenderableManager, jint i, jint primitiveIndex) {
|
||||
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
|
||||
wrapJni(env, [=]() {
|
||||
rm->clearMaterialInstanceAt((RenderableManager::Instance) i, (size_t) primitiveIndex);
|
||||
});
|
||||
rm->clearMaterialInstanceAt((RenderableManager::Instance) i, (size_t) primitiveIndex);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
|
||||
@@ -22,24 +22,18 @@
|
||||
#include <filament/Viewport.h>
|
||||
#include <backend/PixelBufferDescriptor.h>
|
||||
|
||||
#include <exception>
|
||||
|
||||
#include "common/CallbackUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
#include "common/JniUtils.h"
|
||||
|
||||
using namespace filament;
|
||||
using namespace backend;
|
||||
using namespace filament::android;
|
||||
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Renderer_nSkipFrame(JNIEnv *env, jclass, jlong nativeRenderer,
|
||||
Java_com_google_android_filament_Renderer_nSkipFrame(JNIEnv *, jclass, jlong nativeRenderer,
|
||||
jlong vsyncSteadyClockTimeNano) {
|
||||
Renderer *renderer = (Renderer *) nativeRenderer;
|
||||
wrapJni(env, [=]() {
|
||||
renderer->skipFrame(uint64_t(vsyncSteadyClockTimeNano));
|
||||
});
|
||||
renderer->skipFrame(uint64_t(vsyncSteadyClockTimeNano));
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
@@ -49,45 +43,37 @@ Java_com_google_android_filament_Renderer_nShouldRenderFrame(JNIEnv *, jclass, j
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_Renderer_nBeginFrame(JNIEnv *env, jclass, jlong nativeRenderer,
|
||||
Java_com_google_android_filament_Renderer_nBeginFrame(JNIEnv *, jclass, jlong nativeRenderer,
|
||||
jlong nativeSwapChain, jlong frameTimeNanos) {
|
||||
Renderer *renderer = (Renderer *) nativeRenderer;
|
||||
SwapChain *swapChain = (SwapChain *) nativeSwapChain;
|
||||
return wrapJniBackend<jboolean>(env, [=]() {
|
||||
return (jboolean) renderer->beginFrame(swapChain, uint64_t(frameTimeNanos));
|
||||
});
|
||||
return (jboolean) renderer->beginFrame(swapChain, uint64_t(frameTimeNanos));
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Renderer_nEndFrame(JNIEnv *env, jclass, jlong nativeRenderer) {
|
||||
Java_com_google_android_filament_Renderer_nEndFrame(JNIEnv *, jclass, jlong nativeRenderer) {
|
||||
Renderer *renderer = (Renderer *) nativeRenderer;
|
||||
wrapJniBackend(env, [=]() {
|
||||
renderer->endFrame();
|
||||
});
|
||||
renderer->endFrame();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Renderer_nRender(JNIEnv *env, jclass, jlong nativeRenderer,
|
||||
Java_com_google_android_filament_Renderer_nRender(JNIEnv *, jclass, jlong nativeRenderer,
|
||||
jlong nativeView) {
|
||||
Renderer *renderer = (Renderer *) nativeRenderer;
|
||||
View *view = (View *) nativeView;
|
||||
wrapJniBackend(env, [=]() {
|
||||
renderer->render(view);
|
||||
});
|
||||
renderer->render(view);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Renderer_nRenderStandaloneView(JNIEnv *env, jclass, jlong nativeRenderer,
|
||||
Java_com_google_android_filament_Renderer_nRenderStandaloneView(JNIEnv *, jclass, jlong nativeRenderer,
|
||||
jlong nativeView) {
|
||||
Renderer *renderer = (Renderer *) nativeRenderer;
|
||||
View *view = (View *) nativeView;
|
||||
wrapJni(env, [=]() {
|
||||
renderer->renderStandaloneView(view);
|
||||
});
|
||||
renderer->renderStandaloneView(view);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Renderer_nCopyFrame(JNIEnv *env, jclass, jlong nativeRenderer,
|
||||
Java_com_google_android_filament_Renderer_nCopyFrame(JNIEnv *, jclass, jlong nativeRenderer,
|
||||
jlong nativeDstSwapChain,
|
||||
jint dstLeft, jint dstBottom, jint dstWidth, jint dstHeight,
|
||||
jint srcLeft, jint srcBottom, jint srcWidth, jint srcHeight,
|
||||
@@ -96,9 +82,7 @@ Java_com_google_android_filament_Renderer_nCopyFrame(JNIEnv *env, jclass, jlong
|
||||
SwapChain *dstSwapChain = (SwapChain *) nativeDstSwapChain;
|
||||
const filament::Viewport dstViewport {dstLeft, dstBottom, (uint32_t) dstWidth, (uint32_t) dstHeight};
|
||||
const filament::Viewport srcViewport {srcLeft, srcBottom, (uint32_t) srcWidth, (uint32_t) srcHeight};
|
||||
wrapJni(env, [=]() {
|
||||
renderer->copyFrame(dstSwapChain, dstViewport, srcViewport, (uint32_t) flags);
|
||||
});
|
||||
renderer->copyFrame(dstSwapChain, dstViewport, srcViewport, (uint32_t) flags);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
@@ -130,11 +114,10 @@ Java_com_google_android_filament_Renderer_nReadPixels(JNIEnv *env, jclass,
|
||||
(uint32_t) stride,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
return wrapJni<jint>(env, [&]() {
|
||||
renderer->readPixels(uint32_t(xoffset), uint32_t(yoffset), uint32_t(width), uint32_t(height),
|
||||
std::move(desc));
|
||||
return 0;
|
||||
});
|
||||
renderer->readPixels(uint32_t(xoffset), uint32_t(yoffset), uint32_t(width), uint32_t(height),
|
||||
std::move(desc));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
@@ -167,28 +150,23 @@ Java_com_google_android_filament_Renderer_nReadPixelsEx(JNIEnv *env, jclass,
|
||||
(uint32_t) stride,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
return wrapJni<jint>(env, [&]() {
|
||||
renderer->readPixels(renderTarget,
|
||||
uint32_t(xoffset), uint32_t(yoffset), uint32_t(width), uint32_t(height),
|
||||
std::move(desc));
|
||||
return 0;
|
||||
});
|
||||
renderer->readPixels(renderTarget,
|
||||
uint32_t(xoffset), uint32_t(yoffset), uint32_t(width), uint32_t(height),
|
||||
std::move(desc));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jdouble JNICALL
|
||||
Java_com_google_android_filament_Renderer_nGetUserTime(JNIEnv *env, jclass, jlong nativeRenderer) {
|
||||
Java_com_google_android_filament_Renderer_nGetUserTime(JNIEnv*, jclass, jlong nativeRenderer) {
|
||||
Renderer *renderer = (Renderer *) nativeRenderer;
|
||||
return wrapJni<jdouble>(env, [=]() {
|
||||
return renderer->getUserTime();
|
||||
});
|
||||
return renderer->getUserTime();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Renderer_nResetUserTime(JNIEnv *env, jclass, jlong nativeRenderer) {
|
||||
Java_com_google_android_filament_Renderer_nResetUserTime(JNIEnv*, jclass, jlong nativeRenderer) {
|
||||
Renderer *renderer = (Renderer *) nativeRenderer;
|
||||
wrapJni(env, [=]() {
|
||||
renderer->resetUserTime();
|
||||
});
|
||||
renderer->resetUserTime();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
@@ -208,24 +186,20 @@ Java_com_google_android_filament_Renderer_nSetFrameRateOptions(JNIEnv*, jclass,
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Renderer_nSetClearOptions(JNIEnv *env, jclass ,
|
||||
Java_com_google_android_filament_Renderer_nSetClearOptions(JNIEnv *, jclass ,
|
||||
jlong nativeRenderer, jfloat r, jfloat g, jfloat b, jfloat a,
|
||||
jboolean clear, jboolean discard) {
|
||||
Renderer *renderer = (Renderer *) nativeRenderer;
|
||||
wrapJni(env, [=]() {
|
||||
renderer->setClearOptions({ .clearColor = {r, g, b, a},
|
||||
.clear = (bool) clear,
|
||||
.discard = (bool) discard});
|
||||
});
|
||||
renderer->setClearOptions({ .clearColor = {r, g, b, a},
|
||||
.clear = (bool) clear,
|
||||
.discard = (bool) discard});
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Renderer_nSetPresentationTime(JNIEnv *env, jclass ,
|
||||
Java_com_google_android_filament_Renderer_nSetPresentationTime(JNIEnv *, jclass ,
|
||||
jlong nativeRenderer, jlong monotonicClockNanos) {
|
||||
Renderer *renderer = (Renderer *) nativeRenderer;
|
||||
wrapJni(env, [=]() {
|
||||
renderer->setPresentationTime(monotonicClockNanos);
|
||||
});
|
||||
renderer->setPresentationTime(monotonicClockNanos);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
|
||||
@@ -19,11 +19,9 @@
|
||||
#include <filament/Scene.h>
|
||||
|
||||
#include <utils/Entity.h>
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace utils;
|
||||
using namespace filament::android;
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Scene_nSetSkybox(JNIEnv *env, jclass type, jlong nativeScene,
|
||||
@@ -45,20 +43,15 @@ extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Scene_nAddEntity(JNIEnv *env, jclass type, jlong nativeScene,
|
||||
jint entity) {
|
||||
Scene* scene = (Scene*) nativeScene;
|
||||
wrapJni(env, [=]() {
|
||||
scene->addEntity((Entity&) entity);
|
||||
});
|
||||
scene->addEntity((Entity&) entity);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Scene_nAddEntities(JNIEnv *env, jclass type, jlong nativeScene,
|
||||
jintArray entities) {
|
||||
Scene* scene = (Scene*) nativeScene;
|
||||
jsize length = env->GetArrayLength(entities);
|
||||
Entity* nativeEntities = (Entity*) env->GetIntArrayElements(entities, nullptr);
|
||||
wrapJni(env, [=]() {
|
||||
scene->addEntities(nativeEntities, length);
|
||||
});
|
||||
scene->addEntities(nativeEntities, env->GetArrayLength(entities));
|
||||
env->ReleaseIntArrayElements(entities, (jint*) nativeEntities, JNI_ABORT);
|
||||
}
|
||||
|
||||
@@ -66,20 +59,15 @@ extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Scene_nRemove(JNIEnv *env, jclass type, jlong nativeScene,
|
||||
jint entity) {
|
||||
Scene* scene = (Scene*) nativeScene;
|
||||
wrapJni(env, [=]() {
|
||||
scene->remove((Entity&) entity);
|
||||
});
|
||||
scene->remove((Entity&) entity);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Scene_nRemoveEntities(JNIEnv *env, jclass type, jlong nativeScene,
|
||||
jintArray entities) {
|
||||
Scene* scene = (Scene*) nativeScene;
|
||||
jsize length = env->GetArrayLength(entities);
|
||||
Entity* nativeEntities = (Entity*) env->GetIntArrayElements(entities, nullptr);
|
||||
wrapJni(env, [=]() {
|
||||
scene->removeEntities(nativeEntities, length);
|
||||
});
|
||||
scene->removeEntities(nativeEntities, env->GetArrayLength(entities));
|
||||
env->ReleaseIntArrayElements(entities, (jint*) nativeEntities, JNI_ABORT);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <functional>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -23,7 +24,6 @@
|
||||
|
||||
#include "common/CallbackUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace backend;
|
||||
@@ -60,13 +60,11 @@ Java_com_google_android_filament_SkinningBuffer_nBuilderInitialize(JNIEnv*, jcla
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_SkinningBuffer_nBuilderBuild(JNIEnv* env, jclass,
|
||||
Java_com_google_android_filament_SkinningBuffer_nBuilderBuild(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jlong nativeEngine) {
|
||||
SkinningBuffer::Builder* builder = (SkinningBuffer::Builder *) nativeBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return filament::android::wrapJni<jlong>(env, [=]() {
|
||||
return (jlong) builder->build(*engine);
|
||||
});
|
||||
return (jlong) builder->build(*engine);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -78,18 +76,16 @@ Java_com_google_android_filament_SkinningBuffer_nSetBonesAsMatrices(JNIEnv* env,
|
||||
jint offset) {
|
||||
SkinningBuffer *skinningBuffer = (SkinningBuffer *) nativeSkinningBuffer;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return filament::android::wrapJni<jint>(env, [=]() {
|
||||
AutoBuffer nioBuffer(env, matrices, boneCount * 16);
|
||||
void* data = nioBuffer.getData();
|
||||
size_t sizeInBytes = nioBuffer.getSize();
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
skinningBuffer->setBones(*engine,
|
||||
static_cast<filament::math::mat4f const *>(data), (size_t)boneCount, (size_t)offset);
|
||||
return 0;
|
||||
});
|
||||
AutoBuffer nioBuffer(env, matrices, boneCount * 16);
|
||||
void* data = nioBuffer.getData();
|
||||
size_t sizeInBytes = nioBuffer.getSize();
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
skinningBuffer->setBones(*engine,
|
||||
static_cast<filament::math::mat4f const *>(data), (size_t)boneCount, (size_t)offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
@@ -99,18 +95,16 @@ Java_com_google_android_filament_SkinningBuffer_nSetBonesAsQuaternions(JNIEnv* e
|
||||
jint boneCount, jint offset) {
|
||||
SkinningBuffer *skinningBuffer = (SkinningBuffer *) nativeSkinningBuffer;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return filament::android::wrapJni<jint>(env, [=]() {
|
||||
AutoBuffer nioBuffer(env, quaternions, boneCount * 8);
|
||||
void* data = nioBuffer.getData();
|
||||
size_t sizeInBytes = nioBuffer.getSize();
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
skinningBuffer->setBones(*engine,
|
||||
static_cast<RenderableManager::Bone const *>(data), (size_t)boneCount, (size_t)offset);
|
||||
return 0;
|
||||
});
|
||||
AutoBuffer nioBuffer(env, quaternions, boneCount * 8);
|
||||
void* data = nioBuffer.getData();
|
||||
size_t sizeInBytes = nioBuffer.getSize();
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
skinningBuffer->setBones(*engine,
|
||||
static_cast<RenderableManager::Bone const *>(data), (size_t)boneCount, (size_t)offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#include <filament/Skybox.h>
|
||||
|
||||
#include <math/vec4.h>
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
using namespace filament;
|
||||
|
||||
@@ -77,9 +76,7 @@ Java_com_google_android_filament_Skybox_nBuilderBuild(JNIEnv *env, jclass type,
|
||||
jlong nativeSkyBoxBuilder, jlong nativeEngine) {
|
||||
Skybox::Builder *builder = (Skybox::Builder *) nativeSkyBoxBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return filament::android::wrapJni<jlong>(env, [=]() {
|
||||
return (jlong) builder->build(*engine);
|
||||
});
|
||||
return (jlong) builder->build(*engine);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
#include "common/NioUtils.h"
|
||||
#include "common/CallbackUtils.h"
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
|
||||
@@ -114,13 +113,11 @@ Java_com_google_android_filament_Stream_nBuilderHeight(JNIEnv*, jclass,
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_Stream_nBuilderBuild(JNIEnv* env, jclass,
|
||||
Java_com_google_android_filament_Stream_nBuilderBuild(JNIEnv*, jclass,
|
||||
jlong nativeStreamBuilder, jlong nativeEngine) {
|
||||
StreamBuilder* builder = (StreamBuilder*) nativeStreamBuilder;
|
||||
Engine* engine = (Engine*) nativeEngine;
|
||||
return filament::android::wrapJni<jlong>(env, [=]() {
|
||||
return (jlong) builder->builder()->build(*engine);
|
||||
});
|
||||
return (jlong) builder->builder()->build(*engine);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "common/NioUtils.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace filament::geometry;
|
||||
@@ -126,9 +125,7 @@ extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_SurfaceOrientation_nBuilderBuild(JNIEnv* env, jclass,
|
||||
jlong nativeBuilder) {
|
||||
auto wrapper = (JniWrapper *) nativeBuilder;
|
||||
return filament::android::wrapJni<jlong>(env, [=]() {
|
||||
return (jlong) wrapper->builder->build();
|
||||
});
|
||||
return (jlong) wrapper->builder->build();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include <filament/SwapChain.h>
|
||||
|
||||
#include "common/CallbackUtils.h"
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
using namespace filament;
|
||||
|
||||
@@ -59,13 +58,11 @@ Java_com_google_android_filament_SwapChain_nSetFrameScheduledCallback(JNIEnv* en
|
||||
jlong nativeSwapChain, jobject handler, jobject runnable) {
|
||||
SwapChain* swapChain = (SwapChain*) nativeSwapChain;
|
||||
auto* callback = JniCallback::make(env, handler, runnable);
|
||||
filament::android::wrapJni<void>(env, [=]() {
|
||||
swapChain->setFrameScheduledCallback(callback->getHandler(),
|
||||
[callback](backend::PresentCallable) {
|
||||
// Ignore PresentCallable, which is only meaningful with the Metal backend.
|
||||
JniCallback::postToJavaAndDestroy(callback);
|
||||
});
|
||||
});
|
||||
swapChain->setFrameScheduledCallback(callback->getHandler(),
|
||||
[callback](backend::PresentCallable) {
|
||||
// Ignore PresentCallable, which is only meaningful with the Metal backend.
|
||||
JniCallback::postToJavaAndDestroy(callback);
|
||||
});
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <jni.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <android/bitmap.h>
|
||||
@@ -37,14 +38,12 @@
|
||||
|
||||
#include "common/CallbackUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
#include "private/backend/VirtualMachineEnv.h"
|
||||
|
||||
|
||||
using namespace filament;
|
||||
using namespace backend;
|
||||
using namespace filament::android;
|
||||
|
||||
static size_t getTextureDataSize(const Texture *texture,
|
||||
size_t level, Texture::Format format, Texture::Type type,
|
||||
@@ -274,13 +273,12 @@ Java_com_google_android_filament_Texture_nSetImage3D(JNIEnv* env, jclass, jlong
|
||||
(uint32_t) stride,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
return wrapJni<jint>(env, [&]() {
|
||||
texture->setImage(*engine, (size_t) level,
|
||||
(uint32_t) xoffset, (uint32_t) yoffset, (uint32_t) zoffset,
|
||||
(uint32_t) width, (uint32_t) height, (uint32_t) depth,
|
||||
std::move(desc));
|
||||
return 0;
|
||||
});
|
||||
texture->setImage(*engine, (size_t) level,
|
||||
(uint32_t) xoffset, (uint32_t) yoffset, (uint32_t) zoffset,
|
||||
(uint32_t) width, (uint32_t) height, (uint32_t) depth,
|
||||
std::move(desc));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
@@ -309,13 +307,12 @@ Java_com_google_android_filament_Texture_nSetImage3DCompressed(JNIEnv *env, jcla
|
||||
(backend::CompressedPixelDataType) compressedFormat, (uint32_t) compressedSizeInBytes,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
return wrapJni<jint>(env, [&]() {
|
||||
texture->setImage(*engine, (size_t) level,
|
||||
(uint32_t) xoffset, (uint32_t) yoffset, (uint32_t) zoffset,
|
||||
(uint32_t) width, (uint32_t) height, (uint32_t) depth,
|
||||
std::move(desc));
|
||||
return 0;
|
||||
});
|
||||
texture->setImage(*engine, (size_t) level,
|
||||
(uint32_t) xoffset, (uint32_t) yoffset, (uint32_t) zoffset,
|
||||
(uint32_t) width, (uint32_t) height, (uint32_t) depth,
|
||||
std::move(desc));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
@@ -349,13 +346,12 @@ Java_com_google_android_filament_Texture_nSetImageCubemap(JNIEnv *env, jclass,
|
||||
(uint32_t) stride,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
return wrapJni<jint>(env, [&]() {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
texture->setImage(*engine, (size_t) level, std::move(desc), faceOffsets);
|
||||
texture->setImage(*engine, (size_t) level, std::move(desc), faceOffsets);
|
||||
#pragma clang diagnostic pop
|
||||
return 0;
|
||||
});
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
@@ -388,23 +384,20 @@ Java_com_google_android_filament_Texture_nSetImageCubemapCompressed(JNIEnv *env,
|
||||
(backend::CompressedPixelDataType) compressedFormat, (uint32_t) compressedSizeInBytes,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
return wrapJni<jint>(env, [&]() {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
texture->setImage(*engine, (size_t) level, std::move(desc), faceOffsets);
|
||||
texture->setImage(*engine, (size_t) level, std::move(desc), faceOffsets);
|
||||
#pragma clang diagnostic pop
|
||||
return 0;
|
||||
});
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Texture_nSetExternalImage(JNIEnv* env, jclass, jlong nativeTexture,
|
||||
Java_com_google_android_filament_Texture_nSetExternalImage(JNIEnv*, jclass, jlong nativeTexture,
|
||||
jlong nativeEngine, jlong eglImage) {
|
||||
Texture *texture = (Texture *) nativeTexture;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
wrapJni(env, [=]() {
|
||||
texture->setExternalImage(*engine, (void*)eglImage);
|
||||
});
|
||||
texture->setExternalImage(*engine, (void*)eglImage);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
@@ -425,35 +418,33 @@ Java_com_google_android_filament_Texture_nSetExternalImageByAHB(JNIEnv *env, jcl
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
return wrapJni<jboolean>(env, [=]() {
|
||||
if (engine->getBackend() == Backend::OPENGL) {
|
||||
// CAVEAT: we assume that Backend::OPENGL on Android implies PlatformEGLAndroid.
|
||||
if (engine->getBackend() == Backend::OPENGL) {
|
||||
// CAVEAT: we assume that Backend::OPENGL on Android implies PlatformEGLAndroid.
|
||||
#if UTILS_HAS_RTTI
|
||||
if (!dynamic_cast<PlatformEGLAndroid*>(platform)) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
#endif
|
||||
auto* eglPlatform = (PlatformEGLAndroid*) platform;
|
||||
auto ref = eglPlatform->createExternalImage(nativeBuffer, false);
|
||||
texture->setExternalImage(*engine, ref);
|
||||
if (!dynamic_cast<PlatformEGLAndroid*>(platform)) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
#endif
|
||||
auto* eglPlatform = (PlatformEGLAndroid*) platform;
|
||||
auto ref = eglPlatform->createExternalImage(nativeBuffer, false);
|
||||
texture->setExternalImage(*engine, ref);
|
||||
}
|
||||
|
||||
#if FILAMENT_SUPPORTS_VULKAN
|
||||
else if (engine->getBackend() == Backend::VULKAN) {
|
||||
// CAVEAT: we assume that Backend::VULKAN on Android implies VulkanPlatformAndroid.
|
||||
else if (engine->getBackend() == Backend::VULKAN) {
|
||||
// CAVEAT: we assume that Backend::VULKAN on Android implies VulkanPlatformAndroid.
|
||||
#if UTILS_HAS_RTTI
|
||||
if (!dynamic_cast<VulkanPlatformAndroid*>(platform)) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
#endif
|
||||
auto* vulkanPlatform = (VulkanPlatformAndroid*) platform;
|
||||
auto ref = vulkanPlatform->createExternalImage(nativeBuffer, false);
|
||||
texture->setExternalImage(*engine, ref);
|
||||
if (!dynamic_cast<VulkanPlatformAndroid*>(platform)) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
#endif
|
||||
auto* vulkanPlatform = (VulkanPlatformAndroid*) platform;
|
||||
auto ref = vulkanPlatform->createExternalImage(nativeBuffer, false);
|
||||
texture->setExternalImage(*engine, ref);
|
||||
}
|
||||
#endif // FILAMENT_SUPPORTS_VULKAN
|
||||
// success!
|
||||
return JNI_TRUE;
|
||||
});
|
||||
// success!
|
||||
return JNI_TRUE;
|
||||
#else
|
||||
// other platforms could come here
|
||||
return JNI_FALSE;
|
||||
@@ -461,24 +452,20 @@ Java_com_google_android_filament_Texture_nSetExternalImageByAHB(JNIEnv *env, jcl
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Texture_nSetExternalStream(JNIEnv* env, jclass,
|
||||
Java_com_google_android_filament_Texture_nSetExternalStream(JNIEnv*, jclass,
|
||||
jlong nativeTexture, jlong nativeEngine, jlong nativeStream) {
|
||||
Texture *texture = (Texture *) nativeTexture;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
Stream *stream = (Stream *) nativeStream;
|
||||
wrapJni(env, [=]() {
|
||||
texture->setExternalStream(*engine, stream);
|
||||
});
|
||||
texture->setExternalStream(*engine, stream);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_Texture_nGenerateMipmaps(JNIEnv* env, jclass,
|
||||
Java_com_google_android_filament_Texture_nGenerateMipmaps(JNIEnv*, jclass,
|
||||
jlong nativeTexture, jlong nativeEngine) {
|
||||
Texture *texture = (Texture *) nativeTexture;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
wrapJni(env, [=]() {
|
||||
texture->generateMipmaps(*engine);
|
||||
});
|
||||
texture->generateMipmaps(*engine);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
@@ -528,10 +515,9 @@ Java_com_google_android_filament_Texture_nGeneratePrefilterMipmap(JNIEnv *env, j
|
||||
options.sampleCount = sampleCount;
|
||||
options.mirror = mirror;
|
||||
|
||||
return wrapJni<jint>(env, [&]() {
|
||||
filament::generatePrefilterMipmap(texture, *engine, std::move(desc), faceOffsets, &options);
|
||||
return 0;
|
||||
});
|
||||
filament::generatePrefilterMipmap(texture, *engine, std::move(desc), faceOffsets, &options);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -654,12 +640,10 @@ Java_com_google_android_filament_android_TextureHelper_nSetBitmap(JNIEnv* env, j
|
||||
autoBitmap->getType(format),
|
||||
&AutoBitmap::invokeNoCallback, autoBitmap);
|
||||
|
||||
filament::android::wrapJni(env, [&]() {
|
||||
texture->setImage(*engine, (size_t) level,
|
||||
(uint32_t) xoffset, (uint32_t) yoffset,
|
||||
(uint32_t) width, (uint32_t) height,
|
||||
std::move(desc));
|
||||
});
|
||||
texture->setImage(*engine, (size_t) level,
|
||||
(uint32_t) xoffset, (uint32_t) yoffset,
|
||||
(uint32_t) width, (uint32_t) height,
|
||||
std::move(desc));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
@@ -679,12 +663,10 @@ Java_com_google_android_filament_android_TextureHelper_nSetBitmapWithCallback(JN
|
||||
autoBitmap->getType(format),
|
||||
autoBitmap->getHandler(), &AutoBitmap::invoke, autoBitmap);
|
||||
|
||||
filament::android::wrapJni(env, [&]() {
|
||||
texture->setImage(*engine, (size_t) level,
|
||||
(uint32_t) xoffset, (uint32_t) yoffset,
|
||||
(uint32_t) width, (uint32_t) height,
|
||||
std::move(desc));
|
||||
});
|
||||
texture->setImage(*engine, (size_t) level,
|
||||
(uint32_t) xoffset, (uint32_t) yoffset,
|
||||
(uint32_t) width, (uint32_t) height,
|
||||
std::move(desc));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,11 +22,9 @@
|
||||
#include <utils/Entity.h>
|
||||
|
||||
#include <math/mat4.h>
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
using namespace utils;
|
||||
using namespace filament;
|
||||
using namespace filament::android;
|
||||
|
||||
static_assert(sizeof(jint) == sizeof(Entity), "jint and Entity are not compatible!!");
|
||||
|
||||
@@ -47,14 +45,12 @@ Java_com_google_android_filament_TransformManager_nGetInstance(JNIEnv*, jclass,
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_TransformManager_nCreate(JNIEnv* env, jclass,
|
||||
Java_com_google_android_filament_TransformManager_nCreate(JNIEnv*, jclass,
|
||||
jlong nativeTransformManager, jint entity_) {
|
||||
TransformManager* tm = (TransformManager*) nativeTransformManager;
|
||||
return wrapJni<jint>(env, [=]() {
|
||||
Entity entity = *reinterpret_cast<const Entity*>(&entity_);
|
||||
tm->create(entity);
|
||||
return tm->getInstance(entity);
|
||||
});
|
||||
Entity& entity = *reinterpret_cast<Entity*>(&entity_);
|
||||
tm->create(entity);
|
||||
return tm->getInstance(entity);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
@@ -62,18 +58,16 @@ Java_com_google_android_filament_TransformManager_nCreateArray(JNIEnv* env,
|
||||
jclass, jlong nativeTransformManager, jint entity_, jint parent,
|
||||
jfloatArray localTransform_) {
|
||||
TransformManager* tm = (TransformManager*) nativeTransformManager;
|
||||
return wrapJni<jint>(env, [=]() {
|
||||
Entity entity = *reinterpret_cast<const Entity*>(&entity_);
|
||||
if (localTransform_) {
|
||||
jfloat *localTransform = env->GetFloatArrayElements(localTransform_, NULL);
|
||||
tm->create(entity, (TransformManager::Instance) parent,
|
||||
*reinterpret_cast<const filament::math::mat4f *>(localTransform));
|
||||
env->ReleaseFloatArrayElements(localTransform_, localTransform, JNI_ABORT);
|
||||
} else {
|
||||
tm->create(entity, (TransformManager::Instance) parent);
|
||||
}
|
||||
return tm->getInstance(entity);
|
||||
});
|
||||
Entity& entity = *reinterpret_cast<Entity*>(&entity_);
|
||||
if (localTransform_) {
|
||||
jfloat *localTransform = env->GetFloatArrayElements(localTransform_, NULL);
|
||||
tm->create(entity, (TransformManager::Instance) parent,
|
||||
*reinterpret_cast<const filament::math::mat4f *>(localTransform));
|
||||
env->ReleaseFloatArrayElements(localTransform_, localTransform, JNI_ABORT);
|
||||
} else {
|
||||
tm->create(entity, (TransformManager::Instance) parent);
|
||||
}
|
||||
return tm->getInstance(entity);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
@@ -81,18 +75,16 @@ Java_com_google_android_filament_TransformManager_nCreateArrayFp64(JNIEnv* env,
|
||||
jclass, jlong nativeTransformManager, jint entity_, jint parent,
|
||||
jdoubleArray localTransform_) {
|
||||
TransformManager* tm = (TransformManager*) nativeTransformManager;
|
||||
return wrapJni<jint>(env, [=]() {
|
||||
Entity entity = *reinterpret_cast<const Entity*>(&entity_);
|
||||
if (localTransform_) {
|
||||
jdouble *localTransform = env->GetDoubleArrayElements(localTransform_, NULL);
|
||||
tm->create(entity, (TransformManager::Instance) parent,
|
||||
*reinterpret_cast<const filament::math::mat4 *>(localTransform));
|
||||
env->ReleaseDoubleArrayElements(localTransform_, localTransform, JNI_ABORT);
|
||||
} else {
|
||||
tm->create(entity, (TransformManager::Instance) parent);
|
||||
}
|
||||
return tm->getInstance(entity);
|
||||
});
|
||||
Entity& entity = *reinterpret_cast<Entity*>(&entity_);
|
||||
if (localTransform_) {
|
||||
jdouble *localTransform = env->GetDoubleArrayElements(localTransform_, NULL);
|
||||
tm->create(entity, (TransformManager::Instance) parent,
|
||||
*reinterpret_cast<const filament::math::mat4 *>(localTransform));
|
||||
env->ReleaseDoubleArrayElements(localTransform_, localTransform, JNI_ABORT);
|
||||
} else {
|
||||
tm->create(entity, (TransformManager::Instance) parent);
|
||||
}
|
||||
return tm->getInstance(entity);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
#include "common/CallbackUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace filament::math;
|
||||
@@ -83,13 +82,11 @@ Java_com_google_android_filament_VertexBuffer_nBuilderNormalized(JNIEnv*, jclass
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_VertexBuffer_nBuilderBuild(JNIEnv* env, jclass,
|
||||
Java_com_google_android_filament_VertexBuffer_nBuilderBuild(JNIEnv*, jclass,
|
||||
jlong nativeBuilder, jlong nativeEngine) {
|
||||
VertexBuffer::Builder* builder = (VertexBuffer::Builder *) nativeBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return filament::android::wrapJni<jlong>(env, [=]() {
|
||||
return (jlong) builder->build(*engine);
|
||||
});
|
||||
return (jlong) builder->build(*engine);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
@@ -107,34 +104,30 @@ Java_com_google_android_filament_VertexBuffer_nSetBufferAt(JNIEnv *env, jclass,
|
||||
VertexBuffer *vertexBuffer = (VertexBuffer *) nativeVertexBuffer;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
|
||||
return filament::android::wrapJni<jint>(env, [=]() {
|
||||
AutoBuffer nioBuffer(env, buffer, count);
|
||||
void* data = nioBuffer.getData();
|
||||
size_t sizeInBytes = nioBuffer.getSize();
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
AutoBuffer nioBuffer(env, buffer, count);
|
||||
void* data = nioBuffer.getData();
|
||||
size_t sizeInBytes = nioBuffer.getSize();
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto* callback = JniBufferCallback::make(engine, env, handler, runnable, std::move(nioBuffer));
|
||||
auto* callback = JniBufferCallback::make(engine, env, handler, runnable, std::move(nioBuffer));
|
||||
|
||||
BufferDescriptor desc(data, sizeInBytes,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
BufferDescriptor desc(data, sizeInBytes,
|
||||
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
|
||||
|
||||
vertexBuffer->setBufferAt(*engine, (uint8_t) bufferIndex, std::move(desc),
|
||||
(uint32_t) destOffsetInBytes);
|
||||
vertexBuffer->setBufferAt(*engine, (uint8_t) bufferIndex, std::move(desc),
|
||||
(uint32_t) destOffsetInBytes);
|
||||
|
||||
return 0;
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_VertexBuffer_nSetBufferObjectAt(JNIEnv* env, jclass,
|
||||
Java_com_google_android_filament_VertexBuffer_nSetBufferObjectAt(JNIEnv*, jclass,
|
||||
jlong nativeVertexBuffer, jlong nativeEngine, jint bufferIndex, jlong nativeBufferObject) {
|
||||
VertexBuffer *vertexBuffer = (VertexBuffer *) nativeVertexBuffer;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
BufferObject *bufferObject = (BufferObject *) nativeBufferObject;
|
||||
filament::android::wrapJni(env, [=]() {
|
||||
vertexBuffer->setBufferObjectAt(*engine, (uint8_t) bufferIndex, bufferObject);
|
||||
});
|
||||
vertexBuffer->setBufferObjectAt(*engine, (uint8_t) bufferIndex, bufferObject);
|
||||
}
|
||||
|
||||
@@ -21,12 +21,10 @@
|
||||
#include <filament/Viewport.h>
|
||||
|
||||
#include "common/CallbackUtils.h"
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
#include "private/backend/VirtualMachineEnv.h"
|
||||
|
||||
using namespace filament;
|
||||
using namespace filament::android;
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nSetName(JNIEnv* env, jclass, jlong nativeView, jstring name_) {
|
||||
@@ -37,12 +35,10 @@ Java_com_google_android_filament_View_nSetName(JNIEnv* env, jclass, jlong native
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nSetScene(JNIEnv* env, jclass, jlong nativeView, jlong nativeScene) {
|
||||
Java_com_google_android_filament_View_nSetScene(JNIEnv*, jclass, jlong nativeView, jlong nativeScene) {
|
||||
View* view = (View*) nativeView;
|
||||
Scene* scene = (Scene*) nativeScene;
|
||||
wrapJni(env, [=]() {
|
||||
view->setScene(scene);
|
||||
});
|
||||
view->setScene(scene);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
@@ -157,24 +153,6 @@ Java_com_google_android_filament_View_nSetDynamicResolutionOptions(JNIEnv*, jcla
|
||||
view->setDynamicResolutionOptions(options);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nSetGridSize(JNIEnv*, jclass, jlong nativeView, jdouble size) {
|
||||
View* view = (View*) nativeView;
|
||||
view->setGridSize(size);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jdouble JNICALL
|
||||
Java_com_google_android_filament_View_nGetGridSize(JNIEnv*, jclass, jlong nativeView) {
|
||||
View* view = (View*) nativeView;
|
||||
return view->getGridSize();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jdouble JNICALL
|
||||
Java_com_google_android_filament_View_nGetEffectiveGridSize(JNIEnv*, jclass, jlong nativeView) {
|
||||
View* view = (View*) nativeView;
|
||||
return view->getEffectiveGridSize();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nGetLastDynamicResolutionScale(JNIEnv *env, jclass, jlong nativeView, jfloatArray out_) {
|
||||
jfloat* out = env->GetFloatArrayElements(out_, nullptr);
|
||||
@@ -571,27 +549,21 @@ Java_com_google_android_filament_View_nSetGuardBandOptions(JNIEnv *, jclass,
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nSetMaterialGlobal(JNIEnv *env, jclass, jlong nativeView,
|
||||
Java_com_google_android_filament_View_nSetMaterialGlobal(JNIEnv * , jclass, jlong nativeView,
|
||||
jint index, jfloat x, jfloat y, jfloat z, jfloat w) {
|
||||
View *view = (View *) nativeView;
|
||||
wrapJni(env, [=]() {
|
||||
view->setMaterialGlobal((uint32_t)index, { x, y, z, w });
|
||||
});
|
||||
view->setMaterialGlobal((uint32_t)index, { x, y, z, w });
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nGetMaterialGlobal(JNIEnv *env, jclass clazz,
|
||||
jlong nativeView, jint index, jfloatArray out_) {
|
||||
jfloat* out = env->GetFloatArrayElements(out_, nullptr);
|
||||
View *view = (View *) nativeView;
|
||||
wrapJni(env, [=]() {
|
||||
auto result = view->getMaterialGlobal(index);
|
||||
jfloat* out = env->GetFloatArrayElements(out_, nullptr);
|
||||
if (out) {
|
||||
std::copy_n(result.v, 4, out);
|
||||
env->ReleaseFloatArrayElements(out_, out, 0);
|
||||
}
|
||||
});
|
||||
auto result = view->getMaterialGlobal(index);
|
||||
std::copy_n(result.v, 4, out);
|
||||
env->ReleaseFloatArrayElements(out_, out, 0);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
|
||||
@@ -91,8 +91,6 @@ public class BufferObject {
|
||||
* @return the newly created <code>BufferObject</code> object
|
||||
*
|
||||
* @exception IllegalStateException if the BufferObject could not be created
|
||||
* @throws RuntimeException if a runtime error occurred, such as running out of
|
||||
* memory or other resources.
|
||||
*
|
||||
* @see #setBuffer
|
||||
*/
|
||||
|
||||
@@ -321,7 +321,8 @@ public class Engine {
|
||||
* be initialized, for instance if it doesn't support the right version of OpenGL or
|
||||
* OpenGL ES.
|
||||
*
|
||||
* @throws Error if there isn't enough memory to allocate the command buffer.
|
||||
* @exception IllegalStateException can be thrown if there isn't enough memory to
|
||||
* allocate the command buffer.
|
||||
*/
|
||||
public Engine build() {
|
||||
long nativeEngine = nBuilderBuild(mNativeBuilder);
|
||||
@@ -728,8 +729,6 @@ public class Engine {
|
||||
*
|
||||
* @return the active feature level.
|
||||
*
|
||||
* @throws RuntimeException if the feature level cannot be set.
|
||||
*
|
||||
* @see Builder#featureLevel
|
||||
* @see #getSupportedFeatureLevel
|
||||
* @see #getActiveFeatureLevel
|
||||
@@ -776,15 +775,6 @@ public class Engine {
|
||||
return nIsAutomaticInstancingEnabled(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the engine has encountered an unrecoverable failure.
|
||||
*
|
||||
* @return true if an unrecoverable failure has occurred, false otherwise.
|
||||
*/
|
||||
public boolean hasUnrecoverableFailure() {
|
||||
return nHasUnrecoverableFailure(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the configuration settings of this {@link Engine}.
|
||||
*
|
||||
@@ -1271,10 +1261,9 @@ public class Engine {
|
||||
* Destroys a {@link Material} and frees all its associated resources.
|
||||
* <p>
|
||||
* All {@link MaterialInstance} of the specified {@link Material} must be destroyed before
|
||||
* destroying it.
|
||||
* destroying it; if some {@link MaterialInstance} remain, this method fails silently.
|
||||
*
|
||||
* @param material the {@link Material} to destroy
|
||||
* @throws RuntimeException if some MaterialInstances remain.
|
||||
*/
|
||||
public void destroyMaterial(@NonNull Material material) {
|
||||
assertDestroy(nDestroyMaterial(getNativeObject(), material.getNativeObject()));
|
||||
@@ -1591,7 +1580,6 @@ public class Engine {
|
||||
private static native long nGetEntityManager(long nativeEngine);
|
||||
private static native void nSetAutomaticInstancingEnabled(long nativeEngine, boolean enable);
|
||||
private static native boolean nIsAutomaticInstancingEnabled(long nativeEngine);
|
||||
private static native boolean nHasUnrecoverableFailure(long nativeEngine);
|
||||
private static native long nGetMaxStereoscopicEyes(long nativeEngine);
|
||||
private static native int nGetSupportedFeatureLevel(long nativeEngine);
|
||||
private static native int nSetActiveFeatureLevel(long nativeEngine, int ordinal);
|
||||
|
||||
@@ -38,17 +38,7 @@ public class Fence {
|
||||
}
|
||||
|
||||
/**
|
||||
* Client-side wait on the Fence.
|
||||
*
|
||||
* Blocks the current thread until the Fence signals.
|
||||
*
|
||||
* @param mode Whether the command stream is flushed before waiting or not.
|
||||
* @param timeoutNanoSeconds Wait time out in nanoseconds. Using a timeout of 0 is a way to query the state of the fence.
|
||||
* A timeout value of WAIT_FOR_EVER is used to disable the timeout.
|
||||
* @return FenceStatus::CONDITION_SATISFIED on success,
|
||||
* FenceStatus::TIMEOUT_EXPIRED if the time out expired or
|
||||
* FenceStatus::ERROR in other cases.
|
||||
* @throws Error if the backend thread encountered an unrecoverable error.
|
||||
*/
|
||||
public FenceStatus wait(@NonNull Mode mode, long timeoutNanoSeconds) {
|
||||
int nativeResult = nWait(getNativeObject(), mode.ordinal(), timeoutNanoSeconds);
|
||||
@@ -65,15 +55,6 @@ public class Fence {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Client-side wait on a Fence and destroy the Fence.
|
||||
*
|
||||
* @param fence Fence object to wait on.
|
||||
* @param mode Whether the command stream is flushed before waiting or not.
|
||||
* @return FenceStatus::CONDITION_SATISFIED on success,
|
||||
* FenceStatus::ERROR otherwise.
|
||||
* @throws Error if the backend thread encountered an unrecoverable error.
|
||||
*/
|
||||
public static FenceStatus waitAndDestroy(@NonNull Fence fence, @NonNull Mode mode) {
|
||||
int nativeResult = nWaitAndDestroy(fence.getNativeObject(), mode.ordinal());
|
||||
switch (nativeResult) {
|
||||
|
||||
@@ -99,7 +99,6 @@ public class IndexBuffer {
|
||||
* @return the newly created <code>IndexBuffer</code> object
|
||||
*
|
||||
* @exception IllegalStateException if the IndexBuffer could not be created
|
||||
* @throws RuntimeException if a runtime error occurred, such as running out of memory or other resources, or if a parameter to a builder function was invalid.
|
||||
*
|
||||
* @see #setBuffer
|
||||
*/
|
||||
|
||||
@@ -316,8 +316,6 @@ public class IndirectLight {
|
||||
* @return A newly created <code>IndirectLight</code>
|
||||
*
|
||||
* @exception IllegalStateException if a parameter to a builder function was invalid.
|
||||
* @throws RuntimeException if a runtime error occurred, such as running out of
|
||||
* memory or other resources.
|
||||
*/
|
||||
@NonNull
|
||||
public IndirectLight build(@NonNull Engine engine) {
|
||||
|
||||
@@ -781,7 +781,6 @@ public class LightManager {
|
||||
*
|
||||
* @param engine Reference to the {@link Engine} to associate this light with.
|
||||
* @param entity Entity to add the light component to.
|
||||
* @throws RuntimeException if a runtime error occurred, such as running out of memory or other resources, or if a parameter to a builder function was invalid.
|
||||
*/
|
||||
public void build(@NonNull Engine engine, @Entity int entity) {
|
||||
if (!nBuilderBuild(mNativeBuilder, engine.getNativeObject(), entity)) {
|
||||
|
||||
@@ -476,7 +476,6 @@ public class Material {
|
||||
* @return the newly created object
|
||||
*
|
||||
* @exception IllegalStateException if the material could not be created
|
||||
* @throws RuntimeException if a parameter to a builder function was invalid.
|
||||
*/
|
||||
@NonNull
|
||||
public Material build(@NonNull Engine engine) {
|
||||
|
||||
-18
@@ -156,7 +156,6 @@ public class MaterialInstance {
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the material parameter
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name, boolean x) {
|
||||
nSetParameterBool(getNativeObject(), name, x);
|
||||
@@ -167,7 +166,6 @@ public class MaterialInstance {
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the material parameter
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name, float x) {
|
||||
nSetParameterFloat(getNativeObject(), name, x);
|
||||
@@ -178,7 +176,6 @@ public class MaterialInstance {
|
||||
*
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the material parameter
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name, int x) {
|
||||
nSetParameterInt(getNativeObject(), name, x);
|
||||
@@ -190,7 +187,6 @@ public class MaterialInstance {
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name, boolean x, boolean y) {
|
||||
nSetParameterBool2(getNativeObject(), name, x, y);
|
||||
@@ -202,7 +198,6 @@ public class MaterialInstance {
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name, float x, float y) {
|
||||
nSetParameterFloat2(getNativeObject(), name, x, y);
|
||||
@@ -214,7 +209,6 @@ public class MaterialInstance {
|
||||
* @param name the name of the material parameter
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name, int x, int y) {
|
||||
nSetParameterInt2(getNativeObject(), name, x, y);
|
||||
@@ -227,7 +221,6 @@ public class MaterialInstance {
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name, boolean x, boolean y, boolean z) {
|
||||
nSetParameterBool3(getNativeObject(), name, x, y, z);
|
||||
@@ -240,7 +233,6 @@ public class MaterialInstance {
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name, float x, float y, float z) {
|
||||
nSetParameterFloat3(getNativeObject(), name, x, y, z);
|
||||
@@ -253,7 +245,6 @@ public class MaterialInstance {
|
||||
* @param x the value of the first component
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name, int x, int y, int z) {
|
||||
nSetParameterInt3(getNativeObject(), name, x, y, z);
|
||||
@@ -267,7 +258,6 @@ public class MaterialInstance {
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
* @param w the value of the fourth component
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name, boolean x, boolean y, boolean z, boolean w) {
|
||||
nSetParameterBool4(getNativeObject(), name, x, y, z, w);
|
||||
@@ -281,7 +271,6 @@ public class MaterialInstance {
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
* @param w the value of the fourth component
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name, float x, float y, float z, float w) {
|
||||
nSetParameterFloat4(getNativeObject(), name, x, y, z, w);
|
||||
@@ -295,7 +284,6 @@ public class MaterialInstance {
|
||||
* @param y the value of the second component
|
||||
* @param z the value of the third component
|
||||
* @param w the value of the fourth component
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name, int x, int y, int z, int w) {
|
||||
nSetParameterInt4(getNativeObject(), name, x, y, z, w);
|
||||
@@ -311,7 +299,6 @@ public class MaterialInstance {
|
||||
* @param name The name of the material texture parameter
|
||||
* @param texture The texture to set as parameter
|
||||
* @param sampler The sampler to be used with this texture
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name,
|
||||
@NonNull Texture texture, @NonNull TextureSampler sampler) {
|
||||
@@ -333,7 +320,6 @@ public class MaterialInstance {
|
||||
* instance.setParameter("param", MaterialInstance.BooleanElement.BOOL4, a, 0, 4);
|
||||
* }</pre>
|
||||
* </p>
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name,
|
||||
@NonNull BooleanElement type, @NonNull boolean[] v,
|
||||
@@ -356,7 +342,6 @@ public class MaterialInstance {
|
||||
* instance.setParameter("param", MaterialInstance.IntElement.INT4, a, 0, 4);
|
||||
* }</pre>
|
||||
* </p>
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name,
|
||||
@NonNull IntElement type, @NonNull int[] v,
|
||||
@@ -379,7 +364,6 @@ public class MaterialInstance {
|
||||
* material.setDefaultParameter("param", MaterialInstance.FloatElement.FLOAT4, a, 0, 4);
|
||||
* }</pre>
|
||||
* </p>
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name,
|
||||
@NonNull FloatElement type, @NonNull float[] v,
|
||||
@@ -395,7 +379,6 @@ public class MaterialInstance {
|
||||
* @param r red component
|
||||
* @param g green component
|
||||
* @param b blue component
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name, @NonNull Colors.RgbType type,
|
||||
float r, float g, float b) {
|
||||
@@ -412,7 +395,6 @@ public class MaterialInstance {
|
||||
* @param g green component
|
||||
* @param b blue component
|
||||
* @param a alpha component
|
||||
* @throws RuntimeException if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
public void setParameter(@NonNull String name, @NonNull Colors.RgbaType type,
|
||||
float r, float g, float b, float a) {
|
||||
|
||||
-2
@@ -112,8 +112,6 @@ public class MorphTargetBuffer {
|
||||
* @return the newly created <code>MorphTargetBuffer</code> object
|
||||
*
|
||||
* @exception IllegalStateException if the MorphTargetBuffer could not be created
|
||||
* @throws RuntimeException if a runtime error occurred, such as running out of
|
||||
* memory or other resources.
|
||||
*
|
||||
* @see #setMorphTargetBufferOffsetAt
|
||||
*/
|
||||
|
||||
-1
@@ -587,7 +587,6 @@ public class RenderableManager {
|
||||
*
|
||||
* @param engine reference to the <code>Engine</code> to associate this renderable with
|
||||
* @param entity entity to add the renderable component to
|
||||
* @throws RuntimeException if a runtime error occurred, such as running out of memory or other resources, or if a parameter to a builder function was invalid.
|
||||
*/
|
||||
public void build(@NonNull Engine engine, @Entity int entity) {
|
||||
if (!nBuilderBuild(mNativeBuilder, engine.getNativeObject(), entity)) {
|
||||
|
||||
@@ -269,8 +269,9 @@ public class Renderer {
|
||||
|
||||
/**
|
||||
* Set the time at which the frame must be presented to the display.
|
||||
*
|
||||
* <p>
|
||||
* This must be called between {@link #beginFrame} and {@link #endFrame}.
|
||||
* </p>
|
||||
*
|
||||
* @param monotonicClockNanos The time in nanoseconds corresponding to the system monotonic
|
||||
* up-time clock. The presentation time is typically set in the
|
||||
@@ -353,8 +354,6 @@ public class Renderer {
|
||||
* returned and produce a frame anyways, by making calls to {@link #render(View)},
|
||||
* in which case {@link #endFrame} must be called.
|
||||
*
|
||||
* @throws Error if the backend thread encountered an unrecoverable error.
|
||||
*
|
||||
* @see #endFrame
|
||||
* @see #render
|
||||
*/
|
||||
@@ -371,8 +370,6 @@ public class Renderer {
|
||||
*
|
||||
* <br><p>All calls to render() must happen <b>before</b> endFrame().</p>
|
||||
*
|
||||
* @throws Error if the backend thread encountered an unrecoverable error, or if called again after a backend exception was already thrown.
|
||||
*
|
||||
* @see #beginFrame
|
||||
* @see #render
|
||||
*/
|
||||
@@ -428,7 +425,6 @@ public class Renderer {
|
||||
* </ul>
|
||||
*
|
||||
* @param view the {@link View} to render
|
||||
* @throws Error if the backend thread encountered an unrecoverable error, or if called again after a backend exception was already thrown.
|
||||
* @see #beginFrame
|
||||
* @see #endFrame
|
||||
* @see View
|
||||
@@ -458,7 +454,6 @@ public class Renderer {
|
||||
* <li><code>renderStandaloneView()</code> performs potentially heavy computations and cannot be
|
||||
* multi-threaded. However, internally, it is highly multi-threaded to both improve performance
|
||||
* and mitigate the call's latency.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param view the {@link View} to render. This View must have an associated {@link RenderTarget}
|
||||
* @see View
|
||||
@@ -524,14 +519,14 @@ public class Renderer {
|
||||
* <p><code>readPixels</code> must be called within a frame, meaning after {@link #beginFrame}
|
||||
* and before {@link #endFrame}. Typically, <code>readPixels</code> will be called after
|
||||
* {@link #render}.</p>
|
||||
*
|
||||
* <p>After issuing this method, the callback associated with <code>buffer</code> will be invoked on the
|
||||
* main thread, indicating that the read-back has completed. Typically, this will happen
|
||||
* after multiple calls to {@link #beginFrame}, {@link #render}, {@link #endFrame}.</p>
|
||||
*
|
||||
* <p>It is also possible to use a {@link Fence} to wait for the read-back.</p>
|
||||
*
|
||||
* <p><code>readPixels</code> is intended for debugging and testing. It will impact performance significantly.</p>
|
||||
* <br>
|
||||
* <p>After calling this method, the callback associated with <code>buffer</code>
|
||||
* will be invoked on the main thread, indicating that the read-back has completed.
|
||||
* Typically, this will happen after multiple calls to {@link #beginFrame},
|
||||
* {@link #render}, {@link #endFrame}.</p>
|
||||
* <br>
|
||||
* <p><code>readPixels</code> is intended for debugging and testing.
|
||||
* It will impact performance significantly.</p>
|
||||
*
|
||||
* @param xoffset left offset of the sub-region to read back
|
||||
* @param yoffset bottom offset of the sub-region to read back
|
||||
@@ -609,19 +604,18 @@ public class Renderer {
|
||||
*
|
||||
* <p>Typically <code>readPixels</code> will be called after {@link #render} and before
|
||||
* {@link #endFrame}.</p>
|
||||
*
|
||||
* <p>After issuing this method, the callback associated with <code>buffer</code> will be invoked on the
|
||||
* main thread, indicating that the read-back has completed. Typically, this will happen
|
||||
* after multiple calls to {@link #beginFrame}, {@link #render}, {@link #endFrame}.</p>
|
||||
*
|
||||
* <p>It is also possible to use a {@link Fence} to wait for the read-back.</p>
|
||||
*
|
||||
* <br>
|
||||
* <p>After calling this method, the callback associated with <code>buffer</code>
|
||||
* will be invoked on the main thread, indicating that the read-back has completed.
|
||||
* Typically, this will happen after multiple calls to {@link #beginFrame},
|
||||
* {@link #render}, {@link #endFrame}.</p>
|
||||
* <br>
|
||||
* <p>OpenGL only: if issuing a <code>readPixels</code> on a {@link RenderTarget} backed by a
|
||||
* {@link Texture} that had data uploaded to it via {@link Texture#setImage}, the data returned
|
||||
* from <code>readPixels</code> will be y-flipped with respect to the {@link Texture#setImage}
|
||||
* call.</p>
|
||||
*
|
||||
* <p><code>readPixels</code> is intended for debugging and testing. It will impact performance significantly.</p>
|
||||
* <p><code>readPixels</code> is intended for debugging and testing.
|
||||
* It will impact performance significantly.</p>
|
||||
*
|
||||
* @param renderTarget {@link RenderTarget} to read back from
|
||||
* @param xoffset left offset of the sub-region to read back
|
||||
|
||||
@@ -78,8 +78,6 @@ public class SkinningBuffer {
|
||||
* @return the newly created <code>SkinningBuffer</code> object
|
||||
*
|
||||
* @exception IllegalStateException if the SkinningBuffer could not be created
|
||||
* @throws RuntimeException if a runtime error occurred, such as running out of
|
||||
* memory or other resources.
|
||||
*
|
||||
* @see #setBonesAsMatrices
|
||||
* @see #setBonesAsQuaternions
|
||||
|
||||
@@ -885,8 +885,6 @@ public class Texture {
|
||||
* @return A newly created <code>Texture</code>
|
||||
* @exception IllegalStateException if a parameter to a builder function was invalid.
|
||||
* A mode detailed message about the error is output in the system log.
|
||||
* @throws RuntimeException if a runtime error occurred, such as running out of
|
||||
* memory or other resources.
|
||||
*/
|
||||
@NonNull
|
||||
public Texture build(@NonNull Engine engine) {
|
||||
|
||||
@@ -272,8 +272,6 @@ public class VertexBuffer {
|
||||
* @return the newly created <code>VertexBuffer</code> object
|
||||
*
|
||||
* @exception IllegalStateException if the VertexBuffer could not be created
|
||||
* @throws RuntimeException if a runtime error occurred, such as running out of
|
||||
* memory or other resources.
|
||||
*/
|
||||
@NonNull
|
||||
public VertexBuffer build(@NonNull Engine engine) {
|
||||
|
||||
@@ -697,33 +697,6 @@ public class View {
|
||||
options.quality.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the grid size for grid-based world origin snapping.
|
||||
*
|
||||
* @param size The size of the grid cell in world units. If set to 0 or negative,
|
||||
* the grid size is automatically calculated based on the camera frustum.
|
||||
*/
|
||||
public void setGridSize(double size) {
|
||||
nSetGridSize(getNativeObject(), size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the grid size used for grid-based world origin snapping.
|
||||
* @return The grid size in world units. A value of 0 or negative means automatic calculation is enabled.
|
||||
*/
|
||||
public double getGridSize() {
|
||||
return nGetGridSize(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the effective grid size used for grid-based world origin snapping.
|
||||
* If grid size was set to 0 or negative, this returns the automatically calculated size.
|
||||
* @return The effective grid size in world units.
|
||||
*/
|
||||
public double getEffectiveGridSize() {
|
||||
return nGetEffectiveGridSize(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dynamic resolution options associated with this view.
|
||||
* @return value set by {@link #setDynamicResolutionOptions}.
|
||||
@@ -1397,9 +1370,6 @@ public class View {
|
||||
private static native void nSetDithering(long nativeView, int dithering);
|
||||
private static native int nGetDithering(long nativeView);
|
||||
private static native void nSetDynamicResolutionOptions(long nativeView, boolean enabled, boolean homogeneousScaling, float minScale, float maxScale, float sharpness, int quality);
|
||||
private static native void nSetGridSize(long nativeView, double size);
|
||||
private static native double nGetGridSize(long nativeView);
|
||||
private static native double nGetEffectiveGridSize(long nativeView);
|
||||
private static native void nGetLastDynamicResolutionScale(long nativeView, float[] out);
|
||||
private static native void nSetRenderQuality(long nativeView, int hdrColorBufferQuality);
|
||||
private static native void nSetDynamicLightingOptions(long nativeView, float zLightNear, float zLightFar);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
GROUP=com.google.android.filament
|
||||
VERSION_NAME=1.71.3
|
||||
VERSION_NAME=1.71.0
|
||||
|
||||
POM_DESCRIPTION=Real-time physically based rendering engine for Android.
|
||||
|
||||
|
||||
@@ -44,8 +44,6 @@ function print_help {
|
||||
echo " Run all unit tests, will trigger a debug build if needed."
|
||||
echo " -v"
|
||||
echo " Exclude Vulkan support from the Android build."
|
||||
echo " -E"
|
||||
echo " Disable C++ exceptions."
|
||||
echo " -W"
|
||||
echo " Include WebGPU support for the target platform. (NOT functional atm)."
|
||||
echo " -s"
|
||||
@@ -277,7 +275,6 @@ function build_tools_for_split_build {
|
||||
-DCMAKE_BUILD_TYPE="${build_type_arg}" \
|
||||
${WEBGPU_OPTION} \
|
||||
${architectures} \
|
||||
${EXCEPTIONS_OPTION} \
|
||||
../..
|
||||
|
||||
${BUILD_COMMAND} ${WEB_HOST_TOOLS}
|
||||
@@ -321,7 +318,6 @@ function build_desktop_target {
|
||||
${BACKEND_DEBUG_FLAG_OPTION} \
|
||||
${STEREOSCOPIC_OPTION} \
|
||||
${OSMESA_OPTION} \
|
||||
${EXCEPTIONS_OPTION} \
|
||||
${architectures} \
|
||||
../..
|
||||
ln -sf "out/cmake-${lc_target}/compile_commands.json" \
|
||||
@@ -382,7 +378,6 @@ function build_webgl_with_target {
|
||||
-DWEBGL=1 \
|
||||
${WEBGPU_OPTION} \
|
||||
${BACKEND_DEBUG_FLAG_OPTION} \
|
||||
${EXCEPTIONS_OPTION} \
|
||||
../..
|
||||
ln -sf "out/cmake-webgl-${lc_target}/compile_commands.json" \
|
||||
../../compile_commands.json
|
||||
@@ -462,7 +457,6 @@ function build_android_target {
|
||||
${BACKEND_DEBUG_FLAG_OPTION} \
|
||||
${STEREOSCOPIC_OPTION} \
|
||||
${ENABLE_PERFETTO} \
|
||||
${EXCEPTIONS_OPTION} \
|
||||
../..
|
||||
ln -sf "out/cmake-android-${lc_target}-${arch}/compile_commands.json" \
|
||||
../../compile_commands.json
|
||||
@@ -704,7 +698,6 @@ function build_ios_target {
|
||||
${MATDBG_OPTION} \
|
||||
${MATOPT_OPTION} \
|
||||
${STEREOSCOPIC_OPTION} \
|
||||
${EXCEPTIONS_OPTION} \
|
||||
../..
|
||||
ln -sf "out/cmake-ios-${lc_target}-${arch}/compile_commands.json" \
|
||||
../../compile_commands.json
|
||||
@@ -865,7 +858,7 @@ function check_debug_release_build {
|
||||
|
||||
pushd "$(dirname "$0")" > /dev/null
|
||||
|
||||
while getopts ":hacCfgimp:q:uvWslwedtk:bVx:S:X:Py:E" opt; do
|
||||
while getopts ":hacCfgimp:q:uvWslwedtk:bVx:S:X:Py:" opt; do
|
||||
case ${opt} in
|
||||
h)
|
||||
print_help
|
||||
@@ -1016,9 +1009,6 @@ while getopts ":hacCfgimp:q:uvWslwedtk:bVx:S:X:Py:E" opt; do
|
||||
P) ENABLE_PERFETTO="-DFILAMENT_ENABLE_PERFETTO=ON"
|
||||
echo "Enabled perfetto"
|
||||
;;
|
||||
E) EXCEPTIONS_OPTION="-DFILAMENT_ENABLE_EXCEPTIONS=OFF"
|
||||
echo "Disabling exceptions."
|
||||
;;
|
||||
x) BACKEND_DEBUG_FLAG_OPTION="-DFILAMENT_BACKEND_DEBUG_FLAG=${OPTARG}"
|
||||
;;
|
||||
S) case $(echo "${OPTARG}" | tr '[:upper:]' '[:lower:]') in
|
||||
|
||||
@@ -11,7 +11,7 @@ if [ -d "./emsdk" ]; then
|
||||
fi
|
||||
|
||||
# Install emscripten.
|
||||
EMSDK_VERSION=${GITHUB_EMSDK_VERSION-5.0.4}
|
||||
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
|
||||
|
||||
@@ -4,6 +4,6 @@ GITHUB_NINJA_VERSION=1.10.2
|
||||
GITHUB_MESA_VERSION=24.2.1
|
||||
GITHUB_LLVM_VERSION=17
|
||||
GITHUB_NDK_VERSION=29.0.14206865
|
||||
GITHUB_EMSDK_VERSION=5.0.4
|
||||
GITHUB_EMSDK_VERSION=3.1.60
|
||||
GITHUB_VULKANSDK_VERSION=1.4.321.0
|
||||
GITHUB_GLTF_SAMPLE_ASSETS_COMMIT=d441dfdb87413ff412c620849a649d61789a470f
|
||||
|
||||
+9
-12
@@ -163,7 +163,7 @@
|
||||
<p>To build Filament, you must first install the following tools:</p>
|
||||
<ul>
|
||||
<li>CMake 3.22.1 (or more recent)</li>
|
||||
<li>clang 17.0 (or more recent) (Required for Linux and macOS; see <a href="#windows">Windows</a> section for MSVC support)</li>
|
||||
<li>clang 16.0 (or more recent) (Required for Linux and macOS; see <a href="#windows">Windows</a> section for MSVC support)</li>
|
||||
<li><a href="https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages">ninja 1.10</a> (or more recent)</li>
|
||||
</ul>
|
||||
<p>Additional dependencies may be required for your operating system. Please refer to the appropriate
|
||||
@@ -217,10 +217,7 @@ The script offers more features described by executing <code>build.sh -h</code>.
|
||||
<li><code>FILAMENT_INSTALL_BACKEND_TEST</code>: Install the backend test library so it can be consumed on iOS</li>
|
||||
<li><code>FILAMENT_USE_EXTERNAL_GLES3</code>: Experimental: Compile Filament against OpenGL ES 3</li>
|
||||
<li><code>FILAMENT_SKIP_SAMPLES</code>: Don't build sample apps</li>
|
||||
<li><code>FILAMENT_ENABLE_EXCEPTIONS</code>: Enable C++ exceptions (default: ON, OFF for iOS). Required for JNI bindings.</li>
|
||||
<li><code>FILAMENT_ENABLE_RTTI</code>: Enable C++ RTTI (default: OFF).</li>
|
||||
</ul>
|
||||
<p>Note: If you intend to use the JNI library (Android/Java build), you need to have <code>FILAMENT_ENABLE_EXCEPTIONS</code> enabled. If you are using Filament on Android as a pure native library and want to save space, you can disable it (e.g., using <code>./build.sh -E</code>).</p>
|
||||
<p>To turn an option on or off:</p>
|
||||
<pre><code class="language-shell">cd <cmake-build-directory>
|
||||
cmake . -DOPTION=ON # Replace OPTION with the option name, set to ON / OFF
|
||||
@@ -229,16 +226,16 @@ cmake . -DOPTION=ON # Replace OPTION with the option name, set to ON / OFF
|
||||
<h2 id="linux"><a class="header" href="#linux">Linux</a></h2>
|
||||
<p>Make sure you've installed the following dependencies:</p>
|
||||
<ul>
|
||||
<li><code>clang-17</code> or higher</li>
|
||||
<li><code>clang-16</code> or higher</li>
|
||||
<li><code>libglu1-mesa-dev</code></li>
|
||||
<li><code>libc++-17-dev</code> (<code>libcxx-devel</code> and <code>libcxx-static</code> on Fedora) or higher</li>
|
||||
<li><code>libc++abi-17-dev</code> (<code>libcxxabi-static</code> on Fedora) or higher</li>
|
||||
<li><code>libc++-16-dev</code> (<code>libcxx-devel</code> and <code>libcxx-static</code> on Fedora) or higher</li>
|
||||
<li><code>libc++abi-16-dev</code> (<code>libcxxabi-static</code> on Fedora) or higher</li>
|
||||
<li><code>ninja-build</code></li>
|
||||
<li><code>libxi-dev</code></li>
|
||||
<li><code>libxcomposite-dev</code> (<code>libXcomposite-devel</code> on Fedora)</li>
|
||||
<li><code>libxxf86vm-dev</code> (<code>libXxf86vm-devel</code> on Fedora)</li>
|
||||
</ul>
|
||||
<pre><code class="language-shell">sudo apt install clang-17 libglu1-mesa-dev libc++-17-dev libc++abi-17-dev ninja-build libxi-dev libxcomposite-dev libxxf86vm-dev -y
|
||||
<pre><code class="language-shell">sudo apt install clang-16 libglu1-mesa-dev libc++-16-dev libc++abi-16-dev ninja-build libxi-dev libxcomposite-dev libxxf86vm-dev -y
|
||||
</code></pre>
|
||||
<p>After dependencies have been installed, we highly recommend using the <a href="#easy-build">easy build</a>
|
||||
script.</p>
|
||||
@@ -252,15 +249,15 @@ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../release/fila
|
||||
<code>cmake</code> with the following command:</p>
|
||||
<pre><code class="language-shell">mkdir out/cmake-release
|
||||
cd out/cmake-release
|
||||
# Or use a specific version of clang, for instance /usr/bin/clang-17
|
||||
# Or use a specific version of clang, for instance /usr/bin/clang-16
|
||||
CC=/usr/bin/clang CXX=/usr/bin/clang++ CXXFLAGS=-stdlib=libc++ \
|
||||
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../release/filament ../..
|
||||
</code></pre>
|
||||
<p>You can also export the <code>CC</code> and <code>CXX</code> environment variables to always point to <code>clang</code>. Another
|
||||
solution is to use <code>update-alternatives</code> to both change the default compiler, and point to a
|
||||
specific version of clang:</p>
|
||||
<pre><code class="language-shell">update-alternatives --install /usr/bin/clang clang /usr/bin/clang-17 100
|
||||
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-17 100
|
||||
<pre><code class="language-shell">update-alternatives --install /usr/bin/clang clang /usr/bin/clang-16 100
|
||||
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-16 100
|
||||
update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100
|
||||
update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100
|
||||
</code></pre>
|
||||
@@ -451,7 +448,7 @@ started, follow the instructions for building Filament on your platform (<a href
|
||||
<p>Next, you need to install the Emscripten SDK. The following instructions show how to install the
|
||||
same version that our continuous builds use.</p>
|
||||
<pre><code class="language-shell">cd <your chosen parent folder for the emscripten SDK>
|
||||
curl -L https://github.com/emscripten-core/emsdk/archive/refs/tags/5.0.4.zip > emsdk.zip
|
||||
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
|
||||
python ./emsdk.py install latest
|
||||
python ./emsdk.py activate latest
|
||||
|
||||
+8
-8
@@ -159,12 +159,12 @@
|
||||
<div id="content" class="content">
|
||||
<main>
|
||||
<h1 id="filament"><a class="header" href="#filament">Filament</a></h1>
|
||||
<p><a href="https://github.com/google/filament/actions/workflows/status-android.yml"><img src="https://github.com/google/filament/actions/workflows/status-android.yml/badge.svg" alt="Android Build Status" /></a>
|
||||
<a href="https://github.com/google/filament/actions/workflows/status-ios.yml"><img src="https://github.com/google/filament/actions/workflows/status-ios.yml/badge.svg" alt="iOS Build Status" /></a>
|
||||
<a href="https://github.com/google/filament/actions/workflows/status-linux.yml"><img src="https://github.com/google/filament/actions/workflows/status-linux.yml/badge.svg" alt="Linux Build Status" /></a>
|
||||
<a href="https://github.com/google/filament/actions/workflows/status-macos.yml"><img src="https://github.com/google/filament/actions/workflows/status-macos.yml/badge.svg" alt="macOS Build Status" /></a>
|
||||
<a href="https://github.com/google/filament/actions/workflows/status-windows.yml"><img src="https://github.com/google/filament/actions/workflows/status-windows.yml/badge.svg" alt="Windows Build Status" /></a>
|
||||
<a href="https://github.com/google/filament/actions/workflows/status-web.yml"><img src="https://github.com/google/filament/actions/workflows/status-web.yml/badge.svg" alt="Web Build Status" /></a></p>
|
||||
<p><a href="https://github.com/google/filament/actions?query=workflow%3AAndroid"><img src="https://github.com/google/filament/workflows/Android/badge.svg" alt="Android Build Status" /></a>
|
||||
<a href="https://github.com/google/filament/actions?query=workflow%3AiOS"><img src="https://github.com/google/filament/workflows/iOS/badge.svg" alt="iOS Build Status" /></a>
|
||||
<a href="https://github.com/google/filament/actions?query=workflow%3ALinux"><img src="https://github.com/google/filament/workflows/Linux/badge.svg" alt="Linux Build Status" /></a>
|
||||
<a href="https://github.com/google/filament/actions?query=workflow%3AmacOS"><img src="https://github.com/google/filament/workflows/macOS/badge.svg" alt="macOS Build Status" /></a>
|
||||
<a href="https://github.com/google/filament/actions?query=workflow%3AWindows"><img src="https://github.com/google/filament/workflows/Windows/badge.svg" alt="Windows Build Status" /></a>
|
||||
<a href="https://github.com/google/filament/actions?query=workflow%3AWeb"><img src="https://github.com/google/filament/workflows/Web/badge.svg" alt="Web Build Status" /></a></p>
|
||||
<p>Filament is a real-time physically based rendering engine for Android, iOS, Linux, macOS, Windows,
|
||||
and WebGL. It is designed to be as small as possible and as efficient as possible on Android.</p>
|
||||
<h2 id="download"><a class="header" href="#download">Download</a></h2>
|
||||
@@ -181,7 +181,7 @@ important for <code>matc</code> (material compiler).</p>
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.google.android.filament:filament-android:1.71.1'
|
||||
implementation 'com.google.android.filament:filament-android:1.71.0'
|
||||
}
|
||||
</code></pre>
|
||||
<p>Here are all the libraries available in the group <code>com.google.android.filament</code>:</p>
|
||||
@@ -195,7 +195,7 @@ dependencies {
|
||||
</div>
|
||||
<h3 id="ios"><a class="header" href="#ios">iOS</a></h3>
|
||||
<p>iOS projects can use CocoaPods to install the latest release:</p>
|
||||
<pre><code class="language-shell">pod 'Filament', '~> 1.71.1'
|
||||
<pre><code class="language-shell">pod 'Filament', '~> 1.71.0'
|
||||
</code></pre>
|
||||
<h2 id="documentation"><a class="header" href="#documentation">Documentation</a></h2>
|
||||
<ul>
|
||||
|
||||
@@ -319,7 +319,7 @@ the run number is <code>18023632663</code>.</p>
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
<a rel="next prefetch" href="../dup/test_ci_sizeguard.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<a rel="next prefetch" href="../notes/libs.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
@@ -333,7 +333,7 @@ the run number is <code>18023632663</code>.</p>
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
<a rel="next prefetch" href="../dup/test_ci_sizeguard.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<a rel="next prefetch" href="../notes/libs.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
@@ -1,240 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en" class="light sidebar-visible" dir="ltr">
|
||||
<head>
|
||||
<!-- Book generated using mdBook -->
|
||||
<meta charset="UTF-8">
|
||||
<title>CI: sizeguard - Filament</title>
|
||||
|
||||
|
||||
<!-- Custom HTML head -->
|
||||
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="theme-color" content="#ffffff">
|
||||
|
||||
<link rel="shortcut icon" href="../favicon.png">
|
||||
<link rel="stylesheet" href="../css/variables.css">
|
||||
<link rel="stylesheet" href="../css/general.css">
|
||||
<link rel="stylesheet" href="../css/chrome.css">
|
||||
|
||||
<!-- Fonts -->
|
||||
<link rel="stylesheet" href="../FontAwesome/css/font-awesome.css">
|
||||
<link rel="stylesheet" href="../fonts/fonts.css">
|
||||
|
||||
<!-- Highlight.js Stylesheets -->
|
||||
<link rel="stylesheet" href="../highlight.css">
|
||||
<link rel="stylesheet" href="../tomorrow-night.css">
|
||||
<link rel="stylesheet" href="../ayu-highlight.css">
|
||||
|
||||
<!-- Custom theme stylesheets -->
|
||||
|
||||
<!-- MathJax -->
|
||||
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
||||
|
||||
<!-- Provide site root to javascript -->
|
||||
<script>
|
||||
var path_to_root = "../";
|
||||
var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "light" : "light";
|
||||
</script>
|
||||
<!-- Start loading toc.js asap -->
|
||||
<script src="../toc.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="body-container">
|
||||
<!-- Work around some values being stored in localStorage wrapped in quotes -->
|
||||
<script>
|
||||
try {
|
||||
var theme = localStorage.getItem('mdbook-theme');
|
||||
var sidebar = localStorage.getItem('mdbook-sidebar');
|
||||
|
||||
if (theme.startsWith('"') && theme.endsWith('"')) {
|
||||
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
|
||||
}
|
||||
|
||||
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
|
||||
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
|
||||
}
|
||||
} catch (e) { }
|
||||
</script>
|
||||
|
||||
<!-- Set the theme before any content is loaded, prevents flash -->
|
||||
<script>
|
||||
var theme;
|
||||
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
|
||||
if (theme === null || theme === undefined) { theme = default_theme; }
|
||||
const html = document.documentElement;
|
||||
html.classList.remove('light')
|
||||
html.classList.add(theme);
|
||||
html.classList.add("js");
|
||||
</script>
|
||||
|
||||
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
|
||||
|
||||
<!-- Hide / unhide sidebar before it is displayed -->
|
||||
<script>
|
||||
var sidebar = null;
|
||||
var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
|
||||
if (document.body.clientWidth >= 1080) {
|
||||
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
|
||||
sidebar = sidebar || 'visible';
|
||||
} else {
|
||||
sidebar = 'hidden';
|
||||
}
|
||||
sidebar_toggle.checked = sidebar === 'visible';
|
||||
html.classList.remove('sidebar-visible');
|
||||
html.classList.add("sidebar-" + sidebar);
|
||||
</script>
|
||||
|
||||
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
|
||||
<div style="display:flex;align-items:center;justify-content:center">
|
||||
<img class="flogo" src="../images/filament_logo_small.png"></img>
|
||||
</div>
|
||||
<!-- populated by js -->
|
||||
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
|
||||
<noscript>
|
||||
<iframe class="sidebar-iframe-outer" src="../toc.html"></iframe>
|
||||
</noscript>
|
||||
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
|
||||
<div class="sidebar-resize-indicator"></div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div id="page-wrapper" class="page-wrapper">
|
||||
|
||||
<div class="page">
|
||||
<div id="menu-bar-hover-placeholder"></div>
|
||||
<div id="menu-bar" class="menu-bar sticky">
|
||||
<div class="left-buttons">
|
||||
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
|
||||
<i class="fa fa-bars"></i>
|
||||
</label>
|
||||
<!-- Filament: disable themes because the markdeep part does not look good for dark themes -->
|
||||
<!--
|
||||
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
|
||||
<i class="fa fa-paint-brush"></i>
|
||||
</button>
|
||||
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
|
||||
<li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
|
||||
</ul>
|
||||
-->
|
||||
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
|
||||
<i class="fa fa-search"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<h1 class="menu-title">Filament</h1>
|
||||
|
||||
<div class="right-buttons">
|
||||
<a href="https://github.com/google/filament" title="Git repository" aria-label="Git repository">
|
||||
<i id="git-repository-button" class="fa fa-github"></i>
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="search-wrapper" class="hidden">
|
||||
<form id="searchbar-outer" class="searchbar-outer">
|
||||
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
|
||||
</form>
|
||||
<div id="searchresults-outer" class="searchresults-outer hidden">
|
||||
<div id="searchresults-header" class="searchresults-header"></div>
|
||||
<ul id="searchresults">
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
|
||||
<script>
|
||||
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
|
||||
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
|
||||
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
|
||||
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="content" class="content">
|
||||
<main>
|
||||
<h1 id="sizeguard"><a class="header" href="#sizeguard">Sizeguard</a></h1>
|
||||
<p>This directory contains scripts used to monitor and gate the size of Filament artifacts.</p>
|
||||
<h2 id="scripts"><a class="header" href="#scripts">Scripts</a></h2>
|
||||
<h3 id="dump_artifact_sizepy"><a class="header" href="#dump_artifact_sizepy"><code>dump_artifact_size.py</code></a></h3>
|
||||
<p>Computes the sizes of build artifacts (e.g., <code>.aar</code>, <code>.tgz</code>) and their internal contents. It outputs a JSON representation of these sizes.</p>
|
||||
<p><strong>Usage:</strong></p>
|
||||
<pre><code class="language-bash">python3 dump_artifact_size.py out/*.aar > current_size.json
|
||||
</code></pre>
|
||||
<h3 id="check_sizepy"><a class="header" href="#check_sizepy"><code>check_size.py</code></a></h3>
|
||||
<p>Compares a current size JSON (generated by <code>dump_artifact_size.py</code>) against historical data stored in the <code>filament-assets</code> repository. It fails if any artifact's size increase exceeds a specified threshold.</p>
|
||||
<p><strong>Key Arguments:</strong></p>
|
||||
<ul>
|
||||
<li><code>current_json</code>: Path to the local JSON file.</li>
|
||||
<li><code>--threshold</code>: Size increase threshold in bytes (default: 20KB).</li>
|
||||
<li><code>--bypass</code>: If provided, the script will print the comparison but exit successfully even if thresholds are exceeded.</li>
|
||||
</ul>
|
||||
<h3 id="check_bypasspy"><a class="header" href="#check_bypasspy"><code>check_bypass.py</code></a></h3>
|
||||
<p>A utility script that checks the commit message for a specific tag to determine if the sizeguard check should be bypassed.</p>
|
||||
<p><strong>Usage:</strong></p>
|
||||
<ul>
|
||||
<li>Returns exit code <code>0</code> if the tag <code>SIZEGUARD_BYPASS</code> is found in the commit message.</li>
|
||||
<li>Returns exit code <code>1</code> otherwise.</li>
|
||||
</ul>
|
||||
<h2 id="continuous-integration"><a class="header" href="#continuous-integration">Continuous Integration</a></h2>
|
||||
<p>These scripts are integrated into the GitHub Actions workflows (e.g., <code>.github/workflows/presubmit.yml</code>).</p>
|
||||
<p>To bypass a failing sizeguard check in a PR, add the following tag on a new line in your commit message:</p>
|
||||
<pre><code>SIZEGUARD_BYPASS
|
||||
</code></pre>
|
||||
|
||||
</main>
|
||||
|
||||
<nav class="nav-wrapper" aria-label="Page navigation">
|
||||
<!-- Mobile navigation buttons -->
|
||||
<a rel="prev" href="../dup/test_ci_renderdiff.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
<a rel="next prefetch" href="../notes/libs.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
<div style="clear: both"></div>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav class="nav-wide-wrapper" aria-label="Page navigation">
|
||||
<a rel="prev" href="../dup/test_ci_renderdiff.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
<a rel="next prefetch" href="../notes/libs.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
window.playground_copyable = true;
|
||||
</script>
|
||||
|
||||
|
||||
<script src="../elasticlunr.min.js"></script>
|
||||
<script src="../mark.min.js"></script>
|
||||
<script src="../searcher.js"></script>
|
||||
|
||||
<script src="../clipboard.min.js"></script>
|
||||
<script src="../highlight.js"></script>
|
||||
<script src="../book.js"></script>
|
||||
|
||||
<!-- Custom JS scripts -->
|
||||
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -165,7 +165,7 @@
|
||||
|
||||
<nav class="nav-wrapper" aria-label="Page navigation">
|
||||
<!-- Mobile navigation buttons -->
|
||||
<a rel="prev" href="../dup/test_ci_sizeguard.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||||
<a rel="prev" href="../dup/test_ci_renderdiff.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
@@ -179,7 +179,7 @@
|
||||
</div>
|
||||
|
||||
<nav class="nav-wide-wrapper" aria-label="Page navigation">
|
||||
<a rel="prev" href="../dup/test_ci_sizeguard.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||||
<a rel="prev" href="../dup/test_ci_renderdiff.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -100,9 +100,6 @@
|
||||
"test/backend/README.md": {
|
||||
"dest": "dup/test_ci_backend.md"
|
||||
},
|
||||
"test/sizeguard/README.md": {
|
||||
"dest": "dup/test_ci_sizeguard.md"
|
||||
},
|
||||
"filament/backend/test/README.md": {
|
||||
"dest": "dup/backend_test.md"
|
||||
},
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
- [backend](./dup/backend_test.md)
|
||||
- [CI: backend](./dup/test_ci_backend.md)
|
||||
- [CI: renderdiff](./dup/test_ci_renderdiff.md)
|
||||
- [CI: sizeguard](./dup/test_ci_sizeguard.md)
|
||||
- [Libraries](./notes/libs.md)
|
||||
- [bluegl](./dup/bluegl.md)
|
||||
- [bluevk](./dup/bluevk.md)
|
||||
|
||||
@@ -156,7 +156,6 @@ set(SRCS
|
||||
src/ds/StructureDescriptorSet.cpp
|
||||
src/fg/Blackboard.cpp
|
||||
src/fg/DependencyGraph.cpp
|
||||
src/fg/FgviewerManager.cpp
|
||||
src/fg/FrameGraph.cpp
|
||||
src/fg/FrameGraphPass.cpp
|
||||
src/fg/FrameGraphResources.cpp
|
||||
|
||||
@@ -602,7 +602,6 @@ if (FILAMENT_BUILD_TESTING)
|
||||
test/test_CircularBuffer.cpp
|
||||
test/test_CommandBufferQueue.cpp
|
||||
test/test_Template.cpp
|
||||
test/test_AsyncUploads.cpp
|
||||
test/test_Platform.cpp
|
||||
)
|
||||
if (FILAMENT_SUPPORTS_WEBGPU)
|
||||
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
*
|
||||
* createDevice is called by the Metal backend from the backend thread.
|
||||
*/
|
||||
void createDevice(MetalDevice& outDevice) noexcept;
|
||||
virtual void createDevice(MetalDevice& outDevice) noexcept;
|
||||
|
||||
/**
|
||||
* Create a command submission queue on the Metal device object.
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
*
|
||||
* @param device The device which was returned from createDevice()
|
||||
*/
|
||||
void createCommandQueue(
|
||||
virtual void createCommandQueue(
|
||||
MetalDevice& device, MetalCommandQueue& outCommandQueue) noexcept;
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,11 +31,6 @@
|
||||
#include <backend/platforms/OpenGLPlatform.h>
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <thread>
|
||||
#include <shared_mutex>
|
||||
#include <memory>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
/**
|
||||
@@ -63,20 +58,10 @@ protected:
|
||||
bool makeCurrent(ContextType type, SwapChain* drawSwapChain,
|
||||
SwapChain* readSwapChain) override;
|
||||
void commit(SwapChain* swapChain) noexcept override;
|
||||
bool isExtraContextSupported() const noexcept override;
|
||||
void createContext(bool shared) override;
|
||||
void releaseContext() noexcept override;
|
||||
|
||||
private:
|
||||
OSMesaContext mContext;
|
||||
void* mOsMesaApi = nullptr;
|
||||
|
||||
struct ContextInfo {
|
||||
OSMesaContext context;
|
||||
std::unique_ptr<uint8_t[]> buffer;
|
||||
};
|
||||
std::unordered_map<std::thread::id, ContextInfo> mAdditionalContexts;
|
||||
mutable std::shared_mutex mAdditionalContextsLock;
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
#include <utils/Mutex.h>
|
||||
|
||||
#include <vector>
|
||||
#include <exception>
|
||||
#include <atomic>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -77,25 +75,6 @@ public:
|
||||
|
||||
bool isExitRequested() const;
|
||||
|
||||
#ifdef __EXCEPTIONS
|
||||
bool hasUnrecoverableError() const noexcept {
|
||||
return mHasUnrecoverableError.load(std::memory_order_acquire);
|
||||
}
|
||||
void setUnrecoverableException(std::exception_ptr e) noexcept {
|
||||
mBackendException = e;
|
||||
mHasUnrecoverableError.store(true, std::memory_order_release);
|
||||
}
|
||||
void propagateBackendException() const;
|
||||
bool hasExceptionBeenRethrown() const noexcept {
|
||||
return mExceptionRethrown.load(std::memory_order_relaxed);
|
||||
}
|
||||
#else
|
||||
void propagateBackendException() const noexcept {}
|
||||
constexpr bool hasUnrecoverableError() const noexcept { return false; }
|
||||
constexpr bool hasExceptionBeenRethrown() const noexcept { return false; }
|
||||
#endif
|
||||
|
||||
|
||||
private:
|
||||
const size_t mRequiredSize;
|
||||
|
||||
@@ -112,12 +91,6 @@ private:
|
||||
bool mPaused = false;
|
||||
|
||||
static constexpr uint32_t EXIT_REQUESTED = 0x31415926;
|
||||
|
||||
#ifdef __EXCEPTIONS
|
||||
mutable std::exception_ptr mBackendException;
|
||||
std::atomic<bool> mHasUnrecoverableError{false};
|
||||
mutable std::atomic<bool> mExceptionRethrown{false};
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
@@ -75,12 +75,6 @@ public:
|
||||
// thread via `purge()`.
|
||||
virtual void scheduleCallback(CallbackHandler* handler, void* user, CallbackHandler::Callback callback) = 0;
|
||||
|
||||
/**
|
||||
* Flags the driver as having encountered an unrecoverable error.
|
||||
* This will interrupt all pending fence waits and prevent further waits.
|
||||
*/
|
||||
virtual void setUnrecoverableError() noexcept {}
|
||||
|
||||
virtual ShaderModel getShaderModel() const noexcept = 0;
|
||||
|
||||
// The shader languages used for shaders for this driver in order of preference, used to inform
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <exception>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -80,28 +79,8 @@ bool CommandBufferQueue::isExitRequested() const {
|
||||
}
|
||||
|
||||
|
||||
#ifdef __EXCEPTIONS
|
||||
void CommandBufferQueue::propagateBackendException() const {
|
||||
if (UTILS_VERY_UNLIKELY(hasUnrecoverableError())) {
|
||||
if (!mExceptionRethrown.exchange(true, std::memory_order_relaxed)) {
|
||||
std::rethrow_exception(mBackendException);
|
||||
} else {
|
||||
FILAMENT_CHECK_POSTCONDITION(false)
|
||||
<< "Engine is in unrecoverable state due to previous backend exception";
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void CommandBufferQueue::flush() {
|
||||
FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
||||
#ifdef __EXCEPTIONS
|
||||
if (UTILS_VERY_UNLIKELY(hasUnrecoverableError())) {
|
||||
// Drop the current buffer to avoid filling up the circular buffer
|
||||
mCircularBuffer.getBuffer();
|
||||
propagateBackendException();
|
||||
}
|
||||
#endif
|
||||
|
||||
CircularBuffer& circularBuffer = mCircularBuffer;
|
||||
if (circularBuffer.empty()) {
|
||||
|
||||
@@ -284,7 +284,6 @@ public:
|
||||
switch (srcType) {
|
||||
case UBYTE: reshaper = reshapeImageImpl<float, uint8_t>; break;
|
||||
case FLOAT: reshaper = reshapeImageImpl<float, float>; break;
|
||||
case HALF: reshaper = reshapeImageImpl<float, math::half>; break;
|
||||
case INT: reshaper = reshapeImageImpl<float, int32_t>; break;
|
||||
case UINT: reshaper = reshapeImageImpl<float, uint32_t>; break;
|
||||
case UINT_10F_11F_11F_REV:
|
||||
@@ -301,7 +300,6 @@ public:
|
||||
switch (srcType) {
|
||||
case UBYTE: reshaper = reshapeImageImpl<int32_t, uint8_t>; break;
|
||||
case FLOAT: reshaper = reshapeImageImpl<int32_t, float>; break;
|
||||
case HALF: reshaper = reshapeImageImpl<int32_t, math::half>; break;
|
||||
case INT: reshaper = reshapeImageImpl<int32_t, int32_t>; break;
|
||||
case UINT: reshaper = reshapeImageImpl<int32_t, uint32_t>; break;
|
||||
case UINT_10F_11F_11F_REV:
|
||||
@@ -318,7 +316,6 @@ public:
|
||||
switch (srcType) {
|
||||
case UBYTE: reshaper = reshapeImageImpl<uint32_t, uint8_t>; break;
|
||||
case FLOAT: reshaper = reshapeImageImpl<uint32_t, float>; break;
|
||||
case HALF: reshaper = reshapeImageImpl<uint32_t, math::half>; break;
|
||||
case INT: reshaper = reshapeImageImpl<uint32_t, int32_t>; break;
|
||||
case UINT: reshaper = reshapeImageImpl<uint32_t, uint32_t>; break;
|
||||
case UINT_10F_11F_11F_REV:
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include "private/backend/Dispatcher.h"
|
||||
#include "private/backend/Driver.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@@ -215,48 +214,18 @@ public:
|
||||
|
||||
void scheduleCallback(CallbackHandler* handler, void* user, CallbackHandler::Callback callback) final;
|
||||
|
||||
/**
|
||||
* Waits for a predicate to become true or until a timeout is reached.
|
||||
* Returns ERROR if the driver encountered an unrecoverable error.
|
||||
*/
|
||||
template<typename Predicate>
|
||||
FenceStatus waitForFence(Predicate predicate, std::chrono::steady_clock::time_point until) {
|
||||
bool waitForFence(Predicate predicate, std::chrono::steady_clock::time_point until) {
|
||||
std::unique_lock lock(mFenceMutex);
|
||||
bool errorObserved = false;
|
||||
bool success = mFenceCondition.wait_until(lock, until, [&]() {
|
||||
return predicate() ||
|
||||
(errorObserved = UTILS_VERY_UNLIKELY(mHasUnrecoverableError.load(std::memory_order_relaxed)));
|
||||
});
|
||||
|
||||
if (UTILS_VERY_UNLIKELY(errorObserved)) {
|
||||
return FenceStatus::ERROR;
|
||||
}
|
||||
|
||||
return success ? FenceStatus::CONDITION_SATISFIED : FenceStatus::TIMEOUT_EXPIRED;
|
||||
return mFenceCondition.wait_until(lock, until, predicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for a predicate to become true indefinitely.
|
||||
* Returns ERROR if the driver encountered an unrecoverable error.
|
||||
*/
|
||||
template<typename Predicate>
|
||||
FenceStatus waitForFence(Predicate predicate) {
|
||||
void waitForFence(Predicate predicate) {
|
||||
std::unique_lock lock(mFenceMutex);
|
||||
bool errorObserved = false;
|
||||
mFenceCondition.wait(lock, [&]() {
|
||||
return predicate() ||
|
||||
(errorObserved = UTILS_VERY_UNLIKELY(mHasUnrecoverableError.load(std::memory_order_relaxed)));
|
||||
});
|
||||
|
||||
if (UTILS_VERY_UNLIKELY(errorObserved)) {
|
||||
return FenceStatus::ERROR;
|
||||
}
|
||||
return FenceStatus::CONDITION_SATISFIED;
|
||||
mFenceCondition.wait(lock, predicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes an action that signals a fence and notifies all waiters.
|
||||
*/
|
||||
template<typename Action>
|
||||
void signalFence(Action action) {
|
||||
std::lock_guard lock(mFenceMutex);
|
||||
@@ -264,22 +233,6 @@ public:
|
||||
mFenceCondition.notify_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Flags the driver as having encountered an unrecoverable error.
|
||||
*/
|
||||
void setUnrecoverableError() noexcept override {
|
||||
std::lock_guard lock(mFenceMutex);
|
||||
mHasUnrecoverableError.store(true, std::memory_order_relaxed);
|
||||
mFenceCondition.notify_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the driver has encountered an unrecoverable error.
|
||||
*/
|
||||
bool hasUnrecoverableError() const noexcept {
|
||||
return mHasUnrecoverableError.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// Privates
|
||||
// --------------------------------------------------------------------------------------------
|
||||
@@ -322,7 +275,6 @@ private:
|
||||
|
||||
std::condition_variable mFenceCondition;
|
||||
std::mutex mFenceMutex;
|
||||
std::atomic<bool> mHasUnrecoverableError{false};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -175,15 +175,11 @@ public:
|
||||
/**
|
||||
* Update the buffer with data inside src. Potentially allocates a new buffer allocation to hold
|
||||
* the bytes which will be released when the current frame is finished.
|
||||
*
|
||||
* @param cmdBuffer The command buffer to use for the copy. If this is nil, uses the current
|
||||
* pending command buffer.
|
||||
*/
|
||||
using TagResolver = utils::Invocable<const char*(void)>;
|
||||
void copyIntoBuffer(id<MTLCommandBuffer> cmdBuffer, void* src, size_t size, size_t byteOffset,
|
||||
TagResolver&& getHandleTag);
|
||||
void copyIntoBufferUnsynchronized(id<MTLCommandBuffer> cmdBuffer, void* src, size_t size,
|
||||
size_t byteOffset, TagResolver&& getHandleTag);
|
||||
void copyIntoBuffer(void* src, size_t size, size_t byteOffset, TagResolver&& getHandleTag);
|
||||
void copyIntoBufferUnsynchronized(
|
||||
void* src, size_t size, size_t byteOffset, TagResolver&& getHandleTag);
|
||||
|
||||
/**
|
||||
* Denotes that this buffer is used for a draw call ensuring that its allocation remains valid
|
||||
@@ -191,6 +187,7 @@ public:
|
||||
*
|
||||
* @return The MTLBuffer representing the current state of the buffer to bind, it never returns
|
||||
* nil.
|
||||
*
|
||||
*/
|
||||
id<MTLBuffer> getGpuBufferForDraw() noexcept;
|
||||
|
||||
@@ -228,10 +225,10 @@ private:
|
||||
BUMP_ALLOCATOR,
|
||||
};
|
||||
|
||||
void uploadWithPoolBuffer(id<MTLCommandBuffer> cmdBuffer, void* src, size_t size,
|
||||
size_t byteOffset, TagResolver&& getHandleTag) const;
|
||||
void uploadWithBumpAllocator(id<MTLCommandBuffer> cmdBuffer, void* src, size_t size,
|
||||
size_t byteOffset, TagResolver&& getHandleTag) const;
|
||||
void uploadWithPoolBuffer(
|
||||
void* src, size_t size, size_t byteOffset, TagResolver&& getHandleTag) const;
|
||||
void uploadWithBumpAllocator(
|
||||
void* src, size_t size, size_t byteOffset, TagResolver&& getHandleTag) const;
|
||||
|
||||
UploadStrategy mUploadStrategy;
|
||||
TrackedMetalBuffer mBuffer;
|
||||
|
||||
@@ -64,8 +64,8 @@ MetalBuffer::MetalBuffer(MetalContext& context, BufferObjectBinding bindingType,
|
||||
|
||||
MetalBuffer::~MetalBuffer() = default;
|
||||
|
||||
void MetalBuffer::copyIntoBuffer(id<MTLCommandBuffer> cmdBuffer, void* src, size_t size,
|
||||
size_t byteOffset, TagResolver&& getHandleTag) {
|
||||
void MetalBuffer::copyIntoBuffer(
|
||||
void* src, size_t size, size_t byteOffset, TagResolver&& getHandleTag) {
|
||||
if (size <= 0) {
|
||||
return;
|
||||
}
|
||||
@@ -79,24 +79,20 @@ void MetalBuffer::copyIntoBuffer(id<MTLCommandBuffer> cmdBuffer, void* src, size
|
||||
FILAMENT_CHECK_PRECONDITION(!(byteOffset & 0x3))
|
||||
<< "byteOffset must be a multiple of 4, tag=" << getHandleTag();
|
||||
|
||||
id<MTLCommandBuffer> targetCmdBuffer =
|
||||
cmdBuffer ? cmdBuffer : getPendingCommandBuffer(&mContext);
|
||||
|
||||
switch (mUploadStrategy) {
|
||||
case UploadStrategy::BUMP_ALLOCATOR:
|
||||
uploadWithBumpAllocator(targetCmdBuffer, src, size, byteOffset,
|
||||
std::move(getHandleTag));
|
||||
uploadWithBumpAllocator(src, size, byteOffset, std::move(getHandleTag));
|
||||
break;
|
||||
case UploadStrategy::POOL:
|
||||
uploadWithPoolBuffer(targetCmdBuffer, src, size, byteOffset, std::move(getHandleTag));
|
||||
uploadWithPoolBuffer(src, size, byteOffset, std::move(getHandleTag));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MetalBuffer::copyIntoBufferUnsynchronized(id<MTLCommandBuffer> cmdBuffer, void* src,
|
||||
size_t size, size_t byteOffset, TagResolver&& getHandleTag) {
|
||||
void MetalBuffer::copyIntoBufferUnsynchronized(
|
||||
void* src, size_t size, size_t byteOffset, TagResolver&& getHandleTag) {
|
||||
// TODO: implement the unsynchronized version
|
||||
copyIntoBuffer(cmdBuffer, src, size, byteOffset, std::move(getHandleTag));
|
||||
copyIntoBuffer(src, size, byteOffset, std::move(getHandleTag));
|
||||
}
|
||||
|
||||
id<MTLBuffer> MetalBuffer::getGpuBufferForDraw() noexcept {
|
||||
@@ -162,8 +158,8 @@ void MetalBuffer::bindBuffers(id<MTLCommandBuffer> cmdBuffer, id<MTLCommandEncod
|
||||
}
|
||||
}
|
||||
|
||||
void MetalBuffer::uploadWithPoolBuffer(id<MTLCommandBuffer> cmdBuffer, void* src, size_t size,
|
||||
size_t byteOffset, TagResolver&& getHandleTag) const {
|
||||
void MetalBuffer::uploadWithPoolBuffer(
|
||||
void* src, size_t size, size_t byteOffset, TagResolver&& getHandleTag) const {
|
||||
MetalBufferPool* bufferPool = mContext.bufferPool;
|
||||
const MetalBufferPoolEntry* const staging = bufferPool->acquireBuffer(size);
|
||||
FILAMENT_CHECK_POSTCONDITION(staging)
|
||||
@@ -172,6 +168,7 @@ void MetalBuffer::uploadWithPoolBuffer(id<MTLCommandBuffer> cmdBuffer, void* src
|
||||
memcpy(staging->buffer.get().contents, src, size);
|
||||
|
||||
// Encode a blit from the staging buffer into the private GPU buffer.
|
||||
id<MTLCommandBuffer> cmdBuffer = getPendingCommandBuffer(&mContext);
|
||||
id<MTLBlitCommandEncoder> blitEncoder = [cmdBuffer blitCommandEncoder];
|
||||
blitEncoder.label = @"Buffer upload blit - pool buffer";
|
||||
[blitEncoder copyFromBuffer:staging->buffer.get()
|
||||
@@ -185,8 +182,8 @@ void MetalBuffer::uploadWithPoolBuffer(id<MTLCommandBuffer> cmdBuffer, void* src
|
||||
}];
|
||||
}
|
||||
|
||||
void MetalBuffer::uploadWithBumpAllocator(id<MTLCommandBuffer> cmdBuffer, void* src, size_t size,
|
||||
size_t byteOffset, TagResolver&& getHandleTag) const {
|
||||
void MetalBuffer::uploadWithBumpAllocator(
|
||||
void* src, size_t size, size_t byteOffset, TagResolver&& getHandleTag) const {
|
||||
MetalBumpAllocator& allocator = *mContext.bumpAllocator;
|
||||
auto [buffer, offset] = allocator.allocateStagingArea(size);
|
||||
FILAMENT_CHECK_POSTCONDITION(buffer)
|
||||
@@ -199,6 +196,7 @@ void MetalBuffer::uploadWithBumpAllocator(id<MTLCommandBuffer> cmdBuffer, void*
|
||||
memcpy(static_cast<char*>(contents) + offset, src, size);
|
||||
|
||||
// Encode a blit from the staging buffer into the private GPU buffer.
|
||||
id<MTLCommandBuffer> cmdBuffer = getPendingCommandBuffer(&mContext);
|
||||
id<MTLBlitCommandEncoder> blitEncoder = [cmdBuffer blitCommandEncoder];
|
||||
blitEncoder.label = @"Buffer upload blit - bump allocator";
|
||||
[blitEncoder copyFromBuffer:buffer
|
||||
|
||||
@@ -55,13 +55,9 @@ public:
|
||||
|
||||
private:
|
||||
id<MTLDevice> mDevice;
|
||||
|
||||
std::mutex mMutex;
|
||||
// The following are protected by mMutex
|
||||
TrackedMetalBuffer mCurrentUploadBuffer = nil;
|
||||
size_t mHead = 0;
|
||||
|
||||
const size_t mCapacity; // Constant after construction
|
||||
size_t mCapacity;
|
||||
};
|
||||
|
||||
// Manages a pool of Metal buffers, periodically releasing ones that have been unused for awhile.
|
||||
|
||||
@@ -130,40 +130,20 @@ std::pair<id<MTLBuffer>, size_t> MetalBumpAllocator::allocateStagingArea(size_t
|
||||
if (size > mCapacity) {
|
||||
return { [mDevice newBufferWithLength:size options:MTLStorageModeShared], 0 };
|
||||
}
|
||||
assert_invariant(mCurrentUploadBuffer);
|
||||
|
||||
// TODO: We could optimize performance in the future by using thread-local staging areas or
|
||||
// bump allocators per thread. For now, we use a mutex to ensure thread-safety.
|
||||
// Align the head to a 4-byte boundary.
|
||||
mHead = (mHead + 3) & ~3;
|
||||
|
||||
// Try to allocate from the current buffer first
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
assert_invariant(mCurrentUploadBuffer);
|
||||
|
||||
// Align the head to a 4-byte boundary.
|
||||
size_t alignedHead = (mHead + 3) & ~3;
|
||||
|
||||
if (UTILS_LIKELY(alignedHead + size <= mCapacity)) {
|
||||
mHead = alignedHead + size;
|
||||
return { mCurrentUploadBuffer.get(), alignedHead };
|
||||
}
|
||||
if (UTILS_LIKELY(mHead + size <= mCapacity)) {
|
||||
const size_t oldHead = mHead;
|
||||
mHead += size;
|
||||
return { mCurrentUploadBuffer.get(), oldHead };
|
||||
}
|
||||
|
||||
// We're finished with the current allocation or there wasn't enough space.
|
||||
// Create a new buffer outside the lock.
|
||||
id<MTLBuffer> newBuffer = [mDevice newBufferWithLength:mCapacity options:MTLStorageModeShared];
|
||||
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
|
||||
// We need to re-check if another thread already reset the buffer while we were allocating.
|
||||
size_t alignedHead = (mHead + 3) & ~3;
|
||||
|
||||
if (alignedHead + size <= mCapacity) {
|
||||
mHead = alignedHead + size;
|
||||
// newBuffer will be released as it goes out of scope.
|
||||
return { mCurrentUploadBuffer.get(), alignedHead };
|
||||
}
|
||||
|
||||
mCurrentUploadBuffer = { newBuffer, TrackedMetalBuffer::Type::STAGING };
|
||||
// We're finished with the current allocation.
|
||||
mCurrentUploadBuffer = { [mDevice newBufferWithLength:mCapacity options:MTLStorageModeShared],
|
||||
TrackedMetalBuffer::Type::STAGING };
|
||||
mHead = size;
|
||||
|
||||
return { mCurrentUploadBuffer.get(), 0 };
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "DriverBase.h"
|
||||
|
||||
#include "private/backend/HandleAllocator.h"
|
||||
#include "JobQueue.h"
|
||||
|
||||
#include <backend/SamplerDescriptor.h>
|
||||
|
||||
@@ -64,9 +63,6 @@ public:
|
||||
|
||||
MetalContext* getContext() { return mContext; }
|
||||
|
||||
JobQueue* getJobQueue() const noexcept { return mJobQueue.get(); }
|
||||
JobWorker* getJobWorker() const noexcept { return mJobWorker.get(); }
|
||||
|
||||
using DriverBase::scheduleDestroy;
|
||||
|
||||
private:
|
||||
@@ -82,7 +78,7 @@ private:
|
||||
ShaderLanguage preferredLanguage) const noexcept final;
|
||||
|
||||
// Overrides the default implementation by wrapping the call to fn in an @autoreleasepool block.
|
||||
void execute(std::function<void(void)> const& fn) final;
|
||||
void execute(std::function<void(void)> const& fn) noexcept final;
|
||||
|
||||
/*
|
||||
* Tasks run regularly on the driver thread.
|
||||
@@ -171,9 +167,6 @@ private:
|
||||
|
||||
backend::StereoscopicType const mStereoscopicType;
|
||||
backend::AsynchronousMode const mAsynchronousMode;
|
||||
|
||||
JobQueue::Ptr mJobQueue;
|
||||
JobWorker::Ptr mJobWorker;
|
||||
};
|
||||
|
||||
} // namespace backend
|
||||
|
||||
@@ -232,24 +232,6 @@ MetalDriver::MetalDriver(
|
||||
mContext->shaderCompiler = new MetalShaderCompiler(mContext->device, *this, compilerMode);
|
||||
mContext->shaderCompiler->init();
|
||||
|
||||
if (driverConfig.asynchronousMode != AsynchronousMode::NONE) {
|
||||
mJobQueue = JobQueue::create();
|
||||
|
||||
bool const useThreadWorker =
|
||||
(driverConfig.asynchronousMode == AsynchronousMode::THREAD_PREFERRED) &&
|
||||
UTILS_HAS_THREADING;
|
||||
|
||||
if (useThreadWorker) {
|
||||
ThreadWorker::Config threadWorkerConfig{
|
||||
"JobQueueThreadWorker", utils::JobSystem::Priority::NORMAL, []() {}, // onBegin
|
||||
[]() {}, // onEnd
|
||||
};
|
||||
mJobWorker = ThreadWorker::create(mJobQueue, std::move(threadWorkerConfig));
|
||||
} else {
|
||||
mJobWorker = AmortizationWorker::create(mJobQueue);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(FILAMENT_METAL_PROFILING)
|
||||
mContext->log = os_log_create("com.google.filament", "Metal");
|
||||
mContext->signpostId = os_signpost_id_generate(mContext->log);
|
||||
@@ -325,7 +307,7 @@ void MetalDriver::setFrameCompletedCallback(
|
||||
swapChain->setFrameCompletedCallback(handler, std::move(callback));
|
||||
}
|
||||
|
||||
void MetalDriver::execute(std::function<void(void)> const& fn) {
|
||||
void MetalDriver::execute(std::function<void(void)> const& fn) noexcept {
|
||||
@autoreleasepool {
|
||||
fn();
|
||||
}
|
||||
@@ -484,16 +466,7 @@ void MetalDriver::createIndexBufferR(Handle<HwIndexBuffer> ibh, ElementType elem
|
||||
void MetalDriver::createIndexBufferAsyncR(Handle<HwIndexBuffer> ibh, ElementType elementType,
|
||||
uint32_t indexCount, BufferUsage usage, CallbackHandler* handler,
|
||||
CallbackHandler::Callback callback, void* user, utils::ImmutableCString&& tag) {
|
||||
auto elementSize = (uint8_t) getElementTypeSize(elementType);
|
||||
auto* indexBuffer = construct_handle<MetalIndexBuffer>(ibh, *mContext, usage, elementSize,
|
||||
indexCount, true);
|
||||
auto& buffer = indexBuffer->buffer;
|
||||
FILAMENT_CHECK_POSTCONDITION(buffer.wasAllocationSuccessful())
|
||||
<< "Could not allocate Metal index buffer of size " << buffer.getSize()
|
||||
<< ", tag=" << tag.c_str_safe();
|
||||
buffer.setLabel(tag);
|
||||
mHandleAllocator.associateTagToHandle(ibh.getId(), std::move(tag));
|
||||
scheduleCallback(handler, user, callback);
|
||||
// TODO: implement this.
|
||||
}
|
||||
|
||||
void MetalDriver::createBufferObjectR(Handle<HwBufferObject> boh, uint32_t byteCount,
|
||||
@@ -510,14 +483,7 @@ void MetalDriver::createBufferObjectR(Handle<HwBufferObject> boh, uint32_t byteC
|
||||
void MetalDriver::createBufferObjectAsyncR(Handle<HwBufferObject> boh, uint32_t byteCount,
|
||||
BufferObjectBinding bindingType, BufferUsage usage, CallbackHandler* handler,
|
||||
CallbackHandler::Callback callback, void* user, utils::ImmutableCString&& tag) {
|
||||
auto* bufferObject = construct_handle<MetalBufferObject>(boh, *mContext, bindingType, usage,
|
||||
byteCount, true);
|
||||
FILAMENT_CHECK_POSTCONDITION(bufferObject->getBuffer()->wasAllocationSuccessful())
|
||||
<< "Could not allocate Metal buffer of size " << byteCount
|
||||
<< ", tag=" << tag.c_str_safe();
|
||||
bufferObject->getBuffer()->setLabel(tag);
|
||||
mHandleAllocator.associateTagToHandle(boh.getId(), std::move(tag));
|
||||
scheduleCallback(handler, user, callback);
|
||||
// TODO: implement this.
|
||||
}
|
||||
|
||||
// fixme: TextureUsage is a bitfield
|
||||
@@ -572,26 +538,10 @@ void MetalDriver::createTextureR(Handle<HwTexture> th, SamplerType target, uint8
|
||||
}
|
||||
|
||||
void MetalDriver::createTextureAsyncR(Handle<HwTexture> th, SamplerType target, uint8_t levels,
|
||||
TextureFormat format, uint8_t samples, uint32_t width, uint32_t height, uint32_t depth,
|
||||
TextureUsage usage, CallbackHandler* handler, CallbackHandler::Callback callback,
|
||||
void* user, utils::ImmutableCString&& tag) {
|
||||
// Clamp sample count to what the device supports.
|
||||
auto& sc = mContext->sampleCountLookup;
|
||||
samples = sc[std::min(MAX_SAMPLE_COUNT, samples)];
|
||||
|
||||
MetalTexture* texture = construct_handle<MetalTexture>(th, *mContext, target, levels, format,
|
||||
samples, width, height, depth, usage, true);
|
||||
mContext->textures.insert(texture);
|
||||
|
||||
texture->setLabel(tag);
|
||||
|
||||
DEBUG_LOG("createTextureAsyncR(th = %d, target = %s, levels = %d, format = ?, samples = %d, "
|
||||
"width = "
|
||||
"%d, height = %d, depth = %d, usage = %s)\n",
|
||||
th.getId(), stringify(target), levels, samples, width, height, depth, stringify(usage));
|
||||
|
||||
mHandleAllocator.associateTagToHandle(th.getId(), std::move(tag));
|
||||
scheduleCallback(handler, user, callback);
|
||||
TextureFormat format, uint8_t samples, uint32_t width, uint32_t height,
|
||||
uint32_t depth, TextureUsage usage, CallbackHandler* handler,
|
||||
CallbackHandler::Callback callback, void* user, utils::ImmutableCString&& tag) {
|
||||
// TODO: implement this.
|
||||
}
|
||||
|
||||
void MetalDriver::createTextureViewR(Handle<HwTexture> th, Handle<HwTexture> srch,
|
||||
@@ -618,8 +568,7 @@ void MetalDriver::createTextureViewSwizzleAsyncR(Handle<HwTexture> th, Handle<Hw
|
||||
backend::TextureSwizzle r, backend::TextureSwizzle g, backend::TextureSwizzle b,
|
||||
backend::TextureSwizzle a, CallbackHandler* handler,
|
||||
CallbackHandler::Callback const callback, void* user, utils::ImmutableCString&& tag) {
|
||||
createTextureViewSwizzleR(th, srch, r, g, b, a, std::move(tag));
|
||||
scheduleCallback(handler, user, callback);
|
||||
// TODO: implement this.
|
||||
}
|
||||
|
||||
void MetalDriver::createTextureExternalImage2R(Handle<HwTexture> th,
|
||||
@@ -681,13 +630,12 @@ void MetalDriver::importTextureR(Handle<HwTexture> th, intptr_t i,
|
||||
mHandleAllocator.associateTagToHandle(th.getId(), std::move(tag));
|
||||
}
|
||||
|
||||
void MetalDriver::importTextureAsyncR(Handle<HwTexture> th, intptr_t i, SamplerType target,
|
||||
uint8_t levels, TextureFormat format, uint8_t samples, uint32_t width, uint32_t height,
|
||||
void MetalDriver::importTextureAsyncR(Handle<HwTexture> th, intptr_t i,
|
||||
SamplerType target, uint8_t levels,
|
||||
TextureFormat format, uint8_t samples, uint32_t width, uint32_t height,
|
||||
uint32_t depth, TextureUsage usage, CallbackHandler* handler,
|
||||
CallbackHandler::Callback callback, void* user, utils::ImmutableCString&& tag) {
|
||||
importTextureR(th, i, target, levels, format, samples, width, height, depth, usage,
|
||||
std::move(tag));
|
||||
scheduleCallback(handler, user, callback);
|
||||
// TODO: implement this.
|
||||
}
|
||||
|
||||
void MetalDriver::createRenderPrimitiveR(Handle<HwRenderPrimitive> rph,
|
||||
@@ -976,23 +924,23 @@ Handle<HwTexture> MetalDriver::importTextureAsyncS() noexcept {
|
||||
}
|
||||
|
||||
AsyncCallId MetalDriver::update3DImageAsyncS() noexcept {
|
||||
assert_invariant(getJobQueue());
|
||||
return getJobQueue()->issueJobId();
|
||||
// TODO: implement this.
|
||||
return InvalidAsyncCallId;
|
||||
}
|
||||
|
||||
AsyncCallId MetalDriver::setVertexBufferObjectAsyncS() noexcept {
|
||||
assert_invariant(getJobQueue());
|
||||
return getJobQueue()->issueJobId();
|
||||
// TODO: implement this.
|
||||
return InvalidAsyncCallId;
|
||||
}
|
||||
|
||||
AsyncCallId MetalDriver::updateBufferObjectAsyncS() noexcept {
|
||||
assert_invariant(getJobQueue());
|
||||
return getJobQueue()->issueJobId();
|
||||
// TODO: implement this.
|
||||
return InvalidAsyncCallId;
|
||||
}
|
||||
|
||||
AsyncCallId MetalDriver::updateIndexBufferAsyncS() noexcept {
|
||||
assert_invariant(getJobQueue());
|
||||
return getJobQueue()->issueJobId();
|
||||
// TODO: implement this.
|
||||
return InvalidAsyncCallId;
|
||||
}
|
||||
|
||||
Handle<HwRenderPrimitive> MetalDriver::createRenderPrimitiveS() noexcept {
|
||||
@@ -1044,8 +992,8 @@ Handle<HwDescriptorSet> MetalDriver::createDescriptorSetS() noexcept {
|
||||
}
|
||||
|
||||
AsyncCallId MetalDriver::queueCommandAsyncS() noexcept {
|
||||
assert_invariant(getJobQueue());
|
||||
return getJobQueue()->issueJobId();
|
||||
// TODO: implement this.
|
||||
return InvalidAsyncCallId;
|
||||
}
|
||||
|
||||
void MetalDriver::destroyVertexBufferInfo(Handle<HwVertexBufferInfo> vbih) {
|
||||
@@ -1061,13 +1009,7 @@ void MetalDriver::destroyVertexBuffer(Handle<HwVertexBuffer> vbh) {
|
||||
}
|
||||
|
||||
void MetalDriver::destroyIndexBuffer(Handle<HwIndexBuffer> ibh) {
|
||||
if (UTILS_UNLIKELY(!ibh)) {
|
||||
return;
|
||||
}
|
||||
auto* ib = handle_cast<MetalIndexBuffer>(ibh);
|
||||
if (ib->asynchronous) {
|
||||
getJobQueue()->push([this, ibh]() mutable { destruct_handle<MetalIndexBuffer>(ibh); });
|
||||
} else {
|
||||
if (ibh) {
|
||||
destruct_handle<MetalIndexBuffer>(ibh);
|
||||
}
|
||||
}
|
||||
@@ -1076,12 +1018,7 @@ void MetalDriver::destroyBufferObject(Handle<HwBufferObject> boh) {
|
||||
if (UTILS_UNLIKELY(!boh)) {
|
||||
return;
|
||||
}
|
||||
auto* bo = handle_cast<MetalBufferObject>(boh);
|
||||
if (bo->asynchronous) {
|
||||
getJobQueue()->push([this, boh]() mutable { destruct_handle<MetalBufferObject>(boh); });
|
||||
} else {
|
||||
destruct_handle<MetalBufferObject>(boh);
|
||||
}
|
||||
destruct_handle<MetalBufferObject>(boh);
|
||||
}
|
||||
|
||||
void MetalDriver::destroyRenderPrimitive(Handle<HwRenderPrimitive> rph) {
|
||||
@@ -1116,11 +1053,7 @@ void MetalDriver::destroyTexture(Handle<HwTexture> th) {
|
||||
auto* metalTexture = handle_cast<MetalTexture>(th);
|
||||
mContext->textures.erase(metalTexture);
|
||||
|
||||
if (metalTexture->asynchronous) {
|
||||
getJobQueue()->push([this, th]() mutable { destruct_handle<MetalTexture>(th); });
|
||||
} else {
|
||||
destruct_handle<MetalTexture>(th);
|
||||
}
|
||||
destruct_handle<MetalTexture>(th);
|
||||
}
|
||||
|
||||
void MetalDriver::destroyRenderTarget(Handle<HwRenderTarget> rth) {
|
||||
@@ -1197,10 +1130,6 @@ void MetalDriver::terminate() {
|
||||
MetalExternalImage::shutdown(*mContext);
|
||||
mContext->blitter->shutdown();
|
||||
mContext->shaderCompiler->terminate();
|
||||
|
||||
if (getJobWorker()) {
|
||||
getJobWorker()->terminate();
|
||||
}
|
||||
}
|
||||
|
||||
ShaderModel MetalDriver::getShaderModel() const noexcept {
|
||||
@@ -1422,7 +1351,7 @@ bool MetalDriver::isDepthClampSupported() {
|
||||
}
|
||||
|
||||
bool MetalDriver::isAsynchronousModeEnabled() {
|
||||
return getJobQueue() != nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MetalDriver::isWorkaroundNeeded(Workaround workaround) {
|
||||
@@ -1496,38 +1425,17 @@ void MetalDriver::updateIndexBuffer(Handle<HwIndexBuffer> ibh, BufferDescriptor&
|
||||
FILAMENT_CHECK_PRECONDITION(data.buffer)
|
||||
<< "updateIndexBuffer called with a null buffer.";
|
||||
auto* ib = handle_cast<MetalIndexBuffer>(ibh);
|
||||
id<MTLCommandBuffer> cmdBuffer = getPendingCommandBuffer(mContext);
|
||||
ib->buffer.copyIntoBuffer(cmdBuffer, data.buffer, data.size, byteOffset,
|
||||
ib->buffer.copyIntoBuffer(data.buffer, data.size, byteOffset,
|
||||
[&]() { return mHandleAllocator.getHandleTag(ibh.getId()).c_str_safe(); });
|
||||
scheduleDestroy(std::move(data));
|
||||
}
|
||||
|
||||
void MetalDriver::updateIndexBufferAsyncR(AsyncCallId jobId, Handle<HwIndexBuffer> ibh,
|
||||
BufferDescriptor&& data, uint32_t byteOffset, CallbackHandler* handler,
|
||||
CallbackHandler::Callback const callback, void* user) {
|
||||
FILAMENT_CHECK_PRECONDITION(data.buffer)
|
||||
<< "updateIndexBufferAsyncR called with a null buffer.";
|
||||
|
||||
id<MTLCommandBuffer> cmdBuffer = [mContext->commandQueue commandBuffer];
|
||||
auto* ib = handle_cast<MetalIndexBuffer>(ibh);
|
||||
auto tag = mHandleAllocator.getHandleTag(ibh.getId());
|
||||
|
||||
getJobQueue()->push(
|
||||
[this, cmdBuffer, ib, data = std::move(data), byteOffset, handler, callback, user,
|
||||
tag = std::move(tag)]() mutable {
|
||||
ib->buffer.copyIntoBuffer(cmdBuffer, data.buffer, data.size, byteOffset,
|
||||
[&tag]() { return tag.c_str_safe(); });
|
||||
|
||||
[cmdBuffer addCompletedHandler:^(id<MTLCommandBuffer> cb) {
|
||||
scheduleCallback(handler, user, callback);
|
||||
}];
|
||||
|
||||
[cmdBuffer commit];
|
||||
scheduleDestroy(std::move(data));
|
||||
},
|
||||
jobId);
|
||||
// TODO: implement this.
|
||||
}
|
||||
|
||||
|
||||
void MetalDriver::updateBufferObject(Handle<HwBufferObject> boh, BufferDescriptor&& data,
|
||||
uint32_t byteOffset) {
|
||||
FILAMENT_CHECK_PRECONDITION(!isInRenderPass(mContext))
|
||||
@@ -1546,31 +1454,7 @@ void MetalDriver::updateBufferObject(Handle<HwBufferObject> boh, BufferDescripto
|
||||
void MetalDriver::updateBufferObjectAsyncR(AsyncCallId jobId, Handle<HwBufferObject> boh,
|
||||
BufferDescriptor&& data, uint32_t byteOffset, CallbackHandler* handler,
|
||||
CallbackHandler::Callback const callback, void* user) {
|
||||
FILAMENT_CHECK_PRECONDITION(!isInRenderPass(mContext))
|
||||
<< "updateBufferObjectAsyncR must be called outside of a render pass. tag="
|
||||
<< mHandleAllocator.getHandleTag(boh.getId()).c_str_safe();
|
||||
FILAMENT_CHECK_PRECONDITION(data.buffer)
|
||||
<< "updateBufferObjectAsyncR called with a null buffer. tag="
|
||||
<< mHandleAllocator.getHandleTag(boh.getId()).c_str_safe();
|
||||
|
||||
id<MTLCommandBuffer> cmdBuffer = [mContext->commandQueue commandBuffer];
|
||||
auto* bo = handle_cast<MetalBufferObject>(boh);
|
||||
auto tag = mHandleAllocator.getHandleTag(boh.getId());
|
||||
|
||||
getJobQueue()->push(
|
||||
[this, cmdBuffer, bo, data = std::move(data), byteOffset, handler, callback, user,
|
||||
tag = std::move(tag)]() mutable {
|
||||
bo->getBuffer()->copyIntoBuffer(cmdBuffer, data.buffer, data.size, byteOffset,
|
||||
[&tag]() { return tag.c_str_safe(); });
|
||||
|
||||
[cmdBuffer addCompletedHandler:^(id<MTLCommandBuffer> cb) {
|
||||
scheduleCallback(handler, user, callback);
|
||||
}];
|
||||
|
||||
[cmdBuffer commit];
|
||||
scheduleDestroy(std::move(data));
|
||||
},
|
||||
jobId);
|
||||
// TODO: implement this.
|
||||
}
|
||||
|
||||
void MetalDriver::updateBufferObjectUnsynchronized(Handle<HwBufferObject> boh,
|
||||
@@ -1601,8 +1485,7 @@ void MetalDriver::setVertexBufferObject(Handle<HwVertexBuffer> vbh, uint32_t ind
|
||||
void MetalDriver::setVertexBufferObjectAsyncR(AsyncCallId jobId, Handle<HwVertexBuffer> vbh,
|
||||
uint32_t index, Handle<HwBufferObject> boh, CallbackHandler* handler,
|
||||
CallbackHandler::Callback const callback, void* user) {
|
||||
setVertexBufferObject(vbh, index, boh);
|
||||
scheduleCallback(handler, user, callback);
|
||||
// TODO: implement this.
|
||||
}
|
||||
|
||||
void MetalDriver::update3DImage(Handle<HwTexture> th, uint32_t level,
|
||||
@@ -1612,9 +1495,7 @@ void MetalDriver::update3DImage(Handle<HwTexture> th, uint32_t level,
|
||||
FILAMENT_CHECK_PRECONDITION(!isInRenderPass(mContext))
|
||||
<< "update3DImage must be called outside of a render pass.";
|
||||
auto tex = handle_cast<MetalTexture>(th);
|
||||
id<MTLCommandBuffer> cmdBuffer = getPendingCommandBuffer(mContext);
|
||||
tex->loadImage(cmdBuffer, level,
|
||||
MTLRegionMake3D(xoffset, yoffset, zoffset, width, height, depth), data);
|
||||
tex->loadImage(level, MTLRegionMake3D(xoffset, yoffset, zoffset, width, height, depth), data);
|
||||
scheduleDestroy(std::move(data));
|
||||
|
||||
DEBUG_LOG(
|
||||
@@ -1623,33 +1504,12 @@ void MetalDriver::update3DImage(Handle<HwTexture> th, uint32_t level,
|
||||
th.getId(), level, xoffset, yoffset, zoffset, width, height, depth);
|
||||
}
|
||||
|
||||
void MetalDriver::update3DImageAsyncR(AsyncCallId jobId, Handle<HwTexture> th, uint32_t level,
|
||||
uint32_t xoffset, uint32_t yoffset, uint32_t zoffset, uint32_t width, uint32_t height,
|
||||
uint32_t depth, PixelBufferDescriptor&& data, CallbackHandler* handler,
|
||||
void MetalDriver::update3DImageAsyncR(AsyncCallId jobId, Handle<HwTexture> th,
|
||||
uint32_t level, uint32_t xoffset, uint32_t yoffset, uint32_t zoffset,
|
||||
uint32_t width, uint32_t height, uint32_t depth,
|
||||
PixelBufferDescriptor&& data, CallbackHandler* handler,
|
||||
CallbackHandler::Callback const callback, void* user) {
|
||||
FILAMENT_CHECK_PRECONDITION(!isInRenderPass(mContext))
|
||||
<< "update3DImageAsyncR must be called outside of a render pass.";
|
||||
FILAMENT_CHECK_PRECONDITION(data.buffer) << "update3DImageAsyncR called with a null buffer.";
|
||||
|
||||
id<MTLCommandBuffer> cmdBuffer = [mContext->commandQueue commandBuffer];
|
||||
auto* tex = handle_cast<MetalTexture>(th);
|
||||
auto tag = mHandleAllocator.getHandleTag(th.getId());
|
||||
|
||||
getJobQueue()->push(
|
||||
[this, cmdBuffer, tex, level, xoffset, yoffset, zoffset, width, height, depth,
|
||||
data = std::move(data), handler, callback, user,
|
||||
tag = std::move(tag)]() mutable {
|
||||
tex->loadImage(cmdBuffer, level,
|
||||
MTLRegionMake3D(xoffset, yoffset, zoffset, width, height, depth), data);
|
||||
|
||||
[cmdBuffer addCompletedHandler:^(id<MTLCommandBuffer> cb) {
|
||||
scheduleCallback(handler, user, callback);
|
||||
}];
|
||||
|
||||
[cmdBuffer commit];
|
||||
scheduleDestroy(std::move(data));
|
||||
},
|
||||
jobId);
|
||||
// TODO: implement this.
|
||||
}
|
||||
|
||||
void MetalDriver::setupExternalImage2(Platform::ExternalImageHandleRef image) {
|
||||
@@ -2636,20 +2496,12 @@ void MetalDriver::copyToMemoryMappedBuffer(MemoryMappedBufferHandle mmbh, size_t
|
||||
|
||||
void MetalDriver::queueCommandAsyncR(AsyncCallId jobId, utils::Invocable<void()>&& command,
|
||||
CallbackHandler* handler, CallbackHandler::Callback const callback, void* user) {
|
||||
assert_invariant(getJobQueue());
|
||||
getJobQueue()->push(
|
||||
[this, command = std::move(command), handler, callback, user]() {
|
||||
if (command) {
|
||||
command();
|
||||
}
|
||||
scheduleCallback(handler, user, callback);
|
||||
},
|
||||
jobId);
|
||||
// TODO: implement this.
|
||||
}
|
||||
|
||||
bool MetalDriver::cancelAsyncJob(AsyncCallId jobId) {
|
||||
assert_invariant(getJobQueue());
|
||||
return getJobQueue()->cancel(jobId);
|
||||
// TODO: implement this.
|
||||
return false;
|
||||
}
|
||||
|
||||
// explicit instantiation of the Dispatcher
|
||||
|
||||
@@ -222,7 +222,7 @@ public:
|
||||
using TagResolver = MetalBuffer::TagResolver;
|
||||
|
||||
MetalBufferObject(MetalContext& context, BufferObjectBinding bindingType, BufferUsage usage,
|
||||
uint32_t byteCount, bool async = false);
|
||||
uint32_t byteCount);
|
||||
|
||||
void updateBuffer(void* data, size_t size, uint32_t byteOffset, TagResolver&& getHandleTag);
|
||||
void updateBufferUnsynchronized(
|
||||
@@ -264,7 +264,7 @@ struct MetalVertexBuffer : public HwVertexBuffer {
|
||||
|
||||
struct MetalIndexBuffer : public HwIndexBuffer {
|
||||
MetalIndexBuffer(MetalContext& context, BufferUsage usage, uint8_t elementSize,
|
||||
uint32_t indexCount, bool async = false);
|
||||
uint32_t indexCount);
|
||||
|
||||
MetalBuffer buffer;
|
||||
};
|
||||
@@ -307,8 +307,8 @@ struct PixelBufferShape {
|
||||
class MetalTexture : public HwTexture {
|
||||
public:
|
||||
MetalTexture(MetalContext& context, SamplerType target, uint8_t levels, TextureFormat format,
|
||||
uint8_t samples, uint32_t width, uint32_t height, uint32_t depth, TextureUsage usage,
|
||||
bool async = false) noexcept;
|
||||
uint8_t samples, uint32_t width, uint32_t height, uint32_t depth,
|
||||
TextureUsage usage) noexcept;
|
||||
|
||||
// constructors for creating texture views
|
||||
MetalTexture(MetalContext& context, MetalTexture const* src, uint8_t baseLevel,
|
||||
@@ -337,8 +337,7 @@ public:
|
||||
|
||||
std::shared_ptr<MetalExternalImage> getExternalImage() const noexcept { return externalImage; }
|
||||
|
||||
void loadImage(id<MTLCommandBuffer> cmdBuffer, uint32_t level, MTLRegion region,
|
||||
PixelBufferDescriptor& p) noexcept;
|
||||
void loadImage(uint32_t level, MTLRegion region, PixelBufferDescriptor& p) noexcept;
|
||||
void generateMipmaps() noexcept;
|
||||
|
||||
static MTLPixelFormat decidePixelFormat(MetalContext* context, TextureFormat format);
|
||||
@@ -363,12 +362,12 @@ public:
|
||||
MTLPixelFormat devicePixelFormat;
|
||||
|
||||
private:
|
||||
void loadSlice(id<MTLCommandBuffer> cmdBuffer, uint32_t level, MTLRegion region,
|
||||
uint32_t byteOffset, uint32_t slice, PixelBufferDescriptor const& data) noexcept;
|
||||
void loadWithCopyBuffer(id<MTLCommandBuffer> cmdBuffer, uint32_t level, uint32_t slice,
|
||||
MTLRegion region, PixelBufferDescriptor const& data, const PixelBufferShape& shape);
|
||||
void loadWithBlit(id<MTLCommandBuffer> cmdBuffer, uint32_t level, uint32_t slice,
|
||||
MTLRegion region, PixelBufferDescriptor const& data, const PixelBufferShape& shape);
|
||||
void loadSlice(uint32_t level, MTLRegion region, uint32_t byteOffset, uint32_t slice,
|
||||
PixelBufferDescriptor const& data) noexcept;
|
||||
void loadWithCopyBuffer(uint32_t level, uint32_t slice, MTLRegion region, PixelBufferDescriptor const& data,
|
||||
const PixelBufferShape& shape);
|
||||
void loadWithBlit(uint32_t level, uint32_t slice, MTLRegion region, PixelBufferDescriptor const& data,
|
||||
const PixelBufferShape& shape);
|
||||
|
||||
id<MTLTexture> texture = nil;
|
||||
|
||||
|
||||
@@ -546,18 +546,17 @@ MetalAttachment MetalSwapChain::acquireBaseDrawable() {
|
||||
|
||||
|
||||
MetalBufferObject::MetalBufferObject(MetalContext& context, BufferObjectBinding bindingType,
|
||||
BufferUsage usage, uint32_t byteCount, bool async)
|
||||
: HwBufferObject(byteCount, async),
|
||||
buffer(context, bindingType, usage, byteCount) {}
|
||||
BufferUsage usage, uint32_t byteCount)
|
||||
: HwBufferObject(byteCount, false), buffer(context, bindingType, usage, byteCount) {}
|
||||
|
||||
void MetalBufferObject::updateBuffer(void* data, size_t size, uint32_t byteOffset,
|
||||
TagResolver&& getHandleTag) {
|
||||
buffer.copyIntoBuffer(nil, data, size, byteOffset, std::move(getHandleTag));
|
||||
void MetalBufferObject::updateBuffer(
|
||||
void* data, size_t size, uint32_t byteOffset, TagResolver&& getHandleTag) {
|
||||
buffer.copyIntoBuffer(data, size, byteOffset, std::move(getHandleTag));
|
||||
}
|
||||
|
||||
void MetalBufferObject::updateBufferUnsynchronized(void* data, size_t size, uint32_t byteOffset,
|
||||
TagResolver&& getHandleTag) {
|
||||
buffer.copyIntoBufferUnsynchronized(nil, data, size, byteOffset, std::move(getHandleTag));
|
||||
void MetalBufferObject::updateBufferUnsynchronized(
|
||||
void* data, size_t size, uint32_t byteOffset, TagResolver&& getHandleTag) {
|
||||
buffer.copyIntoBufferUnsynchronized(data, size, byteOffset, std::move(getHandleTag));
|
||||
}
|
||||
|
||||
MetalVertexBufferInfo::MetalVertexBufferInfo(MetalContext& context, uint8_t bufferCount,
|
||||
@@ -639,9 +638,8 @@ MetalVertexBuffer::MetalVertexBuffer(MetalContext& context,
|
||||
}
|
||||
|
||||
MetalIndexBuffer::MetalIndexBuffer(MetalContext& context, BufferUsage usage, uint8_t elementSize,
|
||||
uint32_t indexCount, bool async)
|
||||
: HwIndexBuffer(elementSize, indexCount, async),
|
||||
buffer(context, BufferObjectBinding::VERTEX, usage, elementSize * indexCount, true) {}
|
||||
uint32_t indexCount) : HwIndexBuffer(elementSize, indexCount, false),
|
||||
buffer(context, BufferObjectBinding::VERTEX, usage, elementSize * indexCount, true) { }
|
||||
|
||||
MetalProgram::MetalProgram(MetalContext& context, Program&& program) noexcept
|
||||
: HwProgram(program.getName()), mContext(context) {
|
||||
@@ -668,9 +666,8 @@ void MetalProgram::initialize() {
|
||||
|
||||
MetalTexture::MetalTexture(MetalContext& context, SamplerType target, uint8_t levels,
|
||||
TextureFormat format, uint8_t samples, uint32_t width, uint32_t height, uint32_t depth,
|
||||
TextureUsage usage, bool async) noexcept
|
||||
: HwTexture(target, levels, samples, width, height, depth, format, usage, async),
|
||||
context(context) {
|
||||
TextureUsage usage) noexcept
|
||||
: HwTexture(target, levels, samples, width, height, depth, format, usage, false), context(context) {
|
||||
assert_invariant(target != SamplerType::SAMPLER_EXTERNAL);
|
||||
|
||||
devicePixelFormat = decidePixelFormat(&context, format);
|
||||
@@ -896,8 +893,7 @@ PixelBufferShape PixelBufferShape::compute(const PixelBufferDescriptor& data,
|
||||
return result;
|
||||
}
|
||||
|
||||
void MetalTexture::loadImage(id<MTLCommandBuffer> cmdBuffer, uint32_t level, MTLRegion region,
|
||||
PixelBufferDescriptor& p) noexcept {
|
||||
void MetalTexture::loadImage(uint32_t level, MTLRegion region, PixelBufferDescriptor& p) noexcept {
|
||||
PixelBufferDescriptor* data = &p;
|
||||
PixelBufferDescriptor reshapedData;
|
||||
if(reshape(p, reshapedData)) {
|
||||
@@ -907,7 +903,7 @@ void MetalTexture::loadImage(id<MTLCommandBuffer> cmdBuffer, uint32_t level, MTL
|
||||
switch (target) {
|
||||
case SamplerType::SAMPLER_2D:
|
||||
case SamplerType::SAMPLER_3D: {
|
||||
loadSlice(cmdBuffer, level, region, 0, 0, *data);
|
||||
loadSlice(level, region, 0, 0, *data);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -924,7 +920,7 @@ void MetalTexture::loadImage(id<MTLCommandBuffer> cmdBuffer, uint32_t level, MTL
|
||||
|
||||
uint32_t byteOffset = 0;
|
||||
for (uint32_t s = slice; s < slice + sliceCount; s++) {
|
||||
loadSlice(cmdBuffer, level, region, byteOffset, s, *data);
|
||||
loadSlice(level, region, byteOffset, s, *data);
|
||||
byteOffset += shape.bytesPerSlice;
|
||||
}
|
||||
|
||||
@@ -943,8 +939,8 @@ void MetalTexture::generateMipmaps() noexcept {
|
||||
[blitEncoder endEncoding];
|
||||
}
|
||||
|
||||
void MetalTexture::loadSlice(id<MTLCommandBuffer> cmdBuffer, uint32_t level, MTLRegion region,
|
||||
uint32_t byteOffset, uint32_t slice, PixelBufferDescriptor const& data) noexcept {
|
||||
void MetalTexture::loadSlice(uint32_t level, MTLRegion region, uint32_t byteOffset, uint32_t slice,
|
||||
PixelBufferDescriptor const& data) noexcept {
|
||||
const PixelBufferShape shape = PixelBufferShape::compute(data, format, region.size, byteOffset);
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(data.size >= shape.totalBytes)
|
||||
@@ -972,20 +968,20 @@ void MetalTexture::loadSlice(id<MTLCommandBuffer> cmdBuffer, uint32_t level, MTL
|
||||
const bool largeUpload = stagingBufferSize > deviceMaxBufferLength;
|
||||
|
||||
if (conversionNecessary || largeUpload) {
|
||||
loadWithBlit(cmdBuffer, level, slice, region, data, shape);
|
||||
loadWithBlit(level, slice, region, data, shape);
|
||||
} else {
|
||||
loadWithCopyBuffer(cmdBuffer, level, slice, region, data, shape);
|
||||
loadWithCopyBuffer(level, slice, region, data, shape);
|
||||
}
|
||||
}
|
||||
|
||||
void MetalTexture::loadWithCopyBuffer(id<MTLCommandBuffer> blitCommandBuffer, uint32_t level,
|
||||
uint32_t slice, MTLRegion region, PixelBufferDescriptor const& data,
|
||||
const PixelBufferShape& shape) {
|
||||
void MetalTexture::loadWithCopyBuffer(uint32_t level, uint32_t slice, MTLRegion region,
|
||||
PixelBufferDescriptor const& data, const PixelBufferShape& shape) {
|
||||
const size_t stagingBufferSize = shape.totalBytes;
|
||||
auto entry = context.bufferPool->acquireBuffer(stagingBufferSize);
|
||||
memcpy(entry->buffer.get().contents,
|
||||
static_cast<uint8_t*>(data.buffer) + shape.sourceOffset,
|
||||
stagingBufferSize);
|
||||
id<MTLCommandBuffer> blitCommandBuffer = getPendingCommandBuffer(&context);
|
||||
id<MTLBlitCommandEncoder> blitCommandEncoder = [blitCommandBuffer blitCommandEncoder];
|
||||
blitCommandEncoder.label = @"Texture upload buffer blit";
|
||||
[blitCommandEncoder copyFromBuffer:entry->buffer.get()
|
||||
@@ -1007,7 +1003,7 @@ void MetalTexture::loadWithCopyBuffer(id<MTLCommandBuffer> blitCommandBuffer, ui
|
||||
[blitCommandEncoder endEncoding];
|
||||
}
|
||||
|
||||
void MetalTexture::loadWithBlit(id<MTLCommandBuffer> cmdBuffer, uint32_t level, uint32_t slice, MTLRegion region,
|
||||
void MetalTexture::loadWithBlit(uint32_t level, uint32_t slice, MTLRegion region,
|
||||
PixelBufferDescriptor const& data, const PixelBufferShape& shape) {
|
||||
MTLPixelFormat stagingPixelFormat = getMetalFormat(data.format, data.type);
|
||||
MTLTextureDescriptor* descriptor = [MTLTextureDescriptor new];
|
||||
@@ -1024,7 +1020,6 @@ void MetalTexture::loadWithBlit(id<MTLCommandBuffer> cmdBuffer, uint32_t level,
|
||||
#endif
|
||||
|
||||
id<MTLTexture> stagingTexture = [context.device newTextureWithDescriptor:descriptor];
|
||||
|
||||
// FIXME? Why is this not just `MTLRegion sourceRegion = region;` ?
|
||||
MTLRegion sourceRegion = MTLRegionMake3D(0, 0, 0,
|
||||
region.size.width, region.size.height, region.size.depth);
|
||||
@@ -1062,7 +1057,7 @@ void MetalTexture::loadWithBlit(id<MTLCommandBuffer> cmdBuffer, uint32_t level,
|
||||
args.destination.slice = slice;
|
||||
args.destination.region = region;
|
||||
args.destination.texture = destinationTexture;
|
||||
context.blitter->blit(cmdBuffer, args, "Texture upload blit");
|
||||
context.blitter->blit(getPendingCommandBuffer(&context), args, "Texture upload blit");
|
||||
}
|
||||
|
||||
MetalRenderTarget::MetalRenderTarget(MetalContext* context, uint32_t width, uint32_t height,
|
||||
@@ -1433,17 +1428,11 @@ FenceStatus MetalFence::wait(uint64_t timeoutNs) {
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
FenceStatus status;
|
||||
if (timeoutNs == FENCE_WAIT_FOR_EVER) {
|
||||
status = context.driver->waitForFence(predicate);
|
||||
context.driver->waitForFence(predicate);
|
||||
} else {
|
||||
auto const until = std::chrono::steady_clock::now() + ns(timeoutNs);
|
||||
status = context.driver->waitForFence(predicate, until);
|
||||
}
|
||||
|
||||
if (status == FenceStatus::ERROR) {
|
||||
return FenceStatus::ERROR;
|
||||
context.driver->waitForFence(predicate, until);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -2665,17 +2665,12 @@ FenceStatus OpenGLDriver::fenceWait(FenceHandle fh, uint64_t const timeout) {
|
||||
// so we need to wait for that, before using the real fence.
|
||||
// By construction, "f" can't be destroyed while we wait, because its
|
||||
// construction call is in the queue and a destroy call will have to come later.
|
||||
FenceStatus status = waitForFence([f] {
|
||||
waitForFence([f] {
|
||||
return f->fence != nullptr;
|
||||
}, until);
|
||||
|
||||
if (status == FenceStatus::ERROR) {
|
||||
return FenceStatus::ERROR;
|
||||
}
|
||||
|
||||
if (f->fence == nullptr) {
|
||||
// the only possible choice here is that we timed out
|
||||
assert_invariant(status == FenceStatus::TIMEOUT_EXPIRED);
|
||||
assert_invariant(f->state->status == FenceStatus::TIMEOUT_EXPIRED);
|
||||
return FenceStatus::TIMEOUT_EXPIRED;
|
||||
}
|
||||
// here we know that we have the platform fence
|
||||
@@ -2691,17 +2686,13 @@ FenceStatus OpenGLDriver::fenceWait(FenceHandle fh, uint64_t const timeout) {
|
||||
// This is the case where we need to use OpenGL fences
|
||||
#ifndef FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2
|
||||
FenceStatus result = FenceStatus::TIMEOUT_EXPIRED;
|
||||
FenceStatus status = waitForFence([&] {
|
||||
waitForFence([&] {
|
||||
if (f->state->status != FenceStatus::TIMEOUT_EXPIRED) {
|
||||
result = f->state->status;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}, until);
|
||||
|
||||
if (status == FenceStatus::ERROR) {
|
||||
return FenceStatus::ERROR;
|
||||
}
|
||||
return result;
|
||||
#else
|
||||
return FenceStatus::ERROR;
|
||||
|
||||
@@ -16,9 +16,8 @@
|
||||
|
||||
#include <backend/platforms/PlatformOSMesa.h>
|
||||
|
||||
#include <utils/Logger.h>
|
||||
#include <utils/Log.h>
|
||||
#include <utils/Panic.h>
|
||||
#include <utils/ThreadUtils.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <memory>
|
||||
@@ -128,7 +127,9 @@ Driver* PlatformOSMesa::createDriver(void* sharedGLContext,
|
||||
0,
|
||||
};
|
||||
|
||||
mContext = api->fOSMesaCreateContextAttribs(attribs, (OSMesaContext) sharedGLContext);
|
||||
FILAMENT_CHECK_PRECONDITION(sharedGLContext == nullptr)
|
||||
<< "shared GL context is not supported with PlatformOSMesa";
|
||||
mContext = api->fOSMesaCreateContextAttribs(attribs, NULL);
|
||||
|
||||
// We need to do a no-op makecurrent here so that the context will be in a correct state before
|
||||
// any GL calls.
|
||||
@@ -144,12 +145,6 @@ Driver* PlatformOSMesa::createDriver(void* sharedGLContext,
|
||||
|
||||
void PlatformOSMesa::terminate() noexcept {
|
||||
OSMesaAPI* api = (OSMesaAPI*) mOsMesaApi;
|
||||
|
||||
for (auto& it: mAdditionalContexts) {
|
||||
api->fOSMesaDestroyContext(it.second.context);
|
||||
}
|
||||
mAdditionalContexts.clear();
|
||||
|
||||
api->fOSMesaDestroyContext(mContext);
|
||||
delete api;
|
||||
mOsMesaApi = nullptr;
|
||||
@@ -157,74 +152,6 @@ void PlatformOSMesa::terminate() noexcept {
|
||||
bluegl::unbind();
|
||||
}
|
||||
|
||||
bool PlatformOSMesa::isExtraContextSupported() const noexcept { return true; }
|
||||
|
||||
void PlatformOSMesa::createContext(bool shared) {
|
||||
std::thread::id currentThreadId = utils::ThreadUtils::getThreadId();
|
||||
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mAdditionalContextsLock);
|
||||
auto it = mAdditionalContexts.find(currentThreadId);
|
||||
if (it != mAdditionalContexts.end()) {
|
||||
LOG(WARNING) << "Shared context is already created for this thread";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
OSMesaAPI* api = (OSMesaAPI*) mOsMesaApi;
|
||||
|
||||
static constexpr int attribs[] = {
|
||||
OSMESA_FORMAT, GL_RGBA,
|
||||
OSMESA_DEPTH_BITS, 24,
|
||||
OSMESA_STENCIL_BITS, 8,
|
||||
OSMESA_ACCUM_BITS, 0,
|
||||
OSMESA_PROFILE, OSMESA_CORE_PROFILE,
|
||||
0,
|
||||
};
|
||||
|
||||
OSMesaContext context = api->fOSMesaCreateContextAttribs(attribs, shared ? mContext : NULL);
|
||||
if (!context) {
|
||||
LOG(ERROR) << "Failed to create shared context";
|
||||
return;
|
||||
}
|
||||
|
||||
// OSMesa requires a non-null buffer to make a context current. Since we don't have a window
|
||||
// or swapchain here, we use a dummy 1x1 buffer.
|
||||
auto buffer = std::make_unique<uint8_t[]>(1 * 1 * 4 * sizeof(BackingType));
|
||||
|
||||
auto result = api->fOSMesaMakeCurrent(context, buffer.get(), BACKING_GL_TYPE, 1, 1);
|
||||
FILAMENT_CHECK_POSTCONDITION(result == GL_TRUE)
|
||||
<< "OSMesaMakeCurrent failed for extra context!";
|
||||
|
||||
std::lock_guard<std::shared_mutex> lock(mAdditionalContextsLock);
|
||||
mAdditionalContexts[currentThreadId] = { context, std::move(buffer) };
|
||||
}
|
||||
|
||||
void PlatformOSMesa::releaseContext() noexcept {
|
||||
std::thread::id currentThreadId = utils::ThreadUtils::getThreadId();
|
||||
OSMesaContext context = nullptr;
|
||||
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock(mAdditionalContextsLock);
|
||||
auto it = mAdditionalContexts.find(currentThreadId);
|
||||
if (it == mAdditionalContexts.end()) {
|
||||
LOG(WARNING) << "Attempted to destroy non-existing shared context";
|
||||
return;
|
||||
}
|
||||
context = it->second.context;
|
||||
}
|
||||
|
||||
OSMesaAPI* api = (OSMesaAPI*) mOsMesaApi;
|
||||
// Passing NULL as the context is the standard way to unbind in OSMesa.
|
||||
api->fOSMesaMakeCurrent(NULL, NULL, 0, 0, 0);
|
||||
api->fOSMesaDestroyContext(context);
|
||||
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock(mAdditionalContextsLock);
|
||||
mAdditionalContexts.erase(currentThreadId);
|
||||
}
|
||||
}
|
||||
|
||||
Platform::SwapChain* PlatformOSMesa::createSwapChain(void* nativeWindow, uint64_t flags) noexcept {
|
||||
FILAMENT_CHECK_POSTCONDITION(false) << "Cannot create non-headless swapchain";
|
||||
return (SwapChain*) nativeWindow;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user