Add CULLED property to Actor 69/189069/2
authorHeeyong Song <heeyong.song@samsung.com>
Thu, 13 Sep 2018 06:24:43 +0000 (15:24 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Fri, 14 Sep 2018 01:29:53 +0000 (10:29 +0900)
Change-Id: I56806718eb51757edee2042c5031b857ebd49f08

automated-tests/src/dali/utc-Dali-Actor.cpp
dali/devel-api/actors/actor-devel.h
dali/internal/event/actors/actor-impl.cpp
dali/internal/update/manager/render-instruction-processor.cpp
dali/internal/update/nodes/node.cpp
dali/internal/update/nodes/node.h

index 7ab3422..b0a5138 100644 (file)
@@ -263,6 +263,23 @@ struct ChildOrderChangedFunctor
   Actor& mActor;
 };
 
+struct CulledPropertyNotificationFunctor
+{
+  CulledPropertyNotificationFunctor( bool& signalCalled, PropertyNotification& propertyNotification )
+  : mSignalCalled( signalCalled ),
+    mPropertyNotification( propertyNotification )
+  { }
+
+  void operator()( PropertyNotification& source )
+  {
+    mSignalCalled  = true;
+    mPropertyNotification = source;
+  }
+
+  bool& mSignalCalled;
+  PropertyNotification& mPropertyNotification;
+};
+
 } // anonymous namespace
 
 
@@ -7175,3 +7192,50 @@ int UtcDaliChildMovedSignalP(void)
 
   END_TEST;
 }
+
+int utcDaliActorCulled(void)
+{
+  TestApplication application;
+  auto stage = Stage::GetCurrent();
+
+  tet_infoline( "Check that the actor is culled if the actor is out of the screen" );
+
+  Actor actor = Actor::New();
+  actor.SetSize( 10.0f, 10.0f );
+
+  Geometry geometry = CreateQuadGeometry();
+  Shader shader = CreateShader();
+  Renderer renderer = Renderer::New(geometry, shader);
+  actor.AddRenderer( renderer );
+
+  stage.Add( actor );
+
+  application.SendNotification();
+  application.Render( 0 );
+
+  DALI_TEST_EQUALS( actor.GetProperty< bool >( DevelActor::Property::CULLED ), false, TEST_LOCATION );
+
+  PropertyNotification notification = actor.AddPropertyNotification( DevelActor::Property::CULLED, LessThanCondition( 0.5f ) );
+  notification.SetNotifyMode( PropertyNotification::NotifyOnChanged );
+
+  // Connect NotifySignal
+  bool propertyNotificationSignal( false );
+  PropertyNotification source;
+  CulledPropertyNotificationFunctor f( propertyNotificationSignal, source );
+  notification.NotifySignal().Connect( &application, f ) ;
+
+  actor.SetPosition( 1000.0f, 1000.0f );
+
+  application.SendNotification();
+  application.Render();
+
+  application.SendNotification();
+
+  DALI_TEST_EQUALS( actor.GetProperty< bool >( DevelActor::Property::CULLED ), true, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( propertyNotificationSignal, true, TEST_LOCATION );
+  DALI_TEST_EQUALS( source.GetTargetProperty(), static_cast< int >( DevelActor::Property::CULLED ), TEST_LOCATION );
+  DALI_TEST_EQUALS( source.GetTarget().GetProperty< bool >( source.GetTargetProperty() ), true, TEST_LOCATION );
+
+  END_TEST;
+}
index 879742d..5a030a9 100644 (file)
@@ -119,6 +119,13 @@ enum Type
    * @note Setting this to false will allow scaling or rotation around the anchor-point without affecting the actor's position.
    */
   POSITION_USES_ANCHOR_POINT = INHERIT_LAYOUT_DIRECTION + 4,
+
+  /**
+   * @brief Returns whether the actor is culled or not.
+   * @details Name "culled", type Property::BOOLEAN. Read-only
+   * @note True means that the actor is out of the view frustum.
+   */
+  CULLED = INHERIT_LAYOUT_DIRECTION + 5,
 };
 
 } // namespace Property
index bbf91e8..0e3cf2e 100644 (file)
@@ -213,6 +213,7 @@ DALI_PROPERTY( "siblingOrder",              INTEGER,  true,  false, false, Dali:
 DALI_PROPERTY( "opacity",                   FLOAT,    true,  true,  true,  Dali::DevelActor::Property::OPACITY )
 DALI_PROPERTY( "screenPosition",            VECTOR2,  false, false, false, Dali::DevelActor::Property::SCREEN_POSITION )
 DALI_PROPERTY( "positionUsesAnchorPoint",   BOOLEAN,  true,  false, false, Dali::DevelActor::Property::POSITION_USES_ANCHOR_POINT )
+DALI_PROPERTY( "culled",                    BOOLEAN,  false, false, true, Dali::DevelActor::Property::CULLED )
 DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
 
 // Signals
@@ -3771,6 +3772,10 @@ const PropertyInputImpl* Actor::GetSceneObjectInputProperty( Property::Index ind
         property = &mNode->mWorldMatrix;
         break;
 
+      case Dali::DevelActor::Property::CULLED:
+        property = &mNode->mCulled;
+        break;
+
       default:
         break;
     }
@@ -4413,6 +4418,12 @@ bool Actor::GetCurrentPropertyValue( Property::Index index, Property::Value& val
       break;
     }
 
+    case DevelActor::Property::CULLED:
+    {
+      value = mNode->IsCulled( GetEventThreadServices().GetEventBufferIndex() );
+      break;
+    }
+
     default:
     {
       // Must be an event-side only property
index 983b799..bdcbf46 100644 (file)
@@ -160,7 +160,7 @@ inline void AddRendererToRenderList( BufferIndex updateBufferIndex,
                                      bool cull )
 {
   bool inside( true );
-  const Node* node = renderable.mNode;
+  Node* node = renderable.mNode;
 
   if( cull && renderable.mRenderer && !renderable.mRenderer->GetShader().HintEnabled( Dali::Shader::Hint::MODIFIES_GEOMETRY ) )
   {
@@ -202,6 +202,12 @@ inline void AddRendererToRenderList( BufferIndex updateBufferIndex,
 
       Matrix::Multiply( item.mModelViewMatrix, item.mModelMatrix, viewMatrix );
     }
+
+     node->SetCulled( updateBufferIndex, false );
+  }
+  else
+  {
+     node->SetCulled( updateBufferIndex, true );
   }
 }
 
index 48feb8d..6c39e87 100755 (executable)
@@ -88,6 +88,7 @@ Node::Node( unsigned int id )
   mOrientation(),                                                                 // Initialized to identity by default
   mScale( TRANSFORM_PROPERTY_SCALE ),
   mVisible( true ),
+  mCulled( false ),
   mColor( Color::WHITE ),
   mWorldPosition( TRANSFORM_PROPERTY_WORLD_POSITION, Vector3( 0.0f,0.0f,0.0f ) ), // Zero initialized by default
   mWorldScale( TRANSFORM_PROPERTY_WORLD_SCALE, Vector3( 1.0f,1.0f,1.0f ) ),
index a38bda5..f025726 100755 (executable)
@@ -743,6 +743,26 @@ public:
     }
   }
 
+  /**
+   * @brief Sets whether the node is culled or not.
+   * @param[in] bufferIndex The buffer to read from.
+   * @param[in] culled True if the node is culled.
+   */
+  void SetCulled( BufferIndex bufferIndex, bool culled )
+  {
+    mCulled[bufferIndex] = culled;
+  }
+
+  /**
+   * @brief Retrieves whether the node is culled or not.
+   * @param[in] bufferIndex The buffer to read from.
+   * @return True if the node is culled.
+   */
+  bool IsCulled( BufferIndex bufferIndex ) const
+  {
+    return mCulled[bufferIndex];
+  }
+
 public:
   /**
    * @copydoc UniformMap::Add
@@ -858,6 +878,7 @@ public: // Default properties
   TransformManagerPropertyVector3    mScale;                  ///< Local transform; scale relative to parent node
 
   AnimatableProperty<bool>           mVisible;                ///< Visibility can be inherited from the Node hierachy
+  AnimatableProperty<bool>           mCulled;                 ///< True if the node is culled. This is not animatable. It is just double-buffered.
   AnimatableProperty<Vector4>        mColor;                  ///< Color can be inherited from the Node hierarchy
 
   // Inherited properties; read-only from public API