fd18fee910623907f2f1c6a9eff5e1c22103db05
[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) 2018 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/public-api/math/quaternion.h>
25 #include <dali/public-api/math/math-utils.h>
26 #include <dali/public-api/math/vector3.h>
27 #include <dali/integration-api/debug.h>
28 #include <dali/internal/common/message.h>
29 #include <dali/internal/event/common/event-thread-services.h>
30 #include <dali/internal/render/data-providers/node-data-provider.h>
31 #include <dali/internal/update/common/animatable-property.h>
32 #include <dali/internal/update/common/property-owner.h>
33 #include <dali/internal/update/common/scene-graph-buffers.h>
34 #include <dali/internal/update/common/inherited-property.h>
35 #include <dali/internal/update/manager/transform-manager.h>
36 #include <dali/internal/update/manager/transform-manager-property.h>
37 #include <dali/internal/update/nodes/node-declarations.h>
38 #include <dali/internal/update/rendering/scene-graph-renderer.h>
39
40 namespace Dali
41 {
42
43 namespace Internal
44 {
45
46 // Value types used by messages.
47 template <> struct ParameterType< ColorMode > : public BasicType< ColorMode > {};
48 template <> struct ParameterType< PositionInheritanceMode > : public BasicType< PositionInheritanceMode > {};
49 template <> struct ParameterType< ClippingMode::Type > : public BasicType< ClippingMode::Type > {};
50
51 namespace SceneGraph
52 {
53
54 class DiscardQueue;
55 class Layer;
56 class RenderTask;
57 class UpdateManager;
58
59
60 // Flags which require the scene renderable lists to be updated
61 static NodePropertyFlags RenderableUpdateFlags = NodePropertyFlags::TRANSFORM | NodePropertyFlags::CHILD_DELETED;
62
63 /**
64  * Node is the base class for all nodes in the Scene Graph.
65  *
66  * Each node provides a transformation which applies to the node and
67  * its children.  Node data is double-buffered. This allows an update
68  * thread to modify node data, without interferring with another
69  * thread reading the values from the previous update traversal.
70  */
71 class Node : public PropertyOwner, public NodeDataProvider
72 {
73 public:
74
75   // Defaults
76   static const PositionInheritanceMode DEFAULT_POSITION_INHERITANCE_MODE;
77   static const ColorMode DEFAULT_COLOR_MODE;
78
79   // Creation methods
80
81   /**
82    * Construct a new Node.
83    * @param[in] id The unique ID of the node
84    */
85   static Node* New( uint32_t id );
86
87   /**
88    * Deletes a Node.
89    */
90   static void Delete( Node* node );
91
92   /**
93    * Called during UpdateManager::DestroyNode shortly before Node is destroyed.
94    */
95   void OnDestroy();
96
97   // Layer interface
98
99   /**
100    * Query whether the node is a layer.
101    * @return True if the node is a layer.
102    */
103   bool IsLayer()
104   {
105     return mIsLayer;
106   }
107
108   /**
109    * Convert a node to a layer.
110    * @return A pointer to the layer, or NULL.
111    */
112   virtual Layer* GetLayer()
113   {
114     return NULL;
115   }
116
117   /**
118    * This method sets clipping information on the node based on its hierarchy in the scene-graph.
119    * A value is calculated that can be used during sorting to increase sort speed.
120    * @param[in] clippingId The Clipping ID of the node to set
121    * @param[in] clippingDepth The Clipping Depth of the node to set
122    * @param[in] scissorDepth The Scissor Clipping Depth of the node to set
123    */
124   void SetClippingInformation( const uint32_t clippingId, const uint32_t clippingDepth, const uint32_t scissorDepth )
125   {
126     // We only set up the sort value if we have a stencil clipping depth, IE. At least 1 clipping node has been hit.
127     // If not, if we traverse down a clipping tree and back up, and there is another
128     // node on the parent, this will have a non-zero clipping ID that must be ignored
129     if( clippingDepth > 0u )
130     {
131       mClippingDepth = clippingDepth;
132
133       // Calculate the sort value here on write, as when read (during sort) it may be accessed several times.
134       // The items must be sorted by Clipping ID first (so the ID is kept in the most-significant bits).
135       // For the same ID, the clipping nodes must be first, so we negate the
136       // clipping enabled flag and set it as the least significant bit.
137       mClippingSortModifier = ( clippingId << 1u ) | ( mClippingMode == ClippingMode::DISABLED ? 1u : 0u );
138     }
139     else
140     {
141       // If we do not have a clipping depth, then set this to 0 so we do not have a Clipping ID either.
142       mClippingSortModifier = 0u;
143     }
144
145     // The scissor depth does not modify the clipping sort modifier (as scissor clips are 2D only).
146     // For this reason we can always update the member variable.
147     mScissorDepth = scissorDepth;
148   }
149
150   /**
151    * Gets the Clipping ID for this node.
152    * @return The Clipping ID for this node.
153    */
154   uint32_t GetClippingId() const
155   {
156     return mClippingSortModifier >> 1u;
157   }
158
159   /**
160    * Gets the Clipping Depth for this node.
161    * @return The Clipping Depth for this node.
162    */
163   uint32_t GetClippingDepth() const
164   {
165     return mClippingDepth;
166   }
167
168   /**
169    * Gets the Scissor Clipping Depth for this node.
170    * @return The Scissor Clipping Depth for this node.
171    */
172   uint32_t GetScissorDepth() const
173   {
174     return mScissorDepth;
175   }
176
177   /**
178    * Sets the clipping mode for this node.
179    * @param[in] clippingMode The ClippingMode to set
180    */
181   void SetClippingMode( const ClippingMode::Type clippingMode )
182   {
183     mClippingMode = clippingMode;
184   }
185
186   /**
187    * Gets the Clipping Mode for this node.
188    * @return The ClippingMode of this node
189    */
190   ClippingMode::Type GetClippingMode() const
191   {
192     return mClippingMode;
193   }
194
195   /**
196    * Add a renderer to the node
197    * @param[in] renderer The renderer added to the node
198    */
199   void AddRenderer( Renderer* renderer );
200
201   /**
202    * Remove a renderer from the node
203    * @param[in] renderer The renderer to be removed
204    */
205   void RemoveRenderer( Renderer* renderer );
206
207   /*
208    * Get the renderer at the given index
209    * @param[in] index
210    */
211   Renderer* GetRendererAt( uint32_t index ) const
212   {
213     return mRenderer[index];
214   }
215
216   /**
217    * Retrieve the number of renderers for the node
218    */
219   uint32_t GetRendererCount() const
220   {
221     return static_cast<uint32_t>( mRenderer.Size() );
222   }
223
224   // Containment methods
225
226   /**
227    * Query whether a node is the root node. Root nodes cannot have a parent node.
228    * A node becomes a root node, when it is installed by UpdateManager.
229    * @return True if the node is a root node.
230    */
231   bool IsRoot() const
232   {
233     return mIsRoot;
234   }
235
236   /**
237    * Set whether a node is the root node. Root nodes cannot have a parent node.
238    * This method should only be called by UpdateManager.
239    * @pre When isRoot is true, the node must not have a parent.
240    * @param[in] isRoot Whether the node is now a root node.
241    */
242   void SetRoot(bool isRoot);
243
244   /**
245    * Retrieve the parent of a Node.
246    * @return The parent node, or NULL if the Node has not been added to the scene-graph.
247    */
248   Node* GetParent()
249   {
250     return mParent;
251   }
252
253   /**
254    * Retrieve the parent of a Node.
255    * @return The parent node, or NULL if the Node has not been added to the scene-graph.
256    */
257   const Node* GetParent() const
258   {
259     return mParent;
260   }
261
262   /**
263    * Connect a node to the scene-graph.
264    * @pre A node cannot be added to itself.
265    * @pre The parent node is connected to the scene-graph.
266    * @pre The childNode does not already have a parent.
267    * @pre The childNode is not a root node.
268    * @param[in] childNode The child to add.
269    */
270   void ConnectChild( Node* childNode );
271
272   /**
273    * Disconnect a child (& its children) from the scene-graph.
274    * @pre childNode is a child of this Node.
275    * @param[in] updateBufferIndex The current update buffer index.
276    * @param[in] childNode The node to disconnect.
277    */
278   void DisconnectChild( BufferIndex updateBufferIndex, Node& childNode );
279
280   /**
281    * Retrieve the children a Node.
282    * @return The container of children.
283    */
284   const NodeContainer& GetChildren() const
285   {
286     return mChildren;
287   }
288
289   /**
290    * Retrieve the children a Node.
291    * @return The container of children.
292    */
293   NodeContainer& GetChildren()
294   {
295     return mChildren;
296   }
297
298   // Update methods
299
300   /**
301    * Flag that one of the node values has changed in the current frame.
302    * @param[in] flag The flag to set.
303    */
304   void SetDirtyFlag( NodePropertyFlags flag )
305   {
306     mDirtyFlags |= flag;
307   }
308
309   /**
310    * Flag that all of the node values are dirty.
311    */
312   void SetAllDirtyFlags()
313   {
314     mDirtyFlags = NodePropertyFlags::ALL;
315   }
316
317   /**
318    * Query whether a node is dirty.
319    * @return The dirty flags
320    */
321   NodePropertyFlags GetDirtyFlags() const;
322
323   /**
324    * Query inherited dirty flags.
325    *
326    * @param The parentFlags to or with
327    * @return The inherited dirty flags
328    */
329   NodePropertyFlags GetInheritedDirtyFlags( NodePropertyFlags parentFlags ) const;
330
331   /**
332    * Retrieve the parent-origin of the node.
333    * @return The parent-origin.
334    */
335   const Vector3& GetParentOrigin() const
336   {
337     return mParentOrigin.Get(0);
338   }
339
340   /**
341    * Sets both the local & base parent-origins of the node.
342    * @param[in] origin The new local & base parent-origins.
343    */
344   void SetParentOrigin(const Vector3& origin)
345   {
346     mParentOrigin.Set(0,origin );
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.Get(0);
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.Set(0, anchor );
365   }
366
367   /**
368    * Retrieve the local position of the node, relative to its parent.
369    * @param[in] bufferIndex The buffer to read from.
370    * @return The local position.
371    */
372   const Vector3& GetPosition(BufferIndex bufferIndex) const
373   {
374     if( mTransformId != INVALID_TRANSFORM_ID )
375     {
376       return mPosition.Get(bufferIndex);
377     }
378
379     return Vector3::ZERO;
380   }
381
382   /**
383    * Retrieve the position of the node derived from the position of all its parents.
384    * @return The world position.
385    */
386   const Vector3& GetWorldPosition( BufferIndex bufferIndex ) const
387   {
388     return mWorldPosition.Get(bufferIndex);
389   }
390
391   /**
392    * Set whether the Node inherits position.
393    * @param[in] inherit True if the parent position is inherited.
394    */
395   void SetInheritPosition(bool inherit)
396   {
397     if( mTransformId != INVALID_TRANSFORM_ID )
398     {
399       mTransformManager->SetInheritPosition( mTransformId, inherit );
400     }
401   }
402
403   /**
404    * Retrieve the local orientation of the node, relative to its parent.
405    * @param[in] bufferIndex The buffer to read from.
406    * @return The local orientation.
407    */
408   const Quaternion& GetOrientation(BufferIndex bufferIndex) const
409   {
410     if( mTransformId != INVALID_TRANSFORM_ID )
411     {
412       return mOrientation.Get(0);
413     }
414
415     return Quaternion::IDENTITY;
416   }
417
418   /**
419    * Retrieve the orientation of the node derived from the rotation of all its parents.
420    * @param[in] bufferIndex The buffer to read from.
421    * @return The world rotation.
422    */
423   const Quaternion& GetWorldOrientation( BufferIndex bufferIndex ) const
424   {
425     return mWorldOrientation.Get(0);
426   }
427
428   /**
429    * Set whether the Node inherits orientation.
430    * @param[in] inherit True if the parent orientation is inherited.
431    */
432   void SetInheritOrientation(bool inherit)
433   {
434     if( mTransformId != INVALID_TRANSFORM_ID )
435     {
436       mTransformManager->SetInheritOrientation(mTransformId, inherit );
437     }
438   }
439
440   /**
441    * Retrieve the local scale of the node, relative to its parent.
442    * @param[in] bufferIndex The buffer to read from.
443    * @return The local scale.
444    */
445   const Vector3& GetScale(BufferIndex bufferIndex) const
446   {
447     if( mTransformId != INVALID_TRANSFORM_ID )
448     {
449       return mScale.Get(0);
450     }
451
452     return Vector3::ONE;
453   }
454
455
456   /**
457    * Retrieve the scale of the node derived from the scale of all its parents.
458    * @param[in] bufferIndex The buffer to read from.
459    * @return The world scale.
460    */
461   const Vector3& GetWorldScale( BufferIndex bufferIndex ) const
462   {
463     return mWorldScale.Get(0);
464   }
465
466   /**
467    * Set whether the Node inherits scale.
468    * @param inherit True if the Node inherits scale.
469    */
470   void SetInheritScale( bool inherit )
471   {
472     if( mTransformId != INVALID_TRANSFORM_ID )
473     {
474       mTransformManager->SetInheritScale(mTransformId, inherit );
475     }
476   }
477
478   /**
479    * Retrieve the visibility of the node.
480    * @param[in] bufferIndex The buffer to read from.
481    * @return True if the node is visible.
482    */
483   bool IsVisible(BufferIndex bufferIndex) const
484   {
485     return mVisible[bufferIndex];
486   }
487
488   /**
489    * Retrieve the opacity of the node.
490    * @param[in] bufferIndex The buffer to read from.
491    * @return The opacity.
492    */
493   float GetOpacity(BufferIndex bufferIndex) const
494   {
495     return mColor[bufferIndex].a;
496   }
497
498   /**
499    * Retrieve the color of the node.
500    * @param[in] bufferIndex The buffer to read from.
501    * @return The color.
502    */
503   const Vector4& GetColor(BufferIndex bufferIndex) const
504   {
505     return mColor[bufferIndex];
506   }
507
508   /**
509    * Sets the color of the node derived from the color of all its parents.
510    * @param[in] color The world color.
511    * @param[in] updateBufferIndex The current update buffer index.
512    */
513   void SetWorldColor(const Vector4& color, BufferIndex updateBufferIndex)
514   {
515     mWorldColor.Set( updateBufferIndex, color );
516   }
517
518   /**
519    * Sets the color of the node derived from the color of all its parents.
520    * This method should only be called when the parents world color is up-to-date.
521    * @pre The node has a parent.
522    * @param[in] updateBufferIndex The current update buffer index.
523    */
524   void InheritWorldColor( BufferIndex updateBufferIndex )
525   {
526     DALI_ASSERT_DEBUG(mParent != NULL);
527
528     // default first
529     if( mColorMode == USE_OWN_MULTIPLY_PARENT_ALPHA )
530     {
531       const Vector4& ownColor = mColor[updateBufferIndex];
532       mWorldColor.Set( updateBufferIndex, ownColor.r, ownColor.g, ownColor.b, ownColor.a * mParent->GetWorldColor(updateBufferIndex).a );
533     }
534     else if( mColorMode == USE_OWN_MULTIPLY_PARENT_COLOR )
535     {
536       mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) * mColor[updateBufferIndex] );
537     }
538     else if( mColorMode == USE_PARENT_COLOR )
539     {
540       mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) );
541     }
542     else // USE_OWN_COLOR
543     {
544       mWorldColor.Set( updateBufferIndex, mColor[updateBufferIndex] );
545     }
546   }
547
548   /**
549    * Copies the previous inherited scale, if this changed in the previous frame.
550    * This method should be called instead of InheritWorldScale i.e. if the inherited scale
551    * does not need to be recalculated in the current frame.
552    * @param[in] updateBufferIndex The current update buffer index.
553    */
554   void CopyPreviousWorldColor( BufferIndex updateBufferIndex )
555   {
556     mWorldColor.CopyPrevious( updateBufferIndex );
557   }
558
559   /**
560    * Retrieve the color of the node, possibly derived from the color
561    * of all its parents, depending on the value of mColorMode.
562    * @param[in] bufferIndex The buffer to read from.
563    * @return The world color.
564    */
565   const Vector4& GetWorldColor(BufferIndex bufferIndex) const
566   {
567     return mWorldColor[bufferIndex];
568   }
569
570   /**
571    * Set the color mode. This specifies whether the Node uses its own color,
572    * or inherits its parent color.
573    * @param[in] colorMode The new color mode.
574    */
575   void SetColorMode( ColorMode colorMode )
576   {
577     mColorMode = colorMode;
578
579     SetDirtyFlag( NodePropertyFlags::COLOR );
580   }
581
582   /**
583    * Retrieve the color mode.
584    * @return The color mode.
585    */
586   ColorMode GetColorMode() const
587   {
588     return mColorMode;
589   }
590
591   /**
592    * Retrieve the size of the node.
593    * @param[in] bufferIndex The buffer to read from.
594    * @return The size.
595    */
596   const Vector3& GetSize(BufferIndex bufferIndex) const
597   {
598     if( mTransformId != INVALID_TRANSFORM_ID )
599     {
600       return mSize.Get(0);
601     }
602
603     return Vector3::ZERO;
604   }
605
606   /**
607    * Retrieve the bounding sphere of the node
608    * @return A vector4 describing the bounding sphere. XYZ is the center and W is the radius
609    */
610   const Vector4& GetBoundingSphere() const
611   {
612     if( mTransformId != INVALID_TRANSFORM_ID )
613     {
614       return mTransformManager->GetBoundingSphere( mTransformId );
615     }
616
617     return Vector4::ZERO;
618   }
619
620   /**
621    * Retrieve world matrix and size of the node
622    * @param[out] The local to world matrix of the node
623    * @param[out] size The current size of the node
624    */
625   void GetWorldMatrixAndSize( Matrix& worldMatrix, Vector3& size ) const
626   {
627     if( mTransformId != INVALID_TRANSFORM_ID )
628     {
629       mTransformManager->GetWorldMatrixAndSize( mTransformId, worldMatrix, size );
630     }
631   }
632
633   /**
634    * Checks if local matrix has changed since last update
635    * @return true if local matrix has changed, false otherwise
636    */
637   bool IsLocalMatrixDirty() const
638   {
639     return (mTransformId != INVALID_TRANSFORM_ID) &&
640            (mTransformManager->IsLocalMatrixDirty( mTransformId ));
641   }
642
643   /**
644    * Retrieve the cached world-matrix of a node.
645    * @param[in] bufferIndex The buffer to read from.
646    * @return The world-matrix.
647    */
648   const Matrix& GetWorldMatrix( BufferIndex bufferIndex ) const
649   {
650     return mWorldMatrix.Get(bufferIndex);
651   }
652
653   /**
654    * Mark the node as exclusive to a single RenderTask.
655    * @param[in] renderTask The render-task, or NULL if the Node is not exclusive to a single RenderTask.
656    */
657   void SetExclusiveRenderTask( RenderTask* renderTask )
658   {
659     mExclusiveRenderTask = renderTask;
660   }
661
662   /**
663    * Query whether the node is exclusive to a single RenderTask.
664    * @return The render-task, or NULL if the Node is not exclusive to a single RenderTask.
665    */
666   RenderTask* GetExclusiveRenderTask() const
667   {
668     return mExclusiveRenderTask;
669   }
670
671   /**
672    * Set how the Node and its children should be drawn; see Dali::Actor::SetDrawMode() for more details.
673    * @param[in] drawMode The new draw-mode to use.
674    */
675   void SetDrawMode( const DrawMode::Type& drawMode )
676   {
677     mDrawMode = drawMode;
678   }
679
680   /**
681    * Returns whether node is an overlay or not.
682    * @return True if node is an overlay, false otherwise.
683    */
684   DrawMode::Type GetDrawMode() const
685   {
686     return mDrawMode;
687   }
688
689   /*
690    * Returns the transform id of the node
691    * @return The transform component id of the node
692    */
693   TransformId GetTransformId() const
694   {
695     return mTransformId;
696   }
697
698   /**
699    * Equality operator, checks for identity, not values.
700    * @param[in]
701    */
702   bool operator==( const Node* rhs ) const
703   {
704     return ( this == rhs );
705   }
706
707   /**
708    * @brief Sets the sibling order of the node
709    * @param[in] order The new order
710    */
711   void SetDepthIndex( uint32_t depthIndex )
712   {
713     mDepthIndex = depthIndex;
714   }
715
716   /**
717    * @brief Get the depth index of the node
718    * @return Current depth index
719    */
720   uint32_t GetDepthIndex() const
721   {
722     return mDepthIndex;
723   }
724
725   /**
726    * @brief Sets the boolean which states whether the position should use the anchor-point.
727    * @param[in] positionUsesAnchorPoint True if the position should use the anchor-point
728    */
729   void SetPositionUsesAnchorPoint( bool positionUsesAnchorPoint )
730   {
731     if( mTransformId != INVALID_TRANSFORM_ID && mPositionUsesAnchorPoint != positionUsesAnchorPoint )
732     {
733       mPositionUsesAnchorPoint = positionUsesAnchorPoint;
734       mTransformManager->SetPositionUsesAnchorPoint( mTransformId, mPositionUsesAnchorPoint );
735     }
736   }
737
738   /**
739    * @brief Sets whether the node is culled or not.
740    * @param[in] bufferIndex The buffer to read from.
741    * @param[in] culled True if the node is culled.
742    */
743   void SetCulled( BufferIndex bufferIndex, bool culled )
744   {
745     mCulled[bufferIndex] = culled;
746   }
747
748   /**
749    * @brief Retrieves whether the node is culled or not.
750    * @param[in] bufferIndex The buffer to read from.
751    * @return True if the node is culled.
752    */
753   bool IsCulled( BufferIndex bufferIndex ) const
754   {
755     return mCulled[bufferIndex];
756   }
757
758 public:
759   /**
760    * @copydoc UniformMap::Add
761    */
762   void AddUniformMapping( OwnerPointer< UniformPropertyMapping >& map );
763
764   /**
765    * @copydoc UniformMap::Remove
766    */
767   void RemoveUniformMapping( const std::string& uniformName );
768
769   /**
770    * Prepare the node for rendering.
771    * This is called by the UpdateManager when an object is due to be rendered in the current frame.
772    * @param[in] updateBufferIndex The current update buffer index.
773    */
774   void PrepareRender( BufferIndex bufferIndex );
775
776   /**
777    * Called by UpdateManager when the node is added.
778    * Creates a new transform component in the transform manager and initialize all the properties
779    * related to the transformation
780    * @param[in] transformManager A pointer to the trnasform manager (Owned by UpdateManager)
781    */
782   void CreateTransform( SceneGraph::TransformManager* transformManager );
783
784   /**
785    * Reset dirty flags
786    */
787   void ResetDirtyFlags( BufferIndex updateBufferIndex );
788
789 protected:
790
791   /**
792    * Set the parent of a Node.
793    * @param[in] parentNode the new parent.
794    */
795   void SetParent( Node& parentNode );
796
797 protected:
798
799   /**
800    * Protected constructor; See also Node::New()
801    * @param[in] id The Unique ID of the actor creating the node
802    */
803   Node( uint32_t id );
804
805   /**
806    * Protected virtual destructor; See also Node::Delete( Node* )
807    * Kept protected to allow destructor chaining from layer
808    */
809   virtual ~Node();
810
811 private: // from NodeDataProvider
812
813   /**
814    * @copydoc NodeDataProvider::GetModelMatrix
815    */
816   virtual const Matrix& GetModelMatrix( BufferIndex bufferIndex ) const
817   {
818     return GetWorldMatrix( bufferIndex );
819   }
820
821   /**
822    * @copydoc NodeDataProvider::GetRenderColor
823    */
824   virtual const Vector4& GetRenderColor( BufferIndex bufferIndex ) const
825   {
826     return GetWorldColor( bufferIndex );
827   }
828
829 public: // From UniformMapDataProvider
830   /**
831    * @copydoc UniformMapDataProvider::GetUniformMapChanged
832    */
833   virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const
834   {
835     return mUniformMapChanged[bufferIndex];
836   }
837
838   /**
839    * @copydoc UniformMapDataProvider::GetUniformMap
840    */
841   virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const
842   {
843     return mCollectedUniformMap[bufferIndex];
844   }
845
846 private:
847
848   // Undefined
849   Node(const Node&);
850
851   // Undefined
852   Node& operator=(const Node& rhs);
853
854   /**
855    * Recursive helper to disconnect a Node and its children.
856    * Disconnected Nodes have no parent or children.
857    * @param[in] updateBufferIndex The current update buffer index.
858    */
859   void RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex );
860
861 public: // Default properties
862
863   TransformManager*                  mTransformManager;
864   TransformId                        mTransformId;
865   TransformManagerPropertyVector3    mParentOrigin;           ///< Local transform; the position is relative to this. Sets the Transform flag dirty when changed
866   TransformManagerPropertyVector3    mAnchorPoint;            ///< Local transform; local center of rotation. Sets the Transform flag dirty when changed
867   TransformManagerPropertyVector3    mSize;                   ///< Size is provided for layouting
868   TransformManagerPropertyVector3    mPosition;               ///< Local transform; distance between parent-origin & anchor-point
869   TransformManagerPropertyQuaternion mOrientation;            ///< Local transform; rotation relative to parent node
870   TransformManagerPropertyVector3    mScale;                  ///< Local transform; scale relative to parent node
871
872   AnimatableProperty<bool>           mVisible;                ///< Visibility can be inherited from the Node hierachy
873   AnimatableProperty<bool>           mCulled;                 ///< True if the node is culled. This is not animatable. It is just double-buffered.
874   AnimatableProperty<Vector4>        mColor;                  ///< Color can be inherited from the Node hierarchy
875
876   // Inherited properties; read-only from public API
877
878   TransformManagerVector3Input       mWorldPosition;          ///< Full inherited position
879   TransformManagerVector3Input       mWorldScale;
880   TransformManagerQuaternionInput    mWorldOrientation;       ///< Full inherited orientation
881   TransformManagerMatrixInput        mWorldMatrix;            ///< Full inherited world matrix
882   InheritedColor                     mWorldColor;             ///< Full inherited color
883
884   uint32_t                           mClippingSortModifier;   ///< Contains bit-packed clipping information for quick access when sorting
885   const uint32_t                     mId;                     ///< The Unique ID of the node.
886
887 protected:
888
889   Node*                              mParent;                 ///< Pointer to parent node (a child is owned by its parent)
890   RenderTask*                        mExclusiveRenderTask;    ///< Nodes can be marked as exclusive to a single RenderTask
891
892   RendererContainer                  mRenderer;               ///< Container of renderers; not owned
893
894   NodeContainer                      mChildren;               ///< Container of children; not owned
895
896   CollectedUniformMap                mCollectedUniformMap[2]; ///< Uniform maps of the node
897   uint32_t                           mUniformMapChanged[2];   ///< Records if the uniform map has been altered this frame
898   uint32_t                           mClippingDepth;          ///< The number of stencil clipping nodes deep this node is
899   uint32_t                           mScissorDepth;           ///< The number of scissor clipping nodes deep this node is
900
901   uint32_t                           mDepthIndex;             ///< Depth index of the node
902
903   // flags, compressed to bitfield
904   NodePropertyFlags                  mDirtyFlags;             ///< Dirty flags for each of the Node properties
905   uint32_t                           mRegenerateUniformMap:2; ///< Indicate if the uniform map has to be regenerated this frame
906   DrawMode::Type                     mDrawMode:3;             ///< How the Node and its children should be drawn
907   ColorMode                          mColorMode:3;            ///< Determines whether mWorldColor is inherited, 2 bits is enough
908   ClippingMode::Type                 mClippingMode:3;         ///< The clipping mode of this node
909   bool                               mIsRoot:1;               ///< True if the node cannot have a parent
910   bool                               mIsLayer:1;              ///< True if the node is a layer
911   bool                               mPositionUsesAnchorPoint:1; ///< True if the node should use the anchor-point when calculating the position
912   // Changes scope, should be at end of class
913   DALI_LOG_OBJECT_STRING_DECLARATION;
914 };
915
916 // Messages for Node
917
918 inline void SetInheritOrientationMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
919 {
920   typedef MessageValue1< Node, bool > LocalType;
921
922   // Reserve some memory inside the message queue
923   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
924
925   // Construct message in the message queue memory; note that delete should not be called on the return value
926   new (slot) LocalType( &node, &Node::SetInheritOrientation, inherit );
927 }
928
929 inline void SetParentOriginMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& origin )
930 {
931   typedef MessageValue1< Node, Vector3 > LocalType;
932
933   // Reserve some memory inside the message queue
934   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
935
936   // Construct message in the message queue memory; note that delete should not be called on the return value
937   new (slot) LocalType( &node, &Node::SetParentOrigin, origin );
938 }
939
940 inline void SetAnchorPointMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& anchor )
941 {
942   typedef MessageValue1< Node, Vector3 > LocalType;
943
944   // Reserve some memory inside the message queue
945   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
946
947   // Construct message in the message queue memory; note that delete should not be called on the return value
948   new (slot) LocalType( &node, &Node::SetAnchorPoint, anchor );
949 }
950
951 inline void SetInheritPositionMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
952 {
953   typedef MessageValue1< Node, bool > LocalType;
954
955   // Reserve some memory inside the message queue
956   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
957
958   // Construct message in the message queue memory; note that delete should not be called on the return value
959   new (slot) LocalType( &node, &Node::SetInheritPosition, inherit );
960 }
961
962 inline void SetInheritScaleMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
963 {
964   typedef MessageValue1< Node, bool > LocalType;
965
966   // Reserve some memory inside the message queue
967   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
968
969   // Construct message in the message queue memory; note that delete should not be called on the return value
970   new (slot) LocalType( &node, &Node::SetInheritScale, inherit );
971 }
972
973 inline void SetColorModeMessage( EventThreadServices& eventThreadServices, const Node& node, ColorMode colorMode )
974 {
975   typedef MessageValue1< Node, ColorMode > LocalType;
976
977   // Reserve some memory inside the message queue
978   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
979
980   // Construct message in the message queue memory; note that delete should not be called on the return value
981   new (slot) LocalType( &node, &Node::SetColorMode, colorMode );
982 }
983
984 inline void SetDrawModeMessage( EventThreadServices& eventThreadServices, const Node& node, DrawMode::Type drawMode )
985 {
986   typedef MessageValue1< Node, DrawMode::Type > LocalType;
987
988   // Reserve some memory inside the message queue
989   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
990
991   // Construct message in the message queue memory; note that delete should not be called on the return value
992   new (slot) LocalType( &node, &Node::SetDrawMode, drawMode );
993 }
994
995 inline void AddRendererMessage( EventThreadServices& eventThreadServices, const Node& node, Renderer* renderer )
996 {
997   typedef MessageValue1< Node, Renderer* > LocalType;
998
999   // Reserve some memory inside the message queue
1000   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1001
1002   // Construct message in the message queue memory; note that delete should not be called on the return value
1003   new (slot) LocalType( &node, &Node::AddRenderer, renderer );
1004 }
1005
1006 inline void RemoveRendererMessage( EventThreadServices& eventThreadServices, const Node& node, Renderer* renderer )
1007 {
1008   typedef MessageValue1< Node, Renderer* > LocalType;
1009
1010   // Reserve some memory inside the message queue
1011   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1012
1013   // Construct message in the message queue memory; note that delete should not be called on the return value
1014   new (slot) LocalType( &node, &Node::RemoveRenderer, renderer );
1015 }
1016
1017 inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, const Node& node, uint32_t depthIndex )
1018 {
1019   typedef MessageValue1< Node, uint32_t > LocalType;
1020
1021   // Reserve some memory inside the message queue
1022   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1023
1024   // Construct message in the message queue memory; note that delete should not be called on the return value
1025   new (slot) LocalType( &node, &Node::SetDepthIndex, depthIndex );
1026 }
1027
1028 inline void SetClippingModeMessage( EventThreadServices& eventThreadServices, const Node& node, ClippingMode::Type clippingMode )
1029 {
1030   typedef MessageValue1< Node, ClippingMode::Type > LocalType;
1031
1032   // Reserve some memory inside the message queue
1033   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1034
1035   // Construct message in the message queue memory; note that delete should not be called on the return value
1036   new (slot) LocalType( &node, &Node::SetClippingMode, clippingMode );
1037 }
1038
1039 inline void SetPositionUsesAnchorPointMessage( EventThreadServices& eventThreadServices, const Node& node, bool positionUsesAnchorPoint )
1040 {
1041   typedef MessageValue1< Node, bool > LocalType;
1042
1043   // Reserve some memory inside the message queue
1044   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1045
1046   // Construct message in the message queue memory; note that delete should not be called on the return value
1047   new (slot) LocalType( &node, &Node::SetPositionUsesAnchorPoint, positionUsesAnchorPoint );
1048 }
1049
1050 } // namespace SceneGraph
1051
1052 // Template specialisation for OwnerPointer<Node>, because delete is protected
1053 template <>
1054 inline void OwnerPointer<Dali::Internal::SceneGraph::Node>::Reset()
1055 {
1056   if (mObject != NULL)
1057   {
1058     Dali::Internal::SceneGraph::Node::Delete(mObject);
1059     mObject = NULL;
1060   }
1061 }
1062 } // namespace Internal
1063
1064 // Template specialisations for OwnerContainer<Node*>, because delete is protected
1065 template <>
1066 inline void OwnerContainer<Dali::Internal::SceneGraph::Node*>::Delete( Dali::Internal::SceneGraph::Node* pointer )
1067 {
1068   Dali::Internal::SceneGraph::Node::Delete(pointer);
1069 }
1070 } // namespace Dali
1071
1072 #endif // DALI_INTERNAL_SCENE_GRAPH_NODE_H