Skip to content

Commit f88d3ed

Browse files
committed
Merge branch 'rc/1.68.3' into release
2 parents 8167baf + 5f13abd commit f88d3ed

File tree

95 files changed

+1984
-328
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1984
-328
lines changed

.github/actions/mac-prereq/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ runs:
1515
uses: actions/cache@v4 # Use a specific version
1616
with:
1717
path: ~/Library/Caches/Homebrew
18-
key: ${{ runner.os }}-brew-20250424
18+
key: ${{ runner.os }}-brew-20251211
1919
- name: Install Mac Prerequisites
2020
shell: bash
2121
run: |

BUILDING.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ foremost for `arm64-v8a`.
242242

243243
To build Android on Windows machines, see [android/Windows.md](android/Windows.md).
244244

245+
#### Important: SDK location
246+
247+
Either ensure your `ANDROID_HOME` environment variable is set or make sure the root project
248+
contains a `local.properties` file with the `sdk.dir` property pointing to your installation of
249+
the Android SDK.
250+
245251
#### Easy Android build
246252

247253
The easiest way to build Filament for Android is to use `build.sh` and the
@@ -251,8 +257,45 @@ The easiest way to build Filament for Android is to use `build.sh` and the
251257
./build.sh -p android release
252258
```
253259

260+
To build a sample (such as `android/samples/sample-hello-triangle`) for an ARM 64-bit phone, you would run
261+
```shell
262+
./build.sh -p android -q arm64-v8a -k sample-hello-triangle release
263+
```
264+
265+
The output APK can be found in `android/samples/sample-hello-triangle/build/outputs/apk/release/sample-hello-triangle-release-unsigned.apk`
266+
254267
Run `build.sh -h` for more information.
255268

269+
#### Android Studio
270+
271+
You must use the latest stable release of Android Studio.
272+
273+
The Android build of filament is separated into java/kotlin client APIs, a layer of jni bindings
274+
that bridges java/kotlin with native code, and Filament and other component code that have been compiled
275+
into architecture-specific libraries. Our default Android Studio gradle setup can compile java/kotlin and
276+
the jni bindings for you, but it will treat the filament libraries as already compiled and present on
277+
the system.
278+
279+
Therefore, before compiling the sample app or any other targets, you must
280+
make sure that the native filament libraries have been compiled and are located at a prescribed location
281+
so that the jni bindings can link against them. You can do so by using the easy build script
282+
283+
```shell
284+
./build.sh -p android release -q arm64-v8a
285+
```
286+
287+
Note that the above step will also install host machine tools into prescribed locations. These tools are
288+
required for compiling Filament assets such as materials and environment maps.
289+
290+
Now we are ready to compile the apps. To open the project, point Studio to the `android` folder.
291+
After opening the project and syncing with Gradle, select the sample of your choice
292+
using the drop-down widget in the toolbar. Additionally, you will need to select a deployment target.
293+
By doing so, Android Studio will automatically try to compile the app only for that specific
294+
device's architecture. So if you are targeting a new Pixel phone, make sure that the step above
295+
(compiling the library) is targeting ARM 64-bit (`-q arm64-v8a` ), and if you are running the app on
296+
an emulator on a Linux machine with an x86 64-bit chipset, you would indicate (`-q x86_64`) in the above step.
297+
298+
256299
#### Manual builds
257300

258301
Invoke CMake in a build directory of your choice, inside of filament's directory. The commands

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ repositories {
3131
}
3232
3333
dependencies {
34-
implementation 'com.google.android.filament:filament-android:1.68.2'
34+
implementation 'com.google.android.filament:filament-android:1.68.3'
3535
}
3636
```
3737

@@ -51,7 +51,7 @@ Here are all the libraries available in the group `com.google.android.filament`:
5151
iOS projects can use CocoaPods to install the latest release:
5252

5353
```shell
54-
pod 'Filament', '~> 1.68.2'
54+
pod 'Filament', '~> 1.68.3'
5555
```
5656

5757
## Documentation

RELEASE_NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ A new header is inserted each time a *tag* is created.
77
Instead, if you are authoring a PR for the main branch, add your release note to
88
[NEW_RELEASE_NOTES.md](./NEW_RELEASE_NOTES.md).
99

10+
## v1.68.3
11+
12+
- materials: added support for the glTF `KHR_materials_dispersion` extension, which adds dispersion for refractive objects
13+
1014
## v1.68.2
1115

1216
- Support `setPresentationTime` with the Metal backend.

android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ buildscript {
124124

125125
ext.cmakeArgs = [
126126
"--no-warn-unused-cli",
127+
"-DANDROID_WEAK_API_DEFS=ON",
127128
"-DANDROID_PIE=ON",
128129
"-DANDROID_PLATFORM=21",
129130
"-DANDROID_STL=c++_static",

android/filament-android/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ target_include_directories(filament-jni PRIVATE
134134
../../filament/backend/include
135135
../../third_party/robin-map
136136
../../third_party/perfetto
137+
../../libs/bluevk/include
137138
../../libs/utils/include)
138139

139140
# Ordering is significant in the following list. The PRIVATE qualifier prevents transitive deps.
@@ -167,3 +168,9 @@ target_link_libraries(filament-jni
167168

168169
# Force a relink when the version script is changed:
169170
set_target_properties(filament-jni PROPERTIES LINK_DEPENDS ${VERSION_SCRIPT})
171+
172+
if (FILAMENT_SUPPORTS_VULKAN)
173+
add_definitions(-DFILAMENT_SUPPORTS_VULKAN=1)
174+
else()
175+
add_definitions(-DFILAMENT_SUPPORTS_VULKAN=0)
176+
endif()

android/filament-android/src/main/cpp/SkyBox.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ Java_com_google_android_filament_Skybox_nBuilderColor(JNIEnv *, jclass,
6363
builder->color({r, g, b, a});
6464
}
6565

66+
extern "C"
67+
JNIEXPORT void JNICALL
68+
Java_com_google_android_filament_Skybox_nBuilderPriority(JNIEnv *, jclass,
69+
jlong nativeSkyBoxBuilder, jint priority) {
70+
Skybox::Builder *builder = (Skybox::Builder *) nativeSkyBoxBuilder;
71+
builder->priority(uint8_t(priority));
72+
}
73+
6674
extern "C" JNIEXPORT jlong JNICALL
6775
Java_com_google_android_filament_Skybox_nBuilderBuild(JNIEnv *env, jclass type,
6876
jlong nativeSkyBoxBuilder, jlong nativeEngine) {

android/filament-android/src/main/cpp/Texture.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121

2222
#ifdef __ANDROID__
2323
#include <android/bitmap.h>
24+
#include <android/hardware_buffer_jni.h>
25+
#include <backend/platforms/PlatformEGLAndroid.h>
26+
# if FILAMENT_SUPPORTS_VULKAN
27+
# include <backend/platforms/VulkanPlatformAndroid.h>
28+
# endif
2429
#endif
2530

2631
#include <filament/Engine.h>
@@ -388,6 +393,57 @@ Java_com_google_android_filament_Texture_nSetExternalImage(JNIEnv*, jclass, jlon
388393
texture->setExternalImage(*engine, (void*)eglImage);
389394
}
390395

396+
extern "C"
397+
JNIEXPORT jboolean JNICALL
398+
Java_com_google_android_filament_Texture_nSetExternalImageByAHB(JNIEnv *env, jclass clazz,
399+
jlong nativeTexture, jlong nativeEngine, jobject ahb) {
400+
Texture *texture = (Texture *) nativeTexture;
401+
Engine *engine = (Engine *) nativeEngine;
402+
403+
#ifdef __ANDROID__
404+
Platform* platform = engine->getPlatform();
405+
AHardwareBuffer* nativeBuffer = nullptr;
406+
if (__builtin_available(android 26, *)) {
407+
nativeBuffer = AHardwareBuffer_fromHardwareBuffer(env, ahb);
408+
}
409+
if (!nativeBuffer) {
410+
// either we're not on Android 26, or ahb wasn't a AHardwareBuffer
411+
return JNI_FALSE;
412+
}
413+
414+
if (engine->getBackend() == Backend::OPENGL) {
415+
// CAVEAT: we assume that Backend::OPENGL on Android implies PlatformEGLAndroid.
416+
#if UTILS_HAS_RTTI
417+
if (!dynamic_cast<PlatformEGLAndroid*>(platform)) {
418+
return JNI_FALSE;
419+
}
420+
#endif
421+
auto* eglPlatform = (PlatformEGLAndroid*) platform;
422+
auto ref = eglPlatform->createExternalImage(nativeBuffer, false);
423+
texture->setExternalImage(*engine, ref);
424+
}
425+
426+
#if FILAMENT_SUPPORTS_VULKAN
427+
else if (engine->getBackend() == Backend::VULKAN) {
428+
// CAVEAT: we assume that Backend::VULKAN on Android implies VulkanPlatformAndroid.
429+
#if UTILS_HAS_RTTI
430+
if (!dynamic_cast<VulkanPlatformAndroid*>(platform)) {
431+
return JNI_FALSE;
432+
}
433+
#endif
434+
auto* vulkanPlatform = (VulkanPlatformAndroid*) platform;
435+
auto ref = vulkanPlatform->createExternalImage(nativeBuffer, false);
436+
texture->setExternalImage(*engine, ref);
437+
}
438+
#endif // FILAMENT_SUPPORTS_VULKAN
439+
// success!
440+
return JNI_TRUE;
441+
#else
442+
// other platforms could come here
443+
return JNI_FALSE;
444+
#endif // __ANDROID__
445+
}
446+
391447
extern "C" JNIEXPORT void JNICALL
392448
Java_com_google_android_filament_Texture_nSetExternalStream(JNIEnv*, jclass,
393449
jlong nativeTexture, jlong nativeEngine, jlong nativeStream) {
@@ -607,3 +663,4 @@ Java_com_google_android_filament_android_TextureHelper_nSetBitmapWithCallback(JN
607663
}
608664

609665
#endif
666+

android/filament-android/src/main/java/com/google/android/filament/Skybox.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,24 @@ public Builder color(@NonNull @Size(min = 4) float[] color) {
155155
return this;
156156
}
157157

158+
/**
159+
* Set the rendering priority of the Skybox. By default, it is set to the lowest
160+
* priority (7) such that the Skybox is always rendered after the opaque objects,
161+
* to reduce overdraw when depth culling is enabled.
162+
*
163+
* @param priority clamped to the range [0..7], defaults to 4; 7 is lowest priority
164+
* (rendered last).
165+
*
166+
* @return Builder reference for chaining calls.
167+
*
168+
* @see RenderableManager.Builder#priority
169+
*/
170+
@NonNull
171+
public Builder priority(@IntRange(from = 0, to = 7) int priority) {
172+
nBuilderPriority(mNativeBuilder, priority);
173+
return this;
174+
}
175+
158176
/**
159177
* Creates a <code>Skybox</code> object
160178
*
@@ -262,6 +280,7 @@ void clearNativeObject() {
262280
private static native void nBuilderShowSun(long nativeSkyboxBuilder, boolean show);
263281
private static native void nBuilderIntensity(long nativeSkyboxBuilder, float intensity);
264282
private static native void nBuilderColor(long nativeSkyboxBuilder, float r, float g, float b, float a);
283+
private static native void nBuilderPriority(long nativeSkyboxBuilder, int priority);
265284
private static native long nBuilderBuild(long nativeSkyboxBuilder, long nativeEngine);
266285
private static native void nSetLayerMask(long nativeSkybox, int select, int value);
267286
private static native int nGetLayerMask(long nativeSkybox);

android/filament-android/src/main/java/com/google/android/filament/Texture.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@
7171
* @see MaterialInstance#setParameter(String, Texture, TextureSampler)
7272
*/
7373
public class Texture {
74+
75+
private static Class<?> HardwareBufferClass = null;
76+
77+
static {
78+
try {
79+
HardwareBufferClass = Class.forName("android.hardware.HardwareBuffer");
80+
} catch (ClassNotFoundException ignored) {
81+
}
82+
}
83+
7484
private static final Sampler[] sSamplerValues = Sampler.values();
7585
private static final InternalFormat[] sInternalFormatValues = InternalFormat.values();
7686

@@ -1172,6 +1182,38 @@ public void setExternalImage(@NonNull Engine engine, long eglImage) {
11721182
nSetExternalImage(getNativeObject(), engine.getNativeObject(), eglImage);
11731183
}
11741184

1185+
/**
1186+
* Specifies the external image to associate with this <code>Texture</code>.
1187+
*
1188+
* <p>Typically, the external image is OS specific, and can be a video or camera frame.
1189+
* There are many restrictions when using an external image as a texture, such as:</p>
1190+
* <ul>
1191+
* <li> only the level of detail (lod) 0 can be specified</li>
1192+
* <li> only nearest or linear filtering is supported</li>
1193+
* <li> the size and format of the texture is defined by the external image</li>
1194+
* <li> only the CLAMP_TO_EDGE wrap mode is supported</li>
1195+
* </ul>
1196+
*
1197+
* @param engine {@link Engine} this texture is associated to. Must be the
1198+
* instance passed to {@link Builder#build Builder.build()}.
1199+
* @param externalImageRef An OS specific Object. On Android it must be a
1200+
* <code>android.hardware.HardwareBuffer</code>
1201+
*/
1202+
public void setExternalImage(@NonNull Engine engine, Object externalImageRef) {
1203+
if (HardwareBufferClass != null) {
1204+
if (!HardwareBufferClass.isInstance(externalImageRef)) {
1205+
throw new IllegalArgumentException("externalImageRef must be a AHardwareBuffer");
1206+
}
1207+
if (!nSetExternalImageByAHB(getNativeObject(), engine.getNativeObject(), externalImageRef)) {
1208+
throw new IllegalStateException("Error setting AHardwareBuffer as external image");
1209+
}
1210+
} else {
1211+
throw new UnsupportedOperationException(
1212+
"setExternalImage(Engine, Object) not supported on this platform");
1213+
}
1214+
}
1215+
1216+
11751217
/**
11761218
* Specifies the external stream to associate with this <code>Texture</code>.
11771219
*
@@ -1364,6 +1406,8 @@ private static native int nSetImageCubemapCompressed(long nativeTexture, long na
13641406
private static native void nSetExternalImage(
13651407
long nativeObject, long nativeEngine, long eglImage);
13661408

1409+
private static native boolean nSetExternalImageByAHB(long nativeTexture, long nativeObject, Object ahb);
1410+
13671411
private static native void nSetExternalStream(long nativeTexture,
13681412
long nativeEngine, long nativeStream);
13691413

0 commit comments

Comments
 (0)