Removed sets of connected/disconnected nodes. Brought back a vector of sorted nodes...
[platform/core/uifw/dali-core.git] / dali / internal / update / nodes / node.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_NODE_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_NODE_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
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>
40
41 namespace Dali
42 {
43
44 namespace Internal
45 {
46
47 // value types used by messages
48 template <> struct ParameterType< ColorMode > : public BasicType< ColorMode > {};
49 template <> struct ParameterType< PositionInheritanceMode > : public BasicType< PositionInheritanceMode > {};
50
51 namespace SceneGraph
52 {
53
54 class DiscardQueue;
55 class Layer;
56 class NodeAttachment;
57 class RenderTask;
58 class UpdateManager;
59
60 /**
61  * Flag whether property has changed, during the Update phase.
62  */
63 enum NodePropertyFlags
64 {
65   NothingFlag          = 0x000,
66   TransformFlag        = 0x001,
67   VisibleFlag          = 0x002,
68   ColorFlag            = 0x004,
69   SizeFlag             = 0x008,
70   OverlayFlag          = 0x010,
71   SortModifierFlag     = 0x020,
72   ChildDeletedFlag     = 0x040
73 };
74
75 static const int AllFlags = ( ChildDeletedFlag << 1 ) - 1; // all the flags
76
77 /**
78  * Size is not inherited.
79  * VisibleFlag is inherited so that attachments can be synchronized with nodes after they become visible
80  */
81 static const int InheritedDirtyFlags = TransformFlag | VisibleFlag | ColorFlag | OverlayFlag;
82
83 // Flags which require the scene renderable lists to be updated
84 static const int RenderableUpdateFlags = TransformFlag | SortModifierFlag | ChildDeletedFlag;
85
86 /**
87  * Node is the base class for all nodes in the Scene Graph.
88  *
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.
93  */
94 class Node : public PropertyOwner, public NodeDataProvider
95 {
96 public:
97
98   // Defaults
99   static const PositionInheritanceMode DEFAULT_POSITION_INHERITANCE_MODE;
100   static const ColorMode DEFAULT_COLOR_MODE;
101
102   // Creation methods
103
104   /**
105    * Construct a new Node.
106    */
107   static Node* New();
108
109   /**
110    * Virtual destructor
111    */
112   virtual ~Node();
113
114   /**
115    * Overriden delete operator
116    * Deletes the node from its global memory pool
117    */
118   void operator delete( void* ptr );
119
120   /**
121    * Called during UpdateManager::DestroyNode shortly before Node is destroyed.
122    */
123   void OnDestroy();
124
125   // Layer interface
126
127   /**
128    * Query whether the node is a layer.
129    * @return True if the node is a layer.
130    */
131   bool IsLayer()
132   {
133     return (GetLayer() != NULL);
134   }
135
136   /**
137    * Convert a node to a layer.
138    * @return A pointer to the layer, or NULL.
139    */
140   virtual Layer* GetLayer()
141   {
142     return NULL;
143   }
144
145   // Attachments
146
147   /**
148    * Attach an object to this Node; This should only be done by UpdateManager::AttachToNode.
149    * @pre The Node does not already have an attachment.
150    * @param[in] attachment The object to attach.
151    */
152   void Attach( NodeAttachment& attachment );
153
154   /**
155    * Query the node if it has an attachment.
156    * @return True if it has an attachment.
157    */
158   bool HasAttachment() const
159   {
160     return mAttachment;
161   }
162
163   /**
164    * Add a renderer to the node
165    * @param[in] renderer The renderer added to the node
166    */
167   void AddRenderer( Renderer* renderer )
168   {
169     //Check that it has not been already added
170     unsigned int rendererCount( mRenderer.Size() );
171     for( unsigned int i(0); i<rendererCount; ++i )
172     {
173       if( mRenderer[i] == renderer )
174       {
175         //Renderer already in the list
176         return;
177       }
178     }
179
180     //If it is the first renderer added, make sure the world transform will be calculated
181     //in the next update as world transform is not computed if node has no renderers
182     if( rendererCount == 0 )
183     {
184       mDirtyFlags |= TransformFlag;
185     }
186
187     mRenderer.PushBack( renderer );
188   }
189
190   /**
191    * Remove a renderer from the node
192    * @param[in] renderer The renderer to be removed
193    */
194   void RemoveRenderer( Renderer* renderer );
195
196   /*
197    * Get the renderer at the given index
198    * @param[in] index
199    */
200   Renderer* GetRendererAt( unsigned int index )
201   {
202     return mRenderer[index];
203   }
204
205   /**
206    * Retrieve the number of renderers for the node
207    */
208   unsigned int GetRendererCount()
209   {
210     return mRenderer.Size();
211   }
212
213   /**
214    * Retreive the object attached to this node.
215    * @return The attachment.
216    */
217   NodeAttachment& GetAttachment() const
218   {
219     return *mAttachment;
220   }
221
222   // Containment methods
223
224   /**
225    * Query whether a node is the root node. Root nodes cannot have a parent node.
226    * A node becomes a root node, when it is installed by UpdateManager.
227    * @return True if the node is a root node.
228    */
229   bool IsRoot() const
230   {
231     return mIsRoot;
232   }
233
234   /**
235    * Set whether a node is the root node. Root nodes cannot have a parent node.
236    * This method should only be called by UpdateManager.
237    * @pre When isRoot is true, the node must not have a parent.
238    * @param[in] isRoot Whether the node is now a root node.
239    */
240   void SetRoot(bool isRoot);
241
242   /**
243    * Retrieve the parent of a Node.
244    * @return The parent node, or NULL if the Node has not been added to the scene-graph.
245    */
246   Node* GetParent()
247   {
248     return mParent;
249   }
250
251   /**
252    * Retrieve the parent of a Node.
253    * @return The parent node, or NULL if the Node has not been added to the scene-graph.
254    */
255   const Node* GetParent() const
256   {
257     return mParent;
258   }
259
260   /**
261    * Connect a node to the scene-graph.
262    * @pre A node cannot be added to itself.
263    * @pre The parent node is connected to the scene-graph.
264    * @pre The childNode does not already have a parent.
265    * @pre The childNode is not a root node.
266    * @param[in] childNode The child to add.
267    */
268   void ConnectChild( Node* childNode );
269
270   /**
271    * Disconnect a child (& its children) from the scene-graph.
272    * @pre childNode is a child of this Node.
273    * @param[in] updateBufferIndex The current update buffer index.
274    * @param[in] childNode The node to disconnect.
275    */
276   void DisconnectChild( BufferIndex updateBufferIndex, Node& childNode );
277
278   /**
279    * Retrieve the children a Node.
280    * @return The container of children.
281    */
282   const NodeContainer& GetChildren() const
283   {
284     return mChildren;
285   }
286
287   /**
288    * Retrieve the children a Node.
289    * @return The container of children.
290    */
291   NodeContainer& GetChildren()
292   {
293     return mChildren;
294   }
295
296   // Update methods
297
298   /**
299    * Flag that one of the node values has changed in the current frame.
300    * @param[in] flag The flag to set.
301    */
302   void SetDirtyFlag(NodePropertyFlags flag)
303   {
304     mDirtyFlags |= flag;
305   }
306
307   /**
308    * Flag that all of the node values are dirty.
309    */
310   void SetAllDirtyFlags()
311   {
312     mDirtyFlags = AllFlags;
313   }
314
315   /**
316    * Query whether a node is dirty.
317    * @return The dirty flags
318    */
319   int GetDirtyFlags() const;
320
321   /**
322    * Query whether a node is clean.
323    * @return True if the node is clean.
324    */
325   bool IsClean() const
326   {
327     return ( NothingFlag == GetDirtyFlags() );
328   }
329
330   /**
331    * Retrieve the parent-origin of the node.
332    * @return The parent-origin.
333    */
334   const Vector3& GetParentOrigin() const
335   {
336     return mParentOrigin.mValue;
337   }
338
339   /**
340    * Sets both the local & base parent-origins of the node.
341    * @param[in] origin The new local & base parent-origins.
342    */
343   void SetParentOrigin(const Vector3& origin)
344   {
345     mParentOrigin.mValue = origin;
346     mParentOrigin.OnSet();
347   }
348
349   /**
350    * Retrieve the anchor-point of the node.
351    * @return The anchor-point.
352    */
353   const Vector3& GetAnchorPoint() const
354   {
355     return mAnchorPoint.mValue;
356   }
357
358   /**
359    * Sets both the local & base anchor-points of the node.
360    * @param[in] anchor The new local & base anchor-points.
361    */
362   void SetAnchorPoint(const Vector3& anchor)
363   {
364     mAnchorPoint.mValue = anchor;
365     mAnchorPoint.OnSet();
366   }
367
368   /**
369    * Retrieve the local position of the node, relative to its parent.
370    * @param[in] bufferIndex The buffer to read from.
371    * @return The local position.
372    */
373   const Vector3& GetPosition(BufferIndex bufferIndex) const
374   {
375     return mPosition[bufferIndex];
376   }
377
378   /**
379    * Sets both the local & base positions of the node.
380    * @param[in] updateBufferIndex The current update buffer index.
381    * @param[in] position The new local & base position.
382    */
383   void BakePosition(BufferIndex updateBufferIndex, const Vector3& position)
384   {
385     mPosition.Bake( updateBufferIndex, position );
386   }
387
388   /**
389    * Sets the world of the node derived from the position of all its parents.
390    * @param[in] updateBufferIndex The current update buffer index.
391    * @param[in] position The world position.
392    */
393   void SetWorldPosition( BufferIndex updateBufferIndex, const Vector3& position )
394   {
395     mWorldPosition.Set( updateBufferIndex, position );
396   }
397
398   /**
399    * Sets the position of the node derived from the position of all its parents.
400    * This method should only be called when the parent's world position is up-to-date.
401    * With a non-central anchor-point, the local orientation and scale affects the world position.
402    * Therefore the world orientation & scale must be updated before the world position.
403    * @pre The node has a parent.
404    * @param[in] updateBufferIndex The current update buffer index.
405    */
406   void InheritWorldPosition(BufferIndex updateBufferIndex)
407   {
408     DALI_ASSERT_DEBUG(mParent != NULL);
409
410     switch( mPositionInheritanceMode )
411     {
412       case INHERIT_PARENT_POSITION  : ///@see Dali::PositionInheritanceMode for how these modes are expected to work
413       {
414         Vector3 finalPosition(-0.5f, -0.5f, -0.5f);
415
416         finalPosition += mParentOrigin.mValue;
417         finalPosition *= mParent->GetSize(updateBufferIndex);
418         finalPosition += mPosition[updateBufferIndex];
419         finalPosition *= mParent->GetWorldScale(updateBufferIndex);
420         const Quaternion& parentWorldOrientation = mParent->GetWorldOrientation(updateBufferIndex);
421         if(!parentWorldOrientation.IsIdentity())
422         {
423           finalPosition *= parentWorldOrientation;
424         }
425
426         // check if a node needs to be offsetted locally (only applies when AnchorPoint is not central)
427         // dont use operator== as that does a slower comparison (and involves function calls)
428         Vector3 localOffset(0.5f, 0.5f, 0.5f);    // AnchorPoint::CENTER
429         localOffset -= mAnchorPoint.mValue;
430
431         if( ( fabsf( localOffset.x ) >= Math::MACHINE_EPSILON_0 ) ||
432             ( fabsf( localOffset.y ) >= Math::MACHINE_EPSILON_0 ) ||
433             ( fabsf( localOffset.z ) >= Math::MACHINE_EPSILON_0 ) )
434         {
435           localOffset *= mSize[updateBufferIndex];
436
437           Vector3 scale = mWorldScale[updateBufferIndex];
438
439           // Pick up sign of local scale
440           if (mScale[updateBufferIndex].x < 0.0f)
441           {
442             scale.x = -scale.x;
443           }
444           if (mScale[updateBufferIndex].y < 0.0f)
445           {
446             scale.y = -scale.y;
447           }
448           if (mScale[updateBufferIndex].z < 0.0f)
449           {
450             scale.z = -scale.z;
451           }
452
453           // If the anchor-point is not central, then position is affected by the local orientation & scale
454           localOffset *= scale;
455           const Quaternion& localWorldOrientation = mWorldOrientation[updateBufferIndex];
456           if(!localWorldOrientation.IsIdentity())
457           {
458             localOffset *= localWorldOrientation;
459           }
460           finalPosition += localOffset;
461         }
462
463         finalPosition += mParent->GetWorldPosition(updateBufferIndex);
464         mWorldPosition.Set( updateBufferIndex, finalPosition );
465         break;
466       }
467       case USE_PARENT_POSITION_PLUS_LOCAL_POSITION :
468       {
469         // copy parents position plus local transform
470         mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) + mPosition[updateBufferIndex] );
471         break;
472       }
473       case USE_PARENT_POSITION :
474       {
475         // copy parents position
476         mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) );
477         break;
478       }
479       case DONT_INHERIT_POSITION :
480       {
481         // use local position as world position
482         mWorldPosition.Set( updateBufferIndex, mPosition[updateBufferIndex] );
483         break;
484       }
485     }
486   }
487
488   /**
489    * Copies the previous inherited position, if this changed in the previous frame.
490    * This method should be called instead of InheritWorldPosition i.e. if the inherited position
491    * does not need to be recalculated in the current frame.
492    * @param[in] updateBufferIndex The current update buffer index.
493    */
494   void CopyPreviousWorldPosition( BufferIndex updateBufferIndex )
495   {
496     mWorldPosition.CopyPrevious( updateBufferIndex );
497   }
498
499   /**
500    * Retrieve the position of the node derived from the position of all its parents.
501    * @return The world position.
502    */
503   const Vector3& GetWorldPosition( BufferIndex bufferIndex ) const
504   {
505     return mWorldPosition[bufferIndex];
506   }
507
508   /**
509    * Set the position inheritance mode.
510    * @see Dali::Actor::PositionInheritanceMode
511    * @param[in] mode The new position inheritance mode.
512    */
513   void SetPositionInheritanceMode( PositionInheritanceMode mode )
514   {
515     mPositionInheritanceMode = mode;
516
517     SetDirtyFlag(TransformFlag);
518   }
519
520   /**
521    * @return The position inheritance mode.
522    */
523   PositionInheritanceMode GetPositionInheritanceMode() const
524   {
525     return mPositionInheritanceMode;
526   }
527
528   /**
529    * Retrieve the local orientation of the node, relative to its parent.
530    * @param[in] bufferIndex The buffer to read from.
531    * @return The local orientation.
532    */
533   const Quaternion& GetOrientation(BufferIndex bufferIndex) const
534   {
535     return mOrientation[bufferIndex];
536   }
537
538   /**
539    * Sets both the local & base orientations of the node.
540    * @param[in] updateBufferIndex The current update buffer index.
541    * @param[in] orientation The new local & base orientation.
542    */
543   void BakeOrientation(BufferIndex updateBufferIndex, const Quaternion& orientation)
544   {
545     mOrientation.Bake( updateBufferIndex, orientation );
546   }
547
548   /**
549    * Sets the orientation of the node derived from the rotation of all its parents.
550    * @param[in] updateBufferIndex The current update buffer index.
551    * @param[in] orientation The world orientation.
552    */
553   void SetWorldOrientation( BufferIndex updateBufferIndex, const Quaternion& orientation )
554   {
555     mWorldOrientation.Set( updateBufferIndex, orientation );
556   }
557
558   /**
559    * Sets the orientation of the node derived from the rotation of all its parents.
560    * This method should only be called when the parents world orientation is up-to-date.
561    * @pre The node has a parent.
562    * @param[in] updateBufferIndex The current update buffer index.
563    */
564   void InheritWorldOrientation( BufferIndex updateBufferIndex )
565   {
566     DALI_ASSERT_DEBUG(mParent != NULL);
567
568     const Quaternion& localOrientation = mOrientation[updateBufferIndex];
569
570     if(localOrientation.IsIdentity())
571     {
572       mWorldOrientation.Set( updateBufferIndex, mParent->GetWorldOrientation(updateBufferIndex) );
573     }
574     else
575     {
576       Quaternion finalOrientation( mParent->GetWorldOrientation(updateBufferIndex) );
577       finalOrientation *= localOrientation;
578       mWorldOrientation.Set( updateBufferIndex, finalOrientation );
579     }
580   }
581
582   /**
583    * Copies the previous inherited orientation, if this changed in the previous frame.
584    * This method should be called instead of InheritWorldOrientation i.e. if the inherited orientation
585    * does not need to be recalculated in the current frame.
586    * @param[in] updateBufferIndex The current update buffer index.
587    */
588   void CopyPreviousWorldOrientation( BufferIndex updateBufferIndex )
589   {
590     mWorldOrientation.CopyPrevious( updateBufferIndex );
591   }
592
593   /**
594    * Retrieve the orientation of the node derived from the rotation of all its parents.
595    * @param[in] bufferIndex The buffer to read from.
596    * @return The world rotation.
597    */
598   const Quaternion& GetWorldOrientation( BufferIndex bufferIndex ) const
599   {
600     return mWorldOrientation[bufferIndex];
601   }
602
603   /**
604    * Set whether the Node inherits orientation.
605    * @param[in] inherit True if the parent orientation is inherited.
606    */
607   void SetInheritOrientation(bool inherit)
608   {
609     if (inherit != mInheritOrientation)
610     {
611       mInheritOrientation = inherit;
612
613       SetDirtyFlag(TransformFlag);
614     }
615   }
616
617   /**
618    * Query whether the node inherits orientation from its parent.
619    * @return True if the parent orientation is inherited.
620    */
621   bool IsOrientationInherited() const
622   {
623     return mInheritOrientation;
624   }
625
626   /**
627    * Retrieve the local scale of the node, relative to its parent.
628    * @param[in] bufferIndex The buffer to read from.
629    * @return The local scale.
630    */
631   const Vector3& GetScale(BufferIndex bufferIndex) const
632   {
633     return mScale[bufferIndex];
634   }
635
636   /**
637    * Sets the scale of the node derived from the scale of all its parents and a pre-scale
638    * @param[in] updateBufferIndex The current update buffer index.
639    * @param[in] scale The world scale.
640    */
641   void SetWorldScale(BufferIndex updateBufferIndex, const Vector3& scale)
642   {
643     mWorldScale.Set( updateBufferIndex, scale );
644   }
645
646   /**
647    * Sets the scale of the node derived from the scale of all its parents and a pre-scale.
648    * This method should only be called when the parents world scale is up-to-date.
649    * @pre The node has a parent.
650    * @param[in] updateBufferIndex The current update buffer index.
651    */
652   void InheritWorldScale(BufferIndex updateBufferIndex)
653   {
654     DALI_ASSERT_DEBUG(mParent != NULL);
655
656     mWorldScale.Set( updateBufferIndex, mParent->GetWorldScale(updateBufferIndex) * mScale[updateBufferIndex] );
657   }
658
659   /**
660    * Copies the previous inherited scale, if this changed in the previous frame.
661    * This method should be called instead of InheritWorldScale i.e. if the inherited scale
662    * does not need to be recalculated in the current frame.
663    * @param[in] updateBufferIndex The current update buffer index.
664    */
665   void CopyPreviousWorldScale( BufferIndex updateBufferIndex )
666   {
667     mWorldScale.CopyPrevious( updateBufferIndex );
668   }
669
670   /**
671    * Retrieve the scale of the node derived from the scale of all its parents.
672    * @param[in] bufferIndex The buffer to read from.
673    * @return The world scale.
674    */
675   const Vector3& GetWorldScale( BufferIndex bufferIndex ) const
676   {
677     return mWorldScale[bufferIndex];
678   }
679
680   /**
681    * Set whether the Node inherits scale.
682    * @param inherit True if the Node inherits scale.
683    */
684   void SetInheritScale( bool inherit )
685   {
686     if( inherit != mInheritScale )
687     {
688       mInheritScale = inherit;
689
690       SetDirtyFlag( TransformFlag );
691     }
692   }
693
694   /**
695    * Query whether the Node inherits scale.
696    * @return if scale is inherited
697    */
698   bool IsScaleInherited() const
699   {
700     return mInheritScale;
701   }
702
703   /**
704    * Retrieve the visibility of the node.
705    * @param[in] bufferIndex The buffer to read from.
706    * @return True if the node is visible.
707    */
708   bool IsVisible(BufferIndex bufferIndex) const
709   {
710     return mVisible[bufferIndex];
711   }
712
713   /**
714    * Retrieve the opacity of the node.
715    * @param[in] bufferIndex The buffer to read from.
716    * @return The opacity.
717    */
718   float GetOpacity(BufferIndex bufferIndex) const
719   {
720     return mColor[bufferIndex].a;
721   }
722
723   /**
724    * Retrieve the color of the node.
725    * @param[in] bufferIndex The buffer to read from.
726    * @return The color.
727    */
728   const Vector4& GetColor(BufferIndex bufferIndex) const
729   {
730     return mColor[bufferIndex];
731   }
732
733   /**
734    * Sets the color of the node derived from the color of all its parents.
735    * @param[in] color The world color.
736    * @param[in] updateBufferIndex The current update buffer index.
737    */
738   void SetWorldColor(const Vector4& color, BufferIndex updateBufferIndex)
739   {
740     mWorldColor.Set( updateBufferIndex, color );
741   }
742
743   /**
744    * Sets the color of the node derived from the color of all its parents.
745    * This method should only be called when the parents world color is up-to-date.
746    * @pre The node has a parent.
747    * @param[in] updateBufferIndex The current update buffer index.
748    */
749   void InheritWorldColor( BufferIndex updateBufferIndex )
750   {
751     DALI_ASSERT_DEBUG(mParent != NULL);
752
753     // default first
754     if( mColorMode == USE_OWN_MULTIPLY_PARENT_ALPHA )
755     {
756       const Vector4& ownColor = mColor[updateBufferIndex];
757       mWorldColor.Set( updateBufferIndex, ownColor.r, ownColor.g, ownColor.b, ownColor.a * mParent->GetWorldColor(updateBufferIndex).a );
758     }
759     else if( mColorMode == USE_OWN_MULTIPLY_PARENT_COLOR )
760     {
761       mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) * mColor[updateBufferIndex] );
762     }
763     else if( mColorMode == USE_PARENT_COLOR )
764     {
765       mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) );
766     }
767     else // USE_OWN_COLOR
768     {
769       mWorldColor.Set( updateBufferIndex, mColor[updateBufferIndex] );
770     }
771   }
772
773   /**
774    * Copies the previous inherited scale, if this changed in the previous frame.
775    * This method should be called instead of InheritWorldScale i.e. if the inherited scale
776    * does not need to be recalculated in the current frame.
777    * @param[in] updateBufferIndex The current update buffer index.
778    */
779   void CopyPreviousWorldColor( BufferIndex updateBufferIndex )
780   {
781     mWorldColor.CopyPrevious( updateBufferIndex );
782   }
783
784   /**
785    * Retrieve the color of the node, possibly derived from the color
786    * of all its parents, depending on the value of mColorMode.
787    * @param[in] bufferIndex The buffer to read from.
788    * @return The world color.
789    */
790   const Vector4& GetWorldColor(BufferIndex bufferIndex) const
791   {
792     return mWorldColor[bufferIndex];
793   }
794
795   /**
796    * Set the color mode. This specifies whether the Node uses its own color,
797    * or inherits its parent color.
798    * @param[in] colorMode The new color mode.
799    */
800   void SetColorMode(ColorMode colorMode)
801   {
802     mColorMode = colorMode;
803
804     SetDirtyFlag(ColorFlag);
805   }
806
807   /**
808    * Retrieve the color mode.
809    * @return The color mode.
810    */
811   ColorMode GetColorMode() const
812   {
813     return mColorMode;
814   }
815
816   /**
817    * Retrieve the size of the node.
818    * @param[in] bufferIndex The buffer to read from.
819    * @return The size.
820    */
821   const Vector3& GetSize(BufferIndex bufferIndex) const
822   {
823     return mSize[bufferIndex];
824   }
825
826   /**
827    * Set the world-matrix of a node, with scale + rotation + translation.
828    * Scale and rotation are centered at the origin.
829    * Translation is applied independently of the scale or rotatation axis.
830    * @param[in] updateBufferIndex The current update buffer index.
831    * @param[in] scale The scale.
832    * @param[in] rotation The rotation.
833    * @param[in] translation The translation.
834    */
835   void SetWorldMatrix( BufferIndex updateBufferIndex, const Vector3& scale, const Quaternion& rotation, const Vector3& translation )
836   {
837     mWorldMatrix.Get( updateBufferIndex ).SetTransformComponents( scale, rotation, translation );
838     mWorldMatrix.SetDirty( updateBufferIndex );
839   }
840
841   /**
842    * Retrieve the cached world-matrix of a node.
843    * @param[in] bufferIndex The buffer to read from.
844    * @return The world-matrix.
845    */
846   const Matrix& GetWorldMatrix( BufferIndex bufferIndex ) const
847   {
848     return mWorldMatrix[ bufferIndex ];
849   }
850
851   /**
852    * Copy previous frames world matrix
853    * @param[in] updateBufferIndex The current update buffer index.
854    */
855   void CopyPreviousWorldMatrix( BufferIndex updateBufferIndex )
856   {
857     mWorldMatrix.CopyPrevious( updateBufferIndex );
858   }
859
860   /**
861    * Mark the node as exclusive to a single RenderTask.
862    * @param[in] renderTask The render-task, or NULL if the Node is not exclusive to a single RenderTask.
863    */
864   void SetExclusiveRenderTask( RenderTask* renderTask )
865   {
866     mExclusiveRenderTask = renderTask;
867   }
868
869   /**
870    * Query whether the node is exclusive to a single RenderTask.
871    * @return The render-task, or NULL if the Node is not exclusive to a single RenderTask.
872    */
873   RenderTask* GetExclusiveRenderTask() const
874   {
875     return mExclusiveRenderTask;
876   }
877
878   /**
879    * Set how the Node and its children should be drawn; see Dali::Actor::SetDrawMode() for more details.
880    * @param[in] drawMode The new draw-mode to use.
881    */
882   void SetDrawMode( const DrawMode::Type& drawMode )
883   {
884     mDrawMode = drawMode;
885   }
886
887   /**
888    * Returns whether node is an overlay or not.
889    * @return True if node is an overlay, false otherwise.
890    */
891   DrawMode::Type GetDrawMode() const
892   {
893     return mDrawMode;
894   }
895
896   /**
897    * Equality operator, checks for identity, not values.
898    *
899    */
900   bool operator==( const Node* rhs ) const
901   {
902     if ( this == rhs )
903     {
904       return true;
905     }
906     return false;
907   }
908
909   unsigned short GetDepth() const
910   {
911     return mDepth;
912   }
913
914 public:
915   /**
916    * @copydoc UniformMap::Add
917    */
918   void AddUniformMapping( UniformPropertyMapping* map );
919
920   /**
921    * @copydoc UniformMap::Remove
922    */
923   void RemoveUniformMapping( const std::string& uniformName );
924
925   /**
926    * Prepare the node for rendering.
927    * This is called by the UpdateManager when an object is due to be rendered in the current frame.
928    * @param[in] updateBufferIndex The current update buffer index.
929    */
930   void PrepareRender( BufferIndex bufferIndex );
931
932 protected:
933
934   /**
935    * Set the parent of a Node.
936    * @param[in] parentNode the new parent.
937    */
938   void SetParent(Node& parentNode);
939
940   /**
941    * Protected constructor; See also Node::New()
942    */
943   Node();
944
945 private: // from NodeDataProvider
946
947   /**
948    * @copydoc NodeDataProvider::GetModelMatrix
949    */
950   virtual const Matrix& GetModelMatrix( unsigned int bufferId ) const
951   {
952     return GetWorldMatrix( bufferId );
953   }
954
955   /**
956    * @copydoc NodeDataProvider::GetRenderColor
957    */
958   virtual const Vector4& GetRenderColor( unsigned int bufferId ) const
959   {
960     return GetWorldColor( bufferId );
961   }
962
963   virtual const Vector3& GetRenderSize( unsigned int bufferId ) const
964   {
965     return GetSize( bufferId );
966   }
967
968 public: // From UniformMapDataProvider
969   /**
970    * @copydoc UniformMapDataProvider::GetUniformMapChanged
971    */
972   virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const
973   {
974     return mUniformMapChanged[bufferIndex];
975   }
976
977   /**
978    * @copydoc UniformMapDataProvider::GetUniformMap
979    */
980   virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const
981   {
982     return mCollectedUniformMap[bufferIndex];
983   }
984
985 private:
986
987   // Undefined
988   Node(const Node&);
989
990   // Undefined
991   Node& operator=(const Node& rhs);
992
993   /**
994    * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
995    */
996   virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
997
998   /**
999    * Recursive helper to disconnect a Node and its children.
1000    * Disconnected Nodes have no parent or children.
1001    * @param[in] updateBufferIndex The current update buffer index.
1002    */
1003   void RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex );
1004
1005 public: // Default properties
1006
1007   PropertyVector3                mParentOrigin;  ///< Local transform; the position is relative to this. Sets the TransformFlag dirty when changed
1008   PropertyVector3                mAnchorPoint;   ///< Local transform; local center of rotation. Sets the TransformFlag dirty when changed
1009
1010   AnimatableProperty<Vector3>    mSize;          ///< Size is provided for layouting
1011   AnimatableProperty<Vector3>    mPosition;      ///< Local transform; distance between parent-origin & anchor-point
1012   AnimatableProperty<Quaternion> mOrientation;   ///< Local transform; rotation relative to parent node
1013   AnimatableProperty<Vector3>    mScale;         ///< Local transform; scale relative to parent node
1014   AnimatableProperty<bool>       mVisible;       ///< Visibility can be inherited from the Node hierachy
1015   AnimatableProperty<Vector4>    mColor;         ///< Color can be inherited from the Node hierarchy
1016
1017   // Inherited properties; read-only from public API
1018
1019   InheritedVector3    mWorldPosition;     ///< Full inherited position
1020   InheritedQuaternion mWorldOrientation;  ///< Full inherited orientation
1021   InheritedVector3    mWorldScale;        ///< Full inherited scale
1022   InheritedMatrix     mWorldMatrix;       ///< Full inherited world matrix
1023   InheritedColor      mWorldColor;        ///< Full inherited color
1024
1025 protected:
1026
1027   Node*               mParent;                       ///< Pointer to parent node (a child is owned by its parent)
1028   RenderTask*         mExclusiveRenderTask;          ///< Nodes can be marked as exclusive to a single RenderTask
1029
1030   NodeAttachmentOwner mAttachment;                   ///< Optional owned attachment
1031   RendererContainer   mRenderer;                     ///< Container of renderers; not owned
1032
1033   NodeContainer       mChildren;                     ///< Container of children; not owned
1034
1035   CollectedUniformMap mCollectedUniformMap[2];      ///< Uniform maps of the node
1036   unsigned int        mUniformMapChanged[2];        ///< Records if the uniform map has been altered this frame
1037   unsigned int        mRegenerateUniformMap : 2;    ///< Indicate if the uniform map has to be regenerated this frame
1038
1039   // flags, compressed to bitfield
1040   unsigned short mDepth: 12;                        ///< Depth in the hierarchy
1041   int  mDirtyFlags:8;                               ///< A composite set of flags for each of the Node properties
1042
1043   bool mIsRoot:1;                                    ///< True if the node cannot have a parent
1044   bool mInheritOrientation:1;                        ///< Whether the parent's orientation should be inherited.
1045   bool mInheritScale:1;                              ///< Whether the parent's scale should be inherited.
1046
1047   DrawMode::Type          mDrawMode:2;               ///< How the Node and its children should be drawn
1048   PositionInheritanceMode mPositionInheritanceMode:2;///< Determines how position is inherited, 2 bits is enough
1049   ColorMode               mColorMode:2;              ///< Determines whether mWorldColor is inherited, 2 bits is enough
1050
1051   // Changes scope, should be at end of class
1052   DALI_LOG_OBJECT_STRING_DECLARATION;
1053 };
1054
1055 // Messages for Node
1056
1057 inline void SetInheritOrientationMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
1058 {
1059   typedef MessageValue1< Node, bool > LocalType;
1060
1061   // Reserve some memory inside the message queue
1062   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1063
1064   // Construct message in the message queue memory; note that delete should not be called on the return value
1065   new (slot) LocalType( &node, &Node::SetInheritOrientation, inherit );
1066 }
1067
1068 inline void SetParentOriginMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& origin )
1069 {
1070   typedef MessageValue1< Node, Vector3 > LocalType;
1071
1072   // Reserve some memory inside the message queue
1073   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1074
1075   // Construct message in the message queue memory; note that delete should not be called on the return value
1076   new (slot) LocalType( &node, &Node::SetParentOrigin, origin );
1077 }
1078
1079 inline void SetAnchorPointMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& anchor )
1080 {
1081   typedef MessageValue1< Node, Vector3 > LocalType;
1082
1083   // Reserve some memory inside the message queue
1084   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1085
1086   // Construct message in the message queue memory; note that delete should not be called on the return value
1087   new (slot) LocalType( &node, &Node::SetAnchorPoint, anchor );
1088 }
1089
1090 inline void SetPositionInheritanceModeMessage( EventThreadServices& eventThreadServices, const Node& node, PositionInheritanceMode mode )
1091 {
1092   typedef MessageValue1< Node, PositionInheritanceMode > LocalType;
1093
1094   // Reserve some memory inside the message queue
1095   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1096
1097   // Construct message in the message queue memory; note that delete should not be called on the return value
1098   new (slot) LocalType( &node, &Node::SetPositionInheritanceMode, mode );
1099 }
1100
1101 inline void SetInheritScaleMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
1102 {
1103   typedef MessageValue1< Node, bool > LocalType;
1104
1105   // Reserve some memory inside the message queue
1106   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1107
1108   // Construct message in the message queue memory; note that delete should not be called on the return value
1109   new (slot) LocalType( &node, &Node::SetInheritScale, inherit );
1110 }
1111
1112 inline void SetColorModeMessage( EventThreadServices& eventThreadServices, const Node& node, ColorMode colorMode )
1113 {
1114   typedef MessageValue1< Node, ColorMode > LocalType;
1115
1116   // Reserve some memory inside the message queue
1117   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1118
1119   // Construct message in the message queue memory; note that delete should not be called on the return value
1120   new (slot) LocalType( &node, &Node::SetColorMode, colorMode );
1121 }
1122
1123 inline void SetDrawModeMessage( EventThreadServices& eventThreadServices, const Node& node, DrawMode::Type drawMode )
1124 {
1125   typedef MessageValue1< Node, DrawMode::Type > LocalType;
1126
1127   // Reserve some memory inside the message queue
1128   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1129
1130   // Construct message in the message queue memory; note that delete should not be called on the return value
1131   new (slot) LocalType( &node, &Node::SetDrawMode, drawMode );
1132 }
1133
1134 inline void AddRendererMessage( EventThreadServices& eventThreadServices, const Node& node, Renderer* renderer )
1135 {
1136   typedef MessageValue1< Node, Renderer* > LocalType;
1137
1138   // Reserve some memory inside the message queue
1139   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1140
1141   // Construct message in the message queue memory; note that delete should not be called on the return value
1142   new (slot) LocalType( &node, &Node::AddRenderer, renderer );
1143 }
1144
1145 inline void RemoveRendererMessage( EventThreadServices& eventThreadServices, const Node& node, Renderer* renderer )
1146 {
1147   typedef MessageValue1< Node, Renderer* > LocalType;
1148
1149   // Reserve some memory inside the message queue
1150   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1151
1152   // Construct message in the message queue memory; note that delete should not be called on the return value
1153   new (slot) LocalType( &node, &Node::RemoveRenderer, renderer );
1154 }
1155 } // namespace SceneGraph
1156
1157 } // namespace Internal
1158
1159 } // namespace Dali
1160
1161 #endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_H_