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