1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_NODE_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_NODE_H__
5 * Copyright (c) 2015 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/devel-api/common/set-wrapper.h>
25 #include <dali/public-api/math/quaternion.h>
26 #include <dali/public-api/math/math-utils.h>
27 #include <dali/public-api/math/vector3.h>
28 #include <dali/internal/common/message.h>
29 #include <dali/internal/event/common/event-thread-services.h>
30 #include <dali/internal/update/common/animatable-property.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/data-providers/node-data-provider.h>
39 #include <dali/internal/update/rendering/scene-graph-renderer.h>
47 // value types used by messages
48 template <> struct ParameterType< ColorMode > : public BasicType< ColorMode > {};
49 template <> struct ParameterType< PositionInheritanceMode > : public BasicType< PositionInheritanceMode > {};
61 * Flag whether property has changed, during the Update phase.
63 enum NodePropertyFlags
66 TransformFlag = 0x001,
71 SortModifierFlag = 0x020,
72 ChildDeletedFlag = 0x040
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 | 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.
89 * Each node provides a transformation which applies to the node and
90 * its children. Node data is double-buffered. This allows an update
91 * thread to modify node data, without interferring with another
92 * thread reading the values from the previous update traversal.
94 class Node : public PropertyOwner, public NodeDataProvider
99 static const PositionInheritanceMode DEFAULT_POSITION_INHERITANCE_MODE;
100 static const ColorMode DEFAULT_COLOR_MODE;
105 * Construct a new Node.
115 * When a Node is marked "active" it has been disconnected, but its properties have been modified.
116 * @note An inactive Node will be skipped during the UpdateManager ResetProperties stage.
117 * @param[in] isActive True if the Node is active.
119 void SetActive( bool isActive )
121 mIsActive = isActive;
125 * Query whether the Node is active.
126 * @return True if the Node is active.
128 bool IsActive() const
134 * Called during UpdateManager::DestroyNode shortly before Node is destroyed.
141 * Query whether the node is a layer.
142 * @return True if the node is a layer.
146 return (GetLayer() != NULL);
150 * Convert a node to a layer.
151 * @return A pointer to the layer, or NULL.
153 virtual Layer* GetLayer()
161 * Attach an object to this Node; This should only be done by UpdateManager::AttachToNode.
162 * @pre The Node does not already have an attachment.
163 * @param[in] attachment The object to attach.
165 void Attach( NodeAttachment& attachment );
168 * Query the node if it has an attachment.
169 * @return True if it has an attachment.
171 bool HasAttachment() const
177 * Add a renderer to the node
178 * @param[in] renderer The renderer added to the node
180 void AddRenderer( Renderer* renderer )
182 //Check that it has not been already added
183 unsigned int rendererCount( mRenderer.Size() );
184 for( unsigned int i(0); i<rendererCount; ++i )
186 if( mRenderer[i] == renderer )
188 //Renderer already in the list
193 //If it is the first renderer added, make sure the world transform will be calculated
194 //in the next update as world transform is not computed if node has no renderers
195 if( rendererCount == 0 )
197 mDirtyFlags |= TransformFlag;
200 mRenderer.PushBack( renderer );
204 * Remove a renderer from the node
205 * @param[in] renderer The renderer to be removed
207 void RemoveRenderer( Renderer* renderer );
210 * Get the renderer at the given index
213 Renderer* GetRendererAt( unsigned int index )
215 return mRenderer[index];
219 * Retrieve the number of renderers for the node
221 unsigned int GetRendererCount()
223 return mRenderer.Size();
227 * Retreive the object attached to this node.
228 * @return The attachment.
230 NodeAttachment& GetAttachment() const
235 // Containment methods
238 * Query whether a node is the root node. Root nodes cannot have a parent node.
239 * A node becomes a root node, when it is installed by UpdateManager.
240 * @return True if the node is a root node.
248 * Set whether a node is the root node. Root nodes cannot have a parent node.
249 * This method should only be called by UpdateManager.
250 * @pre When isRoot is true, the node must not have a parent.
251 * @param[in] isRoot Whether the node is now a root node.
253 void SetRoot(bool isRoot);
256 * Retrieve the parent of a Node.
257 * @return The parent node, or NULL if the Node has not been added to the scene-graph.
265 * Retrieve the parent of a Node.
266 * @return The parent node, or NULL if the Node has not been added to the scene-graph.
268 const Node* GetParent() const
274 * Connect a node to the scene-graph.
275 * @pre A node cannot be added to itself.
276 * @pre The parent node is connected to the scene-graph.
277 * @pre The childNode does not already have a parent.
278 * @pre The childNode is not a root node.
279 * @param[in] childNode The child to add.
281 void ConnectChild( Node* childNode );
284 * Disconnect a child (& its children) from the scene-graph.
285 * @pre childNode is a child of this Node.
286 * @param[in] updateBufferIndex The current update buffer index.
287 * @param[in] childNode The node to disconnect.
288 * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
289 * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
291 void DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes );
294 * Retrieve the children a Node.
295 * @return The container of children.
297 const NodeContainer& GetChildren() const
303 * Retrieve the children a Node.
304 * @return The container of children.
306 NodeContainer& GetChildren()
314 * Flag that one of the node values has changed in the current frame.
315 * @param[in] flag The flag to set.
317 void SetDirtyFlag(NodePropertyFlags flag)
323 * Flag that all of the node values are dirty.
325 void SetAllDirtyFlags()
327 mDirtyFlags = AllFlags;
331 * Query whether a node is dirty.
332 * @return The dirty flags
334 int GetDirtyFlags() const;
337 * Query whether a node is clean.
338 * @return True if the node is clean.
342 return ( NothingFlag == GetDirtyFlags() );
346 * Retrieve the parent-origin of the node.
347 * @return The parent-origin.
349 const Vector3& GetParentOrigin() const
351 return mParentOrigin.mValue;
355 * Sets both the local & base parent-origins of the node.
356 * @param[in] origin The new local & base parent-origins.
358 void SetParentOrigin(const Vector3& origin)
360 mParentOrigin.mValue = origin;
361 mParentOrigin.OnSet();
365 * Retrieve the anchor-point of the node.
366 * @return The anchor-point.
368 const Vector3& GetAnchorPoint() const
370 return mAnchorPoint.mValue;
374 * Sets both the local & base anchor-points of the node.
375 * @param[in] anchor The new local & base anchor-points.
377 void SetAnchorPoint(const Vector3& anchor)
379 mAnchorPoint.mValue = anchor;
380 mAnchorPoint.OnSet();
384 * Retrieve the local position of the node, relative to its parent.
385 * @param[in] bufferIndex The buffer to read from.
386 * @return The local position.
388 const Vector3& GetPosition(BufferIndex bufferIndex) const
390 return mPosition[bufferIndex];
394 * Sets both the local & base positions of the node.
395 * @param[in] updateBufferIndex The current update buffer index.
396 * @param[in] position The new local & base position.
398 void BakePosition(BufferIndex updateBufferIndex, const Vector3& position)
400 mPosition.Bake( updateBufferIndex, position );
404 * Sets the world of the node derived from the position of all its parents.
405 * @param[in] updateBufferIndex The current update buffer index.
406 * @param[in] position The world position.
408 void SetWorldPosition( BufferIndex updateBufferIndex, const Vector3& position )
410 mWorldPosition.Set( updateBufferIndex, position );
414 * Sets the position of the node derived from the position of all its parents.
415 * This method should only be called when the parent's world position is up-to-date.
416 * With a non-central anchor-point, the local orientation and scale affects the world position.
417 * Therefore the world orientation & scale must be updated before the world position.
418 * @pre The node has a parent.
419 * @param[in] updateBufferIndex The current update buffer index.
421 void InheritWorldPosition(BufferIndex updateBufferIndex)
423 DALI_ASSERT_DEBUG(mParent != NULL);
425 switch( mPositionInheritanceMode )
427 case INHERIT_PARENT_POSITION : ///@see Dali::PositionInheritanceMode for how these modes are expected to work
429 Vector3 finalPosition(-0.5f, -0.5f, -0.5f);
431 finalPosition += mParentOrigin.mValue;
432 finalPosition *= mParent->GetSize(updateBufferIndex);
433 finalPosition += mPosition[updateBufferIndex];
434 finalPosition *= mParent->GetWorldScale(updateBufferIndex);
435 const Quaternion& parentWorldOrientation = mParent->GetWorldOrientation(updateBufferIndex);
436 if(!parentWorldOrientation.IsIdentity())
438 finalPosition *= parentWorldOrientation;
441 // check if a node needs to be offsetted locally (only applies when AnchorPoint is not central)
442 // dont use operator== as that does a slower comparison (and involves function calls)
443 Vector3 localOffset(0.5f, 0.5f, 0.5f); // AnchorPoint::CENTER
444 localOffset -= mAnchorPoint.mValue;
446 if( ( fabsf( localOffset.x ) >= Math::MACHINE_EPSILON_0 ) ||
447 ( fabsf( localOffset.y ) >= Math::MACHINE_EPSILON_0 ) ||
448 ( fabsf( localOffset.z ) >= Math::MACHINE_EPSILON_0 ) )
450 localOffset *= mSize[updateBufferIndex];
452 Vector3 scale = mWorldScale[updateBufferIndex];
454 // Pick up sign of local scale
455 if (mScale[updateBufferIndex].x < 0.0f)
459 if (mScale[updateBufferIndex].y < 0.0f)
463 if (mScale[updateBufferIndex].z < 0.0f)
468 // If the anchor-point is not central, then position is affected by the local orientation & scale
469 localOffset *= scale;
470 const Quaternion& localWorldOrientation = mWorldOrientation[updateBufferIndex];
471 if(!localWorldOrientation.IsIdentity())
473 localOffset *= localWorldOrientation;
475 finalPosition += localOffset;
478 finalPosition += mParent->GetWorldPosition(updateBufferIndex);
479 mWorldPosition.Set( updateBufferIndex, finalPosition );
482 case USE_PARENT_POSITION_PLUS_LOCAL_POSITION :
484 // copy parents position plus local transform
485 mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) + mPosition[updateBufferIndex] );
488 case USE_PARENT_POSITION :
490 // copy parents position
491 mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) );
494 case DONT_INHERIT_POSITION :
496 // use local position as world position
497 mWorldPosition.Set( updateBufferIndex, mPosition[updateBufferIndex] );
504 * Copies the previous inherited position, if this changed in the previous frame.
505 * This method should be called instead of InheritWorldPosition i.e. if the inherited position
506 * does not need to be recalculated in the current frame.
507 * @param[in] updateBufferIndex The current update buffer index.
509 void CopyPreviousWorldPosition( BufferIndex updateBufferIndex )
511 mWorldPosition.CopyPrevious( updateBufferIndex );
515 * Retrieve the position of the node derived from the position of all its parents.
516 * @return The world position.
518 const Vector3& GetWorldPosition( BufferIndex bufferIndex ) const
520 return mWorldPosition[bufferIndex];
524 * Set the position inheritance mode.
525 * @see Dali::Actor::PositionInheritanceMode
526 * @param[in] mode The new position inheritance mode.
528 void SetPositionInheritanceMode( PositionInheritanceMode mode )
530 mPositionInheritanceMode = mode;
532 SetDirtyFlag(TransformFlag);
536 * @return The position inheritance mode.
538 PositionInheritanceMode GetPositionInheritanceMode() const
540 return mPositionInheritanceMode;
544 * Retrieve the local orientation of the node, relative to its parent.
545 * @param[in] bufferIndex The buffer to read from.
546 * @return The local orientation.
548 const Quaternion& GetOrientation(BufferIndex bufferIndex) const
550 return mOrientation[bufferIndex];
554 * Sets both the local & base orientations of the node.
555 * @param[in] updateBufferIndex The current update buffer index.
556 * @param[in] orientation The new local & base orientation.
558 void BakeOrientation(BufferIndex updateBufferIndex, const Quaternion& orientation)
560 mOrientation.Bake( updateBufferIndex, orientation );
564 * Sets the orientation of the node derived from the rotation of all its parents.
565 * @param[in] updateBufferIndex The current update buffer index.
566 * @param[in] orientation The world orientation.
568 void SetWorldOrientation( BufferIndex updateBufferIndex, const Quaternion& orientation )
570 mWorldOrientation.Set( updateBufferIndex, orientation );
574 * Sets the orientation of the node derived from the rotation of all its parents.
575 * This method should only be called when the parents world orientation is up-to-date.
576 * @pre The node has a parent.
577 * @param[in] updateBufferIndex The current update buffer index.
579 void InheritWorldOrientation( BufferIndex updateBufferIndex )
581 DALI_ASSERT_DEBUG(mParent != NULL);
583 const Quaternion& localOrientation = mOrientation[updateBufferIndex];
585 if(localOrientation.IsIdentity())
587 mWorldOrientation.Set( updateBufferIndex, mParent->GetWorldOrientation(updateBufferIndex) );
591 Quaternion finalOrientation( mParent->GetWorldOrientation(updateBufferIndex) );
592 finalOrientation *= localOrientation;
593 mWorldOrientation.Set( updateBufferIndex, finalOrientation );
598 * Copies the previous inherited orientation, if this changed in the previous frame.
599 * This method should be called instead of InheritWorldOrientation i.e. if the inherited orientation
600 * does not need to be recalculated in the current frame.
601 * @param[in] updateBufferIndex The current update buffer index.
603 void CopyPreviousWorldOrientation( BufferIndex updateBufferIndex )
605 mWorldOrientation.CopyPrevious( updateBufferIndex );
609 * Retrieve the orientation of the node derived from the rotation of all its parents.
610 * @param[in] bufferIndex The buffer to read from.
611 * @return The world rotation.
613 const Quaternion& GetWorldOrientation( BufferIndex bufferIndex ) const
615 return mWorldOrientation[bufferIndex];
619 * Set whether the Node inherits orientation.
620 * @param[in] inherit True if the parent orientation is inherited.
622 void SetInheritOrientation(bool inherit)
624 if (inherit != mInheritOrientation)
626 mInheritOrientation = inherit;
628 SetDirtyFlag(TransformFlag);
633 * Query whether the node inherits orientation from its parent.
634 * @return True if the parent orientation is inherited.
636 bool IsOrientationInherited() const
638 return mInheritOrientation;
642 * Retrieve the local scale of the node, relative to its parent.
643 * @param[in] bufferIndex The buffer to read from.
644 * @return The local scale.
646 const Vector3& GetScale(BufferIndex bufferIndex) const
648 return mScale[bufferIndex];
652 * Sets the scale of the node derived from the scale of all its parents and a pre-scale
653 * @param[in] updateBufferIndex The current update buffer index.
654 * @param[in] scale The world scale.
656 void SetWorldScale(BufferIndex updateBufferIndex, const Vector3& scale)
658 mWorldScale.Set( updateBufferIndex, scale );
662 * Sets the scale of the node derived from the scale of all its parents and a pre-scale.
663 * This method should only be called when the parents world scale is up-to-date.
664 * @pre The node has a parent.
665 * @param[in] updateBufferIndex The current update buffer index.
667 void InheritWorldScale(BufferIndex updateBufferIndex)
669 DALI_ASSERT_DEBUG(mParent != NULL);
671 mWorldScale.Set( updateBufferIndex, mParent->GetWorldScale(updateBufferIndex) * mScale[updateBufferIndex] );
675 * Copies the previous inherited scale, if this changed in the previous frame.
676 * This method should be called instead of InheritWorldScale i.e. if the inherited scale
677 * does not need to be recalculated in the current frame.
678 * @param[in] updateBufferIndex The current update buffer index.
680 void CopyPreviousWorldScale( BufferIndex updateBufferIndex )
682 mWorldScale.CopyPrevious( updateBufferIndex );
686 * Retrieve the scale of the node derived from the scale of all its parents.
687 * @param[in] bufferIndex The buffer to read from.
688 * @return The world scale.
690 const Vector3& GetWorldScale( BufferIndex bufferIndex ) const
692 return mWorldScale[bufferIndex];
696 * Set whether the Node inherits scale.
697 * @param inherit True if the Node inherits scale.
699 void SetInheritScale( bool inherit )
701 if( inherit != mInheritScale )
703 mInheritScale = inherit;
705 SetDirtyFlag( TransformFlag );
710 * Query whether the Node inherits scale.
711 * @return if scale is inherited
713 bool IsScaleInherited() const
715 return mInheritScale;
719 * Retrieve the visibility of the node.
720 * @param[in] bufferIndex The buffer to read from.
721 * @return True if the node is visible.
723 bool IsVisible(BufferIndex bufferIndex) const
725 return mVisible[bufferIndex];
729 * Retrieve the opacity of the node.
730 * @param[in] bufferIndex The buffer to read from.
731 * @return The opacity.
733 float GetOpacity(BufferIndex bufferIndex) const
735 return mColor[bufferIndex].a;
739 * Retrieve the color of the node.
740 * @param[in] bufferIndex The buffer to read from.
743 const Vector4& GetColor(BufferIndex bufferIndex) const
745 return mColor[bufferIndex];
749 * Sets the color of the node derived from the color of all its parents.
750 * @param[in] color The world color.
751 * @param[in] updateBufferIndex The current update buffer index.
753 void SetWorldColor(const Vector4& color, BufferIndex updateBufferIndex)
755 mWorldColor.Set( updateBufferIndex, color );
759 * Sets the color of the node derived from the color of all its parents.
760 * This method should only be called when the parents world color is up-to-date.
761 * @pre The node has a parent.
762 * @param[in] updateBufferIndex The current update buffer index.
764 void InheritWorldColor( BufferIndex updateBufferIndex )
766 DALI_ASSERT_DEBUG(mParent != NULL);
769 if( mColorMode == USE_OWN_MULTIPLY_PARENT_ALPHA )
771 const Vector4& ownColor = mColor[updateBufferIndex];
772 mWorldColor.Set( updateBufferIndex, ownColor.r, ownColor.g, ownColor.b, ownColor.a * mParent->GetWorldColor(updateBufferIndex).a );
774 else if( mColorMode == USE_OWN_MULTIPLY_PARENT_COLOR )
776 mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) * mColor[updateBufferIndex] );
778 else if( mColorMode == USE_PARENT_COLOR )
780 mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) );
782 else // USE_OWN_COLOR
784 mWorldColor.Set( updateBufferIndex, mColor[updateBufferIndex] );
789 * Copies the previous inherited scale, if this changed in the previous frame.
790 * This method should be called instead of InheritWorldScale i.e. if the inherited scale
791 * does not need to be recalculated in the current frame.
792 * @param[in] updateBufferIndex The current update buffer index.
794 void CopyPreviousWorldColor( BufferIndex updateBufferIndex )
796 mWorldColor.CopyPrevious( updateBufferIndex );
800 * Retrieve the color of the node, possibly derived from the color
801 * of all its parents, depending on the value of mColorMode.
802 * @param[in] bufferIndex The buffer to read from.
803 * @return The world color.
805 const Vector4& GetWorldColor(BufferIndex bufferIndex) const
807 return mWorldColor[bufferIndex];
811 * Set the color mode. This specifies whether the Node uses its own color,
812 * or inherits its parent color.
813 * @param[in] colorMode The new color mode.
815 void SetColorMode(ColorMode colorMode)
817 mColorMode = colorMode;
819 SetDirtyFlag(ColorFlag);
823 * Retrieve the color mode.
824 * @return The color mode.
826 ColorMode GetColorMode() const
832 * Retrieve the size of the node.
833 * @param[in] bufferIndex The buffer to read from.
836 const Vector3& GetSize(BufferIndex bufferIndex) const
838 return mSize[bufferIndex];
842 * Check if the node is visible i.e Is not fully transparent and has valid size
844 bool ResolveVisibility( BufferIndex updateBufferIndex );
847 * Set the world-matrix of a node, with scale + rotation + translation.
848 * Scale and rotation are centered at the origin.
849 * Translation is applied independently of the scale or rotatation axis.
850 * @param[in] updateBufferIndex The current update buffer index.
851 * @param[in] scale The scale.
852 * @param[in] rotation The rotation.
853 * @param[in] translation The translation.
855 void SetWorldMatrix( BufferIndex updateBufferIndex, const Vector3& scale, const Quaternion& rotation, const Vector3& translation )
857 mWorldMatrix.Get( updateBufferIndex ).SetTransformComponents( scale, rotation, translation );
858 mWorldMatrix.SetDirty( updateBufferIndex );
862 * Retrieve the cached world-matrix of a node.
863 * @param[in] bufferIndex The buffer to read from.
864 * @return The world-matrix.
866 const Matrix& GetWorldMatrix( BufferIndex bufferIndex ) const
868 return mWorldMatrix[ bufferIndex ];
872 * Copy previous frames world matrix
873 * @param[in] updateBufferIndex The current update buffer index.
875 void CopyPreviousWorldMatrix( BufferIndex updateBufferIndex )
877 mWorldMatrix.CopyPrevious( updateBufferIndex );
881 * Mark the node as exclusive to a single RenderTask.
882 * @param[in] renderTask The render-task, or NULL if the Node is not exclusive to a single RenderTask.
884 void SetExclusiveRenderTask( RenderTask* renderTask )
886 mExclusiveRenderTask = renderTask;
890 * Query whether the node is exclusive to a single RenderTask.
891 * @return The render-task, or NULL if the Node is not exclusive to a single RenderTask.
893 RenderTask* GetExclusiveRenderTask() const
895 return mExclusiveRenderTask;
899 * Set how the Node and its children should be drawn; see Dali::Actor::SetDrawMode() for more details.
900 * @param[in] drawMode The new draw-mode to use.
902 void SetDrawMode( const DrawMode::Type& drawMode )
904 mDrawMode = drawMode;
908 * Returns whether node is an overlay or not.
909 * @return True if node is an overlay, false otherwise.
911 DrawMode::Type GetDrawMode() const
917 * Equality operator, checks for identity, not values.
920 bool operator==( const Node* rhs ) const
929 unsigned short GetDepth() const
936 * @copydoc UniformMap::Add
938 void AddUniformMapping( UniformPropertyMapping* map );
941 * @copydoc UniformMap::Remove
943 void RemoveUniformMapping( const std::string& uniformName );
946 * Prepare the node for rendering.
947 * This is called by the UpdateManager when an object is due to be rendered in the current frame.
948 * @param[in] updateBufferIndex The current update buffer index.
950 void PrepareRender( BufferIndex bufferIndex );
955 * Set the parent of a Node.
956 * @param[in] parentNode the new parent.
958 void SetParent(Node& parentNode);
961 * Protected constructor; See also Node::New()
965 private: // from NodeDataProvider
968 * @copydoc NodeDataProvider::GetModelMatrix
970 virtual const Matrix& GetModelMatrix( unsigned int bufferId ) const
972 return GetWorldMatrix( bufferId );
976 * @copydoc NodeDataProvider::GetRenderColor
978 virtual const Vector4& GetRenderColor( unsigned int bufferId ) const
980 return GetWorldColor( bufferId );
983 virtual const Vector3& GetRenderSize( unsigned int bufferId ) const
985 return GetSize( bufferId );
988 public: // From UniformMapDataProvider
990 * @copydoc UniformMapDataProvider::GetUniformMapChanged
992 virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const
994 return mUniformMapChanged[bufferIndex];
998 * @copydoc UniformMapDataProvider::GetUniformMap
1000 virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const
1002 return mCollectedUniformMap[bufferIndex];
1011 Node& operator=(const Node& rhs);
1014 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
1016 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
1019 * Recursive helper to disconnect a Node and its children.
1020 * Disconnected Nodes have no parent or children.
1021 * @param[in] updateBufferIndex The current update buffer index.
1022 * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
1023 * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
1025 void RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes );
1027 public: // Default properties
1029 PropertyVector3 mParentOrigin; ///< Local transform; the position is relative to this. Sets the TransformFlag dirty when changed
1030 PropertyVector3 mAnchorPoint; ///< Local transform; local center of rotation. Sets the TransformFlag dirty when changed
1032 AnimatableProperty<Vector3> mSize; ///< Size is provided for layouting
1033 AnimatableProperty<Vector3> mPosition; ///< Local transform; distance between parent-origin & anchor-point
1034 AnimatableProperty<Quaternion> mOrientation; ///< Local transform; rotation relative to parent node
1035 AnimatableProperty<Vector3> mScale; ///< Local transform; scale relative to parent node
1036 AnimatableProperty<bool> mVisible; ///< Visibility can be inherited from the Node hierachy
1037 AnimatableProperty<Vector4> mColor; ///< Color can be inherited from the Node hierarchy
1039 // Inherited properties; read-only from public API
1041 InheritedVector3 mWorldPosition; ///< Full inherited position
1042 InheritedQuaternion mWorldOrientation; ///< Full inherited orientation
1043 InheritedVector3 mWorldScale; ///< Full inherited scale
1044 InheritedMatrix mWorldMatrix; ///< Full inherited world matrix
1045 InheritedColor mWorldColor; ///< Full inherited color
1049 Node* mParent; ///< Pointer to parent node (a child is owned by its parent)
1050 RenderTask* mExclusiveRenderTask; ///< Nodes can be marked as exclusive to a single RenderTask
1052 NodeAttachmentOwner mAttachment; ///< Optional owned attachment
1053 RendererContainer mRenderer; ///< Container of renderers; not owned
1055 NodeContainer mChildren; ///< Container of children; not owned
1057 CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps of the node
1058 unsigned int mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame
1059 unsigned int mRegenerateUniformMap : 2; ///< Indicate if the uniform map has to be regenerated this frame
1061 // flags, compressed to bitfield
1062 unsigned short mDepth: 12; ///< Depth in the hierarchy
1063 int mDirtyFlags:8; ///< A composite set of flags for each of the Node properties
1065 bool mIsRoot:1; ///< True if the node cannot have a parent
1066 bool mInheritOrientation:1; ///< Whether the parent's orientation should be inherited.
1067 bool mInheritScale:1; ///< Whether the parent's scale should be inherited.
1068 bool mIsActive:1; ///< When a Node is marked "active" it has been disconnected, and its properties have not been modified
1070 DrawMode::Type mDrawMode:2; ///< How the Node and its children should be drawn
1071 PositionInheritanceMode mPositionInheritanceMode:2;///< Determines how position is inherited, 2 bits is enough
1072 ColorMode mColorMode:2; ///< Determines whether mWorldColor is inherited, 2 bits is enough
1074 // Changes scope, should be at end of class
1075 DALI_LOG_OBJECT_STRING_DECLARATION;
1078 // Messages for Node
1080 inline void SetInheritOrientationMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
1082 typedef MessageValue1< Node, bool > LocalType;
1084 // Reserve some memory inside the message queue
1085 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1087 // Construct message in the message queue memory; note that delete should not be called on the return value
1088 new (slot) LocalType( &node, &Node::SetInheritOrientation, inherit );
1091 inline void SetParentOriginMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& origin )
1093 typedef MessageValue1< Node, Vector3 > LocalType;
1095 // Reserve some memory inside the message queue
1096 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1098 // Construct message in the message queue memory; note that delete should not be called on the return value
1099 new (slot) LocalType( &node, &Node::SetParentOrigin, origin );
1102 inline void SetAnchorPointMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& anchor )
1104 typedef MessageValue1< Node, Vector3 > LocalType;
1106 // Reserve some memory inside the message queue
1107 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1109 // Construct message in the message queue memory; note that delete should not be called on the return value
1110 new (slot) LocalType( &node, &Node::SetAnchorPoint, anchor );
1113 inline void SetPositionInheritanceModeMessage( EventThreadServices& eventThreadServices, const Node& node, PositionInheritanceMode mode )
1115 typedef MessageValue1< Node, PositionInheritanceMode > LocalType;
1117 // Reserve some memory inside the message queue
1118 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1120 // Construct message in the message queue memory; note that delete should not be called on the return value
1121 new (slot) LocalType( &node, &Node::SetPositionInheritanceMode, mode );
1124 inline void SetInheritScaleMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
1126 typedef MessageValue1< Node, bool > LocalType;
1128 // Reserve some memory inside the message queue
1129 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1131 // Construct message in the message queue memory; note that delete should not be called on the return value
1132 new (slot) LocalType( &node, &Node::SetInheritScale, inherit );
1135 inline void SetColorModeMessage( EventThreadServices& eventThreadServices, const Node& node, ColorMode colorMode )
1137 typedef MessageValue1< Node, ColorMode > LocalType;
1139 // Reserve some memory inside the message queue
1140 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1142 // Construct message in the message queue memory; note that delete should not be called on the return value
1143 new (slot) LocalType( &node, &Node::SetColorMode, colorMode );
1146 inline void SetDrawModeMessage( EventThreadServices& eventThreadServices, const Node& node, DrawMode::Type drawMode )
1148 typedef MessageValue1< Node, DrawMode::Type > LocalType;
1150 // Reserve some memory inside the message queue
1151 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1153 // Construct message in the message queue memory; note that delete should not be called on the return value
1154 new (slot) LocalType( &node, &Node::SetDrawMode, drawMode );
1157 inline void AddRendererMessage( EventThreadServices& eventThreadServices, const Node& node, Renderer* renderer )
1159 typedef MessageValue1< Node, Renderer* > LocalType;
1161 // Reserve some memory inside the message queue
1162 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1164 // Construct message in the message queue memory; note that delete should not be called on the return value
1165 new (slot) LocalType( &node, &Node::AddRenderer, renderer );
1168 inline void RemoveRendererMessage( EventThreadServices& eventThreadServices, const Node& node, Renderer* renderer )
1170 typedef MessageValue1< Node, Renderer* > LocalType;
1172 // Reserve some memory inside the message queue
1173 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1175 // Construct message in the message queue memory; note that delete should not be called on the return value
1176 new (slot) LocalType( &node, &Node::RemoveRenderer, renderer );
1178 } // namespace SceneGraph
1180 } // namespace Internal
1184 #endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_H_