diff --git a/android/filament-android/src/main/cpp/View.cpp b/android/filament-android/src/main/cpp/View.cpp index e2d8efacb3..f16b76c671 100644 --- a/android/filament-android/src/main/cpp/View.cpp +++ b/android/filament-android/src/main/cpp/View.cpp @@ -49,6 +49,12 @@ Java_com_google_android_filament_View_nSetCamera(JNIEnv*, jclass, view->setCamera(camera); } +extern "C" JNIEXPORT jboolean JNICALL +Java_com_google_android_filament_View_nHasCamera(JNIEnv*, jclass, jlong nativeView) { + View* view = (View*) nativeView; + return (jboolean)view->hasCamera(); +} + extern "C" JNIEXPORT void JNICALL Java_com_google_android_filament_View_nSetColorGrading(JNIEnv*, jclass, jlong nativeView, jlong nativeColorGrading) { diff --git a/android/filament-android/src/main/java/com/google/android/filament/View.java b/android/filament-android/src/main/java/com/google/android/filament/View.java index 28cb268c23..460c25d406 100644 --- a/android/filament-android/src/main/java/com/google/android/filament/View.java +++ b/android/filament-android/src/main/java/com/google/android/filament/View.java @@ -241,6 +241,15 @@ public class View { nSetCamera(getNativeObject(), camera == null ? 0 : camera.getNativeObject()); } + /** + * Query whether a camera is set. + * @return true if a camera is set, false otherwise + * @see #setCamera + */ + public boolean hasCamera() { + return nHasCamera(getNativeObject()); + } + /** * Gets this View's associated Camera, or null if none has been assigned. * @@ -1238,6 +1247,7 @@ public class View { private static native void nSetName(long nativeView, String name); private static native void nSetScene(long nativeView, long nativeScene); private static native void nSetCamera(long nativeView, long nativeCamera); + private static native boolean nHasCamera(long nativeView); private static native void nSetViewport(long nativeView, int left, int bottom, int width, int height); private static native void nSetVisibleLayers(long nativeView, int select, int value); private static native void nSetShadowingEnabled(long nativeView, boolean enabled); diff --git a/filament/include/filament/View.h b/filament/include/filament/View.h index 3cdd527fac..1a1ed96f51 100644 --- a/filament/include/filament/View.h +++ b/filament/include/filament/View.h @@ -189,6 +189,13 @@ public: */ void setCamera(Camera* UTILS_NONNULL camera) noexcept; + /** + * Returns whether a Camera is set. + * @return true if a camera is set. + * @see setCamera() + */ + bool hasCamera() const noexcept; + /** * Returns the Camera currently associated with this View. * @return A reference to the Camera associated to this View. diff --git a/filament/src/View.cpp b/filament/src/View.cpp index 2de966ea0c..58ac1a6afc 100644 --- a/filament/src/View.cpp +++ b/filament/src/View.cpp @@ -31,6 +31,10 @@ void View::setCamera(Camera* camera) noexcept { downcast(this)->setCameraUser(downcast(camera)); } +bool View::hasCamera() const noexcept { + return downcast(this)->hasCamera(); +} + Camera& View::getCamera() noexcept { return downcast(this)->getCameraUser(); } diff --git a/filament/src/details/Renderer.cpp b/filament/src/details/Renderer.cpp index 493060cd6a..d9a20d7937 100644 --- a/filament/src/details/Renderer.cpp +++ b/filament/src/details/Renderer.cpp @@ -482,7 +482,7 @@ void FRenderer::render(FView const* view) { mBeginFrameInternal = {}; } - if (UTILS_LIKELY(view && view->getScene())) { + if (UTILS_LIKELY(view && view->getScene() && view->hasCamera())) { if (mViewRenderedCount) { // This is a good place to kick the GPU, since we've rendered a View before, // and we're about to render another one. diff --git a/filament/src/details/View.h b/filament/src/details/View.h index d707001a42..be15af9e52 100644 --- a/filament/src/details/View.h +++ b/filament/src/details/View.h @@ -389,6 +389,10 @@ public: FCamera& getCameraUser() noexcept { return *mCullingCamera; } void setCameraUser(FCamera* camera) noexcept { setCullingCamera(camera); } + bool hasCamera() const noexcept { + return mCullingCamera != nullptr; + } + backend::Handle getRenderTargetHandle() const noexcept { backend::Handle kEmptyHandle; return mRenderTarget == nullptr ? kEmptyHandle : mRenderTarget->getHwHandle(); diff --git a/libs/filamentapp/src/FilamentApp.cpp b/libs/filamentapp/src/FilamentApp.cpp index 82eba7a231..043fb4c950 100644 --- a/libs/filamentapp/src/FilamentApp.cpp +++ b/libs/filamentapp/src/FilamentApp.cpp @@ -455,18 +455,28 @@ void FilamentApp::run(const Config& config, SetupCallback setupCallback, mReconfigureCameras = false; } + if (config.splitView) { + if(!window->mOrthoView->getView()->hasCamera()) { + Camera const* debugDirectionalShadowCamera = + window->mMainView->getView()->getDirectionalShadowCamera(); + if (debugDirectionalShadowCamera) { + window->mOrthoView->setCamera( + const_cast(debugDirectionalShadowCamera)); + } + } + } + if (renderer->beginFrame(window->getSwapChain())) { - for (filament::View* offscreenView : mOffscreenViews) { + for (filament::View* offscreenView: mOffscreenViews) { renderer->render(offscreenView); } - for (auto const& view : window->mViews) { + for (auto const& view: window->mViews) { renderer->render(view->getView()); } if (postRender) { postRender(mEngine, window->mViews[0]->getView(), mScene, renderer); } renderer->endFrame(); - } else { ++mSkippedFrames; } diff --git a/web/filament-js/jsbindings.cpp b/web/filament-js/jsbindings.cpp index e1a8a89cef..79a573b042 100644 --- a/web/filament-js/jsbindings.cpp +++ b/web/filament-js/jsbindings.cpp @@ -646,6 +646,7 @@ class_("View") .function("setScene", &View::setScene, allow_raw_pointers()) .function("setCamera", &View::setCamera, allow_raw_pointers()) + .function("hasCamera", &View::hasCamera) .function("setColorGrading", &View::setColorGrading, allow_raw_pointers()) .function("setBlendMode", &View::setBlendMode) .function("getBlendMode", &View::getBlendMode)