From ead5a978711a0e9d837068bc9d51fb4308eb6f01 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Fri, 2 Sep 2022 11:11:59 -0700 Subject: [PATCH] make AutomationEngine feature level aware this basically just adds an Engine* parameter too all applySettings methods --- .../src/main/cpp/AutomationEngine.cpp | 13 ++++++++----- .../filament/utils/AutomationEngine.java | 19 ++++++++++++------- .../android/filament/gltf/MainActivity.kt | 2 +- .../gltf-viewer/FILViewController.mm | 2 +- libs/viewer/include/viewer/AutomationEngine.h | 4 ++-- libs/viewer/include/viewer/Settings.h | 8 ++++---- libs/viewer/src/AutomationEngine.cpp | 18 +++++++++--------- libs/viewer/src/Settings.cpp | 9 +++++---- libs/viewer/src/ViewerGui.cpp | 2 +- samples/gltf_viewer.cpp | 4 ++-- samples/image_viewer.cpp | 2 +- 11 files changed, 46 insertions(+), 37 deletions(-) diff --git a/android/filament-utils-android/src/main/cpp/AutomationEngine.cpp b/android/filament-utils-android/src/main/cpp/AutomationEngine.cpp index a7f2cb8766..44eb5ed6b1 100644 --- a/android/filament-utils-android/src/main/cpp/AutomationEngine.cpp +++ b/android/filament-utils-android/src/main/cpp/AutomationEngine.cpp @@ -70,7 +70,8 @@ Java_com_google_android_filament_utils_AutomationEngine_nStartBatchMode(JNIEnv* extern "C" JNIEXPORT void JNICALL Java_com_google_android_filament_utils_AutomationEngine_nTick(JNIEnv* env, jclass klass, - jlong nativeAutomation, jlong view, jlongArray materials, jlong renderer, jfloat deltaTime) { + jlong nativeAutomation, jlong nativeEngine, + jlong view, jlongArray materials, jlong renderer, jfloat deltaTime) { using MaterialPointer = MaterialInstance*; jsize materialCount = 0; jlong* longMaterials = nullptr; @@ -90,7 +91,8 @@ Java_com_google_android_filament_utils_AutomationEngine_nTick(JNIEnv* env, jclas .materials = ptrMaterials, .materialCount = (size_t) materialCount, }; - automation->tick(content, deltaTime); + Engine* engine = (Engine*)nativeEngine; + automation->tick(engine, content, deltaTime); if (longMaterials) { env->ReleaseLongArrayElements(materials, longMaterials, 0); delete[] ptrMaterials; @@ -99,7 +101,8 @@ Java_com_google_android_filament_utils_AutomationEngine_nTick(JNIEnv* env, jclas extern "C" JNIEXPORT void JNICALL Java_com_google_android_filament_utils_AutomationEngine_nApplySettings(JNIEnv* env, jclass klass, - jlong nativeAutomation, jstring json, jlong view, jlongArray materials, jlong nativeIbl, + jlong nativeAutomation, jlong nativeEngine, + jstring json, jlong view, jlongArray materials, jlong nativeIbl, jint sunlightEntity, jintArray assetLights, jlong nativeLm, jlong scene, jlong renderer) { using MaterialPointer = MaterialInstance*; @@ -140,8 +143,8 @@ Java_com_google_android_filament_utils_AutomationEngine_nApplySettings(JNIEnv* e .assetLights = (Entity*) intLights, .assetLightCount = (size_t) lightCount, }; - - automation->applySettings(nativeJson, jsonLength, content); + Engine* engine = (Engine*)nativeEngine; + automation->applySettings(engine, nativeJson, jsonLength, content); env->ReleaseStringUTFChars(json, nativeJson); if (longMaterials) { env->ReleaseLongArrayElements(materials, longMaterials, 0); diff --git a/android/filament-utils-android/src/main/java/com/google/android/filament/utils/AutomationEngine.java b/android/filament-utils-android/src/main/java/com/google/android/filament/utils/AutomationEngine.java index 151b37fe52..93987d6c36 100644 --- a/android/filament-utils-android/src/main/java/com/google/android/filament/utils/AutomationEngine.java +++ b/android/filament-utils-android/src/main/java/com/google/android/filament/utils/AutomationEngine.java @@ -156,10 +156,11 @@ public class AutomationEngine { * This is when settings get applied, screenshots are (optionally) exported, and the internal * test counter is potentially incremented. * + * @param engine The filament Engine of interest. * @param content Contains the Filament View, Materials, and Renderer that get modified. * @param deltaTime The amount of time that has passed since the previous tick in seconds. */ - public void tick(@NonNull ViewerContent content, float deltaTime) { + public void tick(@NonNull Engine engine, @NonNull ViewerContent content, float deltaTime) { if (content.view == null || content.renderer == null) { throw new IllegalStateException("Must provide a View and Renderer"); } @@ -172,7 +173,7 @@ public class AutomationEngine { } long nativeView = content.view.getNativeObject(); long nativeRenderer = content.renderer.getNativeObject(); - nTick(mNativeObject, nativeView, nativeMaterialInstances, nativeRenderer, deltaTime); + nTick(mNativeObject, engine.getNativeObject(), nativeView, nativeMaterialInstances, nativeRenderer, deltaTime); } /** @@ -184,10 +185,12 @@ public class AutomationEngine { * This updates the stashed Settings object, then pushes those settings to the given * Filament objects. Clients can optionally call getColorGrading() after calling this method. * + * @param engine Filament Engine to use. * @param settingsJson Contains the JSON string with a set of changes that need to be pushed. * @param content Contains a set of Filament objects that you want to mutate. */ - public void applySettings(@NonNull String settingsJson, @NonNull ViewerContent content) { + public void applySettings(@NonNull Engine engine, @NonNull String settingsJson, + @NonNull ViewerContent content) { if (content.view == null || content.renderer == null) { throw new IllegalStateException("Must provide a View and Renderer"); } @@ -206,7 +209,8 @@ public class AutomationEngine { long nativeLm = content.lightManager.getNativeObject(); long nativeScene = content.scene.getNativeObject(); long nativeRenderer = content.renderer.getNativeObject(); - nApplySettings(mNativeObject, settingsJson, nativeView, nativeMaterialInstances, + nApplySettings(mNativeObject, engine.getNativeObject(), + settingsJson, nativeView, nativeMaterialInstances, nativeIbl, content.sunlight, content.assetLights, nativeLm, nativeScene, nativeRenderer); } @@ -267,9 +271,10 @@ public class AutomationEngine { int minFrameCount, boolean verbose); private static native void nStartRunning(long nativeObject); private static native void nStartBatchMode(long nativeObject); - private static native void nTick(long nativeObject, long view, long[] materials, long renderer, - float deltaTime); - private static native void nApplySettings(long nativeObject, String jsonSettings, long view, + private static native void nTick(long nativeObject, long nativeEngine, + long view, long[] materials, long renderer, float deltaTime); + private static native void nApplySettings(long nativeObject, long nativeEngine, + String jsonSettings, long view, long[] materials, long ibl, int sunlight, int[] assetLights, long lightManager, long scene, long renderer); private static native void nGetViewerOptions(long nativeObject, Object result); diff --git a/android/samples/sample-gltf-viewer/src/main/java/com/google/android/filament/gltf/MainActivity.kt b/android/samples/sample-gltf-viewer/src/main/java/com/google/android/filament/gltf/MainActivity.kt index 08ff0f36a2..1a2d2cb359 100644 --- a/android/samples/sample-gltf-viewer/src/main/java/com/google/android/filament/gltf/MainActivity.kt +++ b/android/samples/sample-gltf-viewer/src/main/java/com/google/android/filament/gltf/MainActivity.kt @@ -353,7 +353,7 @@ class MainActivity : Activity() { fun loadSettings(message: RemoteServer.ReceivedMessage) { val json = StandardCharsets.UTF_8.decode(message.buffer).toString() viewerContent.assetLights = modelViewer.asset?.lightEntities - automation.applySettings(json, viewerContent) + automation.applySettings(modelViewer.engine, json, viewerContent) modelViewer.view.colorGrading = automation.getColorGrading(modelViewer.engine) modelViewer.cameraFocalLength = automation.viewerOptions.cameraFocalLength updateRootTransform() diff --git a/ios/samples/gltf-viewer/gltf-viewer/FILViewController.mm b/ios/samples/gltf-viewer/gltf-viewer/FILViewController.mm index 2ea0be20b6..703ffa6416 100644 --- a/ios/samples/gltf-viewer/gltf-viewer/FILViewController.mm +++ b/ios/samples/gltf-viewer/gltf-viewer/FILViewController.mm @@ -223,7 +223,7 @@ using namespace ktxreader; .indirectLight = _indirectLight, .sunlight = _sun, }; - _automation->applySettings(message->buffer, message->bufferByteCount, content); + _automation->applySettings(self.modelView.engine, message->buffer, message->bufferByteCount, content); ColorGrading* const colorGrading = _automation->getColorGrading(self.modelView.engine); self.modelView.view->setColorGrading(colorGrading); self.modelView.cameraFocalLength = _automation->getViewerOptions().cameraFocalLength; diff --git a/libs/viewer/include/viewer/AutomationEngine.h b/libs/viewer/include/viewer/AutomationEngine.h index a966e753e8..8747f59d8d 100644 --- a/libs/viewer/include/viewer/AutomationEngine.h +++ b/libs/viewer/include/viewer/AutomationEngine.h @@ -158,7 +158,7 @@ public: * @param content Contains the Filament View, Materials, and Renderer that get modified. * @param deltaTime The amount of time that has passed since the previous tick in seconds. */ - void tick(const ViewerContent& content, float deltaTime); + void tick(Engine* engine, const ViewerContent& content, float deltaTime); /** * Mutates a set of client-owned Filament objects according to a JSON string. @@ -173,7 +173,7 @@ public: * @param jsonLength Number of characters in the json string. * @param content Contains a set of Filament objects that you want to mutate. */ - void applySettings(const char* json, size_t jsonLength, const ViewerContent& content); + void applySettings(Engine* engine, const char* json, size_t jsonLength, const ViewerContent& content); /** * Gets a color grading object that corresponds to the latest settings. diff --git a/libs/viewer/include/viewer/Settings.h b/libs/viewer/include/viewer/Settings.h index 350c244e25..dc54c667fb 100644 --- a/libs/viewer/include/viewer/Settings.h +++ b/libs/viewer/include/viewer/Settings.h @@ -76,11 +76,11 @@ using GuardBandOptions = filament::View::GuardBandOptions; using LightManager = filament::LightManager; // These functions push all editable property values to their respective Filament objects. -void applySettings(const ViewSettings& settings, View* dest); -void applySettings(const MaterialSettings& settings, MaterialInstance* dest); -void applySettings(const LightSettings& settings, IndirectLight* ibl, utils::Entity sunlight, +void applySettings(Engine* engine, const ViewSettings& settings, View* dest); +void applySettings(Engine* engine, const MaterialSettings& settings, MaterialInstance* dest); +void applySettings(Engine* engine, const LightSettings& settings, IndirectLight* ibl, utils::Entity sunlight, utils::Entity* sceneLights, size_t sceneLightCount, LightManager* lm, Scene* scene, View* view); -void applySettings(const ViewerOptions& settings, Camera* camera, Skybox* skybox, +void applySettings(Engine* engine, const ViewerOptions& settings, Camera* camera, Skybox* skybox, Renderer* renderer); // Creates a new ColorGrading object based on the given settings. diff --git a/libs/viewer/src/AutomationEngine.cpp b/libs/viewer/src/AutomationEngine.cpp index 0e0a9fa7b2..19d23ef168 100644 --- a/libs/viewer/src/AutomationEngine.cpp +++ b/libs/viewer/src/AutomationEngine.cpp @@ -154,7 +154,7 @@ void AutomationEngine::exportSettings(const Settings& settings, const char* file gStatus = "Exported to '" + std::string(filename) + "' in the current folder."; } -void AutomationEngine::applySettings(const char* json, size_t jsonLength, +void AutomationEngine::applySettings(Engine* engine, const char* json, size_t jsonLength, const ViewerContent& content) { JsonSerializer serializer; if (!serializer.readJson(json, jsonLength, mSettings)) { @@ -162,15 +162,15 @@ void AutomationEngine::applySettings(const char* json, size_t jsonLength, slog.e << "Badly formed JSON:\n" << jsonWithTerminator.c_str() << io::endl; return; } - viewer::applySettings(mSettings->view, content.view); + viewer::applySettings(engine, mSettings->view, content.view); for (size_t i = 0; i < content.materialCount; i++) { - viewer::applySettings(mSettings->material, content.materials[i]); + viewer::applySettings(engine, mSettings->material, content.materials[i]); } - viewer::applySettings(mSettings->lighting, content.indirectLight, content.sunlight, + viewer::applySettings(engine, mSettings->lighting, content.indirectLight, content.sunlight, content.assetLights, content.assetLightCount, content.lightManager, content.scene, content.view); Camera* camera = &content.view->getCamera(); Skybox* skybox = content.scene->getSkybox(); - viewer::applySettings(mSettings->viewer, camera, skybox, content.renderer); + viewer::applySettings(engine, mSettings->viewer, camera, skybox, content.renderer); } ColorGrading* AutomationEngine::getColorGrading(Engine* engine) { @@ -197,14 +197,14 @@ ViewerOptions AutomationEngine::getViewerOptions() const { return mSettings->viewer; } -void AutomationEngine::tick(const ViewerContent& content, float deltaTime) { - const auto activateTest = [this, content]() { +void AutomationEngine::tick(Engine* engine, const ViewerContent& content, float deltaTime) { + const auto activateTest = [this, engine, content]() { mElapsedTime = 0; mElapsedFrames = 0; mSpec->get(mCurrentTest, mSettings); - viewer::applySettings(mSettings->view, content.view); + viewer::applySettings(engine, mSettings->view, content.view); for (size_t i = 0; i < content.materialCount; i++) { - viewer::applySettings(mSettings->material, content.materials[i]); + viewer::applySettings(engine, mSettings->material, content.materials[i]); } if (mOptions.verbose) { utils::slog.i << "Running test " << mCurrentTest << utils::io::endl; diff --git a/libs/viewer/src/Settings.cpp b/libs/viewer/src/Settings.cpp index f1b5977ed6..d1c31f5834 100644 --- a/libs/viewer/src/Settings.cpp +++ b/libs/viewer/src/Settings.cpp @@ -19,6 +19,7 @@ #include "jsonParseUtils.h" #include "Settings_generated.h" +#include #include #include #include @@ -470,7 +471,7 @@ int parse(jsmntok_t const* tokens, int i, const char* jsonChunk, Settings* out) return i; } -void applySettings(const ViewSettings& settings, View* dest) { +void applySettings(Engine* engine, const ViewSettings& settings, View* dest) { dest->setAntiAliasing(settings.antiAliasing); dest->setTemporalAntiAliasingOptions(settings.taa); dest->setMultiSampleAntiAliasingOptions(settings.msaa); @@ -498,13 +499,13 @@ static void apply(MaterialProperty prop, MaterialInstance* dest) { } } -void applySettings(const MaterialSettings& settings, MaterialInstance* dest) { +void applySettings(Engine* engine, const MaterialSettings& settings, MaterialInstance* dest) { for (const auto& prop : settings.scalar) { apply(prop, dest); } for (const auto& prop : settings.float3) { apply(prop, dest); } for (const auto& prop : settings.float4) { apply(prop, dest); } } -void applySettings(const LightSettings& settings, IndirectLight* ibl, utils::Entity sunlight, +void applySettings(Engine* engine, const LightSettings& settings, IndirectLight* ibl, utils::Entity sunlight, utils::Entity* sceneLights, size_t sceneLightCount, LightManager* lm, Scene* scene, View* view) { auto light = lm->getInstance(sunlight); if (light) { @@ -537,7 +538,7 @@ static LinearColor inverseTonemapSRGB(sRGBColor x) { return (x * -0.155f) / (x - 1.019f); } -void applySettings(const ViewerOptions& settings, Camera* camera, Skybox* skybox, +void applySettings(Engine* engine, const ViewerOptions& settings, Camera* camera, Skybox* skybox, Renderer* renderer) { if (renderer) { // we have to clear because the side-bar doesn't have a background, we cannot use diff --git a/libs/viewer/src/ViewerGui.cpp b/libs/viewer/src/ViewerGui.cpp index 62f7b5500e..57bae6d2e4 100644 --- a/libs/viewer/src/ViewerGui.cpp +++ b/libs/viewer/src/ViewerGui.cpp @@ -986,7 +986,7 @@ void ViewerGui::updateUserInterface() { // At this point, all View settings have been modified, // so we can now push them into the Filament View. - applySettings(mSettings.view, mView); + applySettings(mEngine, mSettings.view, mView); mView->setSoftShadowOptions(mSettings.lighting.softShadowOptions); diff --git a/samples/gltf_viewer.cpp b/samples/gltf_viewer.cpp index de1757179e..18ab8631e0 100644 --- a/samples/gltf_viewer.cpp +++ b/samples/gltf_viewer.cpp @@ -874,7 +874,7 @@ int main(int argc, char** argv) { // This applies clear options, the skybox mask, and some camera settings. Camera& camera = view->getCamera(); Skybox* skybox = scene->getSkybox(); - applySettings(app.viewer->getSettings().viewer, &camera, skybox, renderer); + applySettings(engine, app.viewer->getSettings().viewer, &camera, skybox, renderer); // Check if color grading has changed. ColorGradingSettings& options = app.viewer->getSettings().view.colorGrading; @@ -902,7 +902,7 @@ int main(int argc, char** argv) { .materials = app.asset->getMaterialInstances(), .materialCount = app.asset->getMaterialInstanceCount(), }; - app.automationEngine->tick(content, ImGui::GetIO().DeltaTime); + app.automationEngine->tick(engine, content, ImGui::GetIO().DeltaTime); }; FilamentApp& filamentApp = FilamentApp::get(); diff --git a/samples/image_viewer.cpp b/samples/image_viewer.cpp index de2f3a038a..27ffb17b5b 100644 --- a/samples/image_viewer.cpp +++ b/samples/image_viewer.cpp @@ -333,7 +333,7 @@ int main(int argc, char** argv) { // This applies clear options, the skybox mask, and some camera settings. Camera& camera = view->getCamera(); Skybox* skybox = scene->getSkybox(); - applySettings(app.viewer->getSettings().viewer, &camera, skybox, renderer); + applySettings(engine, app.viewer->getSettings().viewer, &camera, skybox, renderer); // Check if color grading has changed. ColorGradingSettings& options = app.viewer->getSettings().view.colorGrading;