Files
filament/android/filament-android/src/main/cpp/SkyBox.cpp
Mathias Agopian a8ee48c4b7 a series of CL to add RenderTarget support for external textures (#9504)
* add support for AHardwareBuffer to the java bindings

Texture.setEXternalIamge() now can take a AHArdwreBuffer Java object
as a parameter.

* add an API to set the priority of the Skybox

by default the skybox is always drawn last (priority 7) in order to
reduce overdraw. however, when depth culling is not enabled, it
needs to be drawn first. The new Builder::priority() allows to set
an arbitrary priority for the skybox.

* add rendertarget support for external textures

This was in fact mostly already supported, we just were artificially
preventing that usage. It is supported by the EGL_external_image
extension.

It's the responsibility of the caller/user to not attempt to use an
incompatible format, which has undefined behavior.

FIXES=[466395306]

* add a new android sample to test the AHardwareBuffer as render target

---------

Co-authored-by: Powei Feng <powei@google.com>
2025-12-12 14:15:58 -08:00

117 lines
4.1 KiB
C++

/*
* Copyright (C) 2017 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 <jni.h>
#include <filament/Skybox.h>
#include <math/vec4.h>
using namespace filament;
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Skybox_nCreateBuilder(JNIEnv *env, jclass type) {
return (jlong) new Skybox::Builder{};
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Skybox_nDestroyBuilder(JNIEnv *env, jclass type,
jlong nativeSkyBoxBuilder) {
Skybox::Builder *builder = (Skybox::Builder *) nativeSkyBoxBuilder;
delete builder;
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Skybox_nBuilderEnvironment(JNIEnv *env, jclass type,
jlong nativeSkyBoxBuilder, jlong nativeTexture) {
Skybox::Builder *builder = (Skybox::Builder *) nativeSkyBoxBuilder;
Texture *texture = (Texture *) nativeTexture;
builder->environment(texture);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Skybox_nBuilderShowSun(JNIEnv *env, jclass type,
jlong nativeSkyBoxBuilder, jboolean show) {
Skybox::Builder *builder = (Skybox::Builder *) nativeSkyBoxBuilder;
builder->showSun(show);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Skybox_nBuilderIntensity(JNIEnv *env, jclass clazz,
jlong nativeSkyBoxBuilder, jfloat intensity) {
Skybox::Builder *builder = (Skybox::Builder *) nativeSkyBoxBuilder;
builder->intensity(intensity);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Skybox_nBuilderColor(JNIEnv *, jclass,
jlong nativeSkyBoxBuilder, jfloat r, jfloat g, jfloat b, jfloat a) {
Skybox::Builder *builder = (Skybox::Builder *) nativeSkyBoxBuilder;
builder->color({r, g, b, a});
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_Skybox_nBuilderPriority(JNIEnv *, jclass,
jlong nativeSkyBoxBuilder, jint priority) {
Skybox::Builder *builder = (Skybox::Builder *) nativeSkyBoxBuilder;
builder->priority(uint8_t(priority));
}
extern "C" JNIEXPORT jlong JNICALL
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 (jlong) builder->build(*engine);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Skybox_nSetLayerMask(JNIEnv *env, jclass type, jlong nativeSkybox,
jint select, jint value) {
Skybox *skybox = (Skybox *) nativeSkybox;
skybox->setLayerMask((uint8_t) select, (uint8_t) value);
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_Skybox_nGetLayerMask(JNIEnv *env, jclass type,
jlong nativeSkybox) {
Skybox *skybox = (Skybox *) nativeSkybox;
return static_cast<jint>(skybox->getLayerMask());
}
extern "C" JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_Skybox_nGetIntensity(JNIEnv *env, jclass clazz,
jlong nativeSkybox) {
Skybox *skybox = (Skybox *) nativeSkybox;
return static_cast<jint>(skybox->getIntensity());
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Skybox_nSetColor(JNIEnv *, jclass,
jlong nativeSkybox, jfloat r, jfloat g, jfloat b, jfloat a) {
Skybox *skybox = (Skybox *) nativeSkybox;
skybox->setColor({r, g, b, a});
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Skybox_nGetTexture(JNIEnv* env, jclass,
jlong nativeSkybox) {
Skybox *skybox = (Skybox *) nativeSkybox;
Texture const *tex = skybox->getTexture();
return (jlong) tex;
}