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 ];
152 * @return True if default sort function is used
154 bool UsesDefaultSortFunction()
156 return mIsDefaultSortFunction;
162 * Private constructor.
163 * See also Layer::New()
171 Layer& operator=(const Layer& rhs);
173 public: // For update-algorithms
175 RenderableAttachmentContainer stencilRenderables;
176 RenderableAttachmentContainer transparentRenderables;
177 RenderableAttachmentContainer opaqueRenderables;
178 RenderableAttachmentContainer overlayRenderables;
182 SortFunctionType mSortFunction; ///< Used to sort semi-transparent geometry
184 ClippingBox mClippingBox; ///< The clipping box, in window coordinates
185 bool mAllChildTransformsClean[ 2 ]; ///< True if all child nodes transforms are clean,
186 /// double buffered as we need two clean frames before we can reuse N-1 for N+1
187 /// this allows us to cache render items when layer is "static"
188 bool mIsClipping:1; ///< True when clipping is enabled
189 bool mDepthTestDisabled:1; ///< Whether depth test is disabled.
190 bool mIsDefaultSortFunction:1; ///< whether the default depth sort function is used
194 // Messages for Layer
197 * Create a message to set the sort-function of a layer
198 * @param[in] layer The layer
199 * @param[in] function The new sort-function.
201 inline void SetSortFunctionMessage( EventToUpdate& eventToUpdate, const Layer& layer, Dali::Layer::SortFunctionType function )
203 typedef MessageValue1< Layer, Dali::Layer::SortFunctionType > LocalType;
205 // Reserve some memory inside the message queue
206 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
208 // Construct message in the message queue memory; note that delete should not be called on the return value
209 new (slot) LocalType( &layer, &Layer::SetSortFunction, function );
213 * Create a message for enabling/disabling layer clipping
214 * @param[in] layer The layer
215 * @param[in] enabled True if clipping is enabled
217 inline void SetClippingMessage( EventToUpdate& eventToUpdate, const Layer& layer, bool enabled )
219 typedef MessageValue1< Layer, bool > LocalType;
221 // Reserve some memory inside the message queue
222 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
224 // Construct message in the message queue memory; note that delete should not be called on the return value
225 new (slot) LocalType( &layer, &Layer::SetClipping, enabled );
229 * Create a message to set the clipping box of a layer
230 * @param[in] layer The layer
231 * @param[in] clippingbox The clipping box
233 inline void SetClippingBoxMessage( EventToUpdate& eventToUpdate, const Layer& layer, const Dali::ClippingBox& clippingbox )
235 typedef MessageValue1< Layer, Dali::ClippingBox > LocalType;
237 // Reserve some memory inside the message queue
238 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
240 // Construct message in the message queue memory; note that delete should not be called on the return value
241 new (slot) LocalType( &layer, &Layer::SetClippingBox, clippingbox );
245 * Create a message for disabling/enabling depth test.
247 * @see Dali::Layer::SetDepthTestDisabled().
249 * @param[in] layer The layer
250 * @param[in] disable \e true disables depth test. \e false sets the default behaviour.
252 inline void SetDepthTestDisabledMessage( EventToUpdate& eventToUpdate, const Layer& layer, bool disable )
254 typedef MessageValue1< Layer, bool > LocalType;
256 // Reserve some memory inside the message queue
257 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
259 // Construct message in the message queue memory; note that delete should not be called on the return value
260 new (slot) LocalType( &layer, &Layer::SetDepthTestDisabled, disable );
263 } // namespace SceneGraph
265 } // namespace Internal
269 #endif // __DALI_INTERNAL_SCENE_GRAPH_LAYER_H__