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