1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_NODE_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_NODE_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://floralicense.org/license/
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
21 #include <dali/public-api/actors/actor-enumerations.h>
22 #include <dali/public-api/actors/draw-mode.h>
23 #include <dali/public-api/math/quaternion.h>
24 #include <dali/public-api/math/math-utils.h>
25 #include <dali/public-api/math/vector3.h>
26 #include <dali/internal/common/message.h>
27 #include <dali/internal/common/event-to-update.h>
28 #include <dali/internal/update/common/animatable-property.h>
29 #include <dali/internal/update/common/double-buffered.h>
30 #include <dali/internal/update/common/property-owner.h>
31 #include <dali/internal/update/common/property-vector3.h>
32 #include <dali/internal/update/common/scene-graph-buffers.h>
33 #include <dali/internal/update/common/inherited-property.h>
34 #include <dali/integration-api/debug.h>
35 #include <dali/internal/update/nodes/node-declarations.h>
36 #include <dali/internal/update/node-attachments/node-attachment-declarations.h>
37 #include <dali/internal/render/renderers/render-data-provider.h>
45 // value types used by messages
46 template <> struct ParameterType< ColorMode > : public BasicType< ColorMode > {};
47 template <> struct ParameterType< PositionInheritanceMode > : public BasicType< PositionInheritanceMode > {};
60 * Flag whether property has changed, during the Update phase.
62 enum NodePropertyFlags
65 TransformFlag = 0x001,
71 SortModifierFlag = 0x040,
72 ChildDeletedFlag = 0x080
75 static const int AllFlags = ( ChildDeletedFlag << 1 ) - 1; // all the flags
78 * Size is not inherited.
79 * VisibleFlag is inherited so that attachments can be synchronized with nodes after they become visible
81 static const int InheritedDirtyFlags = TransformFlag | VisibleFlag | ColorFlag | ShaderFlag | OverlayFlag;
83 // Flags which require the scene renderable lists to be updated
84 static const int RenderableUpdateFlags = TransformFlag | SortModifierFlag | ChildDeletedFlag;
87 * Node is the base class for all nodes in the Scene Graph.
88 * Each node provides a transformation which applies to the node and its children.
89 * Node data is double-buffered. This allows an update thread to modify node data, without interferring
90 * with another thread reading the values from the previous update traversal.
92 class Node : public PropertyOwner, public RenderDataProvider
97 static const PositionInheritanceMode DEFAULT_POSITION_INHERITANCE_MODE;
98 static const ColorMode DEFAULT_COLOR_MODE;
103 * Construct a new Node.
113 * When a Node is marked "active" it has been disconnected, but its properties have been modified.
114 * @note An inactive Node will be skipped during the UpdateManager ResetProperties stage.
115 * @param[in] isActive True if the Node is active.
117 void SetActive( bool isActive )
119 mIsActive = isActive;
123 * Query whether the Node is active.
124 * @return True if the Node is active.
126 bool IsActive() const
132 * Called during UpdateManager::DestroyNode shortly before Node is destroyed.
139 * Query whether the node is a layer.
140 * @return True if the node is a layer.
144 return (GetLayer() != NULL);
148 * Convert a node to a layer.
149 * @return A pointer to the layer, or NULL.
151 virtual Layer* GetLayer()
159 * Attach an object to this Node; This should only be done by UpdateManager::AttachToNode.
160 * @pre The Node does not already have an attachment.
161 * @param[in] attachment The object to attach.
163 void Attach( NodeAttachment& attachment );
166 * Query the node if it has an attachment.
167 * @return True if it has an attachment.
169 bool HasAttachment() const
175 * Retreive the object attached to this node.
176 * @return The attachment.
178 NodeAttachment& GetAttachment() const
183 // Containment methods
186 * Query whether a node is the root node. Root nodes cannot have a parent node.
187 * A node becomes a root node, when it is installed by UpdateManager.
188 * @return True if the node is a root node.
196 * Set whether a node is the root node. Root nodes cannot have a parent node.
197 * This method should only be called by UpdateManager.
198 * @pre When isRoot is true, the node must not have a parent.
199 * @param[in] isRoot Whether the node is now a root node.
201 void SetRoot(bool isRoot);
204 * Retrieve the parent of a Node.
205 * @return The parent node, or NULL if the Node has not been added to the scene-graph.
213 * Retrieve the parent of a Node.
214 * @return The parent node, or NULL if the Node has not been added to the scene-graph.
216 const Node* GetParent() const
222 * Connect a node to the scene-graph.
223 * @pre A node cannot be added to itself.
224 * @pre The parent node is connected to the scene-graph.
225 * @pre The childNode does not already have a parent.
226 * @pre The childNode is not a root node.
227 * @param[in] childNode The child to add.
229 void ConnectChild( Node* childNode );
232 * Disconnect a child (& its children) from the scene-graph.
233 * @pre childNode is a child of this Node.
234 * @param[in] updateBufferIndex The current update buffer index.
235 * @param[in] childNode The node to disconnect.
236 * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
237 * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
239 void DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes );
242 * Retrieve the children a Node.
243 * @return The container of children.
245 const NodeContainer& GetChildren() const
251 * Retrieve the children a Node.
252 * @return The container of children.
254 NodeContainer& GetChildren()
262 * Set whether the node inherits a shader effect from its parent.
263 * The inherited effect can be overriden using ApplyShader()
264 * @param [in] inherit True if the parent effect is inherited.
266 void SetInheritShader(bool inherit)
268 if (inherit != mInheritShader)
270 mInheritShader = inherit;
272 SetDirtyFlag(ShaderFlag);
277 * Query whether the node inherits a shader from its parent.
278 * @return True if the parent effect is inherited.
280 bool GetInheritShader() const
282 return mInheritShader;
286 * Apply a shader object to this Node.
287 * Shader effects are weakly referenced, potentially by multiple nodes & node attachments.
288 * @param[in] shader The shader to apply.
290 void ApplyShader( Shader* shader );
293 * Remove the shader object from this Node (if any).
298 * Retrieve the applied shader.
299 * @return The applied shader.
301 Shader* GetAppliedShader() const;
304 * Sets the inherited shader of the node.
305 * @param[in] shader The new inherited shader.
307 void SetInheritedShader(Shader* shader);
310 * Retrieve the inherited shader.
311 * @return The inherited shader.
313 Shader* GetInheritedShader() const;
316 * Inherit a shader (if any) applied to the parent node.
317 * This method should only be called when the parents inherited shader is up-to-date.
318 * @param defaultShader pointer to the default shader, used if inherit shader is set to false
319 * @pre The node has a parent.
321 void InheritShader(Shader* defaultShader);
326 * Flag that one of the node values has changed in the current frame.
327 * @param[in] flag The flag to set.
329 void SetDirtyFlag(NodePropertyFlags flag)
335 * Flag that all of the node values are dirty.
337 void SetAllDirtyFlags()
339 mDirtyFlags = AllFlags;
343 * Query whether a node is dirty.
344 * @return The dirty flags
346 int GetDirtyFlags() const;
349 * Query whether a node is clean.
350 * @return True if the node is clean.
354 return ( NothingFlag == GetDirtyFlags() );
358 * Retrieve the parent-origin of the node.
359 * @return The parent-origin.
361 const Vector3& GetParentOrigin() const
363 return mParentOrigin.mValue;
367 * Sets both the local & base parent-origins of the node.
368 * @param[in] origin The new local & base parent-origins.
370 void SetParentOrigin(const Vector3& origin)
372 mParentOrigin.mValue = origin;
373 mParentOrigin.OnSet();
377 * Retrieve the anchor-point of the node.
378 * @return The anchor-point.
380 const Vector3& GetAnchorPoint() const
382 return mAnchorPoint.mValue;
386 * Sets both the local & base anchor-points of the node.
387 * @param[in] anchor The new local & base anchor-points.
389 void SetAnchorPoint(const Vector3& anchor)
391 mAnchorPoint.mValue = anchor;
392 mAnchorPoint.OnSet();
396 * Retrieve the local position of the node, relative to its parent.
397 * @param[in] bufferIndex The buffer to read from.
398 * @return The local position.
400 const Vector3& GetPosition(BufferIndex bufferIndex) const
402 return mPosition[bufferIndex];
406 * Sets both the local & base positions of the node.
407 * @param[in] updateBufferIndex The current update buffer index.
408 * @param[in] position The new local & base position.
410 void BakePosition(BufferIndex updateBufferIndex, const Vector3& position)
412 mPosition.Bake( updateBufferIndex, position );
416 * Sets the world of the node derived from the position of all its parents.
417 * @param[in] updateBufferIndex The current update buffer index.
418 * @param[in] position The world position.
420 void SetWorldPosition( BufferIndex updateBufferIndex, const Vector3& position )
422 mWorldPosition.Set( updateBufferIndex, position );
426 * Sets the position of the node derived from the position of all its parents.
427 * This method should only be called when the parent's world position is up-to-date.
428 * With a non-central anchor-point, the local rotation and scale affects the world position.
429 * Therefore the world rotation & scale must be updated before the world position.
430 * @pre The node has a parent.
431 * @param[in] updateBufferIndex The current update buffer index.
433 void InheritWorldPosition(BufferIndex updateBufferIndex)
435 DALI_ASSERT_DEBUG(mParent != NULL);
437 switch( mPositionInheritanceMode )
439 case INHERIT_PARENT_POSITION : ///@see Dali::PositionInheritanceMode for how these modes are expected to work
441 Vector3 finalPosition(-0.5f, -0.5f, -0.5f);
443 finalPosition += mParentOrigin.mValue;
444 finalPosition *= mParent->GetSize(updateBufferIndex);
445 finalPosition += mPosition[updateBufferIndex];
446 finalPosition *= mParent->GetWorldScale(updateBufferIndex);
447 const Quaternion& parentWorldRotation = mParent->GetWorldRotation(updateBufferIndex);
448 if(!parentWorldRotation.IsIdentity())
450 finalPosition *= parentWorldRotation;
453 // check if a node needs to be offsetted locally (only applies when AnchorPoint is not central)
454 // dont use operator== as that does a slower comparison (and involves function calls)
455 Vector3 localOffset(0.5f, 0.5f, 0.5f); // AnchorPoint::CENTER
456 localOffset -= mAnchorPoint.mValue;
458 if( ( fabsf( localOffset.x ) >= Math::MACHINE_EPSILON_0 ) ||
459 ( fabsf( localOffset.y ) >= Math::MACHINE_EPSILON_0 ) ||
460 ( fabsf( localOffset.z ) >= Math::MACHINE_EPSILON_0 ) )
462 localOffset *= mSize[updateBufferIndex];
464 Vector3 scale = mWorldScale[updateBufferIndex];
465 if(GetTransmitGeometryScaling())
467 // Remove geometry scaling to get back to actor scale
468 scale /= mGeometryScale;
470 // Also pick up sign of local scale
471 if (mScale[updateBufferIndex].x < 0.0f)
475 if (mScale[updateBufferIndex].y < 0.0f)
479 if (mScale[updateBufferIndex].z < 0.0f)
484 // If the anchor-point is not central, then position is affected by the local rotation & scale
485 localOffset *= scale;
486 const Quaternion& localWorldRotation = mWorldRotation[updateBufferIndex];
487 if(!localWorldRotation.IsIdentity())
489 localOffset *= localWorldRotation;
491 finalPosition += localOffset;
494 finalPosition += mParent->GetWorldPosition(updateBufferIndex);
495 mWorldPosition.Set( updateBufferIndex, finalPosition );
498 case USE_PARENT_POSITION_PLUS_LOCAL_POSITION :
500 // copy parents position plus local transform
501 mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) + mPosition[updateBufferIndex] );
504 case USE_PARENT_POSITION :
506 // copy parents position
507 mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) );
510 case DONT_INHERIT_POSITION :
512 // use local position as world position
513 mWorldPosition.Set( updateBufferIndex, mPosition[updateBufferIndex] );
520 * Copies the previous inherited position, if this changed in the previous frame.
521 * This method should be called instead of InheritWorldPosition i.e. if the inherited position
522 * does not need to be recalculated in the current frame.
523 * @param[in] updateBufferIndex The current update buffer index.
525 void CopyPreviousWorldPosition( BufferIndex updateBufferIndex )
527 mWorldPosition.CopyPrevious( updateBufferIndex );
531 * Retrieve the position of the node derived from the position of all its parents.
532 * @return The world position.
534 const Vector3& GetWorldPosition( BufferIndex bufferIndex ) const
536 return mWorldPosition[bufferIndex];
540 * Set the position inheritance mode.
541 * @see Dali::Actor::PositionInheritanceMode
542 * @param[in] mode The new position inheritance mode.
544 void SetPositionInheritanceMode( PositionInheritanceMode mode )
546 mPositionInheritanceMode = mode;
548 SetDirtyFlag(TransformFlag);
552 * @return The position inheritance mode.
554 PositionInheritanceMode GetPositionInheritanceMode() const
556 return mPositionInheritanceMode;
560 * Retrieve the local rotation of the node, relative to its parent.
561 * @param[in] bufferIndex The buffer to read from.
562 * @return The local rotation.
564 const Quaternion& GetRotation(BufferIndex bufferIndex) const
566 return mRotation[bufferIndex];
570 * Sets both the local & base rotations of the node.
571 * @param[in] updateBufferIndex The current update buffer index.
572 * @param[in] rotation The new local & base rotation.
574 void BakeRotation(BufferIndex updateBufferIndex, const Quaternion& rotation)
576 mRotation.Bake( updateBufferIndex, rotation );
580 * Sets the rotation of the node derived from the rotation of all its parents.
581 * @param[in] updateBufferIndex The current update buffer index.
582 * @param[in] rotation The world rotation.
584 void SetWorldRotation( BufferIndex updateBufferIndex, const Quaternion& rotation )
586 mWorldRotation.Set( updateBufferIndex, rotation );
590 * Sets the rotation of the node derived from the rotation of all its parents.
591 * This method should only be called when the parents world rotation is up-to-date.
592 * @pre The node has a parent.
593 * @param[in] updateBufferIndex The current update buffer index.
595 void InheritWorldRotation( BufferIndex updateBufferIndex )
597 DALI_ASSERT_DEBUG(mParent != NULL);
599 const Quaternion& localRotation = mRotation[updateBufferIndex];
601 if(localRotation.IsIdentity())
603 mWorldRotation.Set( updateBufferIndex, mParent->GetWorldRotation(updateBufferIndex) );
607 Quaternion finalRotation( mParent->GetWorldRotation(updateBufferIndex) );
608 finalRotation *= localRotation;
609 mWorldRotation.Set( updateBufferIndex, finalRotation );
614 * Copies the previous inherited rotation, if this changed in the previous frame.
615 * This method should be called instead of InheritWorldRotation i.e. if the inherited rotation
616 * does not need to be recalculated in the current frame.
617 * @param[in] updateBufferIndex The current update buffer index.
619 void CopyPreviousWorldRotation( BufferIndex updateBufferIndex )
621 mWorldRotation.CopyPrevious( updateBufferIndex );
625 * Retrieve the rotation of the node derived from the rotation of all its parents.
626 * @param[in] bufferIndex The buffer to read from.
627 * @return The world rotation.
629 const Quaternion& GetWorldRotation( BufferIndex bufferIndex ) const
631 return mWorldRotation[bufferIndex];
635 * Set whether the Node inherits rotation.
636 * @param[in] inherit True if the parent rotation is inherited.
638 void SetInheritRotation(bool inherit)
640 if (inherit != mInheritRotation)
642 mInheritRotation = inherit;
644 SetDirtyFlag(TransformFlag);
649 * Query whether the node inherits rotation from its parent.
650 * @return True if the parent rotation is inherited.
652 bool IsRotationInherited() const
654 return mInheritRotation;
658 * Set the initial volume of the node. Used for calculating geometry scaling
659 * as the node size is changed when transmitGeometryScaling is set to true.
661 * This property is not animatable.
663 * @param[in] volume The initial volume of this nodes meshes & children
665 void SetInitialVolume( const Vector3& volume)
667 mInitialVolume = volume;
668 SetDirtyFlag(SizeFlag);
672 * Get the initial volume. Used for calculating geometry scaling
673 * when TransmitGeometryScaling is true (i.e., the scaling is baked
674 * into the node tranform)
676 * @return The initial volume of this node and children.
678 Vector3 GetInitialVolume()
680 return mInitialVolume;
684 * Sets whether the geometry scaling should be applied to the node
685 * (In which case, set the initial scale using SetInitialVolume()).
687 * If it is applied to the node, then the attachments are not scaled,
688 * as the scaling is then already baked into the node transform.
690 * @param[in] transmitGeometryScaling true if scaling is to be applied
693 void SetTransmitGeometryScaling(bool transmitGeometryScaling)
695 mTransmitGeometryScaling = transmitGeometryScaling;
696 SetDirtyFlag(SizeFlag);
700 * Find out whether the node allows geometry scaling to be transmitted to its children.
701 * @return true if transmitted.
703 bool GetTransmitGeometryScaling() const
705 return mTransmitGeometryScaling;
709 * Retrieve the local scale of the node, relative to its parent.
710 * @param[in] bufferIndex The buffer to read from.
711 * @return The local scale.
713 const Vector3& GetScale(BufferIndex bufferIndex) const
715 return mScale[bufferIndex];
719 * Sets the scale of the node derived from the scale of all its parents and a pre-scale
720 * @param[in] updateBufferIndex The current update buffer index.
721 * @param[in] scale The world scale.
723 void SetWorldScale(BufferIndex updateBufferIndex, const Vector3& scale)
725 mWorldScale.Set( updateBufferIndex, mGeometryScale * scale );
729 * Sets the scale of the node derived from the scale of all its parents and a pre-scale.
730 * This method should only be called when the parents world scale is up-to-date.
731 * @pre The node has a parent.
732 * @param[in] updateBufferIndex The current update buffer index.
734 void InheritWorldScale(BufferIndex updateBufferIndex)
736 DALI_ASSERT_DEBUG(mParent != NULL);
738 mWorldScale.Set( updateBufferIndex, mParent->GetWorldScale(updateBufferIndex) * mGeometryScale * mScale[updateBufferIndex] );
742 * Copies the previous inherited scale, if this changed in the previous frame.
743 * This method should be called instead of InheritWorldScale i.e. if the inherited scale
744 * does not need to be recalculated in the current frame.
745 * @param[in] updateBufferIndex The current update buffer index.
747 void CopyPreviousWorldScale( BufferIndex updateBufferIndex )
749 mWorldScale.CopyPrevious( updateBufferIndex );
753 * Retrieve the scale of the node derived from the scale of all its parents.
754 * @param[in] bufferIndex The buffer to read from.
755 * @return The world scale.
757 const Vector3& GetWorldScale( BufferIndex bufferIndex ) const
759 return mWorldScale[bufferIndex];
763 * Set whether the Node inherits scale.
764 * @param inherit True if the Node inherits scale.
766 void SetInheritScale( bool inherit )
768 if( inherit != mInheritScale )
770 mInheritScale = inherit;
772 SetDirtyFlag( TransformFlag );
777 * Query whether the Node inherits scale.
778 * @return if scale is inherited
780 bool IsScaleInherited() const
782 return mInheritScale;
786 * Sets a geometry scale, calculated when TransmitGeometryScaling is true.
787 * Must only be used from render thread.
788 * @param[in] geometryScale The geometry scale value
790 void SetGeometryScale(Vector3 geometryScale)
792 mGeometryScale = geometryScale;
794 SetDirtyFlag( TransformFlag );
798 * Retrieve the geometry scale, calculated when TransmitGeometryScaling is true.
799 * @return The geometry scale value.
801 const Vector3& GetGeometryScale() const
803 return mGeometryScale;
807 * Retrieve the visibility of the node.
808 * @param[in] bufferIndex The buffer to read from.
809 * @return True if the node is visible.
811 bool IsVisible(BufferIndex bufferIndex) const
813 return mVisible[bufferIndex];
817 * Retrieves whether a node is fully visible.
818 * A node is fully visible if is visible and all its ancestors are visible.
819 * @param[in] updateBufferIndex The current update buffer index.
820 * @return True if the node is fully visible.
822 bool IsFullyVisible( BufferIndex updateBufferIndex ) const;
825 * Retrieve the opacity of the node.
826 * @param[in] bufferIndex The buffer to read from.
827 * @return The opacity.
829 float GetOpacity(BufferIndex bufferIndex) const
831 return mColor[bufferIndex].a;
835 * Retrieve the color of the node.
836 * @param[in] bufferIndex The buffer to read from.
839 const Vector4& GetColor(BufferIndex bufferIndex) const
841 return mColor[bufferIndex];
845 * Sets the color of the node derived from the color of all its parents.
846 * @param[in] color The world color.
847 * @param[in] updateBufferIndex The current update buffer index.
849 void SetWorldColor(const Vector4& color, BufferIndex updateBufferIndex)
851 mWorldColor.Set( updateBufferIndex, color );
855 * Sets the color of the node derived from the color of all its parents.
856 * This method should only be called when the parents world color is up-to-date.
857 * @pre The node has a parent.
858 * @param[in] updateBufferIndex The current update buffer index.
860 void InheritWorldColor( BufferIndex updateBufferIndex )
862 DALI_ASSERT_DEBUG(mParent != NULL);
865 if( mColorMode == USE_OWN_MULTIPLY_PARENT_ALPHA )
867 const Vector4& ownColor = mColor[updateBufferIndex];
868 mWorldColor.Set( updateBufferIndex, ownColor.r, ownColor.g, ownColor.b, ownColor.a * mParent->GetWorldColor(updateBufferIndex).a );
870 else if( mColorMode == USE_OWN_MULTIPLY_PARENT_COLOR )
872 mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) * mColor[updateBufferIndex] );
874 else if( mColorMode == USE_PARENT_COLOR )
876 mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) );
878 else // USE_OWN_COLOR
880 mWorldColor.Set( updateBufferIndex, mColor[updateBufferIndex] );
885 * Copies the previous inherited scale, if this changed in the previous frame.
886 * This method should be called instead of InheritWorldScale i.e. if the inherited scale
887 * does not need to be recalculated in the current frame.
888 * @param[in] updateBufferIndex The current update buffer index.
890 void CopyPreviousWorldColor( BufferIndex updateBufferIndex )
892 mWorldColor.CopyPrevious( updateBufferIndex );
896 * Retrieve the color of the node, possibly derived from the color
897 * of all its parents, depending on the value of mColorMode.
898 * @param[in] bufferIndex The buffer to read from.
899 * @return The world color.
901 const Vector4& GetWorldColor(BufferIndex bufferIndex) const
903 return mWorldColor[bufferIndex];
907 * Set the color mode. This specifies whether the Node uses its own color,
908 * or inherits its parent color.
909 * @param[in] colorMode The new color mode.
911 void SetColorMode(ColorMode colorMode)
913 mColorMode = colorMode;
915 SetDirtyFlag(ColorFlag);
919 * Retrieve the color mode.
920 * @return The color mode.
922 ColorMode GetColorMode() const
928 * Retrieve the size of the node.
929 * @param[in] bufferIndex The buffer to read from.
932 const Vector3& GetSize(BufferIndex bufferIndex) const
934 return mSize[bufferIndex];
938 * Set the world-matrix of a node, with scale + rotation + translation.
939 * Scale and rotation are centered at the origin.
940 * Translation is applied independently of the scale or rotatation axis.
941 * @param[in] updateBufferIndex The current update buffer index.
942 * @param[in] scale The scale.
943 * @param[in] rotation The rotation.
944 * @param[in] translation The translation.
946 void SetWorldMatrix( BufferIndex updateBufferIndex, const Vector3& scale, const Quaternion& rotation, const Vector3& translation )
948 mWorldMatrix.Get( updateBufferIndex ).SetTransformComponents( scale, rotation, translation );
949 mWorldMatrix.SetDirty( updateBufferIndex );
953 * Retrieve the cached world-matrix of a node.
954 * @param[in] bufferIndex The buffer to read from.
955 * @return The world-matrix.
957 const Matrix& GetWorldMatrix( BufferIndex bufferIndex ) const
959 return mWorldMatrix[ bufferIndex ];
963 * Copy previous frames world matrix
964 * @param[in] updateBufferIndex The current update buffer index.
966 void CopyPreviousWorldMatrix( BufferIndex updateBufferIndex )
968 mWorldMatrix.CopyPrevious( updateBufferIndex );
972 * Mark the node as exclusive to a single RenderTask.
973 * @param[in] renderTask The render-task, or NULL if the Node is not exclusive to a single RenderTask.
975 void SetExclusiveRenderTask( RenderTask* renderTask )
977 mExclusiveRenderTask = renderTask;
981 * Query whether the node is exclusive to a single RenderTask.
982 * @return The render-task, or NULL if the Node is not exclusive to a single RenderTask.
984 RenderTask* GetExclusiveRenderTask() const
986 return mExclusiveRenderTask;
990 * Set how the Node and its children should be drawn; see Dali::Actor::SetDrawMode() for more details.
991 * @param[in] drawMode The new draw-mode to use.
993 void SetDrawMode( const DrawMode::Type& drawMode )
995 mDrawMode = drawMode;
999 * Returns whether node is an overlay or not.
1000 * @return True if node is an overlay, false otherwise.
1002 DrawMode::Type GetDrawMode() const
1008 * Equality operator, checks for identity, not values.
1011 bool operator==( const Node* rhs ) const
1021 * Set the inhibit local transform flag.@n
1022 * Setting this flag will stop the node's local transform (position, scale and orientation)
1023 * being applied on top of its parents transformation.
1024 * @param[in] flag When true, local transformation is inhibited when calculating the world matrix.
1026 void SetInhibitLocalTransform( bool flag )
1028 SetDirtyFlag( TransformFlag );
1029 mInhibitLocalTransform = flag;
1033 * Get the inhibit local transform flag.@n
1034 * See @ref SetInhibitLocalTransform
1035 * @result A flag, when true, local transformation is inhibited when calculating the world matrix.
1037 bool GetInhibitLocalTransform() const
1039 return mInhibitLocalTransform;
1045 * Set the parent of a Node.
1046 * @param[in] parentNode the new parent.
1048 void SetParent(Node& parentNode);
1051 * Protected constructor; See also Node::New()
1055 private: // from RenderDataProvider
1058 * @copydoc RenderDataProvider::GetModelMatrix
1060 virtual const Matrix& GetModelMatrix( unsigned int bufferId )
1062 return GetWorldMatrix( bufferId );
1066 * @copydoc RenderDataProvider::GetRenderColor
1068 virtual const Vector4& GetRenderColor( unsigned int bufferId )
1070 return GetWorldColor( bufferId );
1079 Node& operator=(const Node& rhs);
1082 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
1084 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
1087 * Recursive helper to disconnect a Node and its children.
1088 * Disconnected Nodes have no parent or children.
1089 * @param[in] updateBufferIndex The current update buffer index.
1090 * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
1091 * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
1093 void RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes );
1095 public: // Default properties
1097 PropertyVector3 mParentOrigin; ///< Local transform; the position is relative to this. Sets the TransformFlag dirty when changed
1098 PropertyVector3 mAnchorPoint; ///< Local transform; local center of rotation. Sets the TransformFlag dirty when changed
1100 AnimatableProperty<Vector3> mSize; ///< Size is provided for layouting
1101 AnimatableProperty<Vector3> mPosition; ///< Local transform; distance between parent-origin & anchor-point
1102 AnimatableProperty<Quaternion> mRotation; ///< Local transform; rotation relative to parent node
1103 AnimatableProperty<Vector3> mScale; ///< Local transform; scale relative to parent node
1104 AnimatableProperty<bool> mVisible; ///< Visibility can be inherited from the Node hierachy
1105 AnimatableProperty<Vector4> mColor; ///< Color can be inherited from the Node hierarchy
1107 // Inherited properties; read-only from public API
1109 InheritedProperty<Vector3> mWorldPosition; ///< Full inherited position
1110 InheritedProperty<Quaternion> mWorldRotation; ///< Full inherited rotation
1111 InheritedProperty<Vector3> mWorldScale; ///< Full inherited scale
1112 InheritedProperty<Matrix> mWorldMatrix; ///< Full inherited world matrix
1113 InheritedColor mWorldColor; ///< Full inherited color
1117 Node* mParent; ///< Pointer to parent node (a child is owned by its parent)
1118 Shader* mAppliedShader; ///< A pointer to an applied shader
1119 Shader* mInheritedShader; ///< A pointer to an inherited shader
1120 RenderTask* mExclusiveRenderTask; ///< Nodes can be marked as exclusive to a single RenderTask
1122 NodeAttachmentOwner mAttachment; ///< Optional owned attachment
1123 NodeContainer mChildren; ///< Container of children; not owned
1125 Vector3 mGeometryScale; ///< Applied before calculating world transform.
1126 Vector3 mInitialVolume; ///< Initial volume... TODO - need a better name
1128 // flags, compressed to bitfield
1129 int mDirtyFlags:10; ///< A composite set of flags for each of the Node properties
1131 bool mIsRoot:1; ///< True if the node cannot have a parent
1132 bool mInheritShader:1; ///< Whether the parent's shader should be inherited.
1133 bool mInheritRotation:1; ///< Whether the parent's rotation should be inherited.
1134 bool mInheritScale:1; ///< Whether the parent's scale should be inherited.
1135 bool mTransmitGeometryScaling:1; ///< Whether geometry scaling should be applied to world transform.
1136 bool mInhibitLocalTransform:1; ///< whether local transform should be applied.
1137 bool mIsActive:1; ///< When a Node is marked "active" it has been disconnected, and its properties have not been modified
1139 DrawMode::Type mDrawMode:2; ///< How the Node and its children should be drawn
1140 PositionInheritanceMode mPositionInheritanceMode:2;///< Determines how position is inherited, 2 bits is enough
1141 ColorMode mColorMode:2; ///< Determines whether mWorldColor is inherited, 2 bits is enough
1143 // Changes scope, should be at end of class
1144 DALI_LOG_OBJECT_STRING_DECLARATION;
1147 // Messages for Node
1149 inline void SetInheritShaderMessage( EventToUpdate& eventToUpdate, const Node& node, bool inherit )
1151 typedef MessageValue1< Node, bool > LocalType;
1153 // Reserve some memory inside the message queue
1154 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1156 // Construct message in the message queue memory; note that delete should not be called on the return value
1157 new (slot) LocalType( &node, &Node::SetInheritShader, inherit );
1160 inline void SetInheritRotationMessage( EventToUpdate& eventToUpdate, const Node& node, bool inherit )
1162 typedef MessageValue1< Node, bool > LocalType;
1164 // Reserve some memory inside the message queue
1165 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1167 // Construct message in the message queue memory; note that delete should not be called on the return value
1168 new (slot) LocalType( &node, &Node::SetInheritRotation, inherit );
1171 inline void SetInitialVolumeMessage( EventToUpdate& eventToUpdate, const Node& node, const Vector3& initialVolume )
1173 typedef MessageValue1< Node, Vector3 > LocalType;
1175 // Reserve some memory inside the message queue
1176 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1178 // Construct message in the message queue memory; note that delete should not be called on the return value
1179 new (slot) LocalType( &node, &Node::SetInitialVolume, initialVolume );
1182 inline void SetTransmitGeometryScalingMessage( EventToUpdate& eventToUpdate, const Node& node, bool transmitGeometryScaling )
1184 typedef MessageValue1< Node, bool > LocalType;
1186 // Reserve some memory inside the message queue
1187 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1189 // Construct message in the message queue memory; note that delete should not be called on the return value
1190 new (slot) LocalType( &node, &Node::SetTransmitGeometryScaling, transmitGeometryScaling );
1193 inline void ApplyShaderMessage( EventToUpdate& eventToUpdate, const Node& node, const Shader& constShader )
1195 // Update thread can edit the object
1196 Shader& shader = const_cast< Shader& >( constShader );
1198 typedef MessageValue1< Node, Shader* > LocalType;
1200 // Reserve some memory inside the message queue
1201 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1203 // Construct message in the message queue memory; note that delete should not be called on the return value
1204 new (slot) LocalType( &node, &Node::ApplyShader, &shader );
1207 inline void RemoveShaderMessage( EventToUpdate& eventToUpdate, const Node& node )
1209 typedef Message< Node > LocalType;
1211 // Reserve some memory inside the message queue
1212 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1214 // Construct message in the message queue memory; note that delete should not be called on the return value
1215 new (slot) LocalType( &node, &Node::RemoveShader );
1218 inline void SetParentOriginMessage( EventToUpdate& eventToUpdate, const Node& node, const Vector3& origin )
1220 typedef MessageValue1< Node, Vector3 > LocalType;
1222 // Reserve some memory inside the message queue
1223 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1225 // Construct message in the message queue memory; note that delete should not be called on the return value
1226 new (slot) LocalType( &node, &Node::SetParentOrigin, origin );
1229 inline void SetAnchorPointMessage( EventToUpdate& eventToUpdate, const Node& node, const Vector3& anchor )
1231 typedef MessageValue1< Node, Vector3 > LocalType;
1233 // Reserve some memory inside the message queue
1234 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1236 // Construct message in the message queue memory; note that delete should not be called on the return value
1237 new (slot) LocalType( &node, &Node::SetAnchorPoint, anchor );
1240 inline void SetPositionInheritanceModeMessage( EventToUpdate& eventToUpdate, const Node& node, PositionInheritanceMode mode )
1242 typedef MessageValue1< Node, PositionInheritanceMode > LocalType;
1244 // Reserve some memory inside the message queue
1245 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1247 // Construct message in the message queue memory; note that delete should not be called on the return value
1248 new (slot) LocalType( &node, &Node::SetPositionInheritanceMode, mode );
1251 inline void SetInheritScaleMessage( EventToUpdate& eventToUpdate, const Node& node, bool inherit )
1253 typedef MessageValue1< Node, bool > LocalType;
1255 // Reserve some memory inside the message queue
1256 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1258 // Construct message in the message queue memory; note that delete should not be called on the return value
1259 new (slot) LocalType( &node, &Node::SetInheritScale, inherit );
1262 inline void SetColorModeMessage( EventToUpdate& eventToUpdate, const Node& node, ColorMode colorMode )
1264 typedef MessageValue1< Node, ColorMode > LocalType;
1266 // Reserve some memory inside the message queue
1267 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1269 // Construct message in the message queue memory; note that delete should not be called on the return value
1270 new (slot) LocalType( &node, &Node::SetColorMode, colorMode );
1273 inline void SetDrawModeMessage( EventToUpdate& eventToUpdate, const Node& node, DrawMode::Type drawMode )
1275 typedef MessageValue1< Node, DrawMode::Type > LocalType;
1277 // Reserve some memory inside the message queue
1278 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1280 // Construct message in the message queue memory; note that delete should not be called on the return value
1281 new (slot) LocalType( &node, &Node::SetDrawMode, drawMode );
1284 } // namespace SceneGraph
1286 } // namespace Internal
1290 #endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_H_