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/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 mRenderer.Erase( mRenderer.Begin()+i);
192 mRenderer.PushBack( renderer );
196 * Remove a renderer from the node
197 * @param[in] renderer The renderer to be removed
199 void RemoveRenderer( Renderer* renderer );
202 * Get the renderer at the given index
205 Renderer* GetRendererAt( unsigned int index )
207 return mRenderer[index];
211 * Retrieve the number of renderers for the node
213 unsigned int GetRendererCount()
215 return mRenderer.Size();
219 * Retreive the object attached to this node.
220 * @return The attachment.
222 NodeAttachment& GetAttachment() const
227 // Containment methods
230 * Query whether a node is the root node. Root nodes cannot have a parent node.
231 * A node becomes a root node, when it is installed by UpdateManager.
232 * @return True if the node is a root node.
240 * Set whether a node is the root node. Root nodes cannot have a parent node.
241 * This method should only be called by UpdateManager.
242 * @pre When isRoot is true, the node must not have a parent.
243 * @param[in] isRoot Whether the node is now a root node.
245 void SetRoot(bool isRoot);
248 * Retrieve the parent of a Node.
249 * @return The parent node, or NULL if the Node has not been added to the scene-graph.
257 * Retrieve the parent of a Node.
258 * @return The parent node, or NULL if the Node has not been added to the scene-graph.
260 const Node* GetParent() const
266 * Connect a node to the scene-graph.
267 * @pre A node cannot be added to itself.
268 * @pre The parent node is connected to the scene-graph.
269 * @pre The childNode does not already have a parent.
270 * @pre The childNode is not a root node.
271 * @param[in] childNode The child to add.
273 void ConnectChild( Node* childNode );
276 * Disconnect a child (& its children) from the scene-graph.
277 * @pre childNode is a child of this Node.
278 * @param[in] updateBufferIndex The current update buffer index.
279 * @param[in] childNode The node to disconnect.
280 * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
281 * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
283 void DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes );
286 * Retrieve the children a Node.
287 * @return The container of children.
289 const NodeContainer& GetChildren() const
295 * Retrieve the children a Node.
296 * @return The container of children.
298 NodeContainer& GetChildren()
306 * Flag that one of the node values has changed in the current frame.
307 * @param[in] flag The flag to set.
309 void SetDirtyFlag(NodePropertyFlags flag)
315 * Flag that all of the node values are dirty.
317 void SetAllDirtyFlags()
319 mDirtyFlags = AllFlags;
323 * Query whether a node is dirty.
324 * @return The dirty flags
326 int GetDirtyFlags() const;
329 * Query whether a node is clean.
330 * @return True if the node is clean.
334 return ( NothingFlag == GetDirtyFlags() );
338 * Retrieve the parent-origin of the node.
339 * @return The parent-origin.
341 const Vector3& GetParentOrigin() const
343 return mParentOrigin.mValue;
347 * Sets both the local & base parent-origins of the node.
348 * @param[in] origin The new local & base parent-origins.
350 void SetParentOrigin(const Vector3& origin)
352 mParentOrigin.mValue = origin;
353 mParentOrigin.OnSet();
357 * Retrieve the anchor-point of the node.
358 * @return The anchor-point.
360 const Vector3& GetAnchorPoint() const
362 return mAnchorPoint.mValue;
366 * Sets both the local & base anchor-points of the node.
367 * @param[in] anchor The new local & base anchor-points.
369 void SetAnchorPoint(const Vector3& anchor)
371 mAnchorPoint.mValue = anchor;
372 mAnchorPoint.OnSet();
376 * Retrieve the local position of the node, relative to its parent.
377 * @param[in] bufferIndex The buffer to read from.
378 * @return The local position.
380 const Vector3& GetPosition(BufferIndex bufferIndex) const
382 return mPosition[bufferIndex];
386 * Sets both the local & base positions of the node.
387 * @param[in] updateBufferIndex The current update buffer index.
388 * @param[in] position The new local & base position.
390 void BakePosition(BufferIndex updateBufferIndex, const Vector3& position)
392 mPosition.Bake( updateBufferIndex, position );
396 * Sets the world of the node derived from the position of all its parents.
397 * @param[in] updateBufferIndex The current update buffer index.
398 * @param[in] position The world position.
400 void SetWorldPosition( BufferIndex updateBufferIndex, const Vector3& position )
402 mWorldPosition.Set( updateBufferIndex, position );
406 * Sets the position of the node derived from the position of all its parents.
407 * This method should only be called when the parent's world position is up-to-date.
408 * With a non-central anchor-point, the local orientation and scale affects the world position.
409 * Therefore the world orientation & scale must be updated before the world position.
410 * @pre The node has a parent.
411 * @param[in] updateBufferIndex The current update buffer index.
413 void InheritWorldPosition(BufferIndex updateBufferIndex)
415 DALI_ASSERT_DEBUG(mParent != NULL);
417 switch( mPositionInheritanceMode )
419 case INHERIT_PARENT_POSITION : ///@see Dali::PositionInheritanceMode for how these modes are expected to work
421 Vector3 finalPosition(-0.5f, -0.5f, -0.5f);
423 finalPosition += mParentOrigin.mValue;
424 finalPosition *= mParent->GetSize(updateBufferIndex);
425 finalPosition += mPosition[updateBufferIndex];
426 finalPosition *= mParent->GetWorldScale(updateBufferIndex);
427 const Quaternion& parentWorldOrientation = mParent->GetWorldOrientation(updateBufferIndex);
428 if(!parentWorldOrientation.IsIdentity())
430 finalPosition *= parentWorldOrientation;
433 // check if a node needs to be offsetted locally (only applies when AnchorPoint is not central)
434 // dont use operator== as that does a slower comparison (and involves function calls)
435 Vector3 localOffset(0.5f, 0.5f, 0.5f); // AnchorPoint::CENTER
436 localOffset -= mAnchorPoint.mValue;
438 if( ( fabsf( localOffset.x ) >= Math::MACHINE_EPSILON_0 ) ||
439 ( fabsf( localOffset.y ) >= Math::MACHINE_EPSILON_0 ) ||
440 ( fabsf( localOffset.z ) >= Math::MACHINE_EPSILON_0 ) )
442 localOffset *= mSize[updateBufferIndex];
444 Vector3 scale = mWorldScale[updateBufferIndex];
446 // Pick up sign of local scale
447 if (mScale[updateBufferIndex].x < 0.0f)
451 if (mScale[updateBufferIndex].y < 0.0f)
455 if (mScale[updateBufferIndex].z < 0.0f)
460 // If the anchor-point is not central, then position is affected by the local orientation & scale
461 localOffset *= scale;
462 const Quaternion& localWorldOrientation = mWorldOrientation[updateBufferIndex];
463 if(!localWorldOrientation.IsIdentity())
465 localOffset *= localWorldOrientation;
467 finalPosition += localOffset;
470 finalPosition += mParent->GetWorldPosition(updateBufferIndex);
471 mWorldPosition.Set( updateBufferIndex, finalPosition );
474 case USE_PARENT_POSITION_PLUS_LOCAL_POSITION :
476 // copy parents position plus local transform
477 mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) + mPosition[updateBufferIndex] );
480 case USE_PARENT_POSITION :
482 // copy parents position
483 mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) );
486 case DONT_INHERIT_POSITION :
488 // use local position as world position
489 mWorldPosition.Set( updateBufferIndex, mPosition[updateBufferIndex] );
496 * Copies the previous inherited position, if this changed in the previous frame.
497 * This method should be called instead of InheritWorldPosition i.e. if the inherited position
498 * does not need to be recalculated in the current frame.
499 * @param[in] updateBufferIndex The current update buffer index.
501 void CopyPreviousWorldPosition( BufferIndex updateBufferIndex )
503 mWorldPosition.CopyPrevious( updateBufferIndex );
507 * Retrieve the position of the node derived from the position of all its parents.
508 * @return The world position.
510 const Vector3& GetWorldPosition( BufferIndex bufferIndex ) const
512 return mWorldPosition[bufferIndex];
516 * Set the position inheritance mode.
517 * @see Dali::Actor::PositionInheritanceMode
518 * @param[in] mode The new position inheritance mode.
520 void SetPositionInheritanceMode( PositionInheritanceMode mode )
522 mPositionInheritanceMode = mode;
524 SetDirtyFlag(TransformFlag);
528 * @return The position inheritance mode.
530 PositionInheritanceMode GetPositionInheritanceMode() const
532 return mPositionInheritanceMode;
536 * Retrieve the local orientation of the node, relative to its parent.
537 * @param[in] bufferIndex The buffer to read from.
538 * @return The local orientation.
540 const Quaternion& GetOrientation(BufferIndex bufferIndex) const
542 return mOrientation[bufferIndex];
546 * Sets both the local & base orientations of the node.
547 * @param[in] updateBufferIndex The current update buffer index.
548 * @param[in] orientation The new local & base orientation.
550 void BakeOrientation(BufferIndex updateBufferIndex, const Quaternion& orientation)
552 mOrientation.Bake( updateBufferIndex, orientation );
556 * Sets the orientation of the node derived from the rotation of all its parents.
557 * @param[in] updateBufferIndex The current update buffer index.
558 * @param[in] orientation The world orientation.
560 void SetWorldOrientation( BufferIndex updateBufferIndex, const Quaternion& orientation )
562 mWorldOrientation.Set( updateBufferIndex, orientation );
566 * Sets the orientation of the node derived from the rotation of all its parents.
567 * This method should only be called when the parents world orientation is up-to-date.
568 * @pre The node has a parent.
569 * @param[in] updateBufferIndex The current update buffer index.
571 void InheritWorldOrientation( BufferIndex updateBufferIndex )
573 DALI_ASSERT_DEBUG(mParent != NULL);
575 const Quaternion& localOrientation = mOrientation[updateBufferIndex];
577 if(localOrientation.IsIdentity())
579 mWorldOrientation.Set( updateBufferIndex, mParent->GetWorldOrientation(updateBufferIndex) );
583 Quaternion finalOrientation( mParent->GetWorldOrientation(updateBufferIndex) );
584 finalOrientation *= localOrientation;
585 mWorldOrientation.Set( updateBufferIndex, finalOrientation );
590 * Copies the previous inherited orientation, if this changed in the previous frame.
591 * This method should be called instead of InheritWorldOrientation i.e. if the inherited orientation
592 * does not need to be recalculated in the current frame.
593 * @param[in] updateBufferIndex The current update buffer index.
595 void CopyPreviousWorldOrientation( BufferIndex updateBufferIndex )
597 mWorldOrientation.CopyPrevious( updateBufferIndex );
601 * Retrieve the orientation of the node derived from the rotation of all its parents.
602 * @param[in] bufferIndex The buffer to read from.
603 * @return The world rotation.
605 const Quaternion& GetWorldOrientation( BufferIndex bufferIndex ) const
607 return mWorldOrientation[bufferIndex];
611 * Set whether the Node inherits orientation.
612 * @param[in] inherit True if the parent orientation is inherited.
614 void SetInheritOrientation(bool inherit)
616 if (inherit != mInheritOrientation)
618 mInheritOrientation = inherit;
620 SetDirtyFlag(TransformFlag);
625 * Query whether the node inherits orientation from its parent.
626 * @return True if the parent orientation is inherited.
628 bool IsOrientationInherited() const
630 return mInheritOrientation;
634 * Retrieve the local scale of the node, relative to its parent.
635 * @param[in] bufferIndex The buffer to read from.
636 * @return The local scale.
638 const Vector3& GetScale(BufferIndex bufferIndex) const
640 return mScale[bufferIndex];
644 * Sets the scale of the node derived from the scale of all its parents and a pre-scale
645 * @param[in] updateBufferIndex The current update buffer index.
646 * @param[in] scale The world scale.
648 void SetWorldScale(BufferIndex updateBufferIndex, const Vector3& scale)
650 mWorldScale.Set( updateBufferIndex, scale );
654 * Sets the scale of the node derived from the scale of all its parents and a pre-scale.
655 * This method should only be called when the parents world scale is up-to-date.
656 * @pre The node has a parent.
657 * @param[in] updateBufferIndex The current update buffer index.
659 void InheritWorldScale(BufferIndex updateBufferIndex)
661 DALI_ASSERT_DEBUG(mParent != NULL);
663 mWorldScale.Set( updateBufferIndex, mParent->GetWorldScale(updateBufferIndex) * mScale[updateBufferIndex] );
667 * Copies the previous inherited scale, if this changed in the previous frame.
668 * This method should be called instead of InheritWorldScale i.e. if the inherited scale
669 * does not need to be recalculated in the current frame.
670 * @param[in] updateBufferIndex The current update buffer index.
672 void CopyPreviousWorldScale( BufferIndex updateBufferIndex )
674 mWorldScale.CopyPrevious( updateBufferIndex );
678 * Retrieve the scale of the node derived from the scale of all its parents.
679 * @param[in] bufferIndex The buffer to read from.
680 * @return The world scale.
682 const Vector3& GetWorldScale( BufferIndex bufferIndex ) const
684 return mWorldScale[bufferIndex];
688 * Set whether the Node inherits scale.
689 * @param inherit True if the Node inherits scale.
691 void SetInheritScale( bool inherit )
693 if( inherit != mInheritScale )
695 mInheritScale = inherit;
697 SetDirtyFlag( TransformFlag );
702 * Query whether the Node inherits scale.
703 * @return if scale is inherited
705 bool IsScaleInherited() const
707 return mInheritScale;
711 * Copies the previously used size, if this changed in the previous frame.
712 * @param[in] updateBufferIndex The current update buffer index.
714 void CopyPreviousSize( BufferIndex updateBufferIndex )
716 SetSize( updateBufferIndex, GetSize( 1u - updateBufferIndex ) );
720 * Retrieve the visibility of the node.
721 * @param[in] bufferIndex The buffer to read from.
722 * @return True if the node is visible.
724 bool IsVisible(BufferIndex bufferIndex) const
726 return mVisible[bufferIndex];
730 * Retrieves whether a node is fully visible.
731 * A node is fully visible if is visible and all its ancestors are visible.
732 * @param[in] updateBufferIndex The current update buffer index.
733 * @return True if the node is fully visible.
735 bool IsFullyVisible( BufferIndex updateBufferIndex ) const;
738 * Retrieve the opacity of the node.
739 * @param[in] bufferIndex The buffer to read from.
740 * @return The opacity.
742 float GetOpacity(BufferIndex bufferIndex) const
744 return mColor[bufferIndex].a;
748 * Retrieve the color of the node.
749 * @param[in] bufferIndex The buffer to read from.
752 const Vector4& GetColor(BufferIndex bufferIndex) const
754 return mColor[bufferIndex];
758 * Sets the color of the node derived from the color of all its parents.
759 * @param[in] color The world color.
760 * @param[in] updateBufferIndex The current update buffer index.
762 void SetWorldColor(const Vector4& color, BufferIndex updateBufferIndex)
764 mWorldColor.Set( updateBufferIndex, color );
768 * Sets the color of the node derived from the color of all its parents.
769 * This method should only be called when the parents world color is up-to-date.
770 * @pre The node has a parent.
771 * @param[in] updateBufferIndex The current update buffer index.
773 void InheritWorldColor( BufferIndex updateBufferIndex )
775 DALI_ASSERT_DEBUG(mParent != NULL);
778 if( mColorMode == USE_OWN_MULTIPLY_PARENT_ALPHA )
780 const Vector4& ownColor = mColor[updateBufferIndex];
781 mWorldColor.Set( updateBufferIndex, ownColor.r, ownColor.g, ownColor.b, ownColor.a * mParent->GetWorldColor(updateBufferIndex).a );
783 else if( mColorMode == USE_OWN_MULTIPLY_PARENT_COLOR )
785 mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) * mColor[updateBufferIndex] );
787 else if( mColorMode == USE_PARENT_COLOR )
789 mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) );
791 else // USE_OWN_COLOR
793 mWorldColor.Set( updateBufferIndex, mColor[updateBufferIndex] );
798 * Copies the previous inherited scale, if this changed in the previous frame.
799 * This method should be called instead of InheritWorldScale i.e. if the inherited scale
800 * does not need to be recalculated in the current frame.
801 * @param[in] updateBufferIndex The current update buffer index.
803 void CopyPreviousWorldColor( BufferIndex updateBufferIndex )
805 mWorldColor.CopyPrevious( updateBufferIndex );
809 * Retrieve the color of the node, possibly derived from the color
810 * of all its parents, depending on the value of mColorMode.
811 * @param[in] bufferIndex The buffer to read from.
812 * @return The world color.
814 const Vector4& GetWorldColor(BufferIndex bufferIndex) const
816 return mWorldColor[bufferIndex];
820 * Set the color mode. This specifies whether the Node uses its own color,
821 * or inherits its parent color.
822 * @param[in] colorMode The new color mode.
824 void SetColorMode(ColorMode colorMode)
826 mColorMode = colorMode;
828 SetDirtyFlag(ColorFlag);
832 * Retrieve the color mode.
833 * @return The color mode.
835 ColorMode GetColorMode() const
841 * Sets the size of the node.
842 * @param[in] bufferIndex The buffer to write to.
843 * @param[in] size The size to write.
845 void SetSize( BufferIndex bufferIndex, const Vector3& size )
847 mSize[bufferIndex] = size;
851 * Retrieve the size of the node.
852 * @param[in] bufferIndex The buffer to read from.
855 const Vector3& GetSize(BufferIndex bufferIndex) const
857 return mSize[bufferIndex];
861 * Check if the node is visible i.e Is not fully transparent and has valid size
863 bool ResolveVisibility( BufferIndex updateBufferIndex );
866 * Set the world-matrix of a node, with scale + rotation + translation.
867 * Scale and rotation are centered at the origin.
868 * Translation is applied independently of the scale or rotatation axis.
869 * @param[in] updateBufferIndex The current update buffer index.
870 * @param[in] scale The scale.
871 * @param[in] rotation The rotation.
872 * @param[in] translation The translation.
874 void SetWorldMatrix( BufferIndex updateBufferIndex, const Vector3& scale, const Quaternion& rotation, const Vector3& translation )
876 mWorldMatrix.Get( updateBufferIndex ).SetTransformComponents( scale, rotation, translation );
877 mWorldMatrix.SetDirty( updateBufferIndex );
881 * Retrieve the cached world-matrix of a node.
882 * @param[in] bufferIndex The buffer to read from.
883 * @return The world-matrix.
885 const Matrix& GetWorldMatrix( BufferIndex bufferIndex ) const
887 return mWorldMatrix[ bufferIndex ];
891 * Copy previous frames world matrix
892 * @param[in] updateBufferIndex The current update buffer index.
894 void CopyPreviousWorldMatrix( BufferIndex updateBufferIndex )
896 mWorldMatrix.CopyPrevious( updateBufferIndex );
900 * Mark the node as exclusive to a single RenderTask.
901 * @param[in] renderTask The render-task, or NULL if the Node is not exclusive to a single RenderTask.
903 void SetExclusiveRenderTask( RenderTask* renderTask )
905 mExclusiveRenderTask = renderTask;
909 * Query whether the node is exclusive to a single RenderTask.
910 * @return The render-task, or NULL if the Node is not exclusive to a single RenderTask.
912 RenderTask* GetExclusiveRenderTask() const
914 return mExclusiveRenderTask;
918 * Set how the Node and its children should be drawn; see Dali::Actor::SetDrawMode() for more details.
919 * @param[in] drawMode The new draw-mode to use.
921 void SetDrawMode( const DrawMode::Type& drawMode )
923 mDrawMode = drawMode;
927 * Returns whether node is an overlay or not.
928 * @return True if node is an overlay, false otherwise.
930 DrawMode::Type GetDrawMode() const
936 * Equality operator, checks for identity, not values.
939 bool operator==( const Node* rhs ) const
949 * Set the inhibit local transform flag.@n
950 * Setting this flag will stop the node's local transform (position, scale and orientation)
951 * being applied on top of its parents transformation.
952 * @param[in] flag When true, local transformation is inhibited when calculating the world matrix.
954 void SetInhibitLocalTransform( bool flag )
956 SetDirtyFlag( TransformFlag );
957 mInhibitLocalTransform = flag;
961 * Get the inhibit local transform flag.@n
962 * See @ref SetInhibitLocalTransform
963 * @result A flag, when true, local transformation is inhibited when calculating the world matrix.
965 bool GetInhibitLocalTransform() const
967 return mInhibitLocalTransform;
970 unsigned short GetDepth() const
977 * @copydoc UniformMap::Add
979 void AddUniformMapping( UniformPropertyMapping* map );
982 * @copydoc UniformMap::Remove
984 void RemoveUniformMapping( const std::string& uniformName );
987 * Prepare the node for rendering.
988 * This is called by the UpdateManager when an object is due to be rendered in the current frame.
989 * @param[in] updateBufferIndex The current update buffer index.
991 void PrepareRender( BufferIndex bufferIndex );
996 * Set the parent of a Node.
997 * @param[in] parentNode the new parent.
999 void SetParent(Node& parentNode);
1002 * Protected constructor; See also Node::New()
1006 private: // from NodeDataProvider
1009 * @copydoc NodeDataProvider::GetModelMatrix
1011 virtual const Matrix& GetModelMatrix( unsigned int bufferId ) const
1013 return GetWorldMatrix( bufferId );
1017 * @copydoc NodeDataProvider::GetRenderColor
1019 virtual const Vector4& GetRenderColor( unsigned int bufferId ) const
1021 return GetWorldColor( bufferId );
1024 virtual const Vector3& GetRenderSize( unsigned int bufferId ) const
1026 return GetSize( bufferId );
1029 public: // From UniformMapDataProvider
1031 * @copydoc UniformMapDataProvider::GetUniformMapChanged
1033 virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const
1035 return mUniformMapChanged[bufferIndex];
1039 * @copydoc UniformMapDataProvider::GetUniformMap
1041 virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const
1043 return mCollectedUniformMap[bufferIndex];
1052 Node& operator=(const Node& rhs);
1055 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
1057 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
1060 * Recursive helper to disconnect a Node and its children.
1061 * Disconnected Nodes have no parent or children.
1062 * @param[in] updateBufferIndex The current update buffer index.
1063 * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
1064 * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
1066 void RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes );
1068 public: // Default properties
1070 PropertyVector3 mParentOrigin; ///< Local transform; the position is relative to this. Sets the TransformFlag dirty when changed
1071 PropertyVector3 mAnchorPoint; ///< Local transform; local center of rotation. Sets the TransformFlag dirty when changed
1073 AnimatableProperty<Vector3> mSize; ///< Size is provided for layouting
1074 AnimatableProperty<Vector3> mPosition; ///< Local transform; distance between parent-origin & anchor-point
1075 AnimatableProperty<Quaternion> mOrientation; ///< Local transform; rotation relative to parent node
1076 AnimatableProperty<Vector3> mScale; ///< Local transform; scale relative to parent node
1077 AnimatableProperty<bool> mVisible; ///< Visibility can be inherited from the Node hierachy
1078 AnimatableProperty<Vector4> mColor; ///< Color can be inherited from the Node hierarchy
1080 // Inherited properties; read-only from public API
1082 InheritedVector3 mWorldPosition; ///< Full inherited position
1083 InheritedQuaternion mWorldOrientation; ///< Full inherited orientation
1084 InheritedVector3 mWorldScale; ///< Full inherited scale
1085 InheritedMatrix mWorldMatrix; ///< Full inherited world matrix
1086 InheritedColor mWorldColor; ///< Full inherited color
1090 Node* mParent; ///< Pointer to parent node (a child is owned by its parent)
1091 RenderTask* mExclusiveRenderTask; ///< Nodes can be marked as exclusive to a single RenderTask
1093 NodeAttachmentOwner mAttachment; ///< Optional owned attachment
1094 RendererContainer mRenderer; ///< Container of renderers; not owned
1096 NodeContainer mChildren; ///< Container of children; not owned
1098 CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps of the node
1099 unsigned int mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame
1100 unsigned int mRegenerateUniformMap : 2; ///< Indicate if the uniform map has to be regenerated this frame
1102 // flags, compressed to bitfield
1103 unsigned short mDepth: 12; ///< Depth in the hierarchy
1104 int mDirtyFlags:8; ///< A composite set of flags for each of the Node properties
1106 bool mIsRoot:1; ///< True if the node cannot have a parent
1107 bool mInheritOrientation:1; ///< Whether the parent's orientation should be inherited.
1108 bool mInheritScale:1; ///< Whether the parent's scale should be inherited.
1109 bool mInhibitLocalTransform:1; ///< whether local transform should be applied.
1110 bool mIsActive:1; ///< When a Node is marked "active" it has been disconnected, and its properties have not been modified
1112 DrawMode::Type mDrawMode:2; ///< How the Node and its children should be drawn
1113 PositionInheritanceMode mPositionInheritanceMode:2;///< Determines how position is inherited, 2 bits is enough
1114 ColorMode mColorMode:2; ///< Determines whether mWorldColor is inherited, 2 bits is enough
1116 // Changes scope, should be at end of class
1117 DALI_LOG_OBJECT_STRING_DECLARATION;
1120 // Messages for Node
1122 inline void SetInheritOrientationMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
1124 typedef MessageValue1< Node, bool > LocalType;
1126 // Reserve some memory inside the message queue
1127 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1129 // Construct message in the message queue memory; note that delete should not be called on the return value
1130 new (slot) LocalType( &node, &Node::SetInheritOrientation, inherit );
1133 inline void SetParentOriginMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& origin )
1135 typedef MessageValue1< Node, Vector3 > LocalType;
1137 // Reserve some memory inside the message queue
1138 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1140 // Construct message in the message queue memory; note that delete should not be called on the return value
1141 new (slot) LocalType( &node, &Node::SetParentOrigin, origin );
1144 inline void SetAnchorPointMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& anchor )
1146 typedef MessageValue1< Node, Vector3 > LocalType;
1148 // Reserve some memory inside the message queue
1149 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1151 // Construct message in the message queue memory; note that delete should not be called on the return value
1152 new (slot) LocalType( &node, &Node::SetAnchorPoint, anchor );
1155 inline void SetPositionInheritanceModeMessage( EventThreadServices& eventThreadServices, const Node& node, PositionInheritanceMode mode )
1157 typedef MessageValue1< Node, PositionInheritanceMode > LocalType;
1159 // Reserve some memory inside the message queue
1160 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1162 // Construct message in the message queue memory; note that delete should not be called on the return value
1163 new (slot) LocalType( &node, &Node::SetPositionInheritanceMode, mode );
1166 inline void SetInheritScaleMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
1168 typedef MessageValue1< Node, bool > LocalType;
1170 // Reserve some memory inside the message queue
1171 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1173 // Construct message in the message queue memory; note that delete should not be called on the return value
1174 new (slot) LocalType( &node, &Node::SetInheritScale, inherit );
1177 inline void SetColorModeMessage( EventThreadServices& eventThreadServices, const Node& node, ColorMode colorMode )
1179 typedef MessageValue1< Node, ColorMode > LocalType;
1181 // Reserve some memory inside the message queue
1182 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1184 // Construct message in the message queue memory; note that delete should not be called on the return value
1185 new (slot) LocalType( &node, &Node::SetColorMode, colorMode );
1188 inline void SetDrawModeMessage( EventThreadServices& eventThreadServices, const Node& node, DrawMode::Type drawMode )
1190 typedef MessageValue1< Node, DrawMode::Type > LocalType;
1192 // Reserve some memory inside the message queue
1193 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1195 // Construct message in the message queue memory; note that delete should not be called on the return value
1196 new (slot) LocalType( &node, &Node::SetDrawMode, drawMode );
1199 inline void AddRendererMessage( EventThreadServices& eventThreadServices, const Node& node, Renderer* renderer )
1201 typedef MessageValue1< Node, Renderer* > LocalType;
1203 // Reserve some memory inside the message queue
1204 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1206 // Construct message in the message queue memory; note that delete should not be called on the return value
1207 new (slot) LocalType( &node, &Node::AddRenderer, renderer );
1210 inline void RemoveRendererMessage( EventThreadServices& eventThreadServices, const Node& node, Renderer* renderer )
1212 typedef MessageValue1< Node, Renderer* > LocalType;
1214 // Reserve some memory inside the message queue
1215 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1217 // Construct message in the message queue memory; note that delete should not be called on the return value
1218 new (slot) LocalType( &node, &Node::RemoveRenderer, renderer );
1220 } // namespace SceneGraph
1222 } // namespace Internal
1226 #endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_H_