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