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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/actors/actor-enumerations.h>
23 #include <dali/public-api/actors/draw-mode.h>
24 #include <dali/public-api/math/quaternion.h>
25 #include <dali/public-api/math/math-utils.h>
26 #include <dali/public-api/math/vector3.h>
27 #include <dali/internal/common/message.h>
28 #include <dali/internal/common/event-to-update.h>
29 #include <dali/internal/update/common/animatable-property.h>
30 #include <dali/internal/update/common/double-buffered.h>
31 #include <dali/internal/update/common/property-owner.h>
32 #include <dali/internal/update/common/property-vector3.h>
33 #include <dali/internal/update/common/scene-graph-buffers.h>
34 #include <dali/internal/update/common/inherited-property.h>
35 #include <dali/integration-api/debug.h>
36 #include <dali/internal/update/nodes/node-declarations.h>
37 #include <dali/internal/update/node-attachments/node-attachment-declarations.h>
38 #include <dali/internal/render/renderers/render-data-provider.h>
46 // value types used by messages
47 template <> struct ParameterType< ColorMode > : public BasicType< ColorMode > {};
48 template <> struct ParameterType< PositionInheritanceMode > : public BasicType< PositionInheritanceMode > {};
61 * Flag whether property has changed, during the Update phase.
63 enum NodePropertyFlags
66 TransformFlag = 0x001,
72 SortModifierFlag = 0x040,
73 ChildDeletedFlag = 0x080
76 static const int AllFlags = ( ChildDeletedFlag << 1 ) - 1; // all the flags
79 * Size is not inherited.
80 * VisibleFlag is inherited so that attachments can be synchronized with nodes after they become visible
82 static const int InheritedDirtyFlags = TransformFlag | VisibleFlag | ColorFlag | ShaderFlag | OverlayFlag;
84 // Flags which require the scene renderable lists to be updated
85 static const int RenderableUpdateFlags = TransformFlag | SortModifierFlag | ChildDeletedFlag;
88 * Node is the base class for all nodes in the Scene Graph.
89 * Each node provides a transformation which applies to the node and its children.
90 * Node data is double-buffered. This allows an update thread to modify node data, without interferring
91 * with another thread reading the values from the previous update traversal.
93 class Node : public PropertyOwner, public RenderDataProvider
98 static const PositionInheritanceMode DEFAULT_POSITION_INHERITANCE_MODE;
99 static const ColorMode DEFAULT_COLOR_MODE;
104 * Construct a new Node.
114 * When a Node is marked "active" it has been disconnected, but its properties have been modified.
115 * @note An inactive Node will be skipped during the UpdateManager ResetProperties stage.
116 * @param[in] isActive True if the Node is active.
118 void SetActive( bool isActive )
120 mIsActive = isActive;
124 * Query whether the Node is active.
125 * @return True if the Node is active.
127 bool IsActive() const
133 * Called during UpdateManager::DestroyNode shortly before Node is destroyed.
140 * Query whether the node is a layer.
141 * @return True if the node is a layer.
145 return (GetLayer() != NULL);
149 * Convert a node to a layer.
150 * @return A pointer to the layer, or NULL.
152 virtual Layer* GetLayer()
160 * Attach an object to this Node; This should only be done by UpdateManager::AttachToNode.
161 * @pre The Node does not already have an attachment.
162 * @param[in] attachment The object to attach.
164 void Attach( NodeAttachment& attachment );
167 * Query the node if it has an attachment.
168 * @return True if it has an attachment.
170 bool HasAttachment() const
176 * Retreive the object attached to this node.
177 * @return The attachment.
179 NodeAttachment& GetAttachment() const
184 // Containment methods
187 * Query whether a node is the root node. Root nodes cannot have a parent node.
188 * A node becomes a root node, when it is installed by UpdateManager.
189 * @return True if the node is a root node.
197 * Set whether a node is the root node. Root nodes cannot have a parent node.
198 * This method should only be called by UpdateManager.
199 * @pre When isRoot is true, the node must not have a parent.
200 * @param[in] isRoot Whether the node is now a root node.
202 void SetRoot(bool isRoot);
205 * Retrieve the parent of a Node.
206 * @return The parent node, or NULL if the Node has not been added to the scene-graph.
214 * Retrieve the parent of a Node.
215 * @return The parent node, or NULL if the Node has not been added to the scene-graph.
217 const Node* GetParent() const
223 * Connect a node to the scene-graph.
224 * @pre A node cannot be added to itself.
225 * @pre The parent node is connected to the scene-graph.
226 * @pre The childNode does not already have a parent.
227 * @pre The childNode is not a root node.
228 * @param[in] childNode The child to add.
230 void ConnectChild( Node* childNode );
233 * Disconnect a child (& its children) from the scene-graph.
234 * @pre childNode is a child of this Node.
235 * @param[in] updateBufferIndex The current update buffer index.
236 * @param[in] childNode The node to disconnect.
237 * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
238 * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
240 void DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes );
243 * Retrieve the children a Node.
244 * @return The container of children.
246 const NodeContainer& GetChildren() const
252 * Retrieve the children a Node.
253 * @return The container of children.
255 NodeContainer& GetChildren()
263 * Set whether the node inherits a shader effect from its parent.
264 * The inherited effect can be overriden using ApplyShader()
265 * @param [in] inherit True if the parent effect is inherited.
267 void SetInheritShader(bool inherit)
269 if (inherit != mInheritShader)
271 mInheritShader = inherit;
273 SetDirtyFlag(ShaderFlag);
278 * Query whether the node inherits a shader from its parent.
279 * @return True if the parent effect is inherited.
281 bool GetInheritShader() const
283 return mInheritShader;
287 * Apply a shader object to this Node.
288 * Shader effects are weakly referenced, potentially by multiple nodes & node attachments.
289 * @param[in] shader The shader to apply.
291 void ApplyShader( Shader* shader );
294 * Remove the shader object from this Node (if any).
299 * Retrieve the applied shader.
300 * @return The applied shader.
302 Shader* GetAppliedShader() const;
305 * Sets the inherited shader of the node.
306 * @param[in] shader The new inherited shader.
308 void SetInheritedShader(Shader* shader);
311 * Retrieve the inherited shader.
312 * @return The inherited shader.
314 Shader* GetInheritedShader() const;
317 * Inherit a shader (if any) applied to the parent node.
318 * This method should only be called when the parents inherited shader is up-to-date.
319 * @param defaultShader pointer to the default shader, used if inherit shader is set to false
320 * @pre The node has a parent.
322 void InheritShader(Shader* defaultShader);
327 * Flag that one of the node values has changed in the current frame.
328 * @param[in] flag The flag to set.
330 void SetDirtyFlag(NodePropertyFlags flag)
336 * Flag that all of the node values are dirty.
338 void SetAllDirtyFlags()
340 mDirtyFlags = AllFlags;
344 * Query whether a node is dirty.
345 * @return The dirty flags
347 int GetDirtyFlags() const;
350 * Query whether a node is clean.
351 * @return True if the node is clean.
355 return ( NothingFlag == GetDirtyFlags() );
359 * Retrieve the parent-origin of the node.
360 * @return The parent-origin.
362 const Vector3& GetParentOrigin() const
364 return mParentOrigin.mValue;
368 * Sets both the local & base parent-origins of the node.
369 * @param[in] origin The new local & base parent-origins.
371 void SetParentOrigin(const Vector3& origin)
373 mParentOrigin.mValue = origin;
374 mParentOrigin.OnSet();
378 * Retrieve the anchor-point of the node.
379 * @return The anchor-point.
381 const Vector3& GetAnchorPoint() const
383 return mAnchorPoint.mValue;
387 * Sets both the local & base anchor-points of the node.
388 * @param[in] anchor The new local & base anchor-points.
390 void SetAnchorPoint(const Vector3& anchor)
392 mAnchorPoint.mValue = anchor;
393 mAnchorPoint.OnSet();
397 * Retrieve the local position of the node, relative to its parent.
398 * @param[in] bufferIndex The buffer to read from.
399 * @return The local position.
401 const Vector3& GetPosition(BufferIndex bufferIndex) const
403 return mPosition[bufferIndex];
407 * Sets both the local & base positions of the node.
408 * @param[in] updateBufferIndex The current update buffer index.
409 * @param[in] position The new local & base position.
411 void BakePosition(BufferIndex updateBufferIndex, const Vector3& position)
413 mPosition.Bake( updateBufferIndex, position );
417 * Sets the world of the node derived from the position of all its parents.
418 * @param[in] updateBufferIndex The current update buffer index.
419 * @param[in] position The world position.
421 void SetWorldPosition( BufferIndex updateBufferIndex, const Vector3& position )
423 mWorldPosition.Set( updateBufferIndex, position );
427 * Sets the position of the node derived from the position of all its parents.
428 * This method should only be called when the parent's world position is up-to-date.
429 * With a non-central anchor-point, the local rotation and scale affects the world position.
430 * Therefore the world rotation & scale must be updated before the world position.
431 * @pre The node has a parent.
432 * @param[in] updateBufferIndex The current update buffer index.
434 void InheritWorldPosition(BufferIndex updateBufferIndex)
436 DALI_ASSERT_DEBUG(mParent != NULL);
438 switch( mPositionInheritanceMode )
440 case INHERIT_PARENT_POSITION : ///@see Dali::PositionInheritanceMode for how these modes are expected to work
442 Vector3 finalPosition(-0.5f, -0.5f, -0.5f);
444 finalPosition += mParentOrigin.mValue;
445 finalPosition *= mParent->GetSize(updateBufferIndex);
446 finalPosition += mPosition[updateBufferIndex];
447 finalPosition *= mParent->GetWorldScale(updateBufferIndex);
448 const Quaternion& parentWorldRotation = mParent->GetWorldRotation(updateBufferIndex);
449 if(!parentWorldRotation.IsIdentity())
451 finalPosition *= parentWorldRotation;
454 // check if a node needs to be offsetted locally (only applies when AnchorPoint is not central)
455 // dont use operator== as that does a slower comparison (and involves function calls)
456 Vector3 localOffset(0.5f, 0.5f, 0.5f); // AnchorPoint::CENTER
457 localOffset -= mAnchorPoint.mValue;
459 if( ( fabsf( localOffset.x ) >= Math::MACHINE_EPSILON_0 ) ||
460 ( fabsf( localOffset.y ) >= Math::MACHINE_EPSILON_0 ) ||
461 ( fabsf( localOffset.z ) >= Math::MACHINE_EPSILON_0 ) )
463 localOffset *= mSize[updateBufferIndex];
465 Vector3 scale = mWorldScale[updateBufferIndex];
466 if(GetTransmitGeometryScaling())
468 // Remove geometry scaling to get back to actor scale
469 scale /= mGeometryScale;
471 // Also pick up sign of local scale
472 if (mScale[updateBufferIndex].x < 0.0f)
476 if (mScale[updateBufferIndex].y < 0.0f)
480 if (mScale[updateBufferIndex].z < 0.0f)
485 // If the anchor-point is not central, then position is affected by the local rotation & scale
486 localOffset *= scale;
487 const Quaternion& localWorldRotation = mWorldRotation[updateBufferIndex];
488 if(!localWorldRotation.IsIdentity())
490 localOffset *= localWorldRotation;
492 finalPosition += localOffset;
495 finalPosition += mParent->GetWorldPosition(updateBufferIndex);
496 mWorldPosition.Set( updateBufferIndex, finalPosition );
499 case USE_PARENT_POSITION_PLUS_LOCAL_POSITION :
501 // copy parents position plus local transform
502 mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) + mPosition[updateBufferIndex] );
505 case USE_PARENT_POSITION :
507 // copy parents position
508 mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) );
511 case DONT_INHERIT_POSITION :
513 // use local position as world position
514 mWorldPosition.Set( updateBufferIndex, mPosition[updateBufferIndex] );
521 * Copies the previous inherited position, if this changed in the previous frame.
522 * This method should be called instead of InheritWorldPosition i.e. if the inherited position
523 * does not need to be recalculated in the current frame.
524 * @param[in] updateBufferIndex The current update buffer index.
526 void CopyPreviousWorldPosition( BufferIndex updateBufferIndex )
528 mWorldPosition.CopyPrevious( updateBufferIndex );
532 * Retrieve the position of the node derived from the position of all its parents.
533 * @return The world position.
535 const Vector3& GetWorldPosition( BufferIndex bufferIndex ) const
537 return mWorldPosition[bufferIndex];
541 * Set the position inheritance mode.
542 * @see Dali::Actor::PositionInheritanceMode
543 * @param[in] mode The new position inheritance mode.
545 void SetPositionInheritanceMode( PositionInheritanceMode mode )
547 mPositionInheritanceMode = mode;
549 SetDirtyFlag(TransformFlag);
553 * @return The position inheritance mode.
555 PositionInheritanceMode GetPositionInheritanceMode() const
557 return mPositionInheritanceMode;
561 * Retrieve the local rotation of the node, relative to its parent.
562 * @param[in] bufferIndex The buffer to read from.
563 * @return The local rotation.
565 const Quaternion& GetRotation(BufferIndex bufferIndex) const
567 return mRotation[bufferIndex];
571 * Sets both the local & base rotations of the node.
572 * @param[in] updateBufferIndex The current update buffer index.
573 * @param[in] rotation The new local & base rotation.
575 void BakeRotation(BufferIndex updateBufferIndex, const Quaternion& rotation)
577 mRotation.Bake( updateBufferIndex, rotation );
581 * Sets the rotation of the node derived from the rotation of all its parents.
582 * @param[in] updateBufferIndex The current update buffer index.
583 * @param[in] rotation The world rotation.
585 void SetWorldRotation( BufferIndex updateBufferIndex, const Quaternion& rotation )
587 mWorldRotation.Set( updateBufferIndex, rotation );
591 * Sets the rotation of the node derived from the rotation of all its parents.
592 * This method should only be called when the parents world rotation is up-to-date.
593 * @pre The node has a parent.
594 * @param[in] updateBufferIndex The current update buffer index.
596 void InheritWorldRotation( BufferIndex updateBufferIndex )
598 DALI_ASSERT_DEBUG(mParent != NULL);
600 const Quaternion& localRotation = mRotation[updateBufferIndex];
602 if(localRotation.IsIdentity())
604 mWorldRotation.Set( updateBufferIndex, mParent->GetWorldRotation(updateBufferIndex) );
608 Quaternion finalRotation( mParent->GetWorldRotation(updateBufferIndex) );
609 finalRotation *= localRotation;
610 mWorldRotation.Set( updateBufferIndex, finalRotation );
615 * Copies the previous inherited rotation, if this changed in the previous frame.
616 * This method should be called instead of InheritWorldRotation i.e. if the inherited rotation
617 * does not need to be recalculated in the current frame.
618 * @param[in] updateBufferIndex The current update buffer index.
620 void CopyPreviousWorldRotation( BufferIndex updateBufferIndex )
622 mWorldRotation.CopyPrevious( updateBufferIndex );
626 * Retrieve the rotation of the node derived from the rotation of all its parents.
627 * @param[in] bufferIndex The buffer to read from.
628 * @return The world rotation.
630 const Quaternion& GetWorldRotation( BufferIndex bufferIndex ) const
632 return mWorldRotation[bufferIndex];
636 * Set whether the Node inherits rotation.
637 * @param[in] inherit True if the parent rotation is inherited.
639 void SetInheritRotation(bool inherit)
641 if (inherit != mInheritRotation)
643 mInheritRotation = inherit;
645 SetDirtyFlag(TransformFlag);
650 * Query whether the node inherits rotation from its parent.
651 * @return True if the parent rotation is inherited.
653 bool IsRotationInherited() const
655 return mInheritRotation;
659 * Set the initial volume of the node. Used for calculating geometry scaling
660 * as the node size is changed when transmitGeometryScaling is set to true.
662 * This property is not animatable.
664 * @param[in] volume The initial volume of this nodes meshes & children
666 void SetInitialVolume( const Vector3& volume)
668 mInitialVolume = volume;
669 SetDirtyFlag(SizeFlag);
673 * Get the initial volume. Used for calculating geometry scaling
674 * when TransmitGeometryScaling is true (i.e., the scaling is baked
675 * into the node tranform)
677 * @return The initial volume of this node and children.
679 Vector3 GetInitialVolume()
681 return mInitialVolume;
685 * Sets whether the geometry scaling should be applied to the node
686 * (In which case, set the initial scale using SetInitialVolume()).
688 * If it is applied to the node, then the attachments are not scaled,
689 * as the scaling is then already baked into the node transform.
691 * @param[in] transmitGeometryScaling true if scaling is to be applied
694 void SetTransmitGeometryScaling(bool transmitGeometryScaling)
696 mTransmitGeometryScaling = transmitGeometryScaling;
697 SetDirtyFlag(SizeFlag);
701 * Find out whether the node allows geometry scaling to be transmitted to its children.
702 * @return true if transmitted.
704 bool GetTransmitGeometryScaling() const
706 return mTransmitGeometryScaling;
710 * Retrieve the local scale of the node, relative to its parent.
711 * @param[in] bufferIndex The buffer to read from.
712 * @return The local scale.
714 const Vector3& GetScale(BufferIndex bufferIndex) const
716 return mScale[bufferIndex];
720 * Sets the scale of the node derived from the scale of all its parents and a pre-scale
721 * @param[in] updateBufferIndex The current update buffer index.
722 * @param[in] scale The world scale.
724 void SetWorldScale(BufferIndex updateBufferIndex, const Vector3& scale)
726 mWorldScale.Set( updateBufferIndex, mGeometryScale * scale );
730 * Sets the scale of the node derived from the scale of all its parents and a pre-scale.
731 * This method should only be called when the parents world scale is up-to-date.
732 * @pre The node has a parent.
733 * @param[in] updateBufferIndex The current update buffer index.
735 void InheritWorldScale(BufferIndex updateBufferIndex)
737 DALI_ASSERT_DEBUG(mParent != NULL);
739 mWorldScale.Set( updateBufferIndex, mParent->GetWorldScale(updateBufferIndex) * mGeometryScale * mScale[updateBufferIndex] );
743 * Copies the previous inherited scale, if this changed in the previous frame.
744 * This method should be called instead of InheritWorldScale i.e. if the inherited scale
745 * does not need to be recalculated in the current frame.
746 * @param[in] updateBufferIndex The current update buffer index.
748 void CopyPreviousWorldScale( BufferIndex updateBufferIndex )
750 mWorldScale.CopyPrevious( updateBufferIndex );
754 * Retrieve the scale of the node derived from the scale of all its parents.
755 * @param[in] bufferIndex The buffer to read from.
756 * @return The world scale.
758 const Vector3& GetWorldScale( BufferIndex bufferIndex ) const
760 return mWorldScale[bufferIndex];
764 * Set whether the Node inherits scale.
765 * @param inherit True if the Node inherits scale.
767 void SetInheritScale( bool inherit )
769 if( inherit != mInheritScale )
771 mInheritScale = inherit;
773 SetDirtyFlag( TransformFlag );
778 * Query whether the Node inherits scale.
779 * @return if scale is inherited
781 bool IsScaleInherited() const
783 return mInheritScale;
787 * Sets a geometry scale, calculated when TransmitGeometryScaling is true.
788 * Must only be used from render thread.
789 * @param[in] geometryScale The geometry scale value
791 void SetGeometryScale(Vector3 geometryScale)
793 mGeometryScale = geometryScale;
795 SetDirtyFlag( TransformFlag );
799 * Retrieve the geometry scale, calculated when TransmitGeometryScaling is true.
800 * @return The geometry scale value.
802 const Vector3& GetGeometryScale() const
804 return mGeometryScale;
808 * Retrieve the visibility of the node.
809 * @param[in] bufferIndex The buffer to read from.
810 * @return True if the node is visible.
812 bool IsVisible(BufferIndex bufferIndex) const
814 return mVisible[bufferIndex];
818 * Retrieves whether a node is fully visible.
819 * A node is fully visible if is visible and all its ancestors are visible.
820 * @param[in] updateBufferIndex The current update buffer index.
821 * @return True if the node is fully visible.
823 bool IsFullyVisible( BufferIndex updateBufferIndex ) const;
826 * Retrieve the opacity of the node.
827 * @param[in] bufferIndex The buffer to read from.
828 * @return The opacity.
830 float GetOpacity(BufferIndex bufferIndex) const
832 return mColor[bufferIndex].a;
836 * Retrieve the color of the node.
837 * @param[in] bufferIndex The buffer to read from.
840 const Vector4& GetColor(BufferIndex bufferIndex) const
842 return mColor[bufferIndex];
846 * Sets the color of the node derived from the color of all its parents.
847 * @param[in] color The world color.
848 * @param[in] updateBufferIndex The current update buffer index.
850 void SetWorldColor(const Vector4& color, BufferIndex updateBufferIndex)
852 mWorldColor.Set( updateBufferIndex, color );
856 * Sets the color of the node derived from the color of all its parents.
857 * This method should only be called when the parents world color is up-to-date.
858 * @pre The node has a parent.
859 * @param[in] updateBufferIndex The current update buffer index.
861 void InheritWorldColor( BufferIndex updateBufferIndex )
863 DALI_ASSERT_DEBUG(mParent != NULL);
866 if( mColorMode == USE_OWN_MULTIPLY_PARENT_ALPHA )
868 const Vector4& ownColor = mColor[updateBufferIndex];
869 mWorldColor.Set( updateBufferIndex, ownColor.r, ownColor.g, ownColor.b, ownColor.a * mParent->GetWorldColor(updateBufferIndex).a );
871 else if( mColorMode == USE_OWN_MULTIPLY_PARENT_COLOR )
873 mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) * mColor[updateBufferIndex] );
875 else if( mColorMode == USE_PARENT_COLOR )
877 mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) );
879 else // USE_OWN_COLOR
881 mWorldColor.Set( updateBufferIndex, mColor[updateBufferIndex] );
886 * Copies the previous inherited scale, if this changed in the previous frame.
887 * This method should be called instead of InheritWorldScale i.e. if the inherited scale
888 * does not need to be recalculated in the current frame.
889 * @param[in] updateBufferIndex The current update buffer index.
891 void CopyPreviousWorldColor( BufferIndex updateBufferIndex )
893 mWorldColor.CopyPrevious( updateBufferIndex );
897 * Retrieve the color of the node, possibly derived from the color
898 * of all its parents, depending on the value of mColorMode.
899 * @param[in] bufferIndex The buffer to read from.
900 * @return The world color.
902 const Vector4& GetWorldColor(BufferIndex bufferIndex) const
904 return mWorldColor[bufferIndex];
908 * Set the color mode. This specifies whether the Node uses its own color,
909 * or inherits its parent color.
910 * @param[in] colorMode The new color mode.
912 void SetColorMode(ColorMode colorMode)
914 mColorMode = colorMode;
916 SetDirtyFlag(ColorFlag);
920 * Retrieve the color mode.
921 * @return The color mode.
923 ColorMode GetColorMode() const
929 * Retrieve the size of the node.
930 * @param[in] bufferIndex The buffer to read from.
933 const Vector3& GetSize(BufferIndex bufferIndex) const
935 return mSize[bufferIndex];
939 * Set the world-matrix of a node, with scale + rotation + translation.
940 * Scale and rotation are centered at the origin.
941 * Translation is applied independently of the scale or rotatation axis.
942 * @param[in] updateBufferIndex The current update buffer index.
943 * @param[in] scale The scale.
944 * @param[in] rotation The rotation.
945 * @param[in] translation The translation.
947 void SetWorldMatrix( BufferIndex updateBufferIndex, const Vector3& scale, const Quaternion& rotation, const Vector3& translation )
949 mWorldMatrix.Get( updateBufferIndex ).SetTransformComponents( scale, rotation, translation );
950 mWorldMatrix.SetDirty( updateBufferIndex );
954 * Retrieve the cached world-matrix of a node.
955 * @param[in] bufferIndex The buffer to read from.
956 * @return The world-matrix.
958 const Matrix& GetWorldMatrix( BufferIndex bufferIndex ) const
960 return mWorldMatrix[ bufferIndex ];
964 * Copy previous frames world matrix
965 * @param[in] updateBufferIndex The current update buffer index.
967 void CopyPreviousWorldMatrix( BufferIndex updateBufferIndex )
969 mWorldMatrix.CopyPrevious( updateBufferIndex );
973 * Mark the node as exclusive to a single RenderTask.
974 * @param[in] renderTask The render-task, or NULL if the Node is not exclusive to a single RenderTask.
976 void SetExclusiveRenderTask( RenderTask* renderTask )
978 mExclusiveRenderTask = renderTask;
982 * Query whether the node is exclusive to a single RenderTask.
983 * @return The render-task, or NULL if the Node is not exclusive to a single RenderTask.
985 RenderTask* GetExclusiveRenderTask() const
987 return mExclusiveRenderTask;
991 * Set how the Node and its children should be drawn; see Dali::Actor::SetDrawMode() for more details.
992 * @param[in] drawMode The new draw-mode to use.
994 void SetDrawMode( const DrawMode::Type& drawMode )
996 mDrawMode = drawMode;
1000 * Returns whether node is an overlay or not.
1001 * @return True if node is an overlay, false otherwise.
1003 DrawMode::Type GetDrawMode() const
1009 * Equality operator, checks for identity, not values.
1012 bool operator==( const Node* rhs ) const
1022 * Set the inhibit local transform flag.@n
1023 * Setting this flag will stop the node's local transform (position, scale and orientation)
1024 * being applied on top of its parents transformation.
1025 * @param[in] flag When true, local transformation is inhibited when calculating the world matrix.
1027 void SetInhibitLocalTransform( bool flag )
1029 SetDirtyFlag( TransformFlag );
1030 mInhibitLocalTransform = flag;
1034 * Get the inhibit local transform flag.@n
1035 * See @ref SetInhibitLocalTransform
1036 * @result A flag, when true, local transformation is inhibited when calculating the world matrix.
1038 bool GetInhibitLocalTransform() const
1040 return mInhibitLocalTransform;
1046 * Set the parent of a Node.
1047 * @param[in] parentNode the new parent.
1049 void SetParent(Node& parentNode);
1052 * Protected constructor; See also Node::New()
1056 private: // from RenderDataProvider
1059 * @copydoc RenderDataProvider::GetModelMatrix
1061 virtual const Matrix& GetModelMatrix( unsigned int bufferId )
1063 return GetWorldMatrix( bufferId );
1067 * @copydoc RenderDataProvider::GetRenderColor
1069 virtual const Vector4& GetRenderColor( unsigned int bufferId )
1071 return GetWorldColor( bufferId );
1080 Node& operator=(const Node& rhs);
1083 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
1085 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
1088 * Recursive helper to disconnect a Node and its children.
1089 * Disconnected Nodes have no parent or children.
1090 * @param[in] updateBufferIndex The current update buffer index.
1091 * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
1092 * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
1094 void RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes );
1096 public: // Default properties
1098 PropertyVector3 mParentOrigin; ///< Local transform; the position is relative to this. Sets the TransformFlag dirty when changed
1099 PropertyVector3 mAnchorPoint; ///< Local transform; local center of rotation. Sets the TransformFlag dirty when changed
1101 AnimatableProperty<Vector3> mSize; ///< Size is provided for layouting
1102 AnimatableProperty<Vector3> mPosition; ///< Local transform; distance between parent-origin & anchor-point
1103 AnimatableProperty<Quaternion> mRotation; ///< Local transform; rotation relative to parent node
1104 AnimatableProperty<Vector3> mScale; ///< Local transform; scale relative to parent node
1105 AnimatableProperty<bool> mVisible; ///< Visibility can be inherited from the Node hierachy
1106 AnimatableProperty<Vector4> mColor; ///< Color can be inherited from the Node hierarchy
1108 // Inherited properties; read-only from public API
1110 InheritedProperty<Vector3> mWorldPosition; ///< Full inherited position
1111 InheritedProperty<Quaternion> mWorldRotation; ///< Full inherited rotation
1112 InheritedProperty<Vector3> mWorldScale; ///< Full inherited scale
1113 InheritedProperty<Matrix> mWorldMatrix; ///< Full inherited world matrix
1114 InheritedColor mWorldColor; ///< Full inherited color
1118 Node* mParent; ///< Pointer to parent node (a child is owned by its parent)
1119 Shader* mAppliedShader; ///< A pointer to an applied shader
1120 Shader* mInheritedShader; ///< A pointer to an inherited shader
1121 RenderTask* mExclusiveRenderTask; ///< Nodes can be marked as exclusive to a single RenderTask
1123 NodeAttachmentOwner mAttachment; ///< Optional owned attachment
1124 NodeContainer mChildren; ///< Container of children; not owned
1126 Vector3 mGeometryScale; ///< Applied before calculating world transform.
1127 Vector3 mInitialVolume; ///< Initial volume... TODO - need a better name
1129 // flags, compressed to bitfield
1130 int mDirtyFlags:10; ///< A composite set of flags for each of the Node properties
1132 bool mIsRoot:1; ///< True if the node cannot have a parent
1133 bool mInheritShader:1; ///< Whether the parent's shader should be inherited.
1134 bool mInheritRotation:1; ///< Whether the parent's rotation should be inherited.
1135 bool mInheritScale:1; ///< Whether the parent's scale should be inherited.
1136 bool mTransmitGeometryScaling:1; ///< Whether geometry scaling should be applied to world transform.
1137 bool mInhibitLocalTransform:1; ///< whether local transform should be applied.
1138 bool mIsActive:1; ///< When a Node is marked "active" it has been disconnected, and its properties have not been modified
1140 DrawMode::Type mDrawMode:2; ///< How the Node and its children should be drawn
1141 PositionInheritanceMode mPositionInheritanceMode:2;///< Determines how position is inherited, 2 bits is enough
1142 ColorMode mColorMode:2; ///< Determines whether mWorldColor is inherited, 2 bits is enough
1144 // Changes scope, should be at end of class
1145 DALI_LOG_OBJECT_STRING_DECLARATION;
1148 // Messages for Node
1150 inline void SetInheritShaderMessage( EventToUpdate& eventToUpdate, const Node& node, bool inherit )
1152 typedef MessageValue1< Node, bool > LocalType;
1154 // Reserve some memory inside the message queue
1155 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1157 // Construct message in the message queue memory; note that delete should not be called on the return value
1158 new (slot) LocalType( &node, &Node::SetInheritShader, inherit );
1161 inline void SetInheritRotationMessage( EventToUpdate& eventToUpdate, const Node& node, bool inherit )
1163 typedef MessageValue1< Node, bool > LocalType;
1165 // Reserve some memory inside the message queue
1166 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1168 // Construct message in the message queue memory; note that delete should not be called on the return value
1169 new (slot) LocalType( &node, &Node::SetInheritRotation, inherit );
1172 inline void SetInitialVolumeMessage( EventToUpdate& eventToUpdate, const Node& node, const Vector3& initialVolume )
1174 typedef MessageValue1< Node, Vector3 > LocalType;
1176 // Reserve some memory inside the message queue
1177 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1179 // Construct message in the message queue memory; note that delete should not be called on the return value
1180 new (slot) LocalType( &node, &Node::SetInitialVolume, initialVolume );
1183 inline void SetTransmitGeometryScalingMessage( EventToUpdate& eventToUpdate, const Node& node, bool transmitGeometryScaling )
1185 typedef MessageValue1< Node, bool > LocalType;
1187 // Reserve some memory inside the message queue
1188 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1190 // Construct message in the message queue memory; note that delete should not be called on the return value
1191 new (slot) LocalType( &node, &Node::SetTransmitGeometryScaling, transmitGeometryScaling );
1194 inline void ApplyShaderMessage( EventToUpdate& eventToUpdate, const Node& node, const Shader& constShader )
1196 // Update thread can edit the object
1197 Shader& shader = const_cast< Shader& >( constShader );
1199 typedef MessageValue1< Node, Shader* > LocalType;
1201 // Reserve some memory inside the message queue
1202 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1204 // Construct message in the message queue memory; note that delete should not be called on the return value
1205 new (slot) LocalType( &node, &Node::ApplyShader, &shader );
1208 inline void RemoveShaderMessage( EventToUpdate& eventToUpdate, const Node& node )
1210 typedef Message< Node > LocalType;
1212 // Reserve some memory inside the message queue
1213 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1215 // Construct message in the message queue memory; note that delete should not be called on the return value
1216 new (slot) LocalType( &node, &Node::RemoveShader );
1219 inline void SetParentOriginMessage( EventToUpdate& eventToUpdate, const Node& node, const Vector3& origin )
1221 typedef MessageValue1< Node, Vector3 > LocalType;
1223 // Reserve some memory inside the message queue
1224 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1226 // Construct message in the message queue memory; note that delete should not be called on the return value
1227 new (slot) LocalType( &node, &Node::SetParentOrigin, origin );
1230 inline void SetAnchorPointMessage( EventToUpdate& eventToUpdate, const Node& node, const Vector3& anchor )
1232 typedef MessageValue1< Node, Vector3 > LocalType;
1234 // Reserve some memory inside the message queue
1235 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1237 // Construct message in the message queue memory; note that delete should not be called on the return value
1238 new (slot) LocalType( &node, &Node::SetAnchorPoint, anchor );
1241 inline void SetPositionInheritanceModeMessage( EventToUpdate& eventToUpdate, const Node& node, PositionInheritanceMode mode )
1243 typedef MessageValue1< Node, PositionInheritanceMode > LocalType;
1245 // Reserve some memory inside the message queue
1246 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1248 // Construct message in the message queue memory; note that delete should not be called on the return value
1249 new (slot) LocalType( &node, &Node::SetPositionInheritanceMode, mode );
1252 inline void SetInheritScaleMessage( EventToUpdate& eventToUpdate, const Node& node, bool inherit )
1254 typedef MessageValue1< Node, bool > LocalType;
1256 // Reserve some memory inside the message queue
1257 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1259 // Construct message in the message queue memory; note that delete should not be called on the return value
1260 new (slot) LocalType( &node, &Node::SetInheritScale, inherit );
1263 inline void SetColorModeMessage( EventToUpdate& eventToUpdate, const Node& node, ColorMode colorMode )
1265 typedef MessageValue1< Node, ColorMode > LocalType;
1267 // Reserve some memory inside the message queue
1268 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1270 // Construct message in the message queue memory; note that delete should not be called on the return value
1271 new (slot) LocalType( &node, &Node::SetColorMode, colorMode );
1274 inline void SetDrawModeMessage( EventToUpdate& eventToUpdate, const Node& node, DrawMode::Type drawMode )
1276 typedef MessageValue1< Node, DrawMode::Type > LocalType;
1278 // Reserve some memory inside the message queue
1279 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1281 // Construct message in the message queue memory; note that delete should not be called on the return value
1282 new (slot) LocalType( &node, &Node::SetDrawMode, drawMode );
1285 } // namespace SceneGraph
1287 } // namespace Internal
1291 #endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_H_