1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_LAYER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_LAYER_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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
11 // http://floralicense.org/license/
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.
21 #include <dali/public-api/actors/layer.h>
22 #include <dali/internal/common/event-to-update.h>
23 #include <dali/internal/update/nodes/node.h>
24 #include <dali/internal/update/node-attachments/scene-graph-renderable-attachment-declarations.h>
32 class RenderableAttachment;
34 // value types used by messages
35 template <> struct ParameterType< Dali::Layer::SortFunctionType >
36 : public BasicType< Dali::Layer::SortFunctionType > {};
42 * Layers have a "depth" relative to all other layers in the scene-graph.
43 * Non-layer child nodes (and their attachments) are considered part of the layer.
45 * Layers are rendered separately, and the depth buffer is cleared before each layer is rendered.
46 * Objects in higher layers, are rendered after (in front of) objects in lower layers.
48 class Layer : public Node
52 typedef Dali::Layer::SortFunctionType SortFunctionType;
57 * Construct a new Layer.
58 * @return A smart-pointer to a newly allocated Node
60 static SceneGraph::Layer* New();
68 * From Node, to convert a node to a layer.
71 virtual Layer* GetLayer()
77 * Sets the sort-function of a layer.
78 * @param [in] function The new sort-function.
80 void SetSortFunction( Dali::Layer::SortFunctionType function );
83 * Retrieve the function used to sort semi-transparent geometry in this layer.
84 * @return The sort function.
86 Dali::Layer::SortFunctionType GetSortFunction() const
92 * Sets whether clipping is enabled for a layer.
93 * @param [in] enabled True if clipping is enabled.
95 void SetClipping( bool enabled );
98 * Query whether clipping is enabled for a layer.
99 * @return True if clipping is enabled.
101 bool IsClipping() const
107 * Sets the clipping box of a layer, in window coordinates.
108 * The contents of the layer will not be visible outside this box, when clipping is
109 * enabled. The default clipping box is empty (0,0,0,0).
110 * @param [in] box The clipping box
112 void SetClippingBox( const ClippingBox& box );
115 * Retrieves the clipping box of a layer, in window coordinates.
116 * @return The clipping box
118 const ClippingBox& GetClippingBox() const
124 * @copydoc Dali::Layer::SetDepthTestDisabled()
126 void SetDepthTestDisabled( bool disable );
129 * @copydoc Dali::Layer::IsDepthTestDisabled()
131 bool IsDepthTestDisabled() const;
134 * Enables the reuse of the model view matrices of all renderers for this layer
135 * @param[in] updateBufferIndex The current update buffer index.
136 * @param value to set
138 void SetReuseRenderers( BufferIndex updateBufferIndex, bool value )
140 mAllChildTransformsClean[ updateBufferIndex ] = value;
144 * @return True if all children have been clean for two consequtive frames
146 bool CanReuseRenderers()
148 return mAllChildTransformsClean[ 0 ] && mAllChildTransformsClean[ 1 ];
154 * Private constructor.
155 * See also Layer::New()
163 Layer& operator=(const Layer& rhs);
165 public: // For update-algorithms
167 RenderableAttachmentContainer stencilRenderables;
168 RenderableAttachmentContainer transparentRenderables;
169 RenderableAttachmentContainer opaqueRenderables;
170 RenderableAttachmentContainer overlayRenderables;
174 SortFunctionType mSortFunction; ///< Used to sort semi-transparent geometry
176 ClippingBox mClippingBox; ///< The clipping box, in window coordinates
177 bool mAllChildTransformsClean[ 2 ]; ///< True if all child nodes transforms are clean,
178 /// double buffered as we need two clean frames before we can reuse N-1 for N+1
179 /// this allows us to cache render items when layer is "static"
180 bool mIsClipping:1; ///< True when clipping is enabled
181 bool mDepthTestDisabled:1; ///< Whether depth test is disabled.
184 // Messages for Layer
187 * Create a message to set the sort-function of a layer
188 * @param[in] layer The layer
189 * @param[in] function The new sort-function.
191 inline void SetSortFunctionMessage( EventToUpdate& eventToUpdate, const Layer& layer, Dali::Layer::SortFunctionType function )
193 typedef MessageValue1< Layer, Dali::Layer::SortFunctionType > LocalType;
195 // Reserve some memory inside the message queue
196 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
198 // Construct message in the message queue memory; note that delete should not be called on the return value
199 new (slot) LocalType( &layer, &Layer::SetSortFunction, function );
203 * Create a message for enabling/disabling layer clipping
204 * @param[in] layer The layer
205 * @param[in] enabled True if clipping is enabled
207 inline void SetClippingMessage( EventToUpdate& eventToUpdate, const Layer& layer, bool enabled )
209 typedef MessageValue1< Layer, bool > LocalType;
211 // Reserve some memory inside the message queue
212 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
214 // Construct message in the message queue memory; note that delete should not be called on the return value
215 new (slot) LocalType( &layer, &Layer::SetClipping, enabled );
219 * Create a message to set the clipping box of a layer
220 * @param[in] layer The layer
221 * @param[in] clippingbox The clipping box
223 inline void SetClippingBoxMessage( EventToUpdate& eventToUpdate, const Layer& layer, const Dali::ClippingBox& clippingbox )
225 typedef MessageValue1< Layer, Dali::ClippingBox > LocalType;
227 // Reserve some memory inside the message queue
228 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
230 // Construct message in the message queue memory; note that delete should not be called on the return value
231 new (slot) LocalType( &layer, &Layer::SetClippingBox, clippingbox );
235 * Create a message for disabling/enabling depth test.
237 * @see Dali::Layer::SetDepthTestDisabled().
239 * @param[in] layer The layer
240 * @param[in] disable \e true disables depth test. \e false sets the default behaviour.
242 inline void SetDepthTestDisabledMessage( EventToUpdate& eventToUpdate, const Layer& layer, bool disable )
244 typedef MessageValue1< Layer, bool > LocalType;
246 // Reserve some memory inside the message queue
247 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
249 // Construct message in the message queue memory; note that delete should not be called on the return value
250 new (slot) LocalType( &layer, &Layer::SetDepthTestDisabled, disable );
253 } // namespace SceneGraph
255 } // namespace Internal
259 #endif // __DALI_INTERNAL_SCENE_GRAPH_LAYER_H__