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