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