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