From 6e4491c8528f706d2fa1fd18b78524505ea7d476 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Tue, 12 Mar 2019 13:28:58 -0700 Subject: [PATCH] Make dithering an enum. --- android/filament-android/src/main/cpp/View.cpp | 8 ++++---- .../java/com/google/android/filament/View.java | 18 ++++++++++++------ filament/include/filament/View.h | 18 +++++++++++++----- filament/src/Renderer.cpp | 2 +- filament/src/View.cpp | 4 ++-- filament/src/details/View.h | 6 +++--- samples/material_sandbox.cpp | 4 ++-- 7 files changed, 37 insertions(+), 23 deletions(-) diff --git a/android/filament-android/src/main/cpp/View.cpp b/android/filament-android/src/main/cpp/View.cpp index b50a9cc858..b051084d94 100644 --- a/android/filament-android/src/main/cpp/View.cpp +++ b/android/filament-android/src/main/cpp/View.cpp @@ -124,16 +124,16 @@ Java_com_google_android_filament_View_nGetAntiAliasing(JNIEnv*, jclass, extern "C" JNIEXPORT void JNICALL Java_com_google_android_filament_View_nSetDithering(JNIEnv*, jclass, - jlong nativeView, jboolean dithering) { + jlong nativeView, jint dithering) { View* view = (View*) nativeView; - view->setDithering((bool) dithering); + view->setDithering((View::Dithering) dithering); } -extern "C" JNIEXPORT jboolean JNICALL +extern "C" JNIEXPORT jint JNICALL Java_com_google_android_filament_View_nGetDithering(JNIEnv*, jclass, jlong nativeView) { View* view = (View*) nativeView; - return (jboolean)view->getDithering(); + return (jint)view->getDithering(); } extern "C" JNIEXPORT void JNICALL 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 157ebd2f1e..83d814f917 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 @@ -60,6 +60,11 @@ public class View { FXAA } + public enum Dithering { + NONE, + TEMPORAL + } + public enum DepthPrepass { DEFAULT(-1), DISABLED(0), @@ -160,12 +165,13 @@ public class View { return AntiAliasing.values()[nGetAntiAliasing(getNativeObject())]; } - public void setDithering(boolean dithering) { - nSetDithering(getNativeObject(), dithering); + public void setDithering(@NonNull Dithering dithering) { + nSetDithering(getNativeObject(), dithering.ordinal()); } - public boolean getDithering() { - return nGetDithering(getNativeObject()); + @NonNull + public Dithering getDithering() { + return Dithering.values()[nGetDithering(getNativeObject())]; } public void setDynamicResolutionOptions(@NonNull DynamicResolutionOptions options) { @@ -265,8 +271,8 @@ public class View { private static native int nGetSampleCount(long nativeView); private static native void nSetAntiAliasing(long nativeView, int type); private static native int nGetAntiAliasing(long nativeView); - private static native void nSetDithering(long nativeView, boolean dithering); - private static native boolean nGetDithering(long nativeView); + 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 targetFrameTimeMilli, float headRoomRatio, float scaleRate, diff --git a/filament/include/filament/View.h b/filament/include/filament/View.h index eda7f6ffd7..1ce8eb8150 100644 --- a/filament/include/filament/View.h +++ b/filament/include/filament/View.h @@ -140,7 +140,7 @@ public: /** * List of available post-processing anti-aliasing techniques. */ - enum AntiAliasing : uint8_t { + enum class AntiAliasing : uint8_t { NONE = 0, FXAA = 1 }; @@ -151,6 +151,14 @@ public: ENABLED, }; + /** + * List of available post-processing dithering techniques. + */ + enum class Dithering : uint8_t { + NONE = 0, //!< No dithering + TEMPORAL = 1 //!< Temporal dithering (default) + }; + /** * Sets whether this view is rendered with or without a depth pre-pass. * @@ -378,16 +386,16 @@ public: /** * Enables or disables dithering in the post-processing stage. Enabled by default. * - * @param dithering true to enable, false to disable + * @param dithering dithering type */ - void setDithering(bool dithering) noexcept; + void setDithering(Dithering dithering) noexcept; /** * Queries whether dithering is enabled during the post-processing stage. * - * @return true if post-processing dithering is enabled, false otherwise. + * @return the current dithering type for this view. */ - bool getDithering() const noexcept; + Dithering getDithering() const noexcept; /** * Sets the dynamic resolution options for this view. Dynamic resolution options diff --git a/filament/src/Renderer.cpp b/filament/src/Renderer.cpp index f74159f2b6..d56929638f 100644 --- a/filament/src/Renderer.cpp +++ b/filament/src/Renderer.cpp @@ -165,7 +165,7 @@ void FRenderer::renderJob(ArenaScope& arena, FView& view) { const bool hasPostProcess = view.hasPostProcessPass(); float2 scale = view.updateScale(mFrameInfoManager.getLastFrameTime()); bool useFXAA = view.getAntiAliasing() == View::AntiAliasing::FXAA; - bool dithering = view.getDithering(); + bool dithering = view.getDithering() == View::Dithering::TEMPORAL; if (!hasPostProcess) { // dynamic scaling and FXAA are part of the post-process phase and can't happen if // it's disabled. diff --git a/filament/src/View.cpp b/filament/src/View.cpp index 951b8e2bdb..8a0adc4862 100644 --- a/filament/src/View.cpp +++ b/filament/src/View.cpp @@ -863,11 +863,11 @@ View::AntiAliasing View::getAntiAliasing() const noexcept { return upcast(this)->getAntiAliasing(); } -void View::setDithering(bool dithering) noexcept { +void View::setDithering(Dithering dithering) noexcept { upcast(this)->setDithering(dithering); } -bool View::getDithering() const noexcept { +View::Dithering View::getDithering() const noexcept { return upcast(this)->getDithering(); } diff --git a/filament/src/details/View.h b/filament/src/details/View.h index a606061d2f..7cb2cfd779 100644 --- a/filament/src/details/View.h +++ b/filament/src/details/View.h @@ -162,11 +162,11 @@ public: return mAntiAliasing; } - void setDithering(bool dithering) noexcept { + void setDithering(Dithering dithering) noexcept { mDithering = dithering; } - bool getDithering() const noexcept { + Dithering getDithering() const noexcept { return mDithering; } @@ -287,7 +287,7 @@ private: uint8_t mVisibleLayers = 0x1; uint8_t mSampleCount = 1; AntiAliasing mAntiAliasing = AntiAliasing::FXAA; - bool mDithering = true; + Dithering mDithering = Dithering::TEMPORAL; bool mShadowingEnabled = true; bool mHasPostProcessPass = true; DepthPrepass mDepthPrepass = DepthPrepass::DEFAULT; diff --git a/samples/material_sandbox.cpp b/samples/material_sandbox.cpp index f710f6aa1a..50c04587f5 100644 --- a/samples/material_sandbox.cpp +++ b/samples/material_sandbox.cpp @@ -383,8 +383,8 @@ static void gui(filament::Engine* engine, filament::View*) { } static void preRender(filament::Engine*, filament::View* view, filament::Scene*, filament::Renderer*) { - view->setAntiAliasing(g_params.fxaa ? View::FXAA : View::NONE); - view->setDithering(g_params.dithering); + view->setAntiAliasing(g_params.fxaa ? View::AntiAliasing::FXAA : View::AntiAliasing::NONE); + view->setDithering(g_params.dithering ? View::Dithering::TEMPORAL : View::Dithering::NONE); view->setSampleCount((uint8_t) (g_params.msaa ? 4 : 1)); }