87c3c9811ba4f35c3f2f4bf8f64859d172a18403
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / render-instruction-processor.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/update/manager/render-instruction-processor.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/internal/common/matrix-utils.h>
24 #include <dali/internal/event/actors/layer-impl.h> // for the default sorting function
25 #include <dali/internal/render/common/render-instruction-container.h>
26 #include <dali/internal/render/common/render-instruction.h>
27 #include <dali/internal/render/common/render-item.h>
28 #include <dali/internal/render/common/render-tracker.h>
29 #include <dali/internal/render/renderers/render-renderer.h>
30 #include <dali/internal/render/shaders/render-shader.h>
31 #include <dali/internal/update/manager/sorted-layers.h>
32 #include <dali/internal/update/nodes/partial-rendering-data.h>
33 #include <dali/internal/update/nodes/scene-graph-layer.h>
34 #include <dali/internal/update/render-tasks/scene-graph-render-task.h>
35 #include <dali/internal/update/rendering/scene-graph-texture-set.h>
36 #include <dali/public-api/actors/layer.h>
37
38 namespace
39 {
40 #if defined(DEBUG_ENABLED)
41 Debug::Filter* gRenderListLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_RENDER_LISTS");
42 #endif
43 } // namespace
44
45 namespace Dali
46 {
47 namespace Internal
48 {
49 namespace SceneGraph
50 {
51 namespace
52 {
53 /**
54  * Function which compares render items by shader/textureSet/geometry
55  * @param[in] lhs Left hand side item
56  * @param[in] rhs Right hand side item
57  * @return True if left item is greater than right
58  */
59 inline bool PartialCompareItems(const RenderInstructionProcessor::SortAttributes& lhs,
60                                 const RenderInstructionProcessor::SortAttributes& rhs)
61 {
62   if(lhs.shader == rhs.shader)
63   {
64     if(lhs.textureSet == rhs.textureSet)
65     {
66       return lhs.geometry < rhs.geometry;
67     }
68     return lhs.textureSet < rhs.textureSet;
69   }
70   return lhs.shader < rhs.shader;
71 }
72
73 /**
74  * Function which sorts render items by depth index then by instance
75  * ptrs of shader/textureSet/geometry.
76  * @param[in] lhs Left hand side item
77  * @param[in] rhs Right hand side item
78  * @return True if left item is greater than right
79  */
80 bool CompareItems(const RenderInstructionProcessor::SortAttributes& lhs, const RenderInstructionProcessor::SortAttributes& rhs)
81 {
82   // @todo Consider replacing all these sortAttributes with a single long int that
83   // encapsulates the same data (e.g. the middle-order bits of the ptrs).
84   if(lhs.renderItem->mDepthIndex == rhs.renderItem->mDepthIndex)
85   {
86     return PartialCompareItems(lhs, rhs);
87   }
88   return lhs.renderItem->mDepthIndex < rhs.renderItem->mDepthIndex;
89 }
90
91 /**
92  * Function which sorts the render items by Z function, then
93  * by instance ptrs of shader / geometry / material.
94  * @param[in] lhs Left hand side item
95  * @param[in] rhs Right hand side item
96  * @return True if left item is greater than right
97  */
98 bool CompareItems3D(const RenderInstructionProcessor::SortAttributes& lhs, const RenderInstructionProcessor::SortAttributes& rhs)
99 {
100   const bool lhsIsOpaque = lhs.renderItem->mIsOpaque;
101   if(lhsIsOpaque == rhs.renderItem->mIsOpaque)
102   {
103     if(lhsIsOpaque)
104     {
105       // If both RenderItems are opaque, sort using shader, then material then geometry.
106       return PartialCompareItems(lhs, rhs);
107     }
108     else
109     {
110       // If both RenderItems are transparent, sort using Z, then shader, then material, then geometry.
111       if(Equals(lhs.zValue, rhs.zValue))
112       {
113         return PartialCompareItems(lhs, rhs);
114       }
115       return lhs.zValue > rhs.zValue;
116     }
117   }
118   else
119   {
120     return lhsIsOpaque;
121   }
122 }
123
124 /**
125  * Function which sorts render items by clipping hierarchy, then Z function and instance ptrs of shader / geometry / material.
126  * @param[in] lhs Left hand side item
127  * @param[in] rhs Right hand side item
128  * @return True if left item is greater than right
129  */
130 bool CompareItems3DWithClipping(const RenderInstructionProcessor::SortAttributes& lhs, const RenderInstructionProcessor::SortAttributes& rhs)
131 {
132   // Items must be sorted in order of clipping first, otherwise incorrect clipping regions could be used.
133   if(lhs.renderItem->mNode->mClippingSortModifier == rhs.renderItem->mNode->mClippingSortModifier)
134   {
135     return CompareItems3D(lhs, rhs);
136   }
137
138   return lhs.renderItem->mNode->mClippingSortModifier < rhs.renderItem->mNode->mClippingSortModifier;
139 }
140
141 /**
142  * Set the update area of the node
143  * @param[in] node The node of the renderer
144  * @param[in] isLayer3d Whether we are processing a 3D layer or not
145  * @param[in,out] nodeWorldMatrix The world matrix of the node
146  * @param[in,out] nodeSize The size of the node
147  * @param[in,out] nodeUpdateArea The update area of the node
148  *
149  * @return True if node use it's own UpdateAreaHint, or z transform occured. False if we use nodeUpdateArea equal with Vector4(0, 0, nodeSize.width, nodeSize.height).
150  */
151 inline bool SetNodeUpdateArea(Node* node, bool isLayer3d, Matrix& nodeWorldMatrix, Vector3& nodeSize, Vector4& nodeUpdateArea)
152 {
153   node->GetWorldMatrixAndSize(nodeWorldMatrix, nodeSize);
154
155   if(node->GetUpdateAreaHint() == Vector4::ZERO)
156   {
157     // RenderItem::CalculateViewportSpaceAABB cannot cope with z transform
158     // I don't use item.mModelMatrix.GetTransformComponents() for z transform, would be too slow
159     if(!isLayer3d && nodeWorldMatrix.GetZAxis() == Vector3(0.0f, 0.0f, 1.0f))
160     {
161       nodeUpdateArea = Vector4(0.0f, 0.0f, nodeSize.width, nodeSize.height);
162       return false;
163     }
164     // Keep nodeUpdateArea as Vector4::ZERO, and return true.
165     return true;
166   }
167   else
168   {
169     nodeUpdateArea = node->GetUpdateAreaHint();
170     return true;
171   }
172 }
173
174 /**
175  * Add a renderer to the list
176  * @param updateBufferIndex to read the model matrix from
177  * @param renderList to add the item to
178  * @param renderable Node-Renderer pair
179  * @param viewMatrix used to calculate modelview matrix for the item
180  * @param camera The camera used to render
181  * @param isLayer3d Whether we are processing a 3D layer or not
182  * @param viewportSet Whether the viewport is set or not
183  * @param viewport The viewport
184  * @param cull Whether frustum culling is enabled or not
185  */
186 inline void AddRendererToRenderList(BufferIndex               updateBufferIndex,
187                                     RenderList&               renderList,
188                                     Renderable&               renderable,
189                                     const Matrix&             viewMatrix,
190                                     const SceneGraph::Camera& camera,
191                                     bool                      isLayer3d,
192                                     bool                      viewportSet,
193                                     const Viewport&           viewport,
194                                     bool                      cull)
195 {
196   bool    inside(true);
197   Node*   node = renderable.mNode;
198   Matrix  nodeWorldMatrix(false);
199   Vector3 nodeSize;
200   Vector4 nodeUpdateArea;
201   bool    nodeUpdateAreaSet(false);
202   Matrix  nodeModelViewMatrix(false);
203   bool    nodeModelViewMatrixSet(false);
204
205   // Don't cull items which have render callback
206   bool hasRenderCallback = (renderable.mRenderer && renderable.mRenderer->GetRenderCallback());
207
208   if(cull && renderable.mRenderer && !hasRenderCallback && !renderable.mRenderer->GetShader().HintEnabled(Dali::Shader::Hint::MODIFIES_GEOMETRY) && node->GetClippingMode() == ClippingMode::DISABLED)
209   {
210     const Vector4& boundingSphere = node->GetBoundingSphere();
211     inside                        = (boundingSphere.w > Math::MACHINE_EPSILON_1000) &&
212              (camera.CheckSphereInFrustum(updateBufferIndex, Vector3(boundingSphere), boundingSphere.w));
213
214     if(inside && !isLayer3d && viewportSet)
215     {
216       SetNodeUpdateArea(node, isLayer3d, nodeWorldMatrix, nodeSize, nodeUpdateArea);
217       nodeUpdateAreaSet = true;
218
219       const Vector3& scale = nodeWorldMatrix.GetScale();
220       const Vector3& size  = Vector3(nodeUpdateArea.z, nodeUpdateArea.w, 1.0f) * scale;
221
222       if(size.LengthSquared() > Math::MACHINE_EPSILON_1000)
223       {
224         MatrixUtils::MultiplyTransformMatrix(nodeModelViewMatrix, nodeWorldMatrix, viewMatrix);
225         nodeModelViewMatrixSet = true;
226
227         // Assume actors are at z=0, compute AABB in view space & test rect intersection
228         // against z=0 plane boundaries for frustum. (NOT viewport). This should take into account
229         // magnification due to FOV etc.
230
231         // TODO : Below logic might need to refactor it.
232         // If camera is Perspective, we need to calculate clipping box by FoV. Currently, we just believe default camera setup OrthographicSize well.
233         //  - If then, It must use math calculate like tan(fov) internally. So, we might need calculate it only one times, and cache.
234         ClippingBox boundingBox = RenderItem::CalculateTransformSpaceAABB(nodeModelViewMatrix, Vector3(nodeUpdateArea.x, nodeUpdateArea.y, 0.0f), Vector3(nodeUpdateArea.z, nodeUpdateArea.w, 0.0f));
235         ClippingBox clippingBox = camera.GetOrthographicClippingBox(updateBufferIndex);
236         inside                  = clippingBox.Intersects(boundingBox);
237       }
238     }
239     /*
240      * Note, the API Camera::CheckAABBInFrustum() can be used to test if a bounding box is (partially/fully) inside the view frustum.
241      */
242   }
243
244   if(inside)
245   {
246     bool skipRender(false);
247     bool isOpaque = true;
248     if(!hasRenderCallback)
249     {
250       Renderer::OpacityType opacityType = renderable.mRenderer ? renderable.mRenderer->GetOpacityType(updateBufferIndex, *node) : Renderer::OPAQUE;
251
252       // We can skip render when node is not clipping and transparent
253       skipRender = (opacityType == Renderer::TRANSPARENT && node->GetClippingMode() == ClippingMode::DISABLED);
254
255       isOpaque = (opacityType == Renderer::OPAQUE);
256     }
257
258     if(!skipRender)
259     {
260       // Get the next free RenderItem.
261       RenderItem& item = renderList.GetNextFreeItem();
262
263       item.mNode       = node;
264       item.mIsOpaque   = isOpaque;
265       item.mDepthIndex = isLayer3d ? 0 : node->GetDepthIndex();
266
267       if(DALI_LIKELY(renderable.mRenderer))
268       {
269         item.mRenderer   = renderable.mRenderer->GetRenderer();
270         item.mTextureSet = renderable.mRenderer->GetTextureSet();
271         item.mDepthIndex += renderable.mRenderer->GetDepthIndex();
272       }
273       else
274       {
275         item.mRenderer = Render::RendererKey{};
276       }
277
278       item.mIsUpdated |= isLayer3d;
279
280       if(!nodeUpdateAreaSet)
281       {
282         SetNodeUpdateArea(node, isLayer3d, nodeWorldMatrix, nodeSize, nodeUpdateArea);
283       }
284
285       item.mSize        = nodeSize;
286       item.mUpdateArea  = nodeUpdateArea;
287       item.mModelMatrix = nodeWorldMatrix;
288
289       if(!nodeModelViewMatrixSet)
290       {
291         MatrixUtils::MultiplyTransformMatrix(nodeModelViewMatrix, nodeWorldMatrix, viewMatrix);
292       }
293       item.mModelViewMatrix = nodeModelViewMatrix;
294
295       PartialRenderingData partialRenderingData;
296       partialRenderingData.color               = node->GetWorldColor(updateBufferIndex);
297       partialRenderingData.matrix              = item.mModelViewMatrix;
298       partialRenderingData.updatedPositionSize = item.mUpdateArea;
299       partialRenderingData.size                = item.mSize;
300
301       auto& nodePartialRenderingData = node->GetPartialRenderingData();
302       item.mIsUpdated                = nodePartialRenderingData.IsUpdated(partialRenderingData) || item.mIsUpdated;
303
304       nodePartialRenderingData.Update(partialRenderingData);
305     }
306     else
307     {
308       // Mark as not rendered
309       auto& nodePartialRenderingData     = node->GetPartialRenderingData();
310       nodePartialRenderingData.mRendered = false;
311     }
312
313     node->SetCulled(updateBufferIndex, false);
314   }
315   else
316   {
317     // Mark as not rendered
318     auto& nodePartialRenderingData     = node->GetPartialRenderingData();
319     nodePartialRenderingData.mRendered = false;
320
321     node->SetCulled(updateBufferIndex, true);
322   }
323 }
324
325 /**
326  * Add all renderers to the list
327  * @param updateBufferIndex to read the model matrix from
328  * @param renderList to add the items to
329  * @param renderers to render
330  * NodeRendererContainer Node-Renderer pairs
331  * @param viewMatrix used to calculate modelview matrix for the items
332  * @param camera The camera used to render
333  * @param isLayer3d Whether we are processing a 3D layer or not
334  * @param cull Whether frustum culling is enabled or not
335  */
336 inline void AddRenderersToRenderList(BufferIndex               updateBufferIndex,
337                                      RenderList&               renderList,
338                                      RenderableContainer&      renderers,
339                                      const Matrix&             viewMatrix,
340                                      const SceneGraph::Camera& camera,
341                                      bool                      isLayer3d,
342                                      bool                      viewportSet,
343                                      const Viewport&           viewport,
344                                      bool                      cull)
345 {
346   DALI_LOG_INFO(gRenderListLogFilter, Debug::Verbose, "AddRenderersToRenderList()\n");
347
348   for(auto&& renderer : renderers)
349   {
350     AddRendererToRenderList(updateBufferIndex,
351                             renderList,
352                             renderer,
353                             viewMatrix,
354                             camera,
355                             isLayer3d,
356                             viewportSet,
357                             viewport,
358                             cull);
359   }
360 }
361
362 /**
363  * Try to reuse cached RenderItems from the RenderList
364  * This avoids recalculating the model view matrices in case this part of the scene was static
365  * An example case is a toolbar layer that rarely changes or a popup on top of the rest of the stage
366  * @param layer that is being processed
367  * @param renderList that is cached from frame N-1
368  * @param renderables list of renderables
369  */
370 inline bool TryReuseCachedRenderers(Layer&               layer,
371                                     RenderList&          renderList,
372                                     RenderableContainer& renderables)
373 {
374   bool     retValue        = false;
375   uint32_t renderableCount = static_cast<uint32_t>(renderables.Size());
376   // Check that the cached list originates from this layer and that the counts match
377   if((renderList.GetSourceLayer() == &layer) &&
378      (renderList.GetCachedItemCount() == renderableCount))
379   {
380     // Check that all the same renderers are there. This gives us additional security in avoiding rendering the wrong things.
381     // Render list is sorted so at this stage renderers may be in different order.
382     // Therefore we check a combined sum of all renderer addresses.
383     size_t checkSumNew = 0;
384     size_t checkSumOld = 0;
385     //@todo just use keys, don't deref.
386     for(uint32_t index = 0; index < renderableCount; ++index)
387     {
388       if(DALI_LIKELY(renderables[index].mRenderer))
389       {
390         Render::RendererKey renderer = renderables[index].mRenderer->GetRenderer();
391         checkSumNew += renderer.Value();
392       }
393       if(DALI_LIKELY(renderList.GetItem(index).mRenderer))
394       {
395         checkSumOld += renderList.GetItem(index).mRenderer.Value();
396       }
397     }
398     if(checkSumNew == checkSumOld)
399     {
400       // tell list to reuse its existing items
401       renderList.ReuseCachedItems();
402       retValue = true;
403     }
404   }
405
406   return retValue;
407 }
408
409 inline bool SetupRenderList(RenderableContainer& renderables,
410                             Layer&               layer,
411                             RenderInstruction&   instruction,
412                             bool                 tryReuseRenderList,
413                             RenderList**         renderList)
414 {
415   *renderList = &(instruction.GetNextFreeRenderList(renderables.Size()));
416   (*renderList)->SetClipping(layer.IsClipping(), layer.GetClippingBox());
417   (*renderList)->SetSourceLayer(&layer);
418
419   // Try to reuse cached RenderItems from last time around.
420   return (tryReuseRenderList && TryReuseCachedRenderers(layer, **renderList, renderables));
421 }
422
423 } // Anonymous namespace.
424
425 RenderInstructionProcessor::RenderInstructionProcessor()
426 : mSortingHelper()
427 {
428   // Set up a container of comparators for fast run-time selection.
429   mSortComparitors.Reserve(3u);
430
431   mSortComparitors.PushBack(CompareItems);
432   mSortComparitors.PushBack(CompareItems3D);
433   mSortComparitors.PushBack(CompareItems3DWithClipping);
434 }
435
436 RenderInstructionProcessor::~RenderInstructionProcessor() = default;
437
438 inline void RenderInstructionProcessor::SortRenderItems(BufferIndex bufferIndex, RenderList& renderList, Layer& layer, bool respectClippingOrder, bool isOrthographicCamera)
439 {
440   const uint32_t renderableCount = static_cast<uint32_t>(renderList.Count());
441   // Reserve space if needed.
442   const uint32_t oldcapacity = static_cast<uint32_t>(mSortingHelper.size());
443   if(oldcapacity < renderableCount)
444   {
445     mSortingHelper.reserve(renderableCount);
446     // Add real objects (reserve does not construct objects).
447     mSortingHelper.insert(mSortingHelper.begin() + oldcapacity,
448                           (renderableCount - oldcapacity),
449                           RenderInstructionProcessor::SortAttributes());
450   }
451   else
452   {
453     // Clear extra elements from helper, does not decrease capability.
454     mSortingHelper.resize(renderableCount);
455   }
456
457   // Calculate the sorting value, once per item by calling the layers sort function.
458   // Using an if and two for-loops rather than if inside for as its better for branch prediction.
459
460   // List of zValue calculating functions.
461   const Dali::Layer::SortFunctionType zValueFunctionFromVector3[] = {
462     [](const Vector3& position) { return position.z; },
463     [](const Vector3& position) { return position.LengthSquared(); },
464     layer.GetSortFunction(),
465   };
466
467   // Determine whether we need to use zValue as Euclidean distance or translatoin's z value.
468   // If layer is LAYER_UI or camera is OrthographicProjection mode, we don't need to calculate
469   // renderItem's distance from camera.
470
471   // Here we determine which zValue SortFunctionType (of the 3) to use.
472   //   0 is position z value : Default LAYER_UI or Orthographic camera
473   //   1 is distance square value : Default LAYER_3D and Perspective camera
474   //   2 is user defined function.
475   const int zValueFunctionIndex = layer.UsesDefaultSortFunction() ? ((layer.GetBehavior() == Dali::Layer::LAYER_UI || isOrthographicCamera) ? 0 : 1) : 2;
476
477   for(uint32_t index = 0; index < renderableCount; ++index)
478   {
479     RenderItemKey itemKey = renderList.GetItemKey(index);
480     RenderItem&   item    = *itemKey.Get();
481     if(DALI_LIKELY(item.mRenderer))
482     {
483       item.mRenderer->SetSortAttributes(mSortingHelper[index]);
484     }
485
486     // texture set
487     mSortingHelper[index].textureSet = item.mTextureSet;
488
489     mSortingHelper[index].zValue = zValueFunctionFromVector3[zValueFunctionIndex](item.mModelViewMatrix.GetTranslation3()) - static_cast<float>(item.mDepthIndex);
490
491     // Keep the renderitem pointer in the helper so we can quickly reorder items after sort.
492     mSortingHelper[index].renderItem = itemKey;
493   }
494
495   // Here we determine which comparitor (of the 3) to use.
496   //   0 is LAYER_UI
497   //   1 is LAYER_3D
498   //   2 is LAYER_3D + Clipping
499   const unsigned int comparitorIndex = layer.GetBehavior() == Dali::Layer::LAYER_3D ? respectClippingOrder ? 2u : 1u : 0u;
500
501   std::stable_sort(mSortingHelper.begin(), mSortingHelper.end(), mSortComparitors[comparitorIndex]);
502
503   // Reorder / re-populate the RenderItems in the RenderList to correct order based on the sortinghelper.
504   DALI_LOG_INFO(gRenderListLogFilter, Debug::Verbose, "Sorted Transparent List:\n");
505   RenderItemContainer::Iterator renderListIter = renderList.GetContainer().Begin();
506   for(uint32_t index = 0; index < renderableCount; ++index, ++renderListIter)
507   {
508     *renderListIter = mSortingHelper[index].renderItem;
509     DALI_LOG_INFO(gRenderListLogFilter, Debug::Verbose, "  sortedList[%d] = %x\n", index, mSortingHelper[index].renderItem->mRenderer);
510   }
511 }
512
513 void RenderInstructionProcessor::Prepare(BufferIndex                 updateBufferIndex,
514                                          SortedLayerPointers&        sortedLayers,
515                                          RenderTask&                 renderTask,
516                                          bool                        cull,
517                                          bool                        hasClippingNodes,
518                                          RenderInstructionContainer& instructions)
519 {
520   // Retrieve the RenderInstruction buffer from the RenderInstructionContainer
521   // then populate with instructions.
522   RenderInstruction& instruction             = renderTask.PrepareRenderInstruction(updateBufferIndex);
523   bool               viewMatrixHasNotChanged = !renderTask.ViewMatrixUpdated();
524   bool               isRenderListAdded       = false;
525   bool               isRootLayerDirty        = false;
526
527   const Matrix&             viewMatrix           = renderTask.GetViewMatrix(updateBufferIndex);
528   const SceneGraph::Camera& camera               = renderTask.GetCamera();
529   const bool                isOrthographicCamera = camera.mProjectionMode == Dali::Camera::ProjectionMode::ORTHOGRAPHIC_PROJECTION;
530
531   Viewport viewport;
532   bool     viewportSet = renderTask.QueryViewport(updateBufferIndex, viewport);
533
534   const SortedLayersIter endIter = sortedLayers.end();
535   for(SortedLayersIter iter = sortedLayers.begin(); iter != endIter; ++iter)
536   {
537     Layer&      layer = **iter;
538     const bool  tryReuseRenderList(viewMatrixHasNotChanged && layer.CanReuseRenderers(&camera));
539     const bool  isLayer3D  = layer.GetBehavior() == Dali::Layer::LAYER_3D;
540     RenderList* renderList = nullptr;
541
542     if(layer.IsRoot() && (layer.GetDirtyFlags() != NodePropertyFlags::NOTHING))
543     {
544       // If root-layer & dirty, i.e. a property has changed or a child has been deleted, then we need to ensure we render once more
545       isRootLayerDirty = true;
546     }
547
548     if(!layer.colorRenderables.Empty())
549     {
550       RenderableContainer& renderables = layer.colorRenderables;
551
552       if(!SetupRenderList(renderables, layer, instruction, tryReuseRenderList, &renderList))
553       {
554         renderList->SetHasColorRenderItems(true);
555         AddRenderersToRenderList(updateBufferIndex,
556                                  *renderList,
557                                  renderables,
558                                  viewMatrix,
559                                  camera,
560                                  isLayer3D,
561                                  viewportSet,
562                                  viewport,
563                                  cull);
564
565         // We only use the clipping version of the sort comparitor if any clipping nodes exist within the RenderList.
566         SortRenderItems(updateBufferIndex, *renderList, layer, hasClippingNodes, isOrthographicCamera);
567       }
568
569       isRenderListAdded = true;
570     }
571
572     if(!layer.overlayRenderables.Empty())
573     {
574       RenderableContainer& renderables = layer.overlayRenderables;
575
576       if(!SetupRenderList(renderables, layer, instruction, tryReuseRenderList, &renderList))
577       {
578         renderList->SetHasColorRenderItems(false);
579         AddRenderersToRenderList(updateBufferIndex,
580                                  *renderList,
581                                  renderables,
582                                  viewMatrix,
583                                  camera,
584                                  isLayer3D,
585                                  viewportSet,
586                                  viewport,
587                                  cull);
588
589         // Clipping hierarchy is irrelevant when sorting overlay items, so we specify using the non-clipping version of the sort comparitor.
590         SortRenderItems(updateBufferIndex, *renderList, layer, false, isOrthographicCamera);
591       }
592
593       isRenderListAdded = true;
594     }
595   }
596
597   // Inform the render instruction that all renderers have been added and this frame is complete.
598   instruction.UpdateCompleted();
599
600   if(isRenderListAdded || instruction.mIsClearColorSet || isRootLayerDirty)
601   {
602     instructions.PushBack(updateBufferIndex, &instruction);
603   }
604 }
605
606 } // namespace SceneGraph
607
608 } // namespace Internal
609
610 } // namespace Dali