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 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/actors/layer.h>
23 #include <dali/internal/common/event-to-update.h>
24 #include <dali/internal/update/nodes/node.h>
25 #include <dali/internal/update/node-attachments/scene-graph-renderable-attachment-declarations.h>
33 class RenderableAttachment;
35 // value types used by messages
36 template <> struct ParameterType< Dali::Layer::SortFunctionType >
37 : public BasicType< Dali::Layer::SortFunctionType > {};
43 * Layers have a "depth" relative to all other layers in the scene-graph.
44 * Non-layer child nodes (and their attachments) are considered part of the layer.
46 * Layers are rendered separately, and the depth buffer is cleared before each layer is rendered.
47 * Objects in higher layers, are rendered after (in front of) objects in lower layers.
49 class Layer : public Node
53 typedef Dali::Layer::SortFunctionType SortFunctionType;
58 * Construct a new Layer.
59 * @return A smart-pointer to a newly allocated Node
61 static SceneGraph::Layer* New();
69 * From Node, to convert a node to a layer.
72 virtual Layer* GetLayer()
78 * Sets the sort-function of a layer.
79 * @param [in] function The new sort-function.
81 void SetSortFunction( Dali::Layer::SortFunctionType function );
84 * Retrieve the function used to sort semi-transparent geometry in this layer.
85 * @return The sort function.
87 Dali::Layer::SortFunctionType GetSortFunction() const
93 * Sets whether clipping is enabled for a layer.
94 * @param [in] enabled True if clipping is enabled.
96 void SetClipping( bool enabled );
99 * Query whether clipping is enabled for a layer.
100 * @return True if clipping is enabled.
102 bool IsClipping() const
108 * Sets the clipping box of a layer, in window coordinates.
109 * The contents of the layer will not be visible outside this box, when clipping is
110 * enabled. The default clipping box is empty (0,0,0,0).
111 * @param [in] box The clipping box
113 void SetClippingBox( const ClippingBox& box );
116 * Retrieves the clipping box of a layer, in window coordinates.
117 * @return The clipping box
119 const ClippingBox& GetClippingBox() const
125 * @copydoc Dali::Layer::SetDepthTestDisabled()
127 void SetDepthTestDisabled( bool disable );
130 * @copydoc Dali::Layer::IsDepthTestDisabled()
132 bool IsDepthTestDisabled() const;
135 * Enables the reuse of the model view matrices of all renderers for this layer
136 * @param[in] updateBufferIndex The current update buffer index.
137 * @param value to set
139 void SetReuseRenderers( BufferIndex updateBufferIndex, bool value )
141 mAllChildTransformsClean[ updateBufferIndex ] = value;
145 * @return True if all children have been clean for two consequtive frames
147 bool CanReuseRenderers()
149 return mAllChildTransformsClean[ 0 ] && mAllChildTransformsClean[ 1 ];
153 * @return True if default sort function is used
155 bool UsesDefaultSortFunction()
157 return mIsDefaultSortFunction;
163 * Private constructor.
164 * See also Layer::New()
172 Layer& operator=(const Layer& rhs);
174 public: // For update-algorithms
176 RenderableAttachmentContainer stencilRenderables;
177 RenderableAttachmentContainer transparentRenderables;
178 RenderableAttachmentContainer opaqueRenderables;
179 RenderableAttachmentContainer overlayRenderables;
183 SortFunctionType mSortFunction; ///< Used to sort semi-transparent geometry
185 ClippingBox mClippingBox; ///< The clipping box, in window coordinates
186 bool mAllChildTransformsClean[ 2 ]; ///< True if all child nodes transforms are clean,
187 /// double buffered as we need two clean frames before we can reuse N-1 for N+1
188 /// this allows us to cache render items when layer is "static"
189 bool mIsClipping:1; ///< True when clipping is enabled
190 bool mDepthTestDisabled:1; ///< Whether depth test is disabled.
191 bool mIsDefaultSortFunction:1; ///< whether the default depth sort function is used
195 // Messages for Layer
198 * Create a message to set the sort-function of a layer
199 * @param[in] layer The layer
200 * @param[in] function The new sort-function.
202 inline void SetSortFunctionMessage( EventToUpdate& eventToUpdate, const Layer& layer, Dali::Layer::SortFunctionType function )
204 typedef MessageValue1< Layer, Dali::Layer::SortFunctionType > LocalType;
206 // Reserve some memory inside the message queue
207 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
209 // Construct message in the message queue memory; note that delete should not be called on the return value
210 new (slot) LocalType( &layer, &Layer::SetSortFunction, function );
214 * Create a message for enabling/disabling layer clipping
215 * @param[in] layer The layer
216 * @param[in] enabled True if clipping is enabled
218 inline void SetClippingMessage( EventToUpdate& eventToUpdate, const Layer& layer, bool enabled )
220 typedef MessageValue1< Layer, bool > LocalType;
222 // Reserve some memory inside the message queue
223 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
225 // Construct message in the message queue memory; note that delete should not be called on the return value
226 new (slot) LocalType( &layer, &Layer::SetClipping, enabled );
230 * Create a message to set the clipping box of a layer
231 * @param[in] layer The layer
232 * @param[in] clippingbox The clipping box
234 inline void SetClippingBoxMessage( EventToUpdate& eventToUpdate, const Layer& layer, const Dali::ClippingBox& clippingbox )
236 typedef MessageValue1< Layer, Dali::ClippingBox > LocalType;
238 // Reserve some memory inside the message queue
239 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
241 // Construct message in the message queue memory; note that delete should not be called on the return value
242 new (slot) LocalType( &layer, &Layer::SetClippingBox, clippingbox );
246 * Create a message for disabling/enabling depth test.
248 * @see Dali::Layer::SetDepthTestDisabled().
250 * @param[in] layer The layer
251 * @param[in] disable \e true disables depth test. \e false sets the default behaviour.
253 inline void SetDepthTestDisabledMessage( EventToUpdate& eventToUpdate, const Layer& layer, bool disable )
255 typedef MessageValue1< Layer, bool > LocalType;
257 // Reserve some memory inside the message queue
258 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
260 // Construct message in the message queue memory; note that delete should not be called on the return value
261 new (slot) LocalType( &layer, &Layer::SetDepthTestDisabled, disable );
264 } // namespace SceneGraph
266 } // namespace Internal
270 #endif // __DALI_INTERNAL_SCENE_GRAPH_LAYER_H__