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