Added Blending handling for materials and renderers
[platform/core/uifw/dali-core.git] / dali / internal / update / node-attachments / node-attachment.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_NODE_ATTACHMENT_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_NODE_ATTACHMENT_H__
3
4 /*
5  * Copyright (c) 2014 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 // EXTERNAL INCLUDES
22 #include <cstddef>    // NULL
23
24 // INTERNAL INCLUDES
25 #include <dali/internal/common/message.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace SceneGraph
34 {
35
36 class Node;
37 class RenderableAttachment;
38 class SceneController;
39
40 /**
41  * NodeAttachment is a base class for objects attached to Nodes in the scene graph.
42  * The position of the object is provided by its parent node.
43  * NodeAttachment data is double-buffered. This allows an update thread to modify node data, without interferring
44  * with another thread reading the values from the previous update traversal.
45  */
46 class NodeAttachment
47 {
48 public:
49
50   /**
51    * Virtual destructor
52    */
53   virtual ~NodeAttachment();
54
55   /**
56    * Second-phase construction.
57    * This is called by the UpdateManager when the attachment is attached to the scene-graph.
58    * @param[in] sceneController Allows attachments to get camera controllers.
59    * @param[in] updateBufferIndex The current update buffer index.
60    */
61   virtual void Initialize( SceneController& sceneController, BufferIndex updateBufferIndex ) = 0;
62
63   /**
64    * Called shortly before destruction.
65    * After this method has been called, the SceneController cannot be safely accessed.
66    */
67   virtual void OnDestroy() = 0;
68
69   /**
70    * Called when the parent node is connected to the SceneGraph
71    */
72   virtual void ConnectedToSceneGraph() = 0;
73
74   /**
75    * Called when the parent node is disconnected from the SceneGraph
76    */
77   virtual void DisconnectedFromSceneGraph( ) = 0;
78
79   /**
80    * Set the parent of a NodeAttachment.
81    * @param[in] parent the new parent.
82    */
83   void SetParent( Node& parent );
84
85   /**
86    * Retrieve the parent node of a NodeAttachment.
87    * @return The parent node, or NULL if the NodeAttachment has not been added to the scene-graph.
88    */
89   Node& GetParent()
90   {
91     DALI_ASSERT_DEBUG( mParent != NULL );
92     return *mParent;
93   }
94
95   /**
96    * Retrieve the parent node of a NodeAttachment.
97    * @return The parent node, or NULL if the NodeAttachment has not been added to the scene-graph.
98    */
99   Node& GetParent() const
100   {
101     DALI_ASSERT_DEBUG( mParent != NULL );
102     return *mParent;
103   }
104
105   // RenderableAttachment interface
106
107   /**
108    * Query whether the attachment is renderable i.e. implements the SceneGraph::RenderableAttachment interface.
109    * @return True if the attachment is renderable.
110    */
111   bool IsRenderable()
112   {
113     return (GetRenderable() != NULL);
114   }
115
116   /**
117    * Convert an attachment to a renderable attachment.
118    * @return A pointer to the renderable attachment, or NULL.
119    */
120   virtual RenderableAttachment* GetRenderable() = 0;
121
122   // Update methods
123
124   /**
125    * Called to reset attachment's properties to base values.
126    * Attachments without properties should not override this method
127    */
128   virtual void ResetToBaseValues(BufferIndex bufferIndex) { }
129
130   /**
131    * Called when the attachment or it's owning node is flagged as dirty during scene graph updates.
132    * Allows derived classes to perform extra processing
133    * @param[in] updateBufferIndex The current update buffer index.
134    * @param[in] owningNode The attachment's owning node
135    * @param[in] nodeDirtyFlags of the owning node
136    */
137   virtual void Update( BufferIndex updateBufferIndex, const Node& owningNode, int nodeDirtyFlags ) {}
138
139 protected:
140
141   /**
142    * Derived versions of NodeAttachment should be constructed.
143    */
144   NodeAttachment();
145
146 private:
147
148   // Undefined
149   NodeAttachment( const NodeAttachment& );
150
151   // Undefined
152   NodeAttachment& operator=( const NodeAttachment& rhs );
153
154 protected:
155
156   Node* mParent; ///< Pointer to parent node which owns the attachment.
157 };
158
159 } // namespace SceneGraph
160
161 } // namespace Internal
162
163 } // namespace Dali
164
165 #endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_ATTACHMENT_H__