Messages and ownership of update objects
[platform/core/uifw/dali-core.git] / dali / internal / update / node-attachments / scene-graph-renderer-attachment.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDERER_ATTACHMENT_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDERER_ATTACHMENT_H
3
4 /*
5  * Copyright (c) 2015 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 #include <dali/internal/update/common/double-buffered.h>
21 #include <dali/internal/update/common/property-owner.h>
22 #include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
23
24 namespace Dali
25 {
26 namespace Internal
27 {
28 namespace SceneGraph
29 {
30 class Material;
31 class Geometry;
32
33
34 class RendererAttachment : public RenderableAttachment, public PropertyOwner
35 {
36 public:
37   /**
38    * Constructor
39    */
40   RendererAttachment();
41
42   /**
43    * Destructor
44    */
45   virtual ~RendererAttachment();
46
47   /**
48    * Set the material for the renderer
49    * @param[in] material The material this renderer will use
50    */
51   void SetMaterial(const Material* material);
52
53   /**
54    * Get the material of this renderer
55    * @return the material this renderer uses
56    */
57   const Material& GetMaterial() const;
58
59   /**
60    * Set the geometry for the renderer
61    * @param[in] geometry The geometry this renderer will use
62    */
63   void SetGeometry(const Geometry* geometry);
64
65   /**
66    * Get the geometry of this renderer
67    * @return the geometry this renderer uses
68    */
69   const Geometry& GetGeometry() const;
70
71   /**
72    * Set the depth index
73    * @param[in] index The depth index to use
74    */
75   void SetDepthIndex( int index );
76
77   /**
78    * Get the depth index
79    * @return The depth index to use
80    */
81   int GetDepthIndex() const ;
82
83 private:
84   const Material* mMaterial; ///< The material this renderer uses. (Not owned)
85   const Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)
86   int mDepthIndex;     ///< Used only in PrepareRenderInstructions
87 };
88
89 // Messages for RendererAttachment
90
91 inline void SetMaterialMessage( EventToUpdate& eventToUpdate, const RendererAttachment& attachment, const Material& material )
92 {
93   typedef MessageValue1< RendererAttachment, const Material* > LocalType;
94
95   // Reserve some memory inside the message queue
96   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
97
98   // Construct message in the message queue memory; note that delete should not be called on the return value
99   new (slot) LocalType( &attachment, &RendererAttachment::SetMaterial, &material );
100 }
101
102 inline void SetGeometryMessage( EventToUpdate& eventToUpdate, const RendererAttachment& attachment, const Geometry& geometry )
103 {
104   typedef MessageValue1< RendererAttachment, const Geometry* > LocalType;
105
106   // Reserve some memory inside the message queue
107   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
108
109   // Construct message in the message queue memory; note that delete should not be called on the return value
110   new (slot) LocalType( &attachment, &RendererAttachment::SetGeometry, &geometry );
111 }
112
113 inline void SetDepthIndexMessage( EventToUpdate& eventToUpdate, const RendererAttachment& attachment, int depthIndex )
114 {
115   typedef MessageValue1< RendererAttachment, int > LocalType;
116
117   // Reserve some memory inside the message queue
118   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
119
120   // Construct message in the message queue memory; note that delete should not be called on the return value
121   new (slot) LocalType( &attachment, &RendererAttachment::SetDepthIndex, depthIndex );
122 }
123
124 } // namespace SceneGraph
125 } // namespace Internal
126 } // namespace Dali
127
128
129 #endif //  DALI_INTERNAL_SCENE_GRAPH_RENDERER_ATTACHMENT_H