From 7669369f4952bd67386016a77d8110e4a86a3303 Mon Sep 17 00:00:00 2001 From: seungho baek Date: Wed, 2 Aug 2023 14:03:24 +0900 Subject: [PATCH] [Tizen] Make some camera actor animatable & constraint input Change-Id: I7b164c6885dc3225a0ba13e560a71c13ec23e88c Signed-off-by: seungho baek --- .../src/dali/utc-Dali-CameraActor.cpp | 122 ++++++++++++++- .../event/actors/camera-actor-impl.cpp | 91 ++++++++++- .../internal/event/actors/camera-actor-impl.h | 16 ++ .../manager/render-instruction-processor.cpp | 2 +- .../render-tasks/scene-graph-camera.cpp | 73 ++++++--- .../update/render-tasks/scene-graph-camera.h | 144 ++++++++++++++---- dali/public-api/actors/camera-actor.h | 4 +- 7 files changed, 376 insertions(+), 76 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-CameraActor.cpp b/automated-tests/src/dali/utc-Dali-CameraActor.cpp index 71ada710d..1432ff53f 100644 --- a/automated-tests/src/dali/utc-Dali-CameraActor.cpp +++ b/automated-tests/src/dali/utc-Dali-CameraActor.cpp @@ -1283,7 +1283,7 @@ int UtcDaliCameraActorDefaultProperties(void) { DALI_TEST_EQUALS(*iter, actor.GetPropertyIndex(actor.GetPropertyName(*iter)), TEST_LOCATION); - if(*iter == CameraActor::Property::FIELD_OF_VIEW || *iter == CameraActor::Property::ASPECT_RATIO || *iter == DevelCameraActor::Property::ORTHOGRAPHIC_SIZE) + if(*iter == CameraActor::Property::FIELD_OF_VIEW || *iter == CameraActor::Property::ASPECT_RATIO || *iter == DevelCameraActor::Property::ORTHOGRAPHIC_SIZE || *iter == CameraActor::Property::NEAR_PLANE_DISTANCE || *iter == CameraActor::Property::FAR_PLANE_DISTANCE) { DALI_TEST_CHECK(actor.IsPropertyAnimatable(*iter)); } @@ -1419,8 +1419,8 @@ int UtcDaliCameraActorDefaultPropertiesInherited(void) {"projectionMode", Property::INTEGER, true, false, true, Dali::CameraActor::Property::PROJECTION_MODE}, {"fieldOfView", Property::FLOAT, true, true, true, Dali::CameraActor::Property::FIELD_OF_VIEW}, {"aspectRatio", Property::FLOAT, true, true, true, Dali::CameraActor::Property::ASPECT_RATIO}, - {"nearPlaneDistance", Property::FLOAT, true, false, true, Dali::CameraActor::Property::NEAR_PLANE_DISTANCE}, - {"farPlaneDistance", Property::FLOAT, true, false, true, Dali::CameraActor::Property::FAR_PLANE_DISTANCE}, + {"nearPlaneDistance", Property::FLOAT, true, true, true, Dali::CameraActor::Property::NEAR_PLANE_DISTANCE}, + {"farPlaneDistance", Property::FLOAT, true, true, true, Dali::CameraActor::Property::FAR_PLANE_DISTANCE}, {"leftPlaneDistance", Property::FLOAT, false, false, true, Dali::CameraActor::Property::LEFT_PLANE_DISTANCE}, {"rightPlaneDistance", Property::FLOAT, false, false, true, Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE}, {"topPlaneDistance", Property::FLOAT, false, false, true, Dali::CameraActor::Property::TOP_PLANE_DISTANCE}, @@ -1605,38 +1605,45 @@ int UtcDaliCameraActorAnimatedProperties03(void) Radian sourceFoV = Radian(0.6f); float sourceAspect = 0.7f; + float sourceNearDistance = 0.5f; + float sourceFarDistance = 1000.0f; Radian targetFoV = Radian(0.1f); float targetAspect = 1.3f; + float targetNearDistance = 20.5f; + float targetFarDistance = 30.0f; Matrix expectedProjectionMatrix1; Matrix expectedProjectionMatrix2; Matrix expectedProjectionMatrix3; - // Reduce near-far value for projection matrix epsilon - camera.SetNearClippingPlane(1.0f); - camera.SetFarClippingPlane(3.0f); - // Build expect projection matrix camera.SetFieldOfView(sourceFoV.radian); camera.SetAspectRatio(sourceAspect); + camera.SetNearClippingPlane(sourceNearDistance); + camera.SetFarClippingPlane(sourceFarDistance); application.SendNotification(); application.Render(); camera.GetProperty(CameraActor::Property::PROJECTION_MATRIX).Get(expectedProjectionMatrix1); camera.SetFieldOfView(sourceFoV.radian * 0.6f + targetFoV.radian * 0.4f); camera.SetAspectRatio(sourceAspect * 0.6f + targetAspect * 0.4f); + camera.SetNearClippingPlane(sourceNearDistance * 0.6f + targetNearDistance * 0.4f); + camera.SetFarClippingPlane(sourceFarDistance * 0.6f + targetFarDistance * 0.4f); application.SendNotification(); application.Render(); camera.GetProperty(CameraActor::Property::PROJECTION_MATRIX).Get(expectedProjectionMatrix2); camera.SetFieldOfView(targetFoV.radian); camera.SetAspectRatio(targetAspect); + camera.SetNearClippingPlane(targetNearDistance); + camera.SetFarClippingPlane(targetFarDistance); application.SendNotification(); application.Render(); camera.GetProperty(CameraActor::Property::PROJECTION_MATRIX).Get(expectedProjectionMatrix3); - auto TestAnimationProgress = [&]() { + auto TestAnimationProgress = [&]() + { Matrix projectionMatrix; application.SendNotification(); @@ -1645,6 +1652,8 @@ int UtcDaliCameraActorAnimatedProperties03(void) // progress 0.0 DALI_TEST_EQUALS(camera.GetCurrentProperty(CameraActor::Property::FIELD_OF_VIEW), sourceFoV.radian, TEST_LOCATION); DALI_TEST_EQUALS(camera.GetCurrentProperty(CameraActor::Property::ASPECT_RATIO), sourceAspect, TEST_LOCATION); + DALI_TEST_EQUALS(camera.GetCurrentProperty(CameraActor::Property::NEAR_PLANE_DISTANCE), sourceNearDistance, TEST_LOCATION); + DALI_TEST_EQUALS(camera.GetCurrentProperty(CameraActor::Property::FAR_PLANE_DISTANCE), sourceFarDistance, TEST_LOCATION); camera.GetProperty(CameraActor::Property::PROJECTION_MATRIX).Get(projectionMatrix); DALI_TEST_EQUALS(projectionMatrix, expectedProjectionMatrix1, Epsilon<100000>::value, TEST_LOCATION); @@ -1655,6 +1664,8 @@ int UtcDaliCameraActorAnimatedProperties03(void) // progress 0.4 DALI_TEST_EQUALS(camera.GetCurrentProperty(CameraActor::Property::FIELD_OF_VIEW), sourceFoV.radian * 0.6f + targetFoV.radian * 0.4f, TEST_LOCATION); DALI_TEST_EQUALS(camera.GetCurrentProperty(CameraActor::Property::ASPECT_RATIO), sourceAspect * 0.6f + targetAspect * 0.4f, TEST_LOCATION); + DALI_TEST_EQUALS(camera.GetCurrentProperty(CameraActor::Property::NEAR_PLANE_DISTANCE), sourceNearDistance * 0.6f + targetNearDistance * 0.4f, TEST_LOCATION); + DALI_TEST_EQUALS(camera.GetCurrentProperty(CameraActor::Property::FAR_PLANE_DISTANCE), sourceFarDistance * 0.6f + targetFarDistance * 0.4f, TEST_LOCATION); camera.GetProperty(CameraActor::Property::PROJECTION_MATRIX).Get(projectionMatrix); DALI_TEST_EQUALS(projectionMatrix, expectedProjectionMatrix2, Epsilon<100000>::value, TEST_LOCATION); @@ -1665,6 +1676,8 @@ int UtcDaliCameraActorAnimatedProperties03(void) // progress 1.0 DALI_TEST_EQUALS(camera.GetCurrentProperty(CameraActor::Property::FIELD_OF_VIEW), targetFoV.radian, TEST_LOCATION); DALI_TEST_EQUALS(camera.GetCurrentProperty(CameraActor::Property::ASPECT_RATIO), targetAspect, TEST_LOCATION); + DALI_TEST_EQUALS(camera.GetCurrentProperty(CameraActor::Property::NEAR_PLANE_DISTANCE), targetNearDistance, TEST_LOCATION); + DALI_TEST_EQUALS(camera.GetCurrentProperty(CameraActor::Property::FAR_PLANE_DISTANCE), targetFarDistance, TEST_LOCATION); camera.GetProperty(CameraActor::Property::PROJECTION_MATRIX).Get(projectionMatrix); DALI_TEST_EQUALS(projectionMatrix, expectedProjectionMatrix3, Epsilon<100000>::value, TEST_LOCATION); @@ -1679,9 +1692,13 @@ int UtcDaliCameraActorAnimatedProperties03(void) tet_printf("AnimateTo\n"); camera.SetProperty(CameraActor::Property::FIELD_OF_VIEW, sourceFoV.radian); camera.SetProperty(CameraActor::Property::ASPECT_RATIO, sourceAspect); + camera.SetProperty(CameraActor::Property::NEAR_PLANE_DISTANCE, sourceNearDistance); + camera.SetProperty(CameraActor::Property::FAR_PLANE_DISTANCE, sourceFarDistance); Animation animation = Animation::New(1.0f); animation.AnimateTo(Property(camera, CameraActor::Property::FIELD_OF_VIEW), targetFoV.radian); animation.AnimateTo(Property(camera, CameraActor::Property::ASPECT_RATIO), targetAspect); + animation.AnimateTo(Property(camera, CameraActor::Property::NEAR_PLANE_DISTANCE), targetNearDistance); + animation.AnimateTo(Property(camera, CameraActor::Property::FAR_PLANE_DISTANCE), targetFarDistance); animation.AnimateTo(Property(camera, Actor::Property::POSITION_X), 0.0f); ///< For line coverage. animation.Play(); @@ -1701,8 +1718,18 @@ int UtcDaliCameraActorAnimatedProperties03(void) keyFrames2.Add(0.0f, sourceAspect); keyFrames2.Add(1.0f, targetAspect); + KeyFrames keyFrames3 = KeyFrames::New(); + keyFrames3.Add(0.0f, sourceNearDistance); + keyFrames3.Add(1.0f, targetNearDistance); + + KeyFrames keyFrames4 = KeyFrames::New(); + keyFrames4.Add(0.0f, sourceFarDistance); + keyFrames4.Add(1.0f, targetFarDistance); + animation.AnimateBetween(Property(camera, CameraActor::Property::FIELD_OF_VIEW), keyFrames1); animation.AnimateBetween(Property(camera, CameraActor::Property::ASPECT_RATIO), keyFrames2); + animation.AnimateBetween(Property(camera, CameraActor::Property::NEAR_PLANE_DISTANCE), keyFrames3); + animation.AnimateBetween(Property(camera, CameraActor::Property::FAR_PLANE_DISTANCE), keyFrames4); animation.Play(); @@ -1714,9 +1741,13 @@ int UtcDaliCameraActorAnimatedProperties03(void) tet_printf("AnimateBy\n"); camera.SetProperty(CameraActor::Property::FIELD_OF_VIEW, sourceFoV.radian); camera.SetProperty(CameraActor::Property::ASPECT_RATIO, sourceAspect); + camera.SetProperty(CameraActor::Property::NEAR_PLANE_DISTANCE, sourceNearDistance); + camera.SetProperty(CameraActor::Property::FAR_PLANE_DISTANCE, sourceFarDistance); Animation animation = Animation::New(1.0f); animation.AnimateBy(Property(camera, CameraActor::Property::FIELD_OF_VIEW), targetFoV.radian - sourceFoV.radian); animation.AnimateBy(Property(camera, CameraActor::Property::ASPECT_RATIO), targetAspect - sourceAspect); + animation.AnimateBy(Property(camera, CameraActor::Property::NEAR_PLANE_DISTANCE), targetNearDistance - sourceNearDistance); + animation.AnimateBy(Property(camera, CameraActor::Property::FAR_PLANE_DISTANCE), targetFarDistance - sourceFarDistance); animation.Play(); TestAnimationProgress(); @@ -2941,3 +2972,78 @@ int UtcDaliCameraActorSetProperty(void) END_TEST; } + +int UtcDaliCameraActorConstraintInputProperty(void) +{ + TestApplication application; + tet_infoline("Testing Constraint input properties"); + + CameraActor camera = application.GetScene().GetRenderTaskList().GetTask(0u).GetCameraActor(); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 4u, 4u); + Actor actor = CreateRenderableActor(image, RENDER_SHADOW_VERTEX_SOURCE, RENDER_SHADOW_FRAGMENT_SOURCE); + actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f)); + application.GetScene().Add(actor); + + float projectionMode; + float projectionDirection; + float invertYAxis; + float nearClippingPlane; + float farClippingPlane; + + camera.GetProperty(CameraActor::Property::PROJECTION_MODE).Get(projectionMode); + camera.GetProperty(DevelCameraActor::Property::PROJECTION_DIRECTION).Get(projectionDirection); + camera.GetProperty(CameraActor::Property::INVERT_Y_AXIS).Get(invertYAxis); + camera.GetProperty(CameraActor::Property::NEAR_PLANE_DISTANCE).Get(nearClippingPlane); + camera.GetProperty(CameraActor::Property::FAR_PLANE_DISTANCE).Get(farClippingPlane); + + Property::Index projectionModePropertyIndex = actor.RegisterProperty("projectionMode", 100.0f); + Property::Index projectionDirectionPropertyIndex = actor.RegisterProperty("projectionDirection", 100.0f); + Property::Index invertYAxisPropertyIndex = actor.RegisterProperty("invertYAxis", 100.0f); + Property::Index nearClippingPlanePropertyIndex = actor.RegisterProperty("nearClippingPlane", 100.0f); + Property::Index farClippingPlanePropertyIndex = actor.RegisterProperty("farClippingPlane", 100.0f); + + application.SendNotification(); + application.Render(); + + Constraint projectionModePropertyConstraint = Constraint::New(actor, projectionModePropertyIndex, [](float& output, const PropertyInputContainer& inputs) + { output = static_cast(inputs[0]->GetInteger()); }); + Constraint projectionDirectionPropertyConstraint = Constraint::New(actor, projectionDirectionPropertyIndex, [](float& output, const PropertyInputContainer& inputs) + { output = static_cast(inputs[0]->GetInteger()); }); + Constraint invertYAxisPropertyConstraint = Constraint::New(actor, invertYAxisPropertyIndex, [](float& output, const PropertyInputContainer& inputs) + { output = static_cast(inputs[0]->GetBoolean()); }); + Constraint nearClippingPlanePropertyConstraint = Constraint::New(actor, nearClippingPlanePropertyIndex, EqualToConstraint()); + Constraint farClippingPlanePropertyConstraint = Constraint::New(actor, farClippingPlanePropertyIndex, EqualToConstraint()); + + projectionModePropertyConstraint.AddSource(Source(camera, CameraActor::Property::PROJECTION_MODE)); + projectionDirectionPropertyConstraint.AddSource(Source(camera, DevelCameraActor::Property::PROJECTION_DIRECTION)); + invertYAxisPropertyConstraint.AddSource(Source(camera, CameraActor::Property::INVERT_Y_AXIS)); + nearClippingPlanePropertyConstraint.AddSource(Source(camera, CameraActor::Property::NEAR_PLANE_DISTANCE)); + farClippingPlanePropertyConstraint.AddSource(Source(camera, CameraActor::Property::FAR_PLANE_DISTANCE)); + + projectionModePropertyConstraint.Apply(); + projectionDirectionPropertyConstraint.Apply(); + invertYAxisPropertyConstraint.Apply(); + nearClippingPlanePropertyConstraint.Apply(); + farClippingPlanePropertyConstraint.Apply(); + + application.SendNotification(); + application.Render(); + + float projectionModeResult = actor.GetCurrentProperty(projectionModePropertyIndex); + float projectionDirectionResult = actor.GetCurrentProperty(projectionDirectionPropertyIndex); + float invertYAxisResult = actor.GetCurrentProperty(invertYAxisPropertyIndex); + float nearClippingPlaneResult = actor.GetCurrentProperty(nearClippingPlanePropertyIndex); + float farClippingPlaneResult = actor.GetCurrentProperty(farClippingPlanePropertyIndex); + + DALI_TEST_EQUALS(projectionModeResult, projectionMode, TEST_LOCATION); + DALI_TEST_EQUALS(projectionDirectionResult, projectionDirection, TEST_LOCATION); + DALI_TEST_EQUALS(invertYAxisResult, invertYAxis, TEST_LOCATION); + DALI_TEST_EQUALS(nearClippingPlaneResult, nearClippingPlane, TEST_LOCATION); + DALI_TEST_EQUALS(farClippingPlaneResult, farClippingPlane, TEST_LOCATION); + + END_TEST; +} diff --git a/dali/internal/event/actors/camera-actor-impl.cpp b/dali/internal/event/actors/camera-actor-impl.cpp index 42e0ca1d0..b64803d9d 100644 --- a/dali/internal/event/actors/camera-actor-impl.cpp +++ b/dali/internal/event/actors/camera-actor-impl.cpp @@ -52,8 +52,8 @@ DALI_PROPERTY( "type", INTEGER, true, false, true, Dal DALI_PROPERTY( "projectionMode", INTEGER, true, false, true, Dali::CameraActor::Property::PROJECTION_MODE ) DALI_PROPERTY( "fieldOfView", FLOAT, true, true, true, Dali::CameraActor::Property::FIELD_OF_VIEW ) DALI_PROPERTY( "aspectRatio", FLOAT, true, true, true, Dali::CameraActor::Property::ASPECT_RATIO ) -DALI_PROPERTY( "nearPlaneDistance", FLOAT, true, false, true, Dali::CameraActor::Property::NEAR_PLANE_DISTANCE ) -DALI_PROPERTY( "farPlaneDistance", FLOAT, true, false, true, Dali::CameraActor::Property::FAR_PLANE_DISTANCE ) +DALI_PROPERTY( "nearPlaneDistance", FLOAT, true, true, true, Dali::CameraActor::Property::NEAR_PLANE_DISTANCE ) +DALI_PROPERTY( "farPlaneDistance", FLOAT, true, true, true, Dali::CameraActor::Property::FAR_PLANE_DISTANCE ) DALI_PROPERTY( "leftPlaneDistance", FLOAT, false, false, true, Dali::CameraActor::Property::LEFT_PLANE_DISTANCE ) DALI_PROPERTY( "rightPlaneDistance", FLOAT, false, false, true, Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE ) DALI_PROPERTY( "topPlaneDistance", FLOAT, false, false, true, Dali::CameraActor::Property::TOP_PLANE_DISTANCE ) @@ -425,7 +425,7 @@ void CameraActor::SetNearClippingPlane(float nearClippingPlane) mNearClippingPlane = nearClippingPlane; // sceneObject is being used in a separate thread; queue a message to set - SetNearClippingPlaneMessage(GetEventThreadServices(), GetCameraSceneObject(), mNearClippingPlane); + BakeNearClippingPlaneMessage(GetEventThreadServices(), GetCameraSceneObject(), mNearClippingPlane); } } @@ -434,6 +434,11 @@ float CameraActor::GetNearClippingPlane() const return mNearClippingPlane; } +float CameraActor::GetCurrentNearClippingPlane() const +{ + return GetCameraSceneObject().GetNearClippingPlane(GetEventThreadServices().GetEventBufferIndex()); +} + void CameraActor::SetFarClippingPlane(float farClippingPlane) { mPropertyChanged = true; @@ -442,7 +447,7 @@ void CameraActor::SetFarClippingPlane(float farClippingPlane) mFarClippingPlane = farClippingPlane; // sceneObject is being used in a separate thread; queue a message to set - SetFarClippingPlaneMessage(GetEventThreadServices(), GetCameraSceneObject(), mFarClippingPlane); + BakeFarClippingPlaneMessage(GetEventThreadServices(), GetCameraSceneObject(), mFarClippingPlane); } } @@ -451,6 +456,11 @@ float CameraActor::GetFarClippingPlane() const return mFarClippingPlane; } +float CameraActor::GetCurrentFarClippingPlane() const +{ + return GetCameraSceneObject().GetFarClippingPlane(GetEventThreadServices().GetEventBufferIndex()); +} + void CameraActor::SetInvertYAxis(bool invertYAxis) { if(invertYAxis != mInvertYAxis) @@ -859,6 +869,16 @@ Property::Value CameraActor::GetDefaultPropertyCurrentValue(Property::Index inde ret = GetCurrentAspectRatio(); break; } + case Dali::CameraActor::Property::NEAR_PLANE_DISTANCE: + { + ret = GetCurrentNearClippingPlane(); + break; + } + case Dali::CameraActor::Property::FAR_PLANE_DISTANCE: + { + ret = GetCurrentFarClippingPlane(); + break; + } case Dali::CameraActor::Property::LEFT_PLANE_DISTANCE: { ret = OrthographicSizeConverter(GetCurrentOrthographicSize(), GetCurrentAspectRatio(), mProjectionDirection).LeftPlaneDistance(); @@ -919,6 +939,16 @@ void CameraActor::OnNotifyDefaultPropertyAnimation(Animation& animation, Propert value.Get(mAspectRatio); break; } + case Dali::CameraActor::Property::NEAR_PLANE_DISTANCE: + { + value.Get(mNearClippingPlane); + break; + } + case Dali::CameraActor::Property::FAR_PLANE_DISTANCE: + { + value.Get(mFarClippingPlane); + break; + } } break; } @@ -941,6 +971,16 @@ void CameraActor::OnNotifyDefaultPropertyAnimation(Animation& animation, Propert AdjustValue(mAspectRatio, value); break; } + case Dali::CameraActor::Property::NEAR_PLANE_DISTANCE: + { + AdjustValue(mNearClippingPlane, value); + break; + } + case Dali::CameraActor::Property::FAR_PLANE_DISTANCE: + { + AdjustValue(mFarClippingPlane, value); + break; + } } break; } @@ -967,6 +1007,16 @@ const SceneGraph::PropertyBase* CameraActor::GetSceneObjectAnimatableProperty(Pr { property = GetCameraSceneObject().GetAspectRatio(); break; + } + case Dali::CameraActor::Property::NEAR_PLANE_DISTANCE: + { + property = GetCameraSceneObject().GetNearPlaneDistance(); + break; + } + case Dali::CameraActor::Property::FAR_PLANE_DISTANCE: + { + property = GetCameraSceneObject().GetFarPlaneDistance(); + break; } // no default on purpose as we chain method up to actor } @@ -985,14 +1035,14 @@ const PropertyInputImpl* CameraActor::GetSceneObjectInputProperty(Property::Inde switch(index) { - case Dali::CameraActor::Property::FIELD_OF_VIEW: + case Dali::CameraActor::Property::PROJECTION_MODE: { - property = GetCameraSceneObject().GetFieldOfView(); + property = GetCameraSceneObject().GetProjectionMode(); break; } - case Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE: + case Dali::CameraActor::Property::FIELD_OF_VIEW: { - property = GetCameraSceneObject().GetOrthographicSize(); + property = GetCameraSceneObject().GetFieldOfView(); break; } case Dali::CameraActor::Property::ASPECT_RATIO: @@ -1000,6 +1050,16 @@ const PropertyInputImpl* CameraActor::GetSceneObjectInputProperty(Property::Inde property = GetCameraSceneObject().GetAspectRatio(); break; } + case Dali::CameraActor::Property::NEAR_PLANE_DISTANCE: + { + property = GetCameraSceneObject().GetNearPlaneDistance(); + break; + } + case Dali::CameraActor::Property::FAR_PLANE_DISTANCE: + { + property = GetCameraSceneObject().GetFarPlaneDistance(); + break; + } case Dali::CameraActor::Property::PROJECTION_MATRIX: { property = GetCameraSceneObject().GetProjectionMatrix(); @@ -1009,6 +1069,21 @@ const PropertyInputImpl* CameraActor::GetSceneObjectInputProperty(Property::Inde { property = GetCameraSceneObject().GetViewMatrix(); break; + } + case Dali::CameraActor::Property::INVERT_Y_AXIS: + { + property = GetCameraSceneObject().GetInvertYAxis(); + break; + } + case Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE: + { + property = GetCameraSceneObject().GetOrthographicSize(); + break; + } + case Dali::DevelCameraActor::Property::PROJECTION_DIRECTION: + { + property = GetCameraSceneObject().GetProjectionDirection(); + break; } // no default on purpose as we chain method up to actor } diff --git a/dali/internal/event/actors/camera-actor-impl.h b/dali/internal/event/actors/camera-actor-impl.h index 74ccac5f9..3a20af0c6 100644 --- a/dali/internal/event/actors/camera-actor-impl.h +++ b/dali/internal/event/actors/camera-actor-impl.h @@ -291,6 +291,22 @@ private: */ float GetCurrentAspectRatio() const; + /** + * @brief Retrieve the CameraActor's near clipping plane distance from update side. + * This is either the last value set, or the currently animating value. + * It may be defferent to GetNearClippingPlane() if the set message hasn't been processed yet. + * @return Near clipping plane distance. + */ + float GetCurrentNearClippingPlane() const; + + /** + * @brief Retrieve the CameraActor's far clipping plane distance from update side. + * This is either the last value set, or the currently animating value. + * It may be defferent to GetFarClippingPlane() if the set message hasn't been processed yet. + * @return Far clipping plane distance. + */ + float GetCurrentFarClippingPlane() const; + private: // Data Vector3 mTarget; Vector2 mCanvasSize; diff --git a/dali/internal/update/manager/render-instruction-processor.cpp b/dali/internal/update/manager/render-instruction-processor.cpp index 1979da8a0..86406ae69 100644 --- a/dali/internal/update/manager/render-instruction-processor.cpp +++ b/dali/internal/update/manager/render-instruction-processor.cpp @@ -568,7 +568,7 @@ void RenderInstructionProcessor::Prepare(BufferIndex updateBuffe const Matrix& viewMatrix = renderTask.GetViewMatrix(updateBufferIndex); const SceneGraph::Camera& camera = renderTask.GetCamera(); - const bool isOrthographicCamera = camera.mProjectionMode == Dali::Camera::ProjectionMode::ORTHOGRAPHIC_PROJECTION; + const bool isOrthographicCamera = camera.mProjectionMode[0] == Dali::Camera::ProjectionMode::ORTHOGRAPHIC_PROJECTION; Viewport viewport; bool viewportSet = renderTask.QueryViewport(updateBufferIndex, viewport); diff --git a/dali/internal/update/render-tasks/scene-graph-camera.cpp b/dali/internal/update/render-tasks/scene-graph-camera.cpp index 733e69121..53c08e68c 100644 --- a/dali/internal/update/render-tasks/scene-graph-camera.cpp +++ b/dali/internal/update/render-tasks/scene-graph-camera.cpp @@ -370,19 +370,19 @@ void Camera::SetType(Dali::Camera::Type type) void Camera::SetProjectionMode(Dali::Camera::ProjectionMode mode) { - mProjectionMode = mode; + mProjectionMode.Bake(0, mode); mUpdateProjectionFlag = UPDATE_COUNT; } void Camera::SetProjectionDirection(Dali::DevelCameraActor::ProjectionDirection direction) { - mProjectionDirection = direction; + mProjectionDirection.Bake(0, direction); mUpdateProjectionFlag = UPDATE_COUNT; } void Camera::SetInvertYAxis(bool invertYAxis) { - mInvertYAxis = invertYAxis; + mInvertYAxis.Bake(0, invertYAxis); mUpdateProjectionFlag = UPDATE_COUNT; } @@ -404,15 +404,15 @@ void Camera::BakeAspectRatio(BufferIndex updateBufferIndex, float aspectRatio) mUpdateProjectionFlag = UPDATE_COUNT; } -void Camera::SetNearClippingPlane(float nearClippingPlane) +void Camera::BakeNearClippingPlane(BufferIndex updateBufferIndex, float nearClippingPlane) { - mNearClippingPlane = nearClippingPlane; + mNearClippingPlane.Bake(updateBufferIndex, nearClippingPlane); mUpdateProjectionFlag = UPDATE_COUNT; } -void Camera::SetFarClippingPlane(float farClippingPlane) +void Camera::BakeFarClippingPlane(BufferIndex updateBufferIndex, float farClippingPlane) { - mFarClippingPlane = farClippingPlane; + mFarClippingPlane.Bake(updateBufferIndex, farClippingPlane); mUpdateProjectionFlag = UPDATE_COUNT; } @@ -491,14 +491,14 @@ const Matrix& Camera::GetFinalProjectionMatrix(BufferIndex bufferIndex) const return mFinalProjection[bufferIndex]; } -const PropertyBase* Camera::GetFieldOfView() const +const PropertyBase* Camera::GetProjectionMode() const { - return &mFieldOfView; + return &mProjectionMode; } -const PropertyBase* Camera::GetOrthographicSize() const +const PropertyBase* Camera::GetFieldOfView() const { - return &mOrthographicSize; + return &mFieldOfView; } const PropertyBase* Camera::GetAspectRatio() const @@ -506,6 +506,16 @@ const PropertyBase* Camera::GetAspectRatio() const return &mAspectRatio; } +const PropertyBase* Camera::GetNearPlaneDistance() const +{ + return &mNearClippingPlane; +} + +const PropertyBase* Camera::GetFarPlaneDistance() const +{ + return &mFarClippingPlane; +} + const PropertyInputImpl* Camera::GetProjectionMatrix() const { return &mProjectionMatrix; @@ -516,6 +526,21 @@ const PropertyInputImpl* Camera::GetViewMatrix() const return &mViewMatrix; } +const PropertyBase* Camera::GetInvertYAxis() const +{ + return &mInvertYAxis; +} + +const PropertyBase* Camera::GetOrthographicSize() const +{ + return &mOrthographicSize; +} + +const PropertyBase* Camera::GetProjectionDirection() const +{ + return &mProjectionDirection; +} + void Camera::Update(BufferIndex updateBufferIndex) { // if this has changes in world position we need to update camera for next 2 frames @@ -768,8 +793,8 @@ Dali::Rect Camera::GetOrthographicClippingBox(BufferIndex bufferIndex) const float orthographicSize = mOrthographicSize[bufferIndex]; const float aspect = mAspectRatio[bufferIndex]; - const float halfWidth = mProjectionDirection == DevelCameraActor::ProjectionDirection::VERTICAL ? orthographicSize * aspect : orthographicSize; - const float halfHeight = mProjectionDirection == DevelCameraActor::ProjectionDirection::VERTICAL ? orthographicSize : orthographicSize / aspect; + const float halfWidth = mProjectionDirection[0] == DevelCameraActor::ProjectionDirection::VERTICAL ? orthographicSize * aspect : orthographicSize; + const float halfHeight = mProjectionDirection[0] == DevelCameraActor::ProjectionDirection::VERTICAL ? orthographicSize : orthographicSize / aspect; return Dali::Rect(-halfWidth, -halfHeight, halfWidth * 2.0f, halfHeight * 2.0f); } @@ -792,18 +817,18 @@ uint32_t Camera::UpdateProjection(BufferIndex updateBufferIndex) } else // UPDATE_COUNT == mUpdateProjectionFlag { - switch(mProjectionMode) + switch(mProjectionMode[0]) { case Dali::Camera::PERSPECTIVE_PROJECTION: { Matrix& projectionMatrix = mProjectionMatrix.Get(updateBufferIndex); Perspective(projectionMatrix, - mProjectionDirection, + static_cast(mProjectionDirection[0]), mFieldOfView[updateBufferIndex], mAspectRatio[updateBufferIndex], - mNearClippingPlane, - mFarClippingPlane, - mInvertYAxis); + mNearClippingPlane[updateBufferIndex], + mFarClippingPlane[updateBufferIndex], + mInvertYAxis[0]); //need to apply custom clipping plane if(mUseReflectionClip) @@ -822,7 +847,7 @@ uint32_t Camera::UpdateProjection(BufferIndex updateBufferIndex) } Vector4 customClipping = viewInv * adjReflectPlane; - AdjustNearPlaneForPerspective(projectionMatrix, customClipping, mFarClippingPlane); + AdjustNearPlaneForPerspective(projectionMatrix, customClipping, mFarClippingPlane[updateBufferIndex]); } break; } @@ -830,12 +855,12 @@ uint32_t Camera::UpdateProjection(BufferIndex updateBufferIndex) { Matrix& projectionMatrix = mProjectionMatrix.Get(updateBufferIndex); Orthographic(projectionMatrix, - mProjectionDirection, + static_cast(mProjectionDirection[0]), mOrthographicSize[updateBufferIndex], mAspectRatio[updateBufferIndex], - mNearClippingPlane, - mFarClippingPlane, - mInvertYAxis); + mNearClippingPlane[updateBufferIndex], + mFarClippingPlane[updateBufferIndex], + mInvertYAxis[0]); //need to apply custom clipping plane if(mUseReflectionClip) @@ -854,7 +879,7 @@ uint32_t Camera::UpdateProjection(BufferIndex updateBufferIndex) } Vector4 customClipping = viewInv * adjReflectPlane; - AdjustNearPlaneForOrthographic(projectionMatrix, customClipping, mFarClippingPlane); + AdjustNearPlaneForOrthographic(projectionMatrix, customClipping, mFarClippingPlane[updateBufferIndex]); } break; } diff --git a/dali/internal/update/render-tasks/scene-graph-camera.h b/dali/internal/update/render-tasks/scene-graph-camera.h index 278d765c8..2cc8912ae 100644 --- a/dali/internal/update/render-tasks/scene-graph-camera.h +++ b/dali/internal/update/render-tasks/scene-graph-camera.h @@ -50,6 +50,25 @@ namespace SceneGraph { class SceneController; +template<> +class AnimatableProperty : public AnimatableProperty +{ +public: + AnimatableProperty(Dali::Camera::ProjectionMode initialValue) + : AnimatableProperty(static_cast(initialValue)) + { + } +}; +template<> +class AnimatableProperty : public AnimatableProperty +{ +public: + AnimatableProperty(Dali::DevelCameraActor::ProjectionDirection initialValue) + : AnimatableProperty(static_cast(initialValue)) + { + } +}; + /** * Scene-graph camera object */ @@ -123,7 +142,7 @@ public: */ bool IsYAxisInverted() const { - return mInvertYAxis; + return mInvertYAxis[0]; } /** @@ -156,16 +175,6 @@ public: */ void SetBottomClippingPlane(float bottomClippingPlane); - /** - * @copydoc Dali::Internal::CameraActor::SetNearClippingPlane - */ - void SetNearClippingPlane(float nearClippingPlane); - - /** - * @copydoc Dali::Internal::CameraActor::SetFarClippingPlane - */ - void SetFarClippingPlane(float farClippingPlane); - /** * @copydoc Dali::Internal::CameraActor::RotateProjection */ @@ -227,6 +236,40 @@ public: return mAspectRatio[bufferIndex]; } + /** + * @brief Bakes the near clipping plane distance. + * @param[in] updateBufferIndex The current update buffer index. + * @param[in] nearClippingPlane The near clipping plane distance. + */ + void BakeNearClippingPlane(BufferIndex updateBufferIndex, float nearClippingPlane); + + /** + * @brief Retrieve the near clipping plane distance. + * @param[in] bufferIndex The buffer to read from. + * @return The near clipping plane distance. + */ + float GetNearClippingPlane(BufferIndex bufferIndex) const + { + return mNearClippingPlane[bufferIndex]; + } + + /** + * @brief Bakes the far clipping plane distance. + * @param[in] updateBufferIndex The current update buffer index. + * @param[in] farClippingPlane The far clipping plane distance. + */ + void BakeFarClippingPlane(BufferIndex updateBufferIndex, float farClippingPlane); + + /** + * @brief Retrieve the far clipping plane distance. + * @param[in] bufferIndex The buffer to read from. + * @return The far clipping plane distance. + */ + float GetFarClippingPlane(BufferIndex bufferIndex) const + { + return mFarClippingPlane[bufferIndex]; + } + /** * Sets the reflection plane * @param[in] plane reflection plane @@ -298,18 +341,18 @@ public: const Matrix& GetFinalProjectionMatrix(BufferIndex bufferIndex) const; /** - * Retrieve the field of view property querying interface. + * Retrieve the projection mode property querying interface. * @pre The camera is on-stage. - * @return The field of view property querying interface. + * @return The projection mode property querying interface. */ - const PropertyBase* GetFieldOfView() const; + const PropertyBase* GetProjectionMode() const; /** - * Retrieve the orthographic size property querying interface. + * Retrieve the field of view property querying interface. * @pre The camera is on-stage. - * @return The orthographic size property querying interface. + * @return The field of view property querying interface. */ - const PropertyBase* GetOrthographicSize() const; + const PropertyBase* GetFieldOfView() const; /** * Retrieve the aspect ratio property querying interface. @@ -318,6 +361,20 @@ public: */ const PropertyBase* GetAspectRatio() const; + /** + * Retrieve the near clipping plane distance property querying interface. + * @pre The camera is on-stage. + * @return The near clipping plane distance property querying interface. + */ + const PropertyBase* GetNearPlaneDistance() const; + + /** + * Retrieve the far clipping plane distance property querying interface. + * @pre The camera is on-stage. + * @return The far clipping plane distance property querying interface. + */ + const PropertyBase* GetFarPlaneDistance() const; + /** * Retrieve the projection-matrix property querying interface. * @pre The camera is on-stage. @@ -332,6 +389,27 @@ public: */ const PropertyInputImpl* GetViewMatrix() const; + /** + * Retrieve the value of InvertYAxis property querying interface. + * @pre The camera is on-stage. + * @return The InvertYAxis property value querying interface. + */ + const PropertyBase* GetInvertYAxis() const; + + /** + * Retrieve the orthographic size property querying interface. + * @pre The camera is on-stage. + * @return The orthographic size property querying interface. + */ + const PropertyBase* GetOrthographicSize() const; + + /** + * Retrieve the value of Projection Direction property querying interface. + * @pre The camera is on-stage. + * @return The Projection Direction property value querying interface. + */ + const PropertyBase* GetProjectionDirection() const; + /** * Updates view and projection matrices. * Called by the render task using the camera @@ -388,18 +466,18 @@ private: uint32_t mUpdateProjectionFlag; ///< This is non-zero if the projection matrix requires an update int mProjectionRotation; ///< The rotaion angle of the projection -public: // PROPERTIES - Dali::Camera::Type mType; // Non-animatable - Dali::Camera::ProjectionMode mProjectionMode; // Non-animatable - Dali::DevelCameraActor::ProjectionDirection mProjectionDirection; // Non-animatable - bool mInvertYAxis; // Non-animatable +public: // PROPERTIES + Dali::Camera::Type mType; // Non-animatable + AnimatableProperty mProjectionMode; // Non-animatable, constraint_input + AnimatableProperty mProjectionDirection; // Non-animatable, constraint_input + AnimatableProperty mInvertYAxis; // Non-animatable, constraint_input - AnimatableProperty mFieldOfView; // Animatable - AnimatableProperty mOrthographicSize; // Animatable - AnimatableProperty mAspectRatio; // Animatable + AnimatableProperty mFieldOfView; // Animatable + AnimatableProperty mOrthographicSize; // Animatable + AnimatableProperty mAspectRatio; // Animatable + AnimatableProperty mNearClippingPlane; // Animatable + AnimatableProperty mFarClippingPlane; // Animatable - float mNearClippingPlane; - float mFarClippingPlane; Vector3 mTargetPosition; Dali::Matrix mReflectionMtx; @@ -484,26 +562,26 @@ inline void BakeAspectRatioMessage(EventThreadServices& eventThreadServices, con new(slot) LocalType(&camera, &Camera::BakeAspectRatio, parameter); } -inline void SetNearClippingPlaneMessage(EventThreadServices& eventThreadServices, const Camera& camera, float parameter) +inline void BakeNearClippingPlaneMessage(EventThreadServices& eventThreadServices, const Camera& camera, float parameter) { - using LocalType = MessageValue1; + using LocalType = MessageDoubleBuffered1; // Reserve some memory inside the message queue uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); // Construct message in the message queue memory; note that delete should not be called on the return value - new(slot) LocalType(&camera, &Camera::SetNearClippingPlane, parameter); + new(slot) LocalType(&camera, &Camera::BakeNearClippingPlane, parameter); } -inline void SetFarClippingPlaneMessage(EventThreadServices& eventThreadServices, const Camera& camera, float parameter) +inline void BakeFarClippingPlaneMessage(EventThreadServices& eventThreadServices, const Camera& camera, float parameter) { - using LocalType = MessageValue1; + using LocalType = MessageDoubleBuffered1; // Reserve some memory inside the message queue uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); // Construct message in the message queue memory; note that delete should not be called on the return value - new(slot) LocalType(&camera, &Camera::SetFarClippingPlane, parameter); + new(slot) LocalType(&camera, &Camera::BakeFarClippingPlane, parameter); } inline void SetReflectByPlaneMessage(EventThreadServices& eventThreadServices, const Camera& camera, const Vector4& plane) diff --git a/dali/public-api/actors/camera-actor.h b/dali/public-api/actors/camera-actor.h index f1b214835..79db67d5f 100644 --- a/dali/public-api/actors/camera-actor.h +++ b/dali/public-api/actors/camera-actor.h @@ -106,8 +106,8 @@ public: */ enum { - TYPE = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, ///< name "type", type std::string @SINCE_1_0.0 - PROJECTION_MODE, ///< name "projectionMode", type std::string @SINCE_1_0.0 + TYPE = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, ///< name "type", type int @SINCE_1_0.0 + PROJECTION_MODE, ///< name "projectionMode", type int @SINCE_1_0.0 FIELD_OF_VIEW, ///< name "fieldOfView", type float @SINCE_1_0.0 ASPECT_RATIO, ///< name "aspectRatio", type float @SINCE_1_0.0 NEAR_PLANE_DISTANCE, ///< name "nearPlaneDistance", type float @SINCE_1_0.0 -- 2.34.1