Clipping API feature in Actor
[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   unsigned short GetDepth() const
719   {
720     return mDepth;
721   }
722
723   /**
724    * @brief Turns on or off being a batch parent for the node
725    * @param[in] enabled If true the node becomes a parent for batch of its children
726    */
727   void SetIsBatchParent( bool enabled );
728
729   /**
730    * @brief Tells if the node is a batch parent
731    * @return True if node is a batch parent, false otherwise.
732    */
733   inline bool GetIsBatchParent()
734   {
735     return mIsBatchParent;
736   }
737
738   /**
739    * Set the batch parent of a Node.
740    * @param[in] batchParentNode The new batch parent.
741    */
742   void SetBatchParent( Node* batchParentNode );
743
744   /**
745    * Retrieve the batch parent of a Node.
746    * @return The batch parent node, or NULL if the Node has not been added to the scene-graph.
747    */
748   Node* GetBatchParent() const
749   {
750     return mBatchParent;
751   }
752
753 public:
754   /**
755    * @copydoc UniformMap::Add
756    */
757   void AddUniformMapping( UniformPropertyMapping* map );
758
759   /**
760    * @copydoc UniformMap::Remove
761    */
762   void RemoveUniformMapping( const std::string& uniformName );
763
764   /**
765    * Prepare the node for rendering.
766    * This is called by the UpdateManager when an object is due to be rendered in the current frame.
767    * @param[in] updateBufferIndex The current update buffer index.
768    */
769   void PrepareRender( BufferIndex bufferIndex );
770
771   /**
772    * Called by UpdateManager when the node is added.
773    * Creates a new transform component in the transform manager and initialize all the properties
774    * related to the transformation
775    * @param[in] transformManager A pointer to the trnasform manager (Owned by UpdateManager)
776    */
777   void CreateTransform( SceneGraph::TransformManager* transformManager );
778
779 protected:
780
781   /**
782    * Set the parent of a Node.
783    * @param[in] parentNode the new parent.
784    */
785   void SetParent( Node& parentNode );
786
787 protected:
788
789   /**
790    * Protected constructor; See also Node::New()
791    */
792   Node();
793
794 private: // from NodeDataProvider
795
796   /**
797    * @copydoc NodeDataProvider::GetModelMatrix
798    */
799   virtual const Matrix& GetModelMatrix( unsigned int bufferId ) const
800   {
801     return GetWorldMatrix( bufferId );
802   }
803
804   /**
805    * @copydoc NodeDataProvider::GetRenderColor
806    */
807   virtual const Vector4& GetRenderColor( unsigned int bufferId ) const
808   {
809     return GetWorldColor( bufferId );
810   }
811
812 public: // From UniformMapDataProvider
813   /**
814    * @copydoc UniformMapDataProvider::GetUniformMapChanged
815    */
816   virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const
817   {
818     return mUniformMapChanged[bufferIndex];
819   }
820
821   /**
822    * @copydoc UniformMapDataProvider::GetUniformMap
823    */
824   virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const
825   {
826     return mCollectedUniformMap[bufferIndex];
827   }
828
829 private:
830
831   // Undefined
832   Node(const Node&);
833
834   // Undefined
835   Node& operator=(const Node& rhs);
836
837   /**
838    * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
839    */
840   virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
841
842   /**
843    * Recursive helper to disconnect a Node and its children.
844    * Disconnected Nodes have no parent or children.
845    * @param[in] updateBufferIndex The current update buffer index.
846    */
847   void RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex );
848
849 public: // Default properties
850
851   TransformManager*                  mTransformManager;
852   TransformId                        mTransformId;
853   TransformManagerPropertyVector3    mParentOrigin;           ///< Local transform; the position is relative to this. Sets the TransformFlag dirty when changed
854   TransformManagerPropertyVector3    mAnchorPoint;            ///< Local transform; local center of rotation. Sets the TransformFlag dirty when changed
855   TransformManagerPropertyVector3    mSize;                   ///< Size is provided for layouting
856   TransformManagerPropertyVector3    mPosition;               ///< Local transform; distance between parent-origin & anchor-point
857   TransformManagerPropertyQuaternion mOrientation;            ///< Local transform; rotation relative to parent node
858   TransformManagerPropertyVector3    mScale;                  ///< Local transform; scale relative to parent node
859
860   AnimatableProperty<bool>           mVisible;                ///< Visibility can be inherited from the Node hierachy
861   AnimatableProperty<Vector4>        mColor;                  ///< Color can be inherited from the Node hierarchy
862
863   // Inherited properties; read-only from public API
864
865   TransformManagerVector3Input       mWorldPosition;          ///< Full inherited position
866   TransformManagerVector3Input       mWorldScale;
867   TransformManagerQuaternionInput    mWorldOrientation;       ///< Full inherited orientation
868   TransformManagerMatrixInput        mWorldMatrix;            ///< Full inherited world matrix
869   InheritedColor                     mWorldColor;             ///< Full inherited color
870
871   GeometryBatcher*                   mGeometryBatcher;        ///< A pointer to an instance of geometry batcher
872   uint32_t                           mBatchIndex;             ///< Batch 32bit handle, BATCH_NULL_HANDLE by default
873   uint32_t                           mClippingSortModifier;   ///< Contains bit-packed clipping information for quick access when sorting
874
875   bool                               mIsBatchParent:1;        ///< Marks node as a batch parent
876
877 protected:
878
879   Node*                              mParent;                 ///< Pointer to parent node (a child is owned by its parent)
880   Node*                              mBatchParent;            ///< Pointer to batch parent node
881   RenderTask*                        mExclusiveRenderTask;    ///< Nodes can be marked as exclusive to a single RenderTask
882
883   RendererContainer                  mRenderer;               ///< Container of renderers; not owned
884
885   NodeContainer                      mChildren;               ///< Container of children; not owned
886
887   CollectedUniformMap                mCollectedUniformMap[2]; ///< Uniform maps of the node
888   unsigned int                       mUniformMapChanged[2];   ///< Records if the uniform map has been altered this frame
889   uint32_t                           mClippingDepth;          ///< The number of clipping nodes deep this node is
890   unsigned int                       mRegenerateUniformMap:2; ///< Indicate if the uniform map has to be regenerated this frame
891
892   // flags, compressed to bitfield
893   unsigned short                     mDepth:12;               ///< Depth in the hierarchy
894   int                                mDirtyFlags:8;           ///< A composite set of flags for each of the Node properties
895   DrawMode::Type                     mDrawMode:2;             ///< How the Node and its children should be drawn
896   ColorMode                          mColorMode:2;            ///< Determines whether mWorldColor is inherited, 2 bits is enough
897   ClippingMode::Type                 mClippingMode:2;         ///< The clipping mode of this node
898   bool                               mIsRoot:1;               ///< True if the node cannot have a parent
899
900   // Changes scope, should be at end of class
901   DALI_LOG_OBJECT_STRING_DECLARATION;
902 };
903
904 // Messages for Node
905
906 inline void SetInheritOrientationMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
907 {
908   typedef MessageValue1< Node, bool > LocalType;
909
910   // Reserve some memory inside the message queue
911   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
912
913   // Construct message in the message queue memory; note that delete should not be called on the return value
914   new (slot) LocalType( &node, &Node::SetInheritOrientation, inherit );
915 }
916
917 inline void SetParentOriginMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& origin )
918 {
919   typedef MessageValue1< Node, Vector3 > LocalType;
920
921   // Reserve some memory inside the message queue
922   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
923
924   // Construct message in the message queue memory; note that delete should not be called on the return value
925   new (slot) LocalType( &node, &Node::SetParentOrigin, origin );
926 }
927
928 inline void SetAnchorPointMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& anchor )
929 {
930   typedef MessageValue1< Node, Vector3 > LocalType;
931
932   // Reserve some memory inside the message queue
933   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
934
935   // Construct message in the message queue memory; note that delete should not be called on the return value
936   new (slot) LocalType( &node, &Node::SetAnchorPoint, anchor );
937 }
938
939 inline void SetInheritPositionMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
940 {
941   typedef MessageValue1< Node, bool > LocalType;
942
943   // Reserve some memory inside the message queue
944   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
945
946   // Construct message in the message queue memory; note that delete should not be called on the return value
947   new (slot) LocalType( &node, &Node::SetInheritPosition, inherit );
948 }
949
950 inline void SetInheritScaleMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
951 {
952   typedef MessageValue1< Node, bool > LocalType;
953
954   // Reserve some memory inside the message queue
955   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
956
957   // Construct message in the message queue memory; note that delete should not be called on the return value
958   new (slot) LocalType( &node, &Node::SetInheritScale, inherit );
959 }
960
961 inline void SetColorModeMessage( EventThreadServices& eventThreadServices, const Node& node, ColorMode colorMode )
962 {
963   typedef MessageValue1< Node, ColorMode > LocalType;
964
965   // Reserve some memory inside the message queue
966   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
967
968   // Construct message in the message queue memory; note that delete should not be called on the return value
969   new (slot) LocalType( &node, &Node::SetColorMode, colorMode );
970 }
971
972 inline void SetDrawModeMessage( EventThreadServices& eventThreadServices, const Node& node, DrawMode::Type drawMode )
973 {
974   typedef MessageValue1< Node, DrawMode::Type > LocalType;
975
976   // Reserve some memory inside the message queue
977   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
978
979   // Construct message in the message queue memory; note that delete should not be called on the return value
980   new (slot) LocalType( &node, &Node::SetDrawMode, drawMode );
981 }
982
983 inline void AddRendererMessage( EventThreadServices& eventThreadServices, const Node& node, Renderer* renderer )
984 {
985   typedef MessageValue1< Node, Renderer* > LocalType;
986
987   // Reserve some memory inside the message queue
988   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
989
990   // Construct message in the message queue memory; note that delete should not be called on the return value
991   new (slot) LocalType( &node, &Node::AddRenderer, renderer );
992 }
993
994 inline void RemoveRendererMessage( EventThreadServices& eventThreadServices, const Node& node, Renderer* renderer )
995 {
996   typedef MessageValue1< Node, Renderer* > LocalType;
997
998   // Reserve some memory inside the message queue
999   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1000
1001   // Construct message in the message queue memory; note that delete should not be called on the return value
1002   new (slot) LocalType( &node, &Node::RemoveRenderer, renderer );
1003 }
1004
1005 inline void SetIsBatchParentMessage( EventThreadServices& eventThreadServices, const Node& node, bool isBatchParent )
1006 {
1007   typedef MessageValue1< Node, bool > LocalType;
1008
1009   // Reserve some memory inside the message queue
1010   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1011
1012   // Construct message in the message queue memory; note that delete should not be called on the return value
1013   new (slot) LocalType( &node, &Node::SetIsBatchParent, isBatchParent );
1014 }
1015
1016 inline void SetClippingModeMessage( EventThreadServices& eventThreadServices, const Node& node, ClippingMode::Type clippingMode )
1017 {
1018   typedef MessageValue1< Node, ClippingMode::Type > LocalType;
1019
1020   // Reserve some memory inside the message queue
1021   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1022
1023   // Construct message in the message queue memory; note that delete should not be called on the return value
1024   new (slot) LocalType( &node, &Node::SetClippingMode, clippingMode );
1025 }
1026
1027
1028 } // namespace SceneGraph
1029
1030 } // namespace Internal
1031
1032 } // namespace Dali
1033
1034 #endif // DALI_INTERNAL_SCENE_GRAPH_NODE_H